1

I'm trying to disable the ssl certificate check, but nothing seems to work. I'm using Apache HttpClient 4.5.5.

Here is the last solution I tried:

HttpClientBuilder builder = HttpClients.custom();

System.setProperty("javax.net.ssl.trustStore", "NONE");
System.setProperty("jsse.enableSNIExtension", "false");  
System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");

SSLConnectionSocketFactory sslsf = null;

try {
    SSLContextBuilder sslbuilder = new SSLContextBuilder();
    sslbuilder.loadTrustMaterial(null, new TrustStrategy() {
                @Override
                public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                    return true;
                }
    });
    sslsf = new SSLConnectionSocketFactory(sslbuilder.build(), new NoopHostnameVerifier());
} catch (Exception e) { 
    e.printStackTrace();
}

builder.setSSLSocketFactory(sslsf);

CloseableHttpClient httpclient = builder.build();

HttpGet httpget = new HttpGet("https://ru-moto.com/");

HttpResponse response = httpclient.execute(httpget);

InputStream instream = response.getEntity().getContent();

... // Here goes InputStream reading etc.

I got this exception:

javax.net.ssl.SSLProtocolException: no more data allowed for version 1 certificate
    at sun.security.ssl.HandshakeMessage$CertificateMsg.<init>(HandshakeMessage.java:452)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.upgrade(DefaultHttpClientConnectionOperator.java:193)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.upgrade(PoolingHttpClientConnectionManager.java:389)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:416)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)

...

Caused by: java.security.cert.CertificateParsingException: no more data allowed for version 1 certificate
    at sun.security.x509.X509CertInfo.parse(X509CertInfo.java:672)
    at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:167)
    at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1804)
    at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:195)
    at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:102)
    at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
    at sun.security.ssl.HandshakeMessage$CertificateMsg.<init>(HandshakeMessage.java:449)
    ... 26 more

I tried many solutions:

http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/

https://gist.github.com/wellsb1/bb01c625886633b29eec9444821d7f56

https://stackoverflow.com/a/44019472

https://stackoverflow.com/a/43613265

https://stackoverflow.com/a/45768724

https://memorynotfound.com/ignore-certificate-errors-apache-httpclient/

https://stackoverflow.com/a/5297100

Nothing works, I always get the same exception.

Helen
  • 347
  • 1
  • 4
  • 16
  • My guess is that the server has send a X.509v1 certificate which includes X.509v3 extensions. Some instructions on how to create certificates containing SAN with OpenSSL result in such broken certificates. See [this question](https://stackoverflow.com/questions/48303381/err-ssl-server-cert-bad-format-in-chromium-6-3) for a similar problem. – Steffen Ullrich Feb 01 '18 at 10:15

0 Answers0