Ignorieren, selbst-signierte Zertifikate im Apache-HTTPClient-4.5

Ich versuche alle Zertifikate akzeptieren, und/oder akzeptieren, selbst-signierte Zertifikate mit Apache HTTPClient version 4.5 (tutorial link hier)

Habe ich schon Lösungen, um dieses problem aus einer Reihe von posts auf SO. Bisher hat keiner von Ihnen gearbeitet.

Ich bekomme immer diese Fehlermeldung: Error while trying to execute request. javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

Apache-Docs:

Verwandte StackOverflow Fragen - Hier einige links zu den Lösungen, die ich versucht habe:

Beachten Sie, dass in all diesen Beispielen, die ich bin, auch vorbei an einem cookie speichern, und eine proxy-Anmeldeinformationen Anbieter, die ich zuvor definiert. Diese arbeiten, ich bin nur versuchen, fügen Sie die SSL-Unterstützung.

Versuchen #1

Erstelle ich mein eigenes ssl-Kontext mit SSLContextBuilder und Vertrauen alle selbst unterschrieben Strategien mit TrustSelfSignedStrategy.

SSLContextBuilder sshbuilder = new SSLContextBuilder();
sshbuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sshbuilder.build());

CloseableHttpClient httpclient = HttpClients.custom()
    .setDefaultCredentialsProvider(credsProvider)
    .setDefaultCookieStore(cookieStore)
    .setSSLSocketFactory(sslsf)
    .build();

ERGEBNIS: Hat nicht funktioniert. Habe Error while trying to execute request. javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

Versuchen #2

Gleiche wie oben, aber fügen Sie eine PoolingHttpClientConnectionManager

SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(),SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
        .register("http", new PlainConnectionSocketFactory())
        .register("https", sslsf)
        .build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
cm.setMaxTotal(2000);//max connection

CloseableHttpClient httpclient = HttpClients.custom()
    .setDefaultCredentialsProvider(credsProvider)
    .setDefaultCookieStore(cookieStore)
    .setSSLSocketFactory(sslsf)
    .setConnectionManager(cm)
    .build();

ERGEBNIS: Hat nicht funktioniert. Habe Error while trying to execute request. javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

Versuchen #3

Einfach ALLE Zertifikate akzeptieren durch überschreiben der TrustStrategy (dies wird nicht empfohlen)

SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustStrategy() {
    @Override
    public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        return true;
    }
});
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(),
    SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

CloseableHttpClient httpclient = HttpClients.custom()
    .setDefaultCredentialsProvider(credsProvider)
    .setDefaultCookieStore(cookieStore)
    .setSSLSocketFactory(sslsf)
    .build();

ERGEBNIS: Hat nicht funktioniert. Habe Error while trying to execute request. javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

Versuchen #4

Fand ich etwas nützliches aus diese Antwort:

Als version 4.5 HttpClient deaktiviert SSLv3-Protokoll in der version von
Standard

Hier ist die Lösung, die er gab:

SSLContext sslcontext = SSLContexts.createSystemDefault();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
        sslcontext, new String[] { "TLSv1", "SSLv3" }, null,
        SSLConnectionSocketFactory.getDefaultHostnameVerifier());

Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
        .register("http", PlainConnectionSocketFactory.INSTANCE)
        .register("https", sslConnectionSocketFactory)
        .build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);

httpclient = HttpClients.custom()
    .setDefaultCredentialsProvider(credsProvider)
    .setDefaultCookieStore(cookieStore)
    .setSSLSocketFactory(sslConnectionSocketFactory)
    .setConnectionManager(cm)
    .build();

ERGEBNIS: Hat nicht funktioniert. Habe Error while trying to execute request. javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

InformationsquelleAutor Katie | 2016-10-07
Schreibe einen Kommentar