如何使用Gatling和SSL双向禁用SSL主机名验证

问题描述 投票:1回答:2

我正在尝试使用SSL双向创建Gatling测试,但我无法禁用主机名验证。我正在使用加特林2.3。这是我的加特林配置:

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

我还在我的应用程序开头添加了这个系统属性

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

我可以看到我的密钥库和trutstore正确使用但我一直有这个问题:

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
java ssl ssl-certificate gatling sni
2个回答
1
投票

Gatling SSL documentation你可以尝试禁用SNI(-Djsse.enableSNIExtension=false)。但是,如果你真的需要SNI(SSL虚拟主机),你不想这样做,你需要编写自己的HostNameVerifier代码,虽然我不知道如何在Gatling中包含它。


1
投票

如果有人仍在寻找解决方案:此功能已在Gatling的v3.0中实现。

相关配置参数为:

ahc {
    enableSni = true                                    # When set to true, enable Server Name indication (SNI)
    enableHostnameVerification = false                  # When set to true, enable hostname verification: SSLEngine.setHttpsEndpointIdentificationAlgorithm("HTTPS")
}
© www.soinside.com 2019 - 2024. All rights reserved.