Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip only hostname verification with Apache HttpClient

I need to skip hostname verification with httpclient 4.2.1 without changing the trustmanager. I archived this like this:

    httpClient = new DefaultHttpClient(a, b);
    SSLSocketFactory socketFactory = (SSLSocketFactory) httpClient.getConnectionManager().getSchemeRegistry().get("https").getSchemeSocketFactory();
    socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

... but setHostnameVerifier method i used is deprecated. How can i achieve the same thing with using not deprecated methods?

like image 411
user1985273 Avatar asked Dec 14 '22 15:12

user1985273


1 Answers

DON'T DO THIS!!!

As explained to you at https://stackoverflow.com/a/29547114/3081018 already this is a very bad idea and effectively disables all validation, because an attacker then could use any certificate for some other host to mount a man-in-the-middle attack.

It does not get more secure you ask the same question again.

like image 54
Steffen Ullrich Avatar answered Dec 17 '22 05:12

Steffen Ullrich