"리눅스 자체서명 SSL 인증서 생성"의 두 판 사이의 차이

102번째 줄: 102번째 줄:


==httpd.conf 설정==
==httpd.conf 설정==
[[httpd.conf]] 파일의 맨 아래에 다음 내용 추가<ref>[[httpd.conf 기본값]]일 때는 그냥 하단에 추가만 하면 되지만, 기존에 VirtualHost를 사용중이라면 적절히 수정해야 한다.</ref>
[[httpd.conf]] 파일의 맨 아래에 다음 내용 추가<ref>[[httpd.conf 기본값]]일 때는 그냥 하단에 추가만 하면 되지만, 기존에 VirtualHost를 사용중이라면 적절히 수정해야 한다.</ref>.
단 DocumentRoot는 본인의 상황에 맞게 지정.
<source lang='bash'>
<source lang='bash'>
NameVirtualHost *:443
NameVirtualHost *:443

2012년 9월 25일 (화) 00:26 판

How to create a self-signed SSL Certificate
리눅스 개인서명 SSL 인증서 생성
리눅스 OpenSSL 자체서명 인증서 설치
리눅스 OpenSSL 인증서 설치

1 개요

여기서는 개인 인증기관을 만들고 인증서를 발급받아 보자. 웹브라우저에서는 신뢰할 수 없는 사이트라고 나오지만, 어쨌든 사용자(웹 접속자)만 동의하면 SSL 기능을 이용할 수 있다.

2 확인

리눅스를 설치했다면 아마도 openssl 패키지가 설치되어 있을 것이다.[1]

[root@jmnote ~]# rpm -qa openssl
openssl-1.0.0-20.el6_2.5.x86_64

3 개인키 생성

[root@jmnote ~]# openssl genrsa -des3 -out server.key 2048
Generating RSA private key, 2048 bit long modulus
....................................................................................................................................................................................+++
..........................................................+++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
→ 서버 개인키인 server.key 파일이 생성된다.

4 인증요청서 생성

[root@jmnote ~]# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.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) [XX]:KR
State or Province Name (full name) []:Seoul
Locality Name (eg, city) [Default City]:Yeongdeungpo
Organization Name (eg, company) [Default Company Ltd]:Jmnote
Organizational Unit Name (eg, section) []:Jmnote
Common Name (eg, your name or your server's hostname) []:jmnote.com
Email Address []:web@jmnote.com
→ 자신의 경우에 맞게 적절히 입력
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
→ 그냥 Enter, Enter
→ 서버 인증요청서인 server.csr 파일이 생성되었다.

5 개인키에서 패스워드 제거

키에 패스워드가 들어있으면 아파치 구동시마다 물어본다. 패스워드를 제거하더라도 SSL 암호화 통신에는 문제가 없으므로 제거하자.

[root@jmnote ~]# cp server.key server.key.org
[root@jmnote ~]# openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org:
→ 개인키 패스워드를 입력
writing RSA key
→ 패스워드가 제거된 개인키 파일 server.key 이 생성된다.
[root@jmnote ~]# ll server*
-rw-r--r--. 1 root root 1054 Sep 20 07:53 server.csr
-rw-r--r--. 1 root root 1679 Sep 20 07:56 server.key
-rw-r--r--. 1 root root 1751 Sep 20 07:55 server.key.org
→ 패스워드가 제거된 파일(server.key)은 원래 파일(server.key.org)에 비해 용량이 조금 줄어들었다.

6 인증서 생성

개인키와 인증요청서를 가지고 인증서를 생성해보자.

[root@jmnote ~]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=KR/ST=Seoul/L=Yeongdeungpo/O=Jmnote/OU=Jmnote/CN=jmnote.com/emailAddress=web@jmnote.com
Getting Private key
→ 서버 인증서인 server.csr이 생성되었다.

7 개인키와 인증서 설치

개인키 파일(.key)과 인증서 파일(.crt)을 ssl이라는 파일명으로 httpd.conf 폴더에 복사하자. (httpd.conf 폴더는 설정에 따라 다를 수 있다.)

[root@jmnote ~]# cp server.key /etc/httpd/conf/
[root@jmnote ~]# cp server.crt /etc/httpd/conf/
[root@jmnote ~]# ll /etc/httpd/conf
total 60
-rw-r--r--. 1 root root 34417 Sep 20 07:41 httpd.conf
-rw-r--r--. 1 root root 13139 Feb 14  2012 magic
-rw-r--r--. 1 root root  1298 Sep 20 08:45 server.crt
-rw-r--r--. 1 root root  1679 Sep 20 08:45 server.key

8 httpd.conf 설정

httpd.conf 파일의 맨 아래에 다음 내용 추가[2].

단 DocumentRoot는 본인의 상황에 맞게 지정.
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/httpd/conf/server.crt
SSLCertificateKeyFile /etc/httpd/conf/server.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
CustomLog logs/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
DocumentRoot 폴더위치
</VirtualHost>
→ SSL 접속용 DocumentRoot를 별도로 지정해주자. (예: /var/www/https[3])

9 아파치 재시작

명령어
service httpd restart
실행예시 (성공)
[root@jmnote ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
실행예시 (실패)
[root@jmnote ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: Syntax error on line 1072 of /etc/httpd/conf/httpd.conf:
Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration
                                                           [FAILED]
→ mod_ssl 패키지가 없어서 그렇다. Invalid command 'SSLEngine' 참조.

10 웹브라우저 테스트

이 웹 사이트의 보안 인증서에 문제가 있습니다. 
   
이 웹 사이트에서 제시한 보안 인증서는 신뢰할 만한 인증 기관에서 발급한 것이 아닙니다.
이 웹 사이트에서 제시한 보안 인증서는 다른 웹 사이트 주소에 대해 발급되었습니다.

문제가 있는 인증서를 통해 사용자를 속이거나 사용자가 서버로 보내는 데이터를 가로챌 수도 있습니다.  

이 웹 페이지를 닫고 이 웹 사이트를 계속 탐색하지 않는 것이 좋습니다.  
... (생략)
→ 개인서명이라 신뢰할 수 없다고 하지만[4], 보안 접속은 잘 된다.

11 같이 보기

12 주석

  1. 리눅스는 SSH 접속을 기본 제공하는데, 거기에도 openssl이 필요하다. CentOS 6 최소 설치 패키지 목록에도 포함되어 있다.
  2. httpd.conf 기본값일 때는 그냥 하단에 추가만 하면 되지만, 기존에 VirtualHost를 사용중이라면 적절히 수정해야 한다.
  3. /var/www/html 와 비슷하게 예시 폴더를 지정해보았다. 지정한 폴더가 서버에 실제로 있어야 httpd 시작시 오류가 나지 않는다
  4. IE8의 경우, 주소표시줄이 붉게 표시되고 '인증서 오류'라는 말이 계속 따라다닌다. ㅠ_ㅠ

13 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}