๋ณธ๋ฌธ์œผ๋กœ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•
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
   at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)

 

 

๊ฐ€๋” ๋‚ฎ์€ ์ž๋ฐ”๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋ฉด apiํ˜ธ์ถœ ํ•  ๋•Œ ssl ์ธ์ฆ์„œ ์—๋Ÿฌ๊ฐ€ ํ„ฐ์ง„๋‹ค.

 

์‹ค์ œ ์„œ๋น„์Šค์—์„œ๋Š” ์ ˆ๋Œ€ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์ด ๋น„์ถ”๊ณ , ํ…Œ์ŠคํŠธ/์ž„์‹œ ํ™•์ธ์šฉ์œผ๋กœ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก

ssl ์ธ์ฆ ์—๋Ÿฌ๋ฅผ ๋ฌด์‹œํ•˜๋Š” ์ฝ”๋“œ๋‹ค.

 

SSLBypassExample.java

import javax.net.ssl.*;
import java.security.cert.X509Certificate;

public class SSLBypassExample {
    public static void disableSSLVerification() throws Exception {
        TrustManager[] trustAllCerts = new TrustManager[] {
                new X509TrustManager() {
                    public X509Certificate[] getAcceptedIssuers() { return null; }
                    public void checkClientTrusted(X509Certificate[] certs, String authType) { }
                    public void checkServerTrusted(X509Certificate[] certs, String authType) { }
                }
        };

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
    }
}

 

ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ apiํ˜ธ์ถœ ์ „์— ๋‹ค์Œ์ฒ˜๋Ÿผ ํ˜ธ์ถœํ•˜๋ฉด ๋œ๋‹ค.

SSLBypassExample.disableSSLVerification();

 

๋ฐ˜์‘ํ˜•