프로그래밍
SSL 인증서 변환
코린이골퍼
2023. 4. 4. 14:40
SSL 인증서가 적용된 사이트 관리자는 1년마다 인증서 갱신 작업을 해야 합니다.
자주 하는 일이 아니기 때문에 OpenSSL 명령어를 항상 기억하고 있진 않아
그때그때 검색을 통해 작업을 합니다.
그래서 제가 자주 사용하는 명령어를 모아봤습니다.
인증서 파일 구성
CSR 자동생성 및 NginX용으로 구매를 했기 때문에 파일 구성은 다음과 같고
NginX 서버에 적용할 때는 네모박스의 두 파일만 교체해주면 간단하게 작업이 끝납니다.
함께 동봉된 star_renaissance-code_com.zip이 인증서 원본입니다.
인증서 원본의 압축을 풀어보면 아래와 같습니다.
- Root 인증서 1개
- Chain 인증서 2개
- Root와 Chain들을 합쳐놓은 Bundle 인증서 1개
- 신청한 도메인 인증서 1개
로 구성되어 있는것을 볼 수 있습니다.
이제 이 인증서를 가지고 IIS용 PFX인증서, Tomcat용 JKS인증서를 만들어 보겠습니다.
인증서 합치기
사전 작업으로 도메인 인증서와 Bundle 인증서를 하나로 합쳐줍니다.
star_renaissance-code_com_cert.pem + Chain_RootCA_Bundle.crt
Linux
> cat star_renaissance-code_com_cert.pem Chain_RootCA_Bundle.crt > star_renaissance-code_com.crt
PowerShell
> cat star_renaissance-code_com_cert.pem, Chain_RootCA_Bundle.crt | Out-File -Encoding ascii -FilePath star_renaissance-code_com.crt
PFX 만들기
조금전에 합친 crt 파일과 밖의 폴더에 있던 key 파일을 이용하여 PKCS#12(.pfx)로 변환 합니다.
> openssl pkcs12 -export -in star_renaissance-code_com.crt -inkey renaissance-code_com_NginX_nopass_key.pem -out star_renaissance-code_com.pfx
Loading 'screen' into random state - done
Enter Export Password:
Verifying - Enter Export Password:
unable to write 'random state'
만들어진 PFX파일에 대하여 인증서 가져오기를 한 결과 아래와 같이
정상적으로 만들어진 것을 확인할 수 있습니다.
PFX 인증서 확인
> openssl pkcs12 -info -in star_renaissance-code_com.pfx
Enter Import Password:
MAC Iteration 2048
MAC verified OK
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048
Certificate bag
Bag Attributes
localKeyID: 3C 13 F9 C4 22 FC 16 11 9C C0 F2 5E FE EC 03 CF AF E4 70 4C
subject=/CN=*.?????.?????.???
issuer=/C=GB/ST=Greater Manchester/L=Salford/O=Sectigo Limited/CN=Sectigo RSA Domain Validation Secure Server CA
PFX -> JavaKeyStore(.jks) 변환
> keytool -importkeystore -srckeystore star_renaissance-code_com.pfx -srcstoretype pkcs12 -destkeystore star_renaissance-code_com.jks -deststoretype jks
키 저장소 star_renaissance-code_com.pfx을(를) star_renaissance-code_com.jks(으)로 임포트하는 중...
대상 키 저장소 비밀번호 입력:
새 비밀번호 다시 입력:
소스 키 저장소 비밀번호 입력:
1 별칭에 대한 항목이 성공적으로 임포트되었습니다.
임포트 명령 완료: 성공적으로 임포트된 항목은 1개, 실패하거나 취소된 항목은 0개입니다.
JavaKeyStore(.jks) -> PFX 변환
> keytool -importkeystore -srckeystore star_renaissance-code_com.jks -srcstoretype JKS -srcstorepass "qwer1234" -destkeystore star_renaissance-code_com2.pfx -deststoretype PKCS12 -deststorepass "pw1234"
키 저장소 star_renaissance-code_com.jks을(를) star_renaissance-code_com2.pfx(으)로 임포트하는 중...
<1>에 대한 키 비밀번호를 입력하십시오.
1 별칭에 대한 항목이 성공적으로 임포트되었습니다.
임포트 명령 완료: 성공적으로 임포트된 항목은 1개, 실패하거나 취소된 항목은 0개입니다.
서버 내에서 SSL 인증서 확인하기
> curl https://127.0.0.1 -kIv
* About to connect() to 127.0.0.1 port 443 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 443 (#0)
* Initializing NSS with certpath: /etc/pki/nssdb
* warning: ignoring unsupported value (1) of ssl.verifyhost
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* Peer's certificate issuer is not recognized: 'CN=Sectigo RSA Organization Validation Secure Server CA,O=Sectigo Limited,L=Salford,ST=Greater Manchester,C=GB'
* SSL certificate verify ok.