PKIX path building failed 에러 해결

By | 2022년 11월 9일
Table of Contents

PKIX path building failed 에러 해결

JDK https 통신관련해서 아래 오류가 발생하는 경우가 있다.

pkix path building failed: sun.ecurity.provider.certpath.suncertpathbuilderexception: unable to find valid certification path to requested target

cause: unable to find valid certification path to requested target

원인

수 많은 루트 인증기관 중 내가 인증서를 발급받은 기관이,
JDK 인증기관 목록에 없기때문에 정상적인 인증서라고 해도,
https 통신에 실패한다.

해결책 1

예를 들어, Let's encrypt 에서 발급받은 인증서를,
유효하게 하기 위해서는 아래 작업을,
JDK 마다 해주어야 한다.

개발자가 여러명이면 그 사람들 모두,
PC 에 JDK 가 여러 개 설치되어 있으면 버전마다 전부,
서버에 JDK 가 깔려 있으면 서버에도 이 작업을 해주어야 한다.

curl -o root.cer https://letsencrypt.org/certs/isrgrootx1.pem

curl -o ca.cer https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem

sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -alias letsroot -file root.cer -storepass changeit -noprompt
sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -alias letsca -file ca.cer -storepass changeit -noprompt

해결책 2

JDK 를 인터넷에서 다운받는 것이 아니라,
1 번 작업이 끝난 JDK 를 다운받아 PC 및 서버에 설치한다.

어떻게 보면 가장 합리적인 선택일수도…
사설 인증서를 생성해서 JDK 에 심어놓고,
그 JDK 를 설치하게 하는게 더 좋을 수도 있다.

해결책 3

개발용 도메인을 새로 따고,
JDK 에 포함되어 있는 인증기관에서 인증서를 새로 발급받는다.

해결책 4

Spring Boot 의 경우, 여기 를 참조해서 인증서 유효성 체크를 일시적으로 중지시킬 수 있다.

답글 남기기