Java
[Java] javax.net.ssl.SSLException: Certificate doesn't match any of the subject alternative names 에러 해결
Jane Kwon
2021. 12. 3. 15:59
반응형
항상 하던 작업인데도 다시하면 새로운 에러를 뱉는 놀라운 개발의 세계!
이번엔 SSL 인증서가 해당 호스트 네임과 맞지 않는다는 에러가 발생했다.
I/O error on GET request for "https://jane-shop.kr/create-user": Certificate for <jane-shop.kr> doesn't match any of the subject alternative names: [jane-shop.kr, www.jane-shop.kr]; nested exception is javax.net.ssl.SSLException: Certificate for <jane-shop.kr> doesn't match any of the subject alternative names: [jane-shop.kr, www.jane-shop.kr]
구글링 결과, 기존 소스에서
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setConnectTimeout(1000 * 30);
factory.setReadTimeout(1000 * 60);
RestTemplate rest = new RestTemplate(factory);
다른 호스트에서 인증서를 수락할 수 있도록 호스트 검증자(NoopHostnameVerifier)를 지정해야 한다는데
사실 무슨 말인지 잘 이해는 가지 않지만 우선 따라해봤더니 된다.
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setConnectTimeout(1000 * 30);
factory.setReadTimeout(1000 * 60);
TrustStrategy acceptingTrustStrategy = new TrustSelfSignedStrategy();
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(scsf).build();
factory.setHttpClient(httpClient);
RestTemplate rest = new RestTemplate(factory);
후기)
된다고 좋다고 스테이징 서버에 배포했는데,
같이 작업하는 다른 팀에서 아직 SSL 인증서 적용을 안했다고 했다.
괜히 코드만 늘어났다. SSL 인증서 적용하면서 해당 소스도 원래대로 원복해놨다.
반응형