Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java SSL: how to disable hostname verification

Is there a way for the standard java SSL sockets to disable hostname verfication for ssl connections with a property? The only way I found until now, is to write a hostname verifier which returns true all the time.

Weblogic provides this possibility, it is possible to disable the hostname verification with the following property:

-Dweblogic.security.SSL.ignoreHostnameVerify

like image 984
paweloque Avatar asked May 17 '11 13:05

paweloque


People also ask

How disable SSL hostname verification?

Under Domain > Environment > Servers, double-click the server name. Click the SSL tab. Under Advanced, update Hostname Verification to None. Save the change.

What is SSL hostname verification?

A host name verifier ensures the host name in the URL to which the client connects matches the host name in the digital certificate that the server sends back as part of the SSL connection.


1 Answers

It should be possible to create custom java agent that overrides default HostnameVerifier:

import javax.net.ssl.*; import java.lang.instrument.Instrumentation;  public class LenientHostnameVerifierAgent {     public static void premain(String args, Instrumentation inst) {         HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {             public boolean verify(String s, SSLSession sslSession) {                 return true;             }         });     } } 

Then just add -javaagent:LenientHostnameVerifierAgent.jar to program's java startup arguments.

like image 97
Vadzim Avatar answered Oct 07 '22 18:10

Vadzim