Apache Http Client SSL certificate error

siki

I know it's been asked before but I tried all the solutions that I found and it's still not working.

Basically, I'm trying to get some content via Apache Http Client (4.3) and the website that I'm connecting is having some SSL issues.

First, I was getting and SSLException with and unrecognized_name message. I tried to get around this by setting the jsse.enableSNIExtension property to false.

Then, I got this 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

I then tried supplying my won SSLFactory that would accept all certificates but I'm still getting the same exception. Here's my 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);
}

All help is greatly appreciated!

ok2c

Please also note that trusting self-signed certs does not mean trusting any arbitrary cert.

Try setting up your SSL context this way:

SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, 
    new TrustStrategy() {
        @Override
        public boolean isTrusted(final X509Certificate[] chain, final String authType) 
        throws CertificateException {
            return true;
        }
    })
    .useTLS()
    .build();

Please also note that generally trusting certificates indiscriminately defeats the purpose of using SSL in the first place. Use when absolutely necessary or for testing only

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Apache CURL error SSL: CA certificate set, but certificate verification is disabled

From Dev

HTTP error 403.16 - client certificate trust issue

From Dev

How do I use an SSL client certificate with Apache HttpClient?

From Dev

Configure Apache to send SSL Client certificate to backend server

From Dev

Configure Apache to send SSL Client certificate to backend server

From Dev

Client SSL with an Intermediate Certificate

From Dev

SSL Certificate from client

From Dev

Disable client SSL certificate

From Dev

Creating http Client for Apache Camel to call certificate enabled webservice

From Dev

Apache SSL Certificate configuration - sec_error_inadequate_cert_type

From Dev

curl SSL certificate error

From Dev

SSL certificate error

From Dev

SSL certificate error with curl

From Dev

Scala https client with SSL certificate

From Dev

SSL Client certificate verification on linphone

From Dev

SSL certificate for a local apache server

From Dev

Apache serves an old SSL certificate

From Dev

SSL Certificate at a specific URL on Apache

From Dev

COMODO SSL Certificate on apache CentOS

From Dev

Apache SSL error: Re-negotiation handshake failed: Not accepted by client?

From Dev

Facebook Client Certificate error

From Dev

HTTP library for Ruby with HTTPS, SSL Client Certificate and Keep-Alive support?

From Dev

SSL on Apache HTTP Server

From Dev

Java Firebase error "NoClassDefFoundError: org/apache/http/conn/ssl/StrictHostnameVerifier"

From Dev

Client certificate in HTTP (Windows 8.1)

From Dev

HTTPS Client certificate error ERR_SSL_SERVER_CERT_BAD_FORMAT

From Dev

Symfony installation Error: curl: (35) SSL peer handshake failed, the server most likely requires a client certificate to connect

From Dev

HTTPS Client certificate error ERR_SSL_SERVER_CERT_BAD_FORMAT

From Dev

Firefox does not offer client certificate: SSL_ERROR_HANDSHAKE_FAILURE_ALERT

Related Related

  1. 1

    Apache CURL error SSL: CA certificate set, but certificate verification is disabled

  2. 2

    HTTP error 403.16 - client certificate trust issue

  3. 3

    How do I use an SSL client certificate with Apache HttpClient?

  4. 4

    Configure Apache to send SSL Client certificate to backend server

  5. 5

    Configure Apache to send SSL Client certificate to backend server

  6. 6

    Client SSL with an Intermediate Certificate

  7. 7

    SSL Certificate from client

  8. 8

    Disable client SSL certificate

  9. 9

    Creating http Client for Apache Camel to call certificate enabled webservice

  10. 10

    Apache SSL Certificate configuration - sec_error_inadequate_cert_type

  11. 11

    curl SSL certificate error

  12. 12

    SSL certificate error

  13. 13

    SSL certificate error with curl

  14. 14

    Scala https client with SSL certificate

  15. 15

    SSL Client certificate verification on linphone

  16. 16

    SSL certificate for a local apache server

  17. 17

    Apache serves an old SSL certificate

  18. 18

    SSL Certificate at a specific URL on Apache

  19. 19

    COMODO SSL Certificate on apache CentOS

  20. 20

    Apache SSL error: Re-negotiation handshake failed: Not accepted by client?

  21. 21

    Facebook Client Certificate error

  22. 22

    HTTP library for Ruby with HTTPS, SSL Client Certificate and Keep-Alive support?

  23. 23

    SSL on Apache HTTP Server

  24. 24

    Java Firebase error "NoClassDefFoundError: org/apache/http/conn/ssl/StrictHostnameVerifier"

  25. 25

    Client certificate in HTTP (Windows 8.1)

  26. 26

    HTTPS Client certificate error ERR_SSL_SERVER_CERT_BAD_FORMAT

  27. 27

    Symfony installation Error: curl: (35) SSL peer handshake failed, the server most likely requires a client certificate to connect

  28. 28

    HTTPS Client certificate error ERR_SSL_SERVER_CERT_BAD_FORMAT

  29. 29

    Firefox does not offer client certificate: SSL_ERROR_HANDSHAKE_FAILURE_ALERT

HotTag

Archive