java - 如何使用 Gatting 和 SSL 两种方式禁用 SSL 主机名验证

标签 java ssl ssl-certificate gatling sni

我正在尝试使用 SSL 两种方式创建加特林测试,但我无法禁用主机名验证。我正在使用加特林 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")

我可以看到我的 keystore 和 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

最佳答案

如果有人仍在寻找解决方案:此功能已在 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")
}

关于java - 如何使用 Gatting 和 SSL 两种方式禁用 SSL 主机名验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50755456/

相关文章:

java - 提高 Android GPS 性能

java - DSA 问题 - 使用 .NET 创建 DSA 公钥/私钥,通过 Java(android) 使用公钥

java - Jenkins CI - SSL 握手失败

ssl-certificate - 允许的最大 SAN(主题备用名称)数

wix - 将服务器上已安装的 SSL 证书分配给与 WiX iis :Certificate extensions? 的 https 绑定(bind)

java - JNI 错误 : Local reference table overflow 512 entries

java - 变量似乎未初始化

java - 使用 groovy 的 toURL 方法忽略 SSL 错误

.htaccess - 如何使用 htaccess 从特定的 url 或页面中删除 ssl

vue.js - Nuxt.js/Axios 自签名证书错误