질문&답변
클라우드/리눅스에 관한 질문과 답변을 주고 받는 곳입니다.
리눅스 분류

웹페이지보안(SSL)

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

웹페이지보안(SSL)


웹서핑을 하다 보면 특정사이트에 들어갈때, (예를들면, HOTMAIL에 로그인시) 보안된 페이지를
본다는 다이얼로그박스가 뜨는걸 봤을 것이다.
기존 http방식은 패킷에 대해 plain text로 주고 받는다.
따라서 악의를 가진 사용자가 주고받는 패킷을 가로채어 볼 수 있다.
http는 암호화되는 않은 패킷을 송수신하므로, 로그인의 경우라면 입력된 id, 비밀번호도 가로챌 수
있다는 것이다.
https라고 불리는(secure http라고 보면 된다.) 프로토콜은 기존 http에 ssl을 첨가한 것이다.
실제 ssl은 많이 사용된다.(특히, 은행권에서 인터넷뱅킹과 같은 화폐거래가 포함된 경우.)
https또한 악의적인 사용자가 송수신되는 패킷을 가로챌 수 있으나, 패킷은 이미 암호화되었기 때문에
그 내용을 알기는 상당히 어렵다(보통 불가능하다. 뛰어난 사람은 가능하게 할 수도 있겠지만...)


사용된 패키지들

아파치 1.3.19          (www.apache.org)
openssl 0.9.6a         (www.openssl.org)
mod_ssl 2.8.3-1.3.19   (www.modssl.org)
MM 1.1.3               (www.engelschall.com/sw/mm/)
PHP 4.0.5              (www.php.net)
MySQL 3.23.38          (www.mysql.com)


mod_ssl은 아파치에게 openssl에 대한 interface를 제공한다.
MM Library는 UNIX환경에서 shared memory에 대한 portability를 제공


OPENSSL 설치

[root@ns /down]# tar xvzf openssl-0.9.6a.tar.gz -C /usr/local/src
[root@ns src]# cd /usr/local/src/openssl-0.9.6a/
[root@ns openssl-0.9.6a]# ./config --prefix=/usr/local --openssldir=/usr/local/openssl no-threads -fPIC
[root@ns openssl-0.9.6a]# make; make test; make install

config의 옵션설명
-fPIC: OpenSSL을 Position Independent Code(PIC)로 build한다.
       단지 mod_ssl을 DSO(Dynamic Shared Object)로 build할때만 중요하다.
no-threads: OpenSSL내부 성능을 향상시킨다.


MM Library 설치
[root@ns /down]# tar xvzf mm-1.1.3.tar.gz -C /usr/local/src
[root@ns /down]# cd /usr/local/src/mm-1.1.3/
[root@ns mm-1.1.3]# ./configure --prefix=/usr/local/MM --disable-shared
[root@ns mm-1.1.3]# make;make test; make install

--disable-shared옵션을 넣지 않으면 /path/to/mm-1.1.x/.libs/를 LD_LIBRARY_PATH에
명시적으로 적어줘야 한다.


APACHE, MOD_SSL, PHP, MYSQL 설치

[root@ns /down]# tar xvzf mod_ssl-2.8.3-1.3.19.tar.gz -C /usr/local/src
[root@ns /down]# cd /usr/local/src/mod_ssl-2.8.3-1.3.19/
[root@ns mod_ssl-2.8.3-1.3.19]# ./configure --with-apache=../apache_1.3.19
> --with-mm=../mm-1.1.3
Configuring mod_ssl/2.8.3 for Apache/1.3.19
+ Apache location: ../apache_1.3.19 (Version 1.3.19)
+ MM location: ../mm-1.1.3
+ Auxiliary patch tool: ./etc/patch/patch (local)    
+ Applying packages to Apache source tree:
   o Extended API (EAPI)
   o Distribution Documents
   o SSL Module Source
   o SSL Support
   o SSL Configuration Additions
   o SSL Module Documentation
   o Addons
Done: source extension and patches successfully applied.

Now proceed with the following commands (Bourne-Shell syntax):
$ cd ../apache_1.3.19
$ SSL_BASE=/path/to/openssl ./configure ... --enable-module=ssl
$ make
$ make certificate
$ make install

[root@ns mod_ssl-2.8.3-1.3.19]# cd ../apache_1.3.19/
[root@ns apache_1.3.19]# ./configure --prefix=/usr/local/apache
Configuring for Apache, Version 1.3.19
+ using installation path layout: Apache (config.layout)
Creating Makefile
Creating Configuration.apaci in src
Creating Makefile in src
+ configured for Linux platform
+ setting C compiler to gcc
+ setting C pre-processor to gcc -E
+ checking for system header files
+ adding selected modules
+ checking sizeof various data types
+ doing sanity check on compiler and options
Creating Makefile in src/support
Creating Makefile in src/regex
Creating Makefile in src/os/unix
Creating Makefile in src/ap
Creating Makefile in src/main
Creating Makefile in src/lib/expat-lite
Creating Makefile in src/modules/standard

[root@ns apache_1.3.19]# cd ../php-4.0.5/
[root@ns php-4.0.5]# CFLAGS='-O2 -I/usr/local/include/openssl'
> ./configure  
> --with-apache=../apache_1.3.19
> --with-mysql
> --enable-memory-limit=yes
> --enable-debug=no
[root@ns php-4.0.5]# gmake; gmake install

[root@ns php-4.0.5]# cd ../apache_1.3.19/
[root@ns apache_1.3.19]# SSL_BASE=/usr/local/src/openssl-0.9.6a
> ./configure
> --prefix=/usr/local/apache
> --enable-module=ssl
> --activate-module=src/modules/php4/libphp4.a
> --enable-module=php4
[root@ns apache_1.3.19]# make
중략
..
make[1]: Entering directory `/usr/local/src/apache_1.3.19'
+---------------------------------------------------------------------+
| Before you install the package you now should prepare the SSL       |
| certificate system by running the 'make certificate' command.       |
| For different situations the following variants are provided:       |
|                                                                     |
| % make certificate TYPE=dummy    (dummy self-signed Snake Oil cert) |
| % make certificate TYPE=test     (test cert signed by Snake Oil CA) |
| % make certificate TYPE=custom   (custom cert signed by own CA)     |
| % make certificate TYPE=existing (existing cert)                    |
|        CRT=/path/to/your.crt [KEY=/path/to/your.key]                |
|                                                                     |
| Use TYPE=dummy    when you're a  vendor package maintainer,         |
| the TYPE=test     when you're an admin but want to do tests only,   |
| the TYPE=custom   when you're an admin willing to run a real server |
| and TYPE=existing when you're an admin who upgrades a server.       |
| (The default is TYPE=test)                                          |
|                                                                     |
| Additionally add ALGO=RSA (default) or ALGO=DSA to select           |
| the signature algorithm used for the generated certificate.         |
|                                                                     |
| Use 'make certificate VIEW=1' to display the generated data.        |
|                                                                     |
| Thanks for using Apache & mod_ssl.       Ralf S. Engelschall        |
|                                          rse@engelschall.com        |
|                                          www.engelschall.com        |
+---------------------------------------------------------------------+
make[1]: Leaving directory `/usr/local/src/apache_1.3.19'
<=== src
[root@ns apache_1.3.19]# make certificate
make[1]: Entering directory `/usr/local/src/apache_1.3.19/src'
SSL Certificate Generation Utility (mkcert.sh)
Copyright (c) 1998-2000 Ralf S. Engelschall, All Rights Reserved.

Generating test certificate signed by Snake Oil CA [TEST]
WARNING: Do not use this for real-life/production systems
______________________________________________________________________

STEP 0: Decide the signature algorithm used for certificate
The generated X.509 CA certificate can contain either
RSA or DSA based ingredients. Select the one you want to use.
Signature Algorithm ((R)SA or (D)SA) [R]: 그냥 엔터
______________________________________________________________________

STEP 1: Generating RSA private key (1024 bit) [server.key]
934679 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
...................................................++++++
..........++++++
e is 65537 (0x10001)
______________________________________________________________________

STEP 2: Generating X.509 certificate signing request [server.csr]
Using configuration from .mkcert.cfg
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
1. Country Name             (2 letter code) [XY]:KR      
2. State or Province Name   (full name)     [Snake Desert]:SEOUL
3. Locality Name            (eg, city)      [Snake Town]:SEOUL
4. Organization Name        (eg, company)   [Snake Oil, Ltd]:DBAKOREA                    
5. Organizational Unit Name (eg, section)   [Webserver Team]:DBAKOREA WEB
6. Common Name              (eg, FQDN)      [www.snakeoil.dom]:www.dbakorea.pe.kr
7. Email Address            (eg, name@FQDN) [www@snakeoil.dom]:kang@dbakorea.pe.kr
8. Certificate Validity     (days)          [365]: 그냥엔터
______________________________________________________________________

STEP 3: Generating X.509 certificate signed by Snake Oil CA [server.crt]
Certificate Version (1 or 3) [3]: 그냥 엔터
Signature ok
subject=/C=KR/ST=SEOUL/L=SEOUL/O=DBAKOREA/OU=DBAKOREA WEB/CN=www.dbakorea.pe.kr/Email=kang@dbakorea.pe.kr
Getting CA Private Key
Verify: matching certificate & key modulus
read RSA key
Verify: matching certificate signature
../conf/ssl.crt/server.crt: OK
______________________________________________________________________

STEP 4: Enrypting RSA private key with a pass phrase for security [server.key]
The contents of the server.key file (the generated private key) has to be
kept secret. So we strongly recommend you to encrypt the server.key file
with a Triple-DES cipher and a Pass Phrase.
Encrypt the private key now? [Y/n]: 그냥엔터
read RSA key
writing RSA key
Enter PEM pass phrase: 암호입력(이는 후에 apachectl startssl시 입력하게 된다)
Verifying password - Enter PEM pass phrase: 암호재입력
Fine, you're using an encrypted RSA private key.
______________________________________________________________________

RESULT: Server Certification Files

o  conf/ssl.key/server.key
   The PEM-encoded RSA private key file which you configure
   with the 'SSLCertificateKeyFile' directive (automatically done
   when you install via APACI). KEEP THIS FILE PRIVATE!

o  conf/ssl.crt/server.crt
   The PEM-encoded X.509 certificate file which you configure
   with the 'SSLCertificateFile' directive (automatically done
   when you install via APACI).

o  conf/ssl.csr/server.csr
   The PEM-encoded X.509 certificate signing request file which
   you can send to an official Certificate Authority (CA) in order
   to request a real server certificate (signed by this CA instead
   of our demonstration-only Snake Oil CA) which later can replace
   the conf/ssl.crt/server.crt file.

WARNING: Do not use this for real-life/production systems

make[1]: Leaving directory `/usr/local/src/apache_1.3.19/src'


3가지 중요한 파일들
이 파일들은 make certificate명령에 의해 생성된다.

server key file
위에서 server.key라는 파일은 public/private key를 저장하는 중요한 파일이다.
이 파일은 서버가 암호화를 수행할때 사용되어지는 key를 포함한다.
이 파일은 httpd.conf에서 SSLCertificateKeyFile 디렉티브에 지정된다.
파일은 위의 설치순서를 따랐다면 /usr/local/apache/conf/ssl.key 디렉토리에 위치한다.

certificate file
key와 웹사이트가 지정된 조직에 의해 운영된다는 것을 제공한다.
certificate가 인증된 기관(trusted agency)에 의해 사인되어졌다면, 사용자는 웹사이트를 신뢰할 수 있다.
server certificate file은 웹사이트를 운영중인 조직에 대한 정보를 가지고 있다.
이 파일은 secure session이 시작될때 클라이언트로 전송된다. 클라이언트는 이것을 가지고
사이트가 적합한지 파악하기 위해 사용한다.
이 파일에 사용되는 형식(format)을 지정한 표준이름인 X.509파일로도 불린다.
이 파일은 httpd.conf에서 SSLCertificateFile 디렉티브에 지정된다.

certificate-signing request
certificate와 key로부터의 정보를 포함한다.
이것은 trusted agency(Certificate Authority로 불린다)로 전송하여
signing에 사용된다.




[root@ns apache_1.3.19]# make install
중략..
make[1]: Leaving directory `/usr/local/src/apache_1.3.19'
+--------------------------------------------------------+
| You now have successfully built and installed the      |
| Apache 1.3 HTTP server. To verify that Apache actually |
| works correctly you now should first check the         |
| (initially created or preserved) configuration files   |
|                                                        |
|   /usr/local/apache/conf/httpd.conf
|                                                        |
| and then you should be able to immediately fire up     |
| Apache the first time by running:                      |
|                                                        |
|   /usr/local/apache/bin/apachectl start
|                                                        |
| Or when you want to run it with SSL enabled use:       |
|                                                        |
|   /usr/local/apache/bin/apachectl startssl
|                                                        |
| Thanks for using Apache.       The Apache Group        |
|                                http://www.apache.org/  |
+--------------------------------------------------------+
[root@ns apache_1.3.19]#


설정에 앞서 기초지식(?)에 대해 잠깐 언급하고 넘어가자
certificate를 클라이언트가 받아들이기 위해선 Certificate Authority(CA)로부터의
digltal sign이 필요하다. 많이 사용되는 IE나 Netscape는 받아들일수 있는
CA의 목록을 자체에 내장하고 있다.
만일 인증된 CA로부터의 SSL세션이 아니라면 브라우저는 계속 진행할지의 여부를
사용자에게 물어본다.
certificate파일은 서버설정파일의 SSLCertificateFile이라는 디렉티브에 지정된다.
인증된 CA로부터 sign되어진 certificate을 가지기 위해선, CSR(certificate-signing request)를
만들어서 몇가지 문서와 함께 CA로 보내야한다.
당연히 돈을 지불해야 하는데 대충 년간 250 ~ 1000달러가 소요된다.

몇개의 Certificate Authorities

CertiSign(Brazilian, part of VeriSign) - http://www.certisign.com.br/servidores
Entrust - http://www.entrust.net/
IKS GmbH(German) - http://www.iks-jena.de/produkte/ca
Thawte(part of VeriSign) - http://www.thawte.com/
VeriSign - http://www.verisign.com/site

CA로부터 sign된 certificate를 받았으면 이를 SSLCertificateFile 디렉티브에
지정하면 된다.
하지만, 테스트용으로 한다면 위의 CA에 굳이 sign을 받을 필요는 없다.
테스트를 위해 브라우저에 자신의 사이가 CA라고 박아두자.
아니면 계속 인증된 CA로부터 sign받은 사이트가 아니라고 나올것이다.


특히 중요한 보안 디렉티브

SSLCipherSuite
secure session을 위한 알고리즘을 정하기 위해 사용.
왠만하면 그냥 둔다.

SSLSessionCache
프로세스간 SSL session 정보를 공유할 수 있도록 캐쉬를 지원
none: 사용안함
dbm:session cache를 위한 파일경로

SSLLog, SSLLogLevel
SSL에 대한 정보를 저장하는 로그생성

이제까진 서버의 인증에 대한 것이였는데, 서버가 클라이언트가 인증되었는도 지정할 수 있다.
클라이언트의 certificate를 이용하여 클라이언트인증을 위해 사용되는 디렉티브는 아래와 같은 것들이 있다.

SSLCACertificatePath, SSLCACertificateFile, SSLVerifyClient, SSLVerifyDepth, SSLRequire

httpd.conf에서 SSL의 설정은 파일의 마지막부분 <IfDefineSSL>와 </IfDefineSSL> 사이에 위치한다.
다음부분을 수정했다.

##
## SSL Virtual Host Context
##



#  General setup for the virtual host

DocumentRoot "/webhosting/https"
ServerName dbakorea.pe.kr
ServerAdmin kang@dbakorea.pe.kr
ErrorLog /usr/local/apache/logs/error_log
TransferLog /usr/local/apache/logs/access_log


위에서 보듯이 브라우저상에서 https://dbakorea.pe.kr 라는 주소로 들어오면
서버는 /webhosting/https/index.html파일의 내용을 클라이언트에게 보내준다.
SSL은 하나의 Virtual Host만 가질수 있다.
이런 제한은 차후 버전에 수정될 것이라는 말이 있는데 현재로선 하나밖에 사용할 수 없다.
꽁수로 여러개를 갖게 할 수 있으나, 별로 권하고 싶지 않다.

php가 enable되게 컴파일했는데 이 부분이 php3로 되어있다. 이를 php로 변경한다.

<Files ~ ".(cgi|shtml|phtml|php?)$">
    SSLOptions +StdEnvVars
</Files>

[root@ns conf]# mkdir /webhosting/https
[root@ns conf]# cd /webhosting/https
[root@ns https]# cat > index.php
SSL Test 페이지

<? echo "PHP테스트" ?>
[root@ns https]#  


apachectl start는 ssl을 사용하지 않을때 시작하는 옵션이고,
apachectl startssl은 ssl과 함께 시작할때 사용하는 옵션이다.

[root@ns logs]# apachectl startssl
Apache/1.3.19 mod_ssl/2.8.3 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide us with the pass phrases.

Server dbakorea.pe.kr:443 (RSA)
Enter pass phrase: 암호입력

Ok: Pass Phrase Dialog successful.
/usr/local/apache/bin/apachectl startssl: httpd started

https_connect.jpg


HTTPS로 연결시 화면


https_page.jpg


위에서 작성한 https://dbakorea.pe.kr/index.php로 연결시 화면


This article comes from dbakorea.pe.kr (Leave this line as is)

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,034 명
  • 현재 강좌수 :  35,787 개
  • 현재 접속자 :  275 명