2016년 9월 28일 수요일

[Java] SSLHandshakeException 처리 방안


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​

SSLHandshakeException 은 https 통신시 인증서 없이 통신할 경우 발생한다고 하는데,
해결 방법은 구글링을 통해 알아본 결과 java keystore 에 인증서를 추가하는 방법이 있다.

1. 첨부 파일을 다운 받고(따로 폴더를 만들어도 된다.) InstallCert.java 로 rename 한다.
2. javac InstallCert.java
3. java -cp ./ InstallCert yourdomain:port
4. 1을 치고 엔터를 눌러 인증서 저장 (jssecacerts 파일이 생성된다) 이 부분은 스크린샷을 넣고 싶으나 생략하고, 참고사이트 2번째를 방문해서 봐주세요.
5. sudo cp jssecacerts "{$JAVA_HOME}"/jre/lib/security/​  : ("{$JAVA_HOME}" 은 환경변수의 값을 넣으면 된다.
6. 3번을 똑같이 치면 ( java -cp ./ InstallCert yourdomain:port )​ 처음과 다르게 성공적으로 접속했다고 뜨면 완료된 것이다.

-----------------------------------------------------------------------------------
[rainn@~/InstallCert] $ java -cp ./ InstallCert ldap.yourcompany.com:636
Loading KeyStore jssecacerts...
Opening connection to ldap.yourcompany.com:636...
Starting SSL handshake...
No errors, certificate is already trusted
Server sent 1 certificate(s):

 1 Subject
   Issuer  CN=yourcompany, DC=yourcompany, DC=com
   sha1    3e b9 5b 42 57 90 55 49 31 e8 98 9e 5c d7 e7 d5 ad 40 5f 17
   md5     50 79 80 d5 29 cd 69 f4 50 74 84 54 2b 4e 1c 3a

Enter certificate to add to trusted keystore or 'q' to quit: [1]

q

KeyStore not changed
------------------------------------------------------------------------------------


참고 사이트

http://knight76.tistory.com/1930 (SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed / java.lang.UnsupportedOperationException at InstallCert$SavingTrustManager.getAcceptedIssuers (installcert.java))
http://lesstif.com/pages/viewpage.action?pageId=12451848​ (Java 의 keystore에 SSL Server 인증서를 import 하는 방법​)​
http://tskwon.tistory.com/323 (MAC 에서 JAVA_HOME 경로 확인)

댓글 없음:

댓글 쓰기