암호화 된 사설 SSL 인증서 만들기

🗓️

Self-signed public certificate with encrypted private key

만드는 방법

  1. 그냥 RSA 개인키를 만든다.
  2. 그 RSA 개인키를 encryption 한다.
  3. 서티 사이닝을 한다
  4. encrypted 된 RSA 개인키로 공개키를 만든다.
  5. pem 키

1. RSA 개인키 생성

openssl genrsa -out private.key 2048

2. RSA 개인키 암호화

아래 두가지 중 택 1

openssl pkcs8 -v1 PBE-SHA1-3DES -topk8 \
              -in private.key -out private_enc.key
  • 3DES 방식
openssl pkcs8 -v2 aes-256-cbc -v2prf hmacWithSHA512 -topk8 \
              -in private.key -out private_enc.key
  • AES의 경우. (마찬가지)

3. 서티 사이닝

openssl req -new -key private_enc.key -out private_request.csr
  • 이때 셀프 정보 들어감
Enter pass phrase for private_enc.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]: 
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

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

4. 암호화된 개인키로 공개키 만들기

openssl x509 -req -days 3650 \
             -in private_request.csr -signkey private_enc.key \
             -out private_enc_cert.crt
  • 이때 또 비밀번호 물어봄
Enter pass phrase for private_enc.key:
Certificate request self-signature ok
subject=C=, ST=, L=, O=

5. pem 키 생성

cat private_enc_cert.crt > private_enc.pem
cat private_enc.key >> private_enc.pem
cat private_enc.pem
  • 까보면 encrypted 랑 아닌거랑 시그니처 차이가 있음
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
-----BEGIN ENCRYPTED PRIVATE KEY-----
....
-----END ENCRYPTED PRIVATE KEY-----

최종 아래와 같은 키 목록

[root@ct02 ssl_cert]# ll
합계 20
-rw-------. 1 root root 1704  1월 10 11:45 private.key
-rw-------. 1 root root 1785  1월 10 11:45 private_enc.key
-rw-r--r--. 1 root root 2965  1월 10 13:33 private_enc.pem
-rw-r--r--. 1 root root 1180  1월 10 11:48 private_enc_cert.crt
-rw-r--r--. 1 root root  956  1월 10 11:48 private_request.csr

사용 시 복사하는 키

  • pem 키
  • RSA 키 (암호화 안된 개인키)
cp -rfp /root/ssl_cert/private_enc.pem /etc/ssl/private/private_enc.pem 
cp -rfp /root/ssl_cert/private.key /etc/ssl/private/private_enc.pem.key