본문 바로가기
AWS, Infra/linux

[OpenSSL] Wildcard SSL 인증서의 유효성을 확인할 수 없는 경우 (PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target)

by RoJae 2022. 9. 5.

 

 

최근 Wildcard SSL 인증서를 사용하는 경우, 아래와 같은 상황이 벌어졌다.

 

프론트엔드 : “재성님 통신이 안되는데요..?” 🙄
나 (백엔드) : “네 ..?”
프론트엔드 : “PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”라고 하네요??
나 (백엔드) : “Postman API는 잘 되는데..” 😥
 
 
 
 
으잉??

 

생각을 해보니.. 얼마 전에 Postman에서 
“Openssl 통신에 등록되어 있지 않은 SSL 도메인과 통신을 할거냐?” 
 
라고 물어봤던 기억이 났다. ✨
 
 
대강 요런 에러였다..
 
 
 
 
 
 

✔ OpenSSL을 윈도우에서 확인해보자.

이미 회사에서 인증서를 구입하여 사용하고 있고, 그 인증서가 와일드카드 인증서라면
OpenSSL에 등록은 당연히 되어 있을 것이다.
 
OpenSSL 윈도우 버전을 다운받자.
 
 

Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

Minimum system requirements: Windows XP or later 32MB RAM 200MHz CPU 30MB hard drive space Recommended system requirements: Windows XP or later 128MB RAM 500MHz CPU 300MB hard drive space September 9, 2021 - OpenSSL 3.0 is available. Users should currently

slproweb.com

 
OpenSSL 다운로드 (윈도우)
 
 
나는 참고로 Win64 OpenSSL MSI를 다운받았다.
설치를 마지막에, Donation은 미안하지만 무시했다.. 😢
 
 
 
 
기본 경로로 설치를 했다면, 아래처럼 하면 된다.
cd C:\Program Files\OpenSSL-Win64\bin
openssl.exe openssl s_client -connect 도메인 주소:443
 
 
 
나의 경우 결과를 보면..
CONNECTED(000001C8)
depth=0 C = KR, ST = {지역명}, O = "{인증서 기관명칭}. ,Ltd.", CN = *.도메인
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C = KR, ST = {지역명}, O = "{인증서 기관명칭}. ,Ltd.", CN = *.도메인
verify error:num=21:unable to get local issuer certificate
verify return:1
depth=0 C = KR, ST = {지역명}, O = "{인증서 기관명칭}. ,Ltd.", CN = *.도메인
verify return:1
---
Certificate chain
... 생략 ...
---
Server certificate
-----BEGIN CERTIFICATE-----
... 생략 ...
-----END CERTIFICATE-----
... 생략 ...
---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 2438 bytes and written 421 bytes
Verification error: unable to verify the first certificate
---
... 생략 ...
SSL-Session:
    Protocol  : TLSv1.2
    ... 생략 ...
    Start Time: 1662351809
    Timeout   : 7200 (sec)
    Verify return code: 21 (unable to verify the first certificate)
    Extended master secret: yes
---
closed
 
 
 
 
문제가 되는게, 이 부분이다.
CONNECTED(000001C8)
depth=0 C = KR, ST = {지역명}, O = "{인증서 기관명칭}. ,Ltd.", CN = *.도메인
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C = KR, ST = {지역명}, O = "{인증서 기관명칭}. ,Ltd.", CN = *.도메인
verify error:num=21:unable to get local issuer certificate
verify return:1
depth=0 C = KR, ST = {지역명}, O = "{인증서 기관명칭}. ,Ltd.", CN = *.도메인
verify return:1
 
 
 
 
ROOT 체인과 ROOT 인증서를 등록하지 않았으니 오류가 발생하였다.
아마 와일드카드 인증서는 인증이 되었지만, ROOT 인증서가 없어서 발생하는 문제로 보인다.
와일드카드 인증서도 ROOT 인증서와 체인들이 필요할테니 말이다.
unable to get local issuer certificate
 
 
 
즉 ROOT 체인들이 없었다.. 🙄
 
 

 


✔ SSL 인증서를 다시 만들어주자 (PEM-formatted SSL Certificate)

 
간단하게 아래 명령어로 인증서 데이터들을 묶어준다.
나의 경우 haproxy의 문제였으니, PEM 포맷으로 묶었다.
 
순서는 가급적 지켜주자. (개인키 파일 순서는 상관이 없다고 한다) 
# cat 개인키_파일 + 서버인증서 + 루트_체인인증서 > 엮어서 파일 덮어쓰기
cat domain.com_privateKey_nopass.pem star_domain_com_cert.pem Chain_RootCA_Bundle.crt > ./star_domain_com.pem
 
 
 
 
그리고 아래와 같은 부분은 직접 개행해준다.
-----END RSA----------BEGIN RSA------ (이런 부분은 직접 개행해줍니다)
....
-----END RSA-----
 
혹시 ROOT 체인 Bundle이 없다면, 만들어 주면 된다.
어차피 체인들과 ROOT CA 인증서의 조합이다.
 
 
순서는 아래와 같다.
중간체인2 인증서 → 중간체인1 인증서 → ROOT 인증서
 
# Linux or UNIX-like Operating Systems:
cat ComodoRSADomainValidationSecureServerCA.crt ComodoRSAAddTrustCA.crt AddTrustExternalCARoot.crt > yourDomain.ca-bundle

# Windows or DOS:
copy ComodoRSADomainValidationSecureServerCA.crt + ComodoRSAAddTrustCA.crt + AddTrustExternalCARoot.crt yourDomain.ca-bundle
 
 
 
 
나는 아래처럼 했다. (위와 다른게 없다)
cat ChainCA2.crt ChainCA1.crt RootCA.crt > domain.ca-bundle (혹은 domain.crt)
 
 

 


✔ 서버 재기동 및 확인

서버를 재기동하고 다시 확인해보았다.
cd C:\Program Files\OpenSSL-Win64\bin
openssl.exe openssl s_client -connect 도메인 주소:443
 
 
 
결과가 달라졌다. 아마 정상인 것 같다. 😎
CONNECTED(000001CC)
depth=3 C = GB, ST = Greater Manchester, L = Salford, O = Comodo CA Limited, CN = AAA Certificate Services
verify error:num=19:self-signed certificate in certificate chain
verify return:1
depth=3 C = GB, ST = Greater Manchester, L = Salford, O = Comodo CA Limited, CN = AAA Certificate Services
verify return:1
depth=2 C = US, ST = New Jersey, L = Jersey City, O = The USERTRUST Network, CN = USERTrust RSA Certification Authority
verify return:1
depth=1 C = GB, ST = Greater Manchester, L = Salford, O = Sectigo Limited, CN = Sectigo RSA Organization Validation Secure Server CA
verify return:1
depth=0 C = KR, ST = {지역명}, O = "{인증서 기관명칭}. ,Ltd.", CN = *.도메인
verify return:1
---
Certificate chain
 ... 인증서 체인 부분입니다 ...
 ... 생략합니다 ...
---
 
 
 
 
👏 프론트와도 통신이 정상적이고, 문제 없다는 회신을 받았다.
 
 
 
 

✔ 마치면서

와일드카드 인증서의 갱신이 잦은 일은 아니기 때문에 잊고 사는 것 보다는
 
다음에도 헤매지 않도록, 기록을 남겼다. 😁
 
 
 
 

✔ 참고 

 

What is CA bundle? Creating my own bundle file

Our site uses cookies We use cookies to provide our services and analyze site usage in accordance with our Privacy Policy. By choosing "Accept", you agree to the storage of all types of cookies used on the site. If you do not wish to use optional cookies,

cleantalk.org

 

how does an SSL certificate chain bundle arranged?

I have 4 certificate files like this: 1.certum_certificate.crt 2.certum_certificate.pem 3.Intermediate_CA2.cer 4.Intermediate_CA.cer 5.Root_CA.cer I put these files content by this order in a bundle

stackoverflow.com

 
 
 
 
 

 

댓글