달력

3

« 2024/3 »

  • 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
  • 31

'Ca'에 해당되는 글 1

  1. 2010.04.27 Openssl 사설인증기관(CA) 만들기 - Part 1 3
반응형

Openssl 을 이용하여 CA(Certificate Authority : 인증기관)을 만드는 방법

Openssl 이 인스톨 되어 있으면, 다음과 같이 버전을 확인 할 수 있습니다.

 root@ubtdesk:/usr/local/openssl# openssl version
OpenSSL 1.0.0 29 Mar 2010

그리고 다음과 같이 openssl 환경 설정 파일을 변경 합니다.

root@ubtdesk:/usr/local/openssl# vi openssl.cnf

####################################################################
[ ca ]
default_ca      = CA_default            # The default ca section

####################################################################
[ CA_default ]

dir             = /usr/local/openssl/CA # Where everything is kept
certs           = $dir/certs            # Where the issued certs are kept
crl_dir         = $dir/crl              # Where the issued crl are kept
database        = $dir/index.txt        # database index file.
#unique_subject = no                    # Set to 'no' to allow creation of
                                        # several ctificates with same subject.
new_certs_dir   = $dir/newcerts         # default place for new certs.

certificate     = $dir/ca.crt           # The CA certificate
serial          = $dir/serial           # The current serial number
crlnumber       = $dir/crlnumber        # the current crl number
                                        # must be commented out to leave a V1 CRL
crl             = $dir/crl.pem          # The current CRL
private_key     = $dir/private/ca.key   # The private key
RANDFILE        = $dir/private/.rand    # private random number file

x509_extensions = usr_cert              # The extentions to add to the cert

# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt        = ca_default            # Subject Name options
cert_opt        = ca_default            # Certificate field options

# Extension copying option: use with caution.
# copy_extensions = copy

# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crlnumber must also be commented out to leave a V1 CRL.
# crl_extensions        = crl_ext

default_days    = 365                   # how long to certify for
default_crl_days= 30                    # how long before next CRL
default_md      = default               # use public key default MD
preserve        = no                    # keep passed DN ordering

# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy          = policy_match

# For the CA policy
[ policy_match ]
countryName             = match
#stateOrProvinceName     = match
organizationName        = match
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional


옵션 설명을 하자면,
dir 은 CA 의 관리 파일들이 저장될 디렉토리를 나타냅니다. (기본 값으로 demoCA 로 되어 있음)
certs 는 발급된 인증서들을 넣어 놓는 디렉토리이며,
crl 은 발급된 인증서 폐기 목록을 넣는 디렉토리 입니다.
database 는 인증서의 발급과 관련된 내용을 저장하는 txt 형태의 파일입니다.
newcerts 는 openssl ca 명령으로 사용자들의 인증서를 발급할때 인증서가 저장되는 디렉토리 입니다.
certificate 는 CA 자신의 인증서 파일의 위치 이며,
serial 은 현재까지 발급된 인증들의 시리얼 넘버 입니다. (1씩 증가함)
crlnumber 는 현재까지 발급된 CRL 시리얼 넘버 입니다.
private_key 는 CA 자신의 개인키 파일의 위치입니다.

default_days 는 인증서 발급시 기본 유효기간이며 (365 일 = 1년)

[ policy_name ] 은 인증서를 발급할 때 어떤 정책을 가져갈지에 대한 부분으로
countryName = match 라고 설정하면 countryName 이 다른 인증서는 발급을 하지 않습니다.
마찬가지로 stateOrProvinceName 과 organizationName 도 match 로 설정하여 이 3부분은 CA와 동일하게 설정해야만
인증서 발급이 가능합니다.
값이 optional 이면 있어도, 없어도 되는 항목이며,
supplied 는 반드시 있어야 하는 값입니다.


환경설정을 마졌으면, 다음과 같이 디렉토리 및 파일들을 만듭니다.

root@ubtdesk:/usr/local/openssl# mkdir CA
root@ubtdesk:/usr/local/openssl# cd CA
root@ubtdesk:/usr/local/openssl/CA# mkdir certs
root@ubtdesk:/usr/local/openssl/CA# mkdir newcerts
root@ubtdesk:/usr/local/openssl/CA# mkdir crl
root@ubtdesk:/usr/local/openssl/CA# mkdir private
root@ubtdesk:/usr/local/openssl/CA# touch serial
root@ubtdesk:/usr/local/openssl/CA# echo "00" > serial
root@ubtdesk:/usr/local/openssl/CA# touch index.txt
root@ubtdesk:/usr/local/openssl/CA# ls -l
합계 16
drwxr-xr-x 2 root root 4096 2010-04-27 16:17 certs
drwxr-xr-x 2 root root 4096 2010-04-27 16:18 crl
-rw-r--r-- 1 root root    0 2010-04-27 16:18 index.txt
drwxr-xr-x 2 root root 4096 2010-04-27 16:18 newcerts
drwxr-xr-x 2 root root 4096 2010-04-27 16:18 private
-rw-r--r-- 1 root root    0 2010-04-27 16:18 serial
root@ubtdesk:/usr/local/openssl/CA#

자~! 이제 CA 구성을 위한 환경설정을 모두 마쳤습니다.
그럼 이제 CA 생성을 위하여 CA 자신의 개인키/공개키 쌍을 만들고 CA 자신의 인증서를 발급해야 합니다.


1) CA 개인키/공개키 쌍 생성 및 키값 확인
 root@ubtdesk:/usr/local/openssl/CA# openssl genrsa -des3 -out private/ca.key 1024
Generating RSA private key, 1024 bit long modulus
...............++++++
.........................++++++
e is 65537 (0x10001)
Enter pass phrase for private/ca.key: CA키 비밀번호입력
Verifying - Enter pass phrase for private/ca.key: CA키 비밀번호확인

root@ubtdesk:/usr/local/openssl/CA# ls -l private/ca.key
-rw-r--r-- 1 root root 963 2010-04-27 16:23 private/ca.key

root@ubtdesk:/usr/local/openssl/CA# openssl rsa -in private/ca.key -text
Enter pass phrase for private/ca.key: CA키 비밀번호입력
Private-Key: (1024 bit)
modulus:
    00:b1:1e:34:bc:ff:12:88:a5:f0:4a:07:dd:3e:0b:
    68:c3:3d:d5:6f:41:dd:26:42:93:b8:07:df:ae:5f:
    d7:35:ed:f9:2d:87:ea:75:d5:5b:26:33:23:89:29:
    9f:34:4e:e8:91:7e:4f:c3:c0:01:50:12:9f:80:6e:
    e6:71:d5:93:c6:bb:0c:a4:23:d8:d4:1f:a2:77:5d:
    f3:75:1d:b5:69:98:be:a2:66:52:50:60:9d:b7:61:
    9c:44:88:52:c7:a8:0e:f1:92:c6:07:f6:d7:15:8d:
    7b:80:0a:c8:a9:ba:95:b0:fe:23:ec:fc:c2:e8:e7:
    39:0a:e0:0e:6e:07:28:a7:83
publicExponent: 65537 (0x10001)
privateExponent:
    57:1e:b0:7a:36:4c:fb:82:03:cb:a6:4a:a0:f6:23:
    b5:c5:78:72:9d:47:16:46:b1:3a:58:45:22:14:6a:
    5b:50:8e:bc:62:9a:65:13:69:1e:45:11:39:aa:8b:
    70:c3:4f:8a:21:43:42:d9:f2:cb:5c:1d:b0:a2:dc:
    1f:2a:1a:e1:58:2d:07:8c:a8:71:57:e5:35:3b:a9:
    7f:e1:f7:73:df:28:4a:97:be:30:e5:b1:0b:33:e2:
    b4:14:f5:bf:e4:a2:c2:b0:42:e4:ab:97:bd:1f:81:
    62:f4:7d:d6:70:63:61:9a:1b:aa:cc:8f:e1:6a:69:
    cc:fc:a6:b4:2e:4f:36:a1
prime1:
    00:d5:b7:8e:3d:31:24:bd:dc:9b:5a:0e:46:09:21:
    5b:04:76:16:f8:e7:ad:51:5f:18:c5:79:5d:f3:7d:
    e5:f6:54:7d:39:9b:64:a7:87:c7:2d:fc:f9:00:c0:
    fd:8f:7b:f8:fe:29:c6:50:c8:e4:2c:6a:31:b5:dc:
    45:e7:ce:40:b5
prime2:
    00:d4:28:f7:13:28:ab:78:d8:a7:e1:78:a4:df:37:
    9a:a5:36:95:46:46:63:1d:b6:e0:a4:ba:cd:ff:53:
    d7:ab:4a:63:ee:e5:cb:50:9b:e3:3b:b4:c3:89:b8:
    ce:85:6d:80:3d:3e:3f:e4:56:ea:e2:ce:a9:97:91:
    5a:1d:1a:42:57
exponent1:
    12:7e:42:b1:aa:d9:fa:0f:e7:e5:80:0c:b1:67:90:
    7f:af:54:47:8f:8c:a0:d8:f0:c4:cd:be:c2:7e:27:
    73:0c:56:95:b0:8b:a2:2f:8e:9d:bd:21:32:de:80:
    52:75:30:d3:95:7b:d2:ab:bf:8a:d4:59:9e:da:03:
    b6:8e:53:6d
exponent2:
    79:e7:c3:f8:5d:41:11:e2:23:ac:b9:9e:ba:a7:ff:
    92:f8:e7:13:07:34:c2:89:27:51:60:09:27:b1:ec:
    55:7f:1c:26:d4:21:5c:03:06:b1:72:ef:7c:3e:15:
    64:b3:83:a1:2d:18:97:42:9e:1a:8e:b7:01:e1:42:
    0f:40:dc:67
coefficient:
    00:ac:03:7c:97:2b:78:9c:a2:0e:d7:dc:de:0a:3a:
    31:12:ef:46:ac:84:0d:fc:9d:ba:1d:ab:2d:c5:26:
    68:76:00:f8:25:af:ab:aa:d5:c2:79:7a:f5:32:af:
    ee:8c:af:6d:ad:9a:81:ac:83:0a:27:b3:55:76:73:
    f0:64:61:50:2b
writing RSA key
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCxHjS8/xKIpfBKB90+C2jDPdVvQd0mQpO4B9+uX9c17fkth+p1
1VsmMyOJKZ80TuiRfk/DwAFQEp+AbuZx1ZPGuwykI9jUH6J3XfN1HbVpmL6iZlJQ
YJ23YZxEiFLHqA7xksYH9tcVjXuACsipupWw/iPs/MLo5zkK4A5uByingwIDAQAB
AoGAVx6wejZM+4IDy6ZKoPYjtcV4cp1HFkaxOlhFIhRqW1COvGKaZRNpHkUROaqL
cMNPiiFDQtnyy1wdsKLcHyoa4VgtB4yocVflNTupf+H3c98oSpe+MOWxCzPitBT1
v+SiwrBC5KuXvR+BYvR91nBjYZobqsyP4WppzPymtC5PNqECQQDVt449MSS93Jta
DkYJIVsEdhb4561RXxjFeV3zfeX2VH05m2Snh8ct/PkAwP2Pe/j+KcZQyOQsajG1
3EXnzkC1AkEA1Cj3EyireNin4Xik3zeapTaVRkZjHbbgpLrN/1PXq0pj7uXLUJvj
O7TDibjOhW2APT4/5Fbq4s6pl5FaHRpCVwJAEn5CsarZ+g/n5YAMsWeQf69UR4+M
oNjwxM2+wn4ncwxWlbCLoi+Onb0hMt6AUnUw05V70qu/itRZntoDto5TbQJAeefD
+F1BEeIjrLmeuqf/kvjnEwc0woknUWAJJ7HsVX8cJtQhXAMGsXLvfD4VZLODoS0Y
l0KeGo63AeFCD0DcZwJBAKwDfJcreJyiDtfc3go6MRLvRqyEDfyduh2rLcUmaHYA
+CWvq6rVwnl69TKv7oyvba2agayDCiezVXZz8GRhUCs=
-----END RSA PRIVATE KEY-----

옵션 설명을 하자면,
openssl genrsa 는 rsa용 키 생성과 관련된 커맨드이고,
-des3는 생성되는 키 값을 des3 알고리즘을 이용하여 암호화 한다는 이야기며, (생략하면 키 파일에 암호가 제거 됩니다)
-out 은 생성되는 키 이름을 지정하고,
1024는 생성되는 키의 사이즈를 이야기 합니다.


추후 openssl skey -in ca.key -out ca_noenc.key 와 같은 명령으로 키 파일의 암호를 제거 할 수 있습니다.

2) CA 인증서 요청 파일 생성 / CA 셀프인증서 생성

root@ubtdesk:/usr/local/openssl/CA# openssl req -new -key private/ca.key -out ca.csr
Enter pass phrase for private/ca.key: CA키 비밀번호입력
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]:Seoul
Locality Name (eg, city) []:Seoul
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Soongsil University
Organizational Unit Name (eg, section) []:Network Security Laboratory
Common Name (eg, YOUR name) []:CA(Certificate Authority)
Email Address []:ca@memoz.net

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

root@ubtdesk:/usr/local/openssl/CA# openssl ca -in ca.csr -out ca.crt -selfsign -keyfile private/ca.key
Using configuration from /usr/local/openssl/openssl.cnf
Enter pass phrase for private/ca.key:
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 0 (0x0)
        Validity
            Not Before: Apr 27 08:12:02 2010 GMT
            Not After : Apr 27 08:12:02 2011 GMT
        Subject:
            countryName               = KR
            organizationName          = Soongsil University
            organizationalUnitName    = Network Security Laboratory
            commonName                = CA(Certificate Authority)
            emailAddress              = ca@memoz.net
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                2B:38:40:8F:A6:FA:1D:79:BF:48:4F:E4:E2:3B:3C:D6:D1:0F:BB:D9
            X509v3 Authority Key Identifier:
                keyid:2B:38:40:8F:A6:FA:1D:79:BF:48:4F:E4:E2:3B:3C:D6:D1:0F:BB:D9

Certificate is to be certified until Apr 27 08:12:02 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
root@ubtdesk:/usr/local/openssl/CA# cat serial
01
root@ubtdesk:/usr/local/openssl/CA# cat index.txt
V       110427081202Z           00      unknown /C=KR/O=Soongsil University/OU=Network Security Laboratory/CN=CA(Certificate Authority)/emailAddress=ca@memoz.net

root@ubtdesk:/usr/local/openssl/CA# ls -l newcerts/
합계 4
-rw-r--r-- 1 root root 3322 2010-04-27 17:12 00.pem


옵션 설명을 하자면,
openssl req 커맨드는 인증서 생성을 위한 인증서 생성 요청파일 (.csr 확장자) 을 만드는 커맨드로,
-new 는 신규 인증서 요청 파일 생성
-key 는 인증서 요청 파일에 들어갈 키값 파일을 지정해줍니다. (키값 중 공개키 등을 사용하겠죠?)
-out 은 생성될 인증서 요청 파일 명 입니다.

openssl ca 커맨드는 OpenSSL 에서 제공하는 데모 CA 기능을 이용하는 것으로, 인증기관 자기 자신의 인증서 생성 부터 시작합니다.
-in 인증서 요청 파일(.csr)
-out 인증기관(CA)의 개인키로 서명된 인증서 파일
-selfsign CA의 인증서를 생성할때 사용하는 옵션으로, 자기 자신의 개인키로 자기 자신의 공개키가 포함된 인증서를 생성
-keyfile 인증기관의 키가 있는 위치


위와 같은 과정을 거쳐서, 사설 인증기관을 생성 할 수 있습니다.
신규로 생성되는 인증서는 newcert 디렉토리에 시리얼번호.pem 형태로 저장되며,
발급이력은 index.txt 를 통하여 확인 할 수 있습니다.
반응형
:
Posted by 째시기