Search code examples
javasslssl-certificategatlingsni

How to disable SSL hostname verification with Gatling and SSL two way


I'm trying to create a Gatling test with SSL two way but I'm not able to disable hostname verification. I'm using Gatling 2.3. Here's my Gatling configuration :

ssl {
  keyStore {
    type = "JKS"
    file = "keystore.jks"
    password = "changeit"
    #algorithm = ""
  }
  trustStore {
    type = "JKS"
    file = "truststore.jks"
    password = "changeit"
    #algorithm = ""
  }
}
ahc {
  acceptAnyCertificate = true
  ....
}

I have also added this system properties at the beginning of my App

System.setProperty("jdk.tls.allowUnsafeServerCertChange", "true")
System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true")

I can see that my keystore and trutstore are correctly used but I keep having this issue :

java.security.cert.CertificateException: No subject alternative DNS name matching <my_dns> found.
at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:204)
at sun.security.util.HostnameChecker.match(HostnameChecker.java:95)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:455)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:436)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:252)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:136)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1493)
... 28 common frames omitted

Solution

  • If someone is still looking for a solution: this feature has been implemented in v3.0 of Gatling.

    The relevant configuration parameters are:

    ahc {
        enableSni = true                                    # When set to true, enable Server Name indication (SNI)
        enableHostnameVerification = false                  # When set to true, enable hostname verification: SSLEngine.setHttpsEndpointIdentificationAlgorithm("HTTPS")
    }