Solaris

OpenSSL

알 수 없는 사용자 2008. 2. 27.
728x90

OpenSSL

설치할 OpenSSL 버전

  • OpenSSL 0.9.8a

OpenSSL을 사용할 어플리케이션 버전

  • Apache 2.0.50

들어가기 전에

  • OpenSSL은 보안 향상을 위해 사용된다. 그러나 OpenSSL에는 아직 버그가 존재하기 때문에, 수시로 OpenSSL의 버전을 확인해 업데이트 해주어야 한다.
  • SSL은 주로 패킷 스나이핑으로 인한 피해를 줄여줄 뿐이다. 그 이상은 안된다. 만능이 아니다! SSL 설치하고 '보안은 끝'이라고 생각하는 것은 오산일 뿐이다. [SSL을 설치했는데 왜 해킹을 당했나요?]라는 질문은 참 바보같은 질문이다. 해킹에는 수십~수백가지 방법이 있으며, SSL은 그중 하나인 패킷 스나이핑을 무력화할 뿐이다. (패킷스나이핑이 되지 않도록 하는게 아니라, 스나이핑 해봤자 내용이 암호화되어있어 무슨 내용인지 알 수 없도록 만드는 것이다)
  • SSL의 단점? 단 한가지있다. 느리다는 것이다. 느려도 너무 느리다. 패킷의 인코딩/디코딩에 많은 CPU자원을 소모한다. 필자는 이런 서버에는 과감히 다음과 같이 말한다. 'SSL 쓰지말아' 패킷 암호화를 하지 않아도 보안을 향상시킬 수 있는 다른 방법도 많다.
  • 최종 갱신일: 2008-02-05
  • 이 문서는 http://www.solanara.net/ 에서 최신버전을 구할 수 있다.

1. OpenSSL 설치

# 패키지 설치
root@wl ~ # wget ftp://ftp.sunfreeware.com/pub/freeware/intel/9/openssl-0.9.8e-sol9-x86-local.gz
root@wl ~ # gunzip openssl-0.9.8e-sol9-intel-local.gz
root@wl ~ # pkgadd -d openssl-0.9.8e-sol9-intel-local

# OpenSSL 소스 설치: http://www.openssl.org
root@wl ~ # wget http://www.openssl.org/source/openssl-0.9.8g.tar.gz
root@wl ~ # gtar xvfz openssl-0.9.8g.tar.gz
root@wl ~ # cd openssl-0.9.8g
root@wl ~/openssl-0.9.8g # ./config
root@wl ~/openssl-0.9.8g # make
root@wl ~/openssl-0.9.8g # make test 1)
root@wl ~/openssl-0.9.8g # make install

# 환경 설정
root@wl ~ # vi /etc/profile
# for OpenSSL located at /usr/local/ssl
if [ -d /usr/local/ssl ]
then
  PATH=$PATH:/usr/local/ssl/bin
  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/ssl/lib
fi
1) OpenSSL은 반드시 테스트를 하자. 흔하지는 않지만 gcc, cc의 버그로 인해 테스트에 실패하는 경우가 있다. 이런경우 패치를 하거나, gcc, cc, openssl 버전을 낮추거나 gcc, cc의 옵티마이징을 꺼야 한다.

2. OpenSSL 인증서 만들기

root@wl ~ # cd /usr/local/ssl/certs
root@wl /usr/local/ssl/certs # openssl req -new -nodes -out req.pem -keyout req.key
Generating a 1024 bit RSA private key
.......++++++
.......++++++
writing new private key to '/usr/local/ssl/certs/root.cert'
-----
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) [AU]:KR
State or Province Name (full name) [Some-State]:GyungGiDo
Locality Name (eg, city) []:Suwon
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Solanara
Organizational Unit Name (eg, section) []:SolanaraTeam
Common Name (eg, YOUR name) []:wl.solanara.net 1)
Email Address []:admin@solanara.net
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
root@wl /usr/local/ssl/certs # ls -alF 2)
1) Apache설정파일인 httpd.conf의 ServerName에 들어갈 값을 적어준다. 아파치는 이부분을 검사한다. 도메인이 있다면 www.company.com과 같이 전체를 다 써준다. 없다면 192.186.0.1과 같이 IP를 써도 된다. 다른 내용을 쓰면 인증을 다시 받아야 하는 불상사가 생길 수 있다. 유료 루트 인증기관에 보내기 전에 전화를 걸어 반드시 확인하도록 한다.
2) 총 2개의 파일이 생성되었다. req.key는 공개키로 잘 보관해야한다. req.pem (certificate signing request)파일은 CA(Certification Authority=인증기관, 예: 베리사인, 타우트)에게 보내 인증 받아야 한다.

3. Root CA가 되기

CA에서 인증 받으려면 비용이 들기 때문에 테스트용으로는 자신이 CA가 될 필요가 있다. 그런데 CA가 되려면 Root CA(최상위 인증 기관)의 인증이 필요하다. 그리고 그 인증을 받기 위해서는 비용이 든다. 따라서 여기서는 Root CA가 되는 방법을 소개한다. Root CA도 CA중 하나이므로 CA가 하는 일을 모두 할 수 있다.
root@wl /usr/local/ssl/certs # openssl genrsa -des3 -out ca.key 1024 1)
Generating RSA private key, 1024 bit long modulus
............................++++++
............++++++
e is 65537 (0x10001)
Enter pass phrase for ca.key:*****
Verifying - Enter pass phrase for ca.key: *****
root@wl /usr/local/ssl/certs # openssl req -new -x509 -days 365 -key ca.key -out ca.crt 2)
Enter pass phrase for ca.key:
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) [AU]:KR
State or Province Name (full name) [Some-State]:GyungGiDo
Locality Name (eg, city) []:Suwon
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Solanara
Organizational Unit Name (eg, section) []:SolanaraTeam
Common Name (eg, YOUR name) []:WindyHana
Email Address []:admin@solanara.net
root@wl /usr/local/ssl/certs # openssl x509 -req -CA ca.crt -CAkey ca.key -days 365 -in req.pem -out signed-req.pem -CAcreateserial 3)
Signature ok
subject=/C=KR/ST=GyungGiDo/L=Suwon/O=Solanara/OU=SolanaraTeam/CN=wl.solanara.net/emailAddress=admin@solanara.net
Getting CA Private Key
Enter pass phrase for ca.key:*****
root@wl /usr/local/ssl/certs # chmod 600 *
root@wl /usr/local/ssl/certs # ls -alF 4)
총 18
drwxr-xr-x   2 root     bin          512 10월 26일  13:44 ./
drwxr-xr-x  10 root     bin          512 10월 26일  13:40 ../
-rw-------   1 root     other       1074 10월 26일  13:44 ca.crt
-rw-------   1 root     other        963 10월 26일  13:43 ca.key
-rw-------   1 root     other         17 10월 26일  13:44 ca.srl
-rw-------   1 root     other        887 10월 26일  13:43 req.key
-rw-------   1 root     other        676 10월 26일  13:43 req.pem
-rw-------   1 root     other        855 10월 26일  13:44 signed-req.pem
root@wl /usr/local/ssl/certs # 
1) Root CA의 1024bit private key 파일을 만든다. 결과 파일은 ca.key 이다.
2) 인증서를 만든다. 결과파일은 ca.crt파일이다. ca.crt를 Internet Explorer에 등록해주면 '올바르지 않은 CA'라는 에러메시지를 없앨 수 있다.
3) 이제 Root CA가 되는 일은 끝났다. 클라이언트가 요청한 req.pem을 싸인해주자. 결과파일은 signed-req.pem이다. 베리싸인과 같은 인증 기관은 이 명령 한줄만 실행 해주면 된다. (그러면서 도대체 얼마를 받는거야... ㅡ,.ㅡ)
4) ca.key와 req.key는 소중하게 보관해야 한다. 절대 외부에 유출되서는 안된다.
아파치와 같은 여러 유닉스 데몬에서 SSL을 사용할 때 사용되는 파일은 req.key와 signed-req.pem의 내용이며, 몇몇 데몬은 ca.crt의 내용까지 요구하는 경우도 있다. (형태가 파일인 경우가 대부분이지만 DB에 저장된 문자열일 수도 있다. 실제로 req.key 와 signed-req.pem 은 vi 에디터등으로 열어 내용을 볼 수 있는 텍스트 파일이다) ca.key파일은 디스켓에 담아 별도로 보관한다. (이것이 유출되지 않아야 SSL의 보안이 안전해진다. CA는 이 키 파일의 보안에 많은 비용을 들인다)

3. 어플리케이션 설치

※ Apache 프로그램 설치

root@wl ~/httpd-2.0.50 # ./configure --prefix=/usr/local/apache2 --enable-so --with-mpm=worker \
 --enable-ssl --with-ssl=/usr/local/ssl
root@wl ~/httpd-2.0.50 # make
root@wl ~/httpd-2.0.50 # make install
root@wl ~/httpd-2.0.50 # mkdir /usr/local/apache2/conf/ssl.key
root@wl ~/httpd-2.0.50 # cd /usr/local/apache2/conf/ssl.key
root@wl /usr/local/apache2/conf/ssl.key # ln -s /usr/local/ssl/certs/req.key server.key # Server Private Key
root@wl /usr/local/apache2/conf/ssl.key # mkdir /usr/local/apache2/conf/ssl.crt
root@wl /usr/local/apache2/conf/ssl.key # cd /usr/local/apache2/conf/ssl.crt
root@wl /usr/local/apache2/conf/ssl.crt # ln -s /usr/local/ssl/certs/signed-req.pem server.crt # Server Certificate
root@wl /usr/local/apache2/conf/ssl.key # apachectl startssl # 아파치 시작. apachectl start 만하면 SSL이 시작되지 않는다.
root@wl /usr/local/apache2/conf/ssl.key # apachectl stop # 아파치 종료
728x90

댓글