자바(Java)

[자바Java] javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

xemaker 2017. 6. 20. 08:53

타 시스템과 연동하는 부분을 자바로 개발해야 하는데 아래와 같은 오류가 났다.

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target


ssl 관련 인것 같은데.. 


TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager(){

@Override

public X509Certificate[] getAcceptedIssuers(){

return null;

}

@Override

public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException{

}

public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException{

}

}};


try{

SSLContext sc = SSLContext.getInstance("SSL");

sc.init(null, trustAllCerts, new java.security.SecureRandom());

HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

}catch(Exception e){

logger.error("SSLContext : "+ e.toString());

}


위에처럼 코딩 하니까 그 에러가 나지 않았다.