본문 바로가기

보안/웹 해킹_보안

데비안 Apache SSL

 SSL 인증서 또는 웹 암호화 솔루션의 적용

 

웹을 통하여 회원신상, 금융거래, 카드번호 등 데이터의 기밀성이 요구되는 데이터가 전송된다면 SSL을 적용하거나 기타 웹 암호화 제품의 적용을 고려하여야 한다.

Apache에서는 mod-ssl을 이용하여 SSL 암호화를 적용할 수 있다. SSL의 적용은 기본적으로 OpenSSL을 이용한 Apache SSL모듈(apache/mod-ssl)을 이용하여 생성한 자체 SSL 인증서를 이용할 수도 있고, 유료로 제공되는 SSL인증서를 이용할 수 도 있다.

자체 SSL인증서와 유료 인증서 방식의 차이점은 접속하는 사용자 관점에서 해당 사이트가 정말로 그 사용자가 믿고(알고)있는 웹 사이트인지 여부에 대하여 제3(인증기관)이 보증해 주느냐 안해주느냐의 차이다. 데이터에 이용되는 암호화 수준은 알고리즘과 키길이와 관련되므로 별개의 문제이다.

2012818일 정보통신망 이용촉진및 정보보호등에 관한 법률에서 보안서버의무화를 정의하고

하고 있다. 개인 정보를 취급하는 사이트는 SSL 보안 인증을 의무화하고 위반시 과태료를 부과하도록 되어 있다.



개인 서명 인증서를 이용한 443번 포트로 실행되는 아파치 웹서버설정

Host 구성


/etc/hostname  /etc/hosts 파일을 확인한다.

# cat /etc/hostname

bt.foo.org

# cat /etc/hosts

127.0.0.1       bt.foo.org  bt  localhost
127.0.1.1       ssl.bt.foo.org   
btssl

Create and Sign Certificate
    
인증서와 키를 저장하기 위한  /etc/apache2/ssl 디렉토리를 생성한다.


#  cd  /etc/apache2/

#  mkdir ssl

#  cd ssl

 

패스워드(passparse) 없이  private key file 을 생성한다.
# openssl genrsa -out bt.foo.org.key 4096

Certificate Signing Request (CSR)을 생성한다.
# openssl req -new -key bt.foo.org.key  > bt.foo.org.csr

Self-signed SSL certificate 을 생성한다.
# openssl x509 -req -days 365 -in bt.foo.org.csr -signkey bt.foo.org.key -out bt.foo.org.crt


ssl 디렉토리 목록을 확인한다.

# ls –l

 lrwxrwxrwx 1 root root   10 28. Jun 02:53 7c783bfb -> apache.pem
-rw------- 1 root root 2680 28. Jun 02:53 apache.pem
-rw-r--r-- 1 root root 1976 28. Jun 03:09 deblabapachessl.org.crt
-rw-r--r-- 1 root root 1736 28. Jun 03:08 deblabapachessl.org.csr
-rw-r--r-- 1 root root 3243 28. Jun 03:05 deblabapachessl.org.key 


Configure Apache

 

ssl module을 활성화 한다.
# a2enmod ssl


# vi  /etc/apache/ports.conf    다음과 같이 수정한다.

NameVirtualHost *:443
Listen: 80

<IfModule mod_ssl.c>

  Listen 443
</
IfModule>

<
IfModule mod_gnutls.c>
    Listen 443
</
IfModule>


# vi /etc/apache2/sites-enabled/000-default 을 편집한다.

<
VirtualHost *:443>
       
ServerAdmin webmaster@localhost
        
ServerName deblabapachessl.org
       
DocumentRoot /var/www
        <Directory />
                Options
FollowSymLinks
               
AllowOverride None
        </Directory>
        <Directory /
var/www/>
                Options Indexes
FollowSymLinks MultiViews
               
AllowOverride None
                Order
allow,deny
                allow from all
        </Directory>

       
ErrorLog ${APACHE_LOG_DIR}/error.log
       
LogLevel warn
       
CustomLog ${APACHE_LOG_DIR}/access.log combined
 
   




++++++++++++++++참고++++++++++++++++++++++

Requirements

1x Debian node (basic install)


Host Configruation

check your /etc/hostname and /etc/hosts for next values:

/etc/hostname

bt.foo.org

/etc/hosts

127.0.0.1       bt.foo.org  bt  localhost
127.0.1.1       ssl.bt.foo.org   btssl



Install Apache

apt-get install apache2


Create and Sign Certificate


인증서와 키를 저장하기 위한  /etc/apache2/ssl 디렉토리를 생성한다.

mkdir /etc/apache2/ssl

       cd /etc/apache2/ssl/

첫번째 방법) local selfsigned cert 을 다음 명령어로 생성한다.

 /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem

끝)  go to apache config Part (look for apache.pem and disable with # other key, certs)


두번째 방법)

 ssl/ 로 이동한다.

cd  /etc/apache2/ssl/

패스워드(passparse) 없이  private key file 을 생성한다.

openssl genrsa -out bt.foo.org.key 4096

Certificate Signing Request (CSR)을 생성한다.

openssl req -new -key bt.foo.org.key > bt.foo.org.csr

self-signed SSL certificate 을 생성한다.

openssl x509 -req -days 365 -in bt.foo.org.csr -signkey bt.foo.org.key -out bt.foo.org.crt


ssl 디렉토리 목록을 확인한다.

ls -l
lrwxrwxrwx 1 root root   10 28. Jun 02:53 7c783bfb -> apache.pem
-rw------- 1 root root 2680 28. Jun 02:53 apache.pem
-rw-r--r-- 1 root root 1976 28. Jun 03:09 deblabapachessl.org.crt
-rw-r--r-- 1 root root 1736 28. Jun 03:08 deblabapachessl.org.csr
-rw-r--r-- 1 root root 3243 28. Jun 03:05 deblabapachessl.org.key

 

Configure Apache

 

Ok, since we have created a self signed certificate it is time to configure apache :), I do not like to have  port 80 open or to run the server over http if you just wish to have https so I do as next:

ssl module을 활성화 한다.

a2enmod ssl


 /etc/apache/ports.conf 을 다음과 같이 수정한다.

NameVirtualHost *:443
Listen: 80

<IfModule mod_ssl.c>

  Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

HINT: in case you wish to have port 80 also open and http in use DO NOT CHANGE ANYTHING HERE!!!


/etc/apache2/sites-enabled/000-default 을 편집한다.

add(for http port 80) 또는   in case off https and port 433 
                                          
HINT: comment out part with crt,key, or pem depending on your chosen way example shows first way!!! 

<VirtualHost *:443>
        ServerAdmin webmaster@localhost
         ServerName deblabapachessl.org
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

 ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
     SSLEngine On

#    SSLCertificateFile /etc/apache2/ssl/deblabapachessl.org.crt
#   SSLCertificateKeyFile /etc/apache2/ssl/deblabapachessl.org.key
SSLCertificateFile /etc/apache2/ssl/apache.pem

</VirtualHost>

Test

Configuration에 문제가 없는지 다음 명령을 실행하여 확인한다.

apache2ctl configtest

문제가 없다면 다음과 같은 메시지가 출력된다.

Syntax OK

아파치 서버를 재 시작한다.

/etc/init.d/apache restart

if you have disabled a port 80 http will not work but in any case https :)
go t: 

https://your_server/

and you will see default page with:

It works!