Skip to content

SSL #
Find similar titles

Structured data

Category
Computer science

SSL (Secure Sockets Layer) 이란? #

  • HTTP 통신기밀성을 유지 못하는 문제가 있으며 해당 문제를 해결하기 위한 프로토콜을 개발하게 되었다.
  • 현재 전세계에서 가장 많이 사용되는 프로토콜이다.
  • 브라우저 접속 시 HTTPS로 접속

사전 준비 #

1. openssl 설치

[root@localhost Downloads]# wget -c http://www.openssl.org/source/openssl-1.0.2.tar.gz
[root@localhost Downloads]# tar -xzvf openssl-1.0.2.tar.gz
[root@localhost Downloads]# cd openssl-1.0.2
[root@localhost openssl-1.0.2]# ./config --prefix=/usr/local --openssldir=/usr/local/openssl
[root@localhost openssl-1.0.2]# make
[root@localhost openssl-1.0.2]# make install

2. apache 설치 - mod_ssl.so 모듈 확인 - 2.x 버전에서는 mod_ssl.so 모듈이 기본 포함되어 있음 - httpd -l 명령어로 mod_so.c 모듈 확인 - 포트 확인 ( SSL 기본 포트 443 )

리눅스 사설 인증서 생성 #

openssl genrsa -out server.key 2048
  • RSA 2048bit Private Key를 생성

    [root@dev local]#  openssl genrsa -out server.key 2048
    Generating RSA private key, 2048 bit long modulus
    ............................................................+++
    .................+++
    e is 65537 (0x10001)
    [root@dev local]#
    
    openssl req -new -key server.key -out server.csr
    
  • CSR을 생성한다. X.509에 필요한 몇가지 정보들을 입력한다.

    [root@dev local]# openssl req -new -key server.key -out server.csr
    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.
    -----
    Country Name (2 letter code) [XX]:KR
    State or Province Name (full name) []:KOREA
    Locality Name (eg, city) [Default City]:Suwon
    Organization Name (eg, company) [Default Company Ltd]:insilicogen
    Organizational Unit Name (eg, section) []:DSC
    Common Name (eg, your name or your server's hostname) []:^C
    [root@dev local]# openssl req -new -key server.key -out server.csr
    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.
    -----
    Country Name (2 letter code) [XX]:kr
    State or Province Name (full name) []:korea
    Locality Name (eg, city) [Default City]:suwon
    Organization Name (eg, company) [Default Company Ltd]:insilicogen
    Organizational Unit Name (eg, section) []:dsc
    Common Name (eg, your name or your server's hostname) []:semantics.insilicogen.com
    Email Address []:dhkim@insilicogen.com
    
    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []:
    An optional company name []:
    You have mail in /var/spool/mail/root
    [root@dev local]#
    
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    
  • 유효기간 365일짜리 사설인증서를 생성한다

    [root@dev local]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    Signature ok
    subject=/C=kr/ST=korea/L=suwon/O=insilicogen/OU=dsc/CN=semantics.insilicogen.com/emailAddress=dhkim@insilicogen.com
    Getting Private key
    You have mail in /var/spool/mail/root
    [root@dev local]#
    
  • 생성파일 : server.crt server.csr server.key

  • 인증서를 생성했다면 .csr 파일은 삭제해도 된다.

아파치 설정 #

yum 으로 아파치 설치 시 #

  • mod_ssl.so 모듈이 있는지 확인
    • /etc/httpd/modules 에 파일 존재 확인
    • 없으면 yum insltall mod_ssl 로 재설치 가능
  • 설치 후 /etc/httpd/conf.d/ssl.conf 설정 파일 생성됨

컴파일 하여 아파치 설치 #

[root@localhost httpd-2.2.29]# ./configure --prefix=/usr/local/apache2 --enable-module=so --enable-so --enable-mods-shared=ssl --with-ssl=/usr/local/openssl --enable-ssl=shared
[root@localhost httpd-2.2.29]# make
[root@localhost httpd-2.2.29]# make install
[root@localhost httpd-2.2.29]# cd /usr/local/apache2/modules
[root@localhost modules]# ls
mod_jk.so

1. 아파치 설정파일 ({APACHE_HOME}/conf/httpd.conf)

....
LoadModule ssl_module modules/mod_ssl.so
....

2. SSL 설정파일 ({APACHE_HOME}/conf/extra/httpd-ssl.conf)

Listen 443
...    
<VirtualHost _default_:443>
...
SSLCertificateFile "/usr/local/apache2/conf/cert/server.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/cert/server.key"
...
</VirtualHost>

3. Proxy 설정변경 ({APACHE_HOME}/conf/extra/httpd-vhosts.conf)

NameVirtualHost *:80

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
  • 서버에 접속하는 모든 접근을 SSL을 이용해 서비스 하는 경우 설정
    • Apache 컴파일 전에 설정내용에 다음 속성을 추가해야 함 ./configure --enable-rewrite=true

아파치톰캣 연동을 위한 mod_jk.so 모듈 추가 #

0.0.1_20210630_7_v33