Apache Http-Client SSL-Zertifikat-Fehler

Ich weiß, es ist gefragt worden, bevor, aber ich habe versucht, alle Lösungen, die ich gefunden habe und funktioniert es immer noch nicht.

Grundsätzlich, ich versuche, einige Inhalte über den Apache Http-Client (4.3) und die website, die ich bin, die Verbindung mit SSL Probleme.

Ersten war ich immer und SSLException mit und unrecognized_name Nachricht. Ich habe versucht, dies zu umgehen, indem die jsse.enableSNIExtension Eigenschaft false.

Dann, bekam ich diese exception:
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

Dann habe ich versucht, die Angabe meiner gewonnen SSLFactory würde, dass alle Zertifikate akzeptieren, aber ich bin noch immer die gleiche exception. Hier ist mein code:

private static void sslTest() throws Exception {
    System.setProperty("jsse.enableSNIExtension", "false");

    SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial(null, new TrustSelfSignedStrategy())
            .useTLS()
            .build();

    SSLConnectionSocketFactory connectionFactory =
            new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());

    CookieStore cookieStore = new BasicCookieStore();
    HttpClientContext context = HttpClientContext.create();
    context.setCookieStore(cookieStore);

    CloseableHttpClient httpclient = HttpClients.custom()
            .setSSLSocketFactory(connectionFactory)
            .setDefaultCookieStore(cookieStore)
            .build();

    URI uri = new URIBuilder()
            .setScheme("https")
            .setHost(BASE_URL)
            .build();

    String responseBody = httpclient.execute(new HttpGet(uri), RESPONSE_HANDLER);
}

Alle Hilfe wird sehr geschätzt!

InformationsquelleAutor siki | 2014-07-13
Schreibe einen Kommentar