Я получаю эта ошибка:
javax.net.ssl.SSLHandshakeException: получено фатальное предупреждение: Handshake_failure
Насколько я понимаю из документации, из коробки оно должно работать так ( и это работает для сайтов, не использующих https):
Код: Выделить всё
url = "https://dabar.srce.hr/";
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
// trust all certificates
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslSF).build();
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response = httpclient.execute(httpGet);
System.out.println(response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
System.out.println(EntityUtils.toString(entity));
Код: Выделить всё
System.setProperty("jsse.enableSNIExtension", "true");
Код: Выделить всё
SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE) {
String targetHost = "";
@Override
public Socket createLayeredSocket(Socket socket, String target, int port, HttpContext context)
throws IOException {
this.targetHost = target;
return super.createLayeredSocket(socket, target, port, context);
}
@Override
protected void prepareSocket(SSLSocket socket) throws IOException {
try {
PropertyUtils.setProperty(socket, "host", this.targetHost);
} catch (Exception ex) {
}
super.prepareSocket(socket);
}
@Override
public Socket connectSocket(int connectTimeout, Socket socket, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context)
throws IOException {
if (socket instanceof SSLSocket) {
try {
PropertyUtils.setProperty(socket, "host", host.getHostName());
} catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
return super.connectSocket(connectTimeout, socket, host, remoteAddress,
localAddress, context);
}
};
Подробнее здесь: https://stackoverflow.com/questions/388 ... erver-uses
Мобильная версия