블로그 이미지
훅크선장

카테고리

분류 전체보기 (362)
사진이야기 (23)
펭귄컴퓨팅 (121)
컴퓨터보안 (84)
절름발이 프로그래머 (59)
하드웨어개조 (23)
멀알려줄까 (35)
홈베이킹&홈쿠킹 (2)
잡다한것들 (15)
Total
Today
Yesterday

달력

« » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

공지사항

태그목록

최근에 올라온 글

이틀간 많은 문서를 뒤졌지만, 도저히 쉽게 설명한 문서가 없어서 애를 먹었습니다.
다행히 삽질을 통해서, 성공하였습니다.  
가장 많이 참고한 문서는 
디렉토리 위치 설명이 잘 안되어 있었습니다.

CentOS 에서는 시작 위치가 /usr/share/ssl/  입니다. 이곳에 openssl.cnf 가 존재합니다.
RHEL 에서는 시작 위치가 /etc/pki/tls/ 입니다. 이곳에 openssl.cnf가 존재합니다.
모든 인증서 작업은 이 디렉토리에서 이루어져야만 합니다.

CentOS에서는 openssl.cnf를 수정할 필요가 없지만, RHEL은 약간 수정이 필요합니다.
기존 파일을 백업하고, 다음과 같이 수정하면 됩니다. (꼭 디렉토리 명을 demoCA로 할 필요는 없습니다. openssl.cnf를 잘 이해한다면, 디렉토리 위치나 디렉토리명은 알아서 설정하면 됩니다.)
[root@localhost tls]# cp openssl.cnf openssl.cnf.org
[root@localhost tls]# vi openssl.cnf
modify :
dir             = ../../CA              # Where everything is kept
->
dir             = ./demoCA
[root@localhost tls]# sync
[root@localhost tls]# ls
cert.pem  certs  misc  openssl.cnf  openssl.cnf.org  private

이제부터 필요한 디렉토리와 파일들을 생성합니다. CA로써 가져야되는 디렉토리와 파일들입니다.
디렉토리들과 파일들은 demoCA라는 디렉토리 밑에 생성되어야 합니다.
[root@localhost tls]# mkdir demoCA
[root@localhost tls]# cd demoCA
[root@localhost demoCA]# mkdir certs
[root@localhost demoCA]# mkdir crl
[root@localhost demoCA]# mkdir newcerts
[root@localhost demoCA]# mkdir private
[root@localhost demoCA]# touch index.txt
[root@localhost demoCA]# echo "0001" > serial
[root@localhost demoCA]# echo "0001" > crlnumber
[root@localhost demoCA]# ls
certs  crl  crlnumber  index.txt  newcerts  private  serial

환경이 완료되었으면, 원래 작업 디렉토리로 돌아옵니다.
그리고, CA용 비밀키와 인증서를 생성합니다.

[root@localhost demoCA]# cd ..
[root@localhost tls]# ls
cert.pem  certs  demoCA  misc  openssl.cnf  openssl.cnf.org  private

비밀키를 생성할 때는 반드시 패스워드가 필요합니다.(확인을 위해서, 두 번 넣습니다.)
[root@localhost tls]# openssl genrsa -des3 -out ca.key 1024
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:

비밀키를 기반으로 인증서를 만듭니다. 앞에서 넣었던 비밀키 패스워드를 입력해야 합니다.
인증서에는 국가, 지역, 도시, 기관, 부서, 시스템 명과 이메일 주소를 넣어줘야 합니다.
어떤 값을 넣어줘도 상관은 없습니다만,  국가, 지역, 도시, 기관명은 반드시 CA가 인증해주는 다른 인증서를 만들 때도 동일하게 하여야합니다. 잘 기억해야 됩니다. 밑에 보이는 것을 참고해서 넣으면 됩니다.
[root@localhost tls]# openssl req -new -x509 -days 365 -key ca.key -out ca.crt
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) [GB]:KR
State or Province Name (full name) [Berkshire]:Seoul
Locality Name (eg, city) [Newbury]:Seoul
Organization Name (eg, company) [My Company Ltd]:MyCompany
Organizational Unit Name (eg, section) []:Research
Common Name (eg, your name or your server's hostname) []:RHEL
Email Address []:hook@mail.com

이것으로 CA용 비밀키와 인증서가 생성되었습니다.
[root@localhost tls]# ls
ca.crt  ca.key  cert.pem  certs  demoCA  misc  openssl.cnf  openssl.cnf.org  private

이제 서버용으로 사용할 비밀키와 인증서를 만듭니다.
비밀키는 패스워드를 꼭 두 번 넣습니다.
[root@localhost tls]# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
.........++++++
........++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:

서버용 인증서 요청파일을 만듭니다. 바로 인증서가 만들어지지 않는 것은 CA의 서명을 받아야 하기 때문입니다.
먼저 비밀키의 패스워드를 입력합니다.
CA 인증서를 만들 때와 비슷하게, 국가, 지역, 도시, 기관, 부서, 시스템 명과 이메일 주소를 넣어야 합니다.
국가, 지역, 도시, 기관명은 반드시 CA 인증서와 동일하게 넣어야 합니다. 그렇지 않으면, CA의 서명을 받을 수 없습니다.
부서, 시스템 명과 이메일 주소를 알아서 넣습니다. (CA 랑 동일해도 상관없습니다.)
요청을 하기 위한 추가속성을 입력하라고 합니다. 아무 값이나 넣어도 상관없습니다.
[root@localhost tls]# openssl req -new -days 365 -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) [GB]:KR
State or Province Name (full name) [Berkshire]:Seoul
Locality Name (eg, city) [Newbury]:Seoul
Organization Name (eg, company) [My Company Ltd]:MyCompany
Organizational Unit Name (eg, section) []:Research
Common Name (eg, your name or your server's hostname) []:MyServer
Email Address []:hook@mail.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:password
An optional company name []:None

인증서 요청파일이 완성되었으면, CA의 서명과정을 거칩니다.
CA 비밀키의 패스워드를 입력합니다.
그러면, CA 서명을 할 것인지를 물어보고, 또 한번 발급할 것인가를 물어봅니다. 모두 y 로 응답합니다.
[root@localhost tls]# openssl ca -in server.csr -out server.crt -keyfile ca.key -cert ca.crt
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for ca.key:
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Aug 24 05:48:50 2010 GMT
            Not After : Aug 24 05:48:50 2011 GMT
        Subject:
            countryName               = KR
            stateOrProvinceName       = Seoul
            organizationName          = MyCompany
            organizationalUnitName    = Research
            commonName                = MyServer
            emailAddress              = hook@mail.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                CB:4E:81:5A:58:79:98:76:89:B3:B1:5C:6F:B5:77:CD:8C:9D:3B:01
            X509v3 Authority Key Identifier: 
                keyid:35:82:E4:7B:71:D1:F5:10:72:C2:0F:A5:0E:54:34:E3:C9:39:63:60

Certificate is to be certified until Aug 24 05:48:50 2011 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

이것으로 CA 인증을 받은 서버의 인증서가 생성되었습니다.

아래의 과정은 클라이언트용 비밀키와 인증서의 생성과정으로 서버용 만들기와 동일합니다.
동일한 과정으로 여러 개의 비밀키와 인증서를 만들 수 있습니다.

[root@localhost tls]# openssl genrsa -des3 -out client.key 1024
Generating RSA private key, 1024 bit long modulus
...++++++
..............++++++
e is 65537 (0x10001)
Enter pass phrase for client.key:
Verifying - Enter pass phrase for client.key:
[root@localhost tls]# openssl req -new -days 365 -key client.key -out client.csr
Enter pass phrase for client.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) [GB]:KR
State or Province Name (full name) [Berkshire]:Seoul
Locality Name (eg, city) [Newbury]:Seoul
Organization Name (eg, company) [My Company Ltd]:MyCompany
Organizational Unit Name (eg, section) []:Research
Common Name (eg, your name or your server's hostname) []:MyClient
Email Address []:hook@mail.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:password
An optional company name []:None
[root@localhost tls]# openssl ca -in client.csr -out client.crt -keyfile ca.key -cert ca.crt
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for ca.key:
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 2 (0x2)
        Validity
            Not Before: Aug 24 05:50:19 2010 GMT
            Not After : Aug 24 05:50:19 2011 GMT
        Subject:
            countryName               = KR
            stateOrProvinceName       = Seoul
            organizationName          = MyCompany
            organizationalUnitName    = Research
            commonName                = MyClient
            emailAddress              = hook@mail.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                B0:CE:BA:FD:1D:17:4B:DF:4F:9A:36:37:DB:D8:8E:7A:A8:7C:C9:FF
            X509v3 Authority Key Identifier: 
                keyid:35:82:E4:7B:71:D1:F5:10:72:C2:0F:A5:0E:54:34:E3:C9:39:63:60

Certificate is to be certified until Aug 24 05:50:19 2011 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

현재까지 발급된 상황을 보면, CA용 비밀키와 인증서가 생성되었고,
서버용과 클라이언트용 비밀키와 인증서가 생성되었습니다.
CA가 관리하는 내용을 한번 검토해 봅니다.
[root@localhost tls]# ll
total 132
-rw-r--r-- 1 root root 1257 Aug 24 14:47 ca.crt
-rw-r--r-- 1 root root  963 Aug 24 14:46 ca.key
lrwxrwxrwx 1 root root   19 Jun  3 20:14 cert.pem -> certs/ca-bundle.crt
drwxr-xr-x 2 root root 4096 Aug 24 13:43 certs
-rw-r--r-- 1 root root 3209 Aug 24 14:50 client.crt
-rw-r--r-- 1 root root  757 Aug 24 14:50 client.csr
-rw-r--r-- 1 root root  963 Aug 24 14:49 client.key
drwxr-xr-x 6 root root 4096 Aug 24 14:50 demoCA
drwxr-xr-x 2 root root 4096 Jun  3 20:14 misc
-rw-r--r-- 1 root root 9828 Aug 24 14:43 openssl.cnf
-rw-r--r-- 1 root root 9828 Aug 24 14:42 openssl.cnf.org
drwxr-xr-x 2 root root 4096 Jul 23 10:06 private
-rw-r--r-- 1 root root 3209 Aug 24 14:48 server.crt
-rw-r--r-- 1 root root  757 Aug 24 14:48 server.csr
-rw-r--r-- 1 root root  963 Aug 24 14:47 server.key
[root@localhost tls]# cd demoCA
[root@localhost demoCA]# ll
total 88
drwxr-xr-x 2 root root 4096 Aug 24 14:44 certs
drwxr-xr-x 2 root root 4096 Aug 24 14:44 crl
-rw-r--r-- 1 root root    5 Aug 24 14:45 crlnumber
-rw-r--r-- 1 root root  212 Aug 24 14:50 index.txt
-rw-r--r-- 1 root root   20 Aug 24 14:50 index.txt.attr
-rw-r--r-- 1 root root   21 Aug 24 14:48 index.txt.attr.old
-rw-r--r-- 1 root root  106 Aug 24 14:48 index.txt.old
drwxr-xr-x 2 root root 4096 Aug 24 14:50 newcerts
drwxr-xr-x 2 root root 4096 Aug 24 14:45 private
-rw-r--r-- 1 root root    3 Aug 24 14:50 serial
-rw-r--r-- 1 root root    3 Aug 24 14:48 serial.old
[root@localhost demoCA]# ls certs/
[root@localhost demoCA]# ls crl
[root@localhost demoCA]# ls newcerts/
01.pem  02.pem
[root@localhost demoCA]# ll newcerts
total 16
-rw-r--r-- 1 root root 3209 Aug 24 14:48 01.pem
-rw-r--r-- 1 root root 3209 Aug 24 14:50 02.pem
[root@localhost demoCA]# ll private/
total 0

index.txt 파일에는 발급된 인증서에 대한 간략 정보가 기록되어 있습니다.
[root@localhost demoCA]# cat index.txt
V       110824054850Z           01      unknown /C=KR/ST=Seoul/O=MyCompany/OU=Research/CN=MyServer/emailAddress=hook@mail.com
V       110824055019Z           02      unknown /C=KR/ST=Seoul/O=MyCompany/OU=Research/CN=MyClient/emailAddress=hook@mail.com
[root@localhost demoCA]# cat index.txt.attr
unique_subject = no

serial 파일에는 발급된 인증서의 개수가 기록되어 있습니다. 총 3개의 인증서가 발급되었음을 알 수 있습니다.
[root@localhost demoCA]# cat serial
03
[root@localhost demoCA]# 

Posted by 훅크선장
, |