Java Gatling中的SSL签名证书认证

Java Gatling中的SSL签名证书认证,java,scala,ssl,https,gatling,Java,Scala,Ssl,Https,Gatling,我需要与需要CA签名证书的服务对话。我在自己的用户名上有证书,并且在服务器端导入了相同的证书。因此,当我发送请求时,我将生成用于服务器身份验证的证书,服务器将匹配这些证书并发送回响应 当我在浏览器中请求URL时,它会自动选择/请求(在弹出窗口中)并在我的用户名上显示证书,当我选择该用户名时,请求会加载正确的响应 现在我想在加特林模拟同样的事情。然而在加特林我得到了401(未经授权) 我在服务器端验证,当我从浏览器发送请求时,我可以看到证书正在通过,但当我从Gatling发送请求时,证书不会与身份

我需要与需要CA签名证书的服务对话。我在自己的用户名上有证书,并且在服务器端导入了相同的证书。因此,当我发送请求时,我将生成用于服务器身份验证的证书,服务器将匹配这些证书并发送回响应

当我在浏览器中请求URL时,它会自动选择/请求(在弹出窗口中)并在我的用户名上显示证书,当我选择该用户名时,请求会加载正确的响应

现在我想在加特林模拟同样的事情。然而在加特林我得到了401(未经授权)

我在服务器端验证,当我从浏览器发送请求时,我可以看到证书正在通过,但当我从Gatling发送请求时,证书不会与身份验证请求一起发送。在服务器端,它说没有找到证书

我已经将我的用户名CA签名证书导入JDK密钥库并发送请求,如下所示

def execute(): ScenarioBuilder = {
val parameters = Map("$filter" -> "${Id}")
val positionsScenario: ScenarioBuilder = scenario("Locations")
  .feed(accountFeed)
  .exec(requestHandler.getSAPRequest("Locations", parameters))
positionsScenario
}

def getRequest(requestName: String, parameters: Map[String, String]): ChainBuilder = {
val messageBuilder = exec(http(requestName)
  .get(s"$uri")
  .queryParamMap(parameters)
  .check(status.is(200))
)
messageBuilder
}
我已经使用system.property配置了我的证书,因为gatling.conf没有在场景中发送证书

    System.setProperty("gatling.http.ssl.trustStore.file", "C:/Program Files/Java/jdk1.8.0_111/jre/lib/security/cacerts")
    System.setProperty("gatling.http.ssl.trustStore.password", "changeit")
    System.setProperty("gatling.http.ssl.trustStore.type", "JKS")

    System.setProperty("gatling.http.ssl.keyStore.file", "C:/Program Files/Java/jdk1.8.0_111/jre/lib/security/vikram")
    System.setProperty("gatling.http.ssl.keyStore.password", "changeit")
    System.setProperty("gatling.http.ssl.keyStore.type", "JKS")
这是盖特林的日志

    Session(SAPPositions,4,Map(gatling.http.ssl.keyStore.password -> changeit, 
    gatling.http.cache.dns -> io.gatling.http.resolver.ShuffleJdkNameResolver@6e027c67, 
    gatling.http.ssl.trustStore.type -> JKS, gatling.http.ssl.trustStore.password -> changeit, 
    accountId -> (account_id eq '000194878-182182-AU-AUD'), 
    gatling.http.ssl.keyStore.file -> C:/Program Files/Java/jdk1.8.0_111/jre/lib/security/vikram, 
    gatling.http.ssl.keyStore.type -> JKS, gatling.http.referer -> https://d3u.internal.com/sap/op/data/ACCOUNT_LOCATION_API_SRV/locationapi?%24filter=%28account_id%20eq%20%27000194878, 
    gatling.http.ssl.trustStore.file -> C:/Program Files/Java/jdk1.8.0_111/jre/lib/security/cacerts, 
    gatling.http.cookies -> CookieJar(Map(CookieKey(sap-usercontext,d3u.internal.com,/) -> StoredCookie(sap-usercontext=sap-client=100; path=/,true,false,1517797866679))))
 1517797866640,0,KO,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$458/906347731@1443b002)
=========================
HTTP request:
GET https://d3u.internal.com/sap/op/data/ACCOUNT_LOCATION_API_SRV/locationapi?%24filter=%28account_id%20eq%20%27000194878
headers=
Connection: Keep-Alive
Accept: */*
Accept-Encoding: gzip, deflate
Host: d3u.internal.com
=========================
HTTP response:
status=
401 Unauthorized
headers= 
set-cookie: sap-usercontext=sap-client=100; path=/
content-type: text/html; charset=utf-8
sap-system: D3U
www-authenticate: Basic realm="SAP NetWeaver Application Server [D3U/100]"
Transfer-Encoding: chunked
Content-Encoding: gzip
这是我的服务器端日志:

[Thr 139749210060544]   Server-configured Ciphersuites: "TLS_ECDHE_RSA_WITH_AES128_GCM_SHA256:TLS_ECDHE_RSA_WITH_AES256_GCM_SHA384:T
[Thr 139749210060544] Mon Feb  5 11:09:34 2018
[Thr 139749210060544]   Client-offered Ciphersuites: "TLS_RSA_WITH_AES256_CBC_SHA:TLS_RSA_WITH_AES128_CBC_SHA:TLS_RSA_WITH_RC4_128_S
[Thr 139749210060544]   No Client Certificate
[Thr 139749210060544]   New session (TLSv1.2, TLS_RSA_WITH_AES128_CBC_SHA)
[Thr 139749210060544]   HexDump of new SSL session ID { &buf= 7f19c001306c, buf_len= 32 }
[Thr 139749210060544]    00000: 3e 2d 9e fb b6 f3 bf 63  fb 49 27 75 f3 d8 24 c7   >-.....c .I'u..$.
[Thr 139749210060544]    00010: 90 85 bb ed 5e 39 d6 cc  15 27 25 04 fe 29 44 3f   ....^9.. .'%..)D?
[Thr 139749210060544]   SapSSLISessionStartFin(sssl_hdl=7f19c0016b50)==SAP_O_K
[Thr 139749210060544]  in/out: status = "new SSL session,TLSv1.2,TLS_RSA_WITH_AES128_CBC_SHA, **NO client cert"**
[Thr 139749210060544] <<- SapSSLSessionStartNB(sssl_hdl=7f19c0016b50)==SAP_O_K
[Thr 139749210060544] HttpParseRequestHeader: no content length set
[Thr 139749210060544] HttpParseRequestHeader: no transfer-encoding set
[Thr 139749210060544] HttpParseRequestHeader: Version: 1001
[Thr 139749210060544] HttpParseRequestHeader: Keep-Alive: 0
[Thr 139749210060544] HttpParseRequestHeader: no server port set
[Thr 139749210060544] HTTP request (raw) [5/540445/1]:
[Thr 139749210060544]   GET /sap/bc/gui/sap/its/webgui?sap-client=000 HTTP/1.1
[Thr 139749210060544]   host: d3u.internal.com
[Thr 139749210060544]   connection: Close
[Thr 139749210060544] Connection Info: role=Server, local=vd3u01.internal.com:44300, peer=10.137.249.2, protocol=HTTPS
[Thr 139749210060544] ->> SapSSLGetPeerInfo(sssl_hdl=7f19c0016b50, &cert=7f19e605e990, &cert_len=7f19e605e99c,
[Thr 139749210060544]    &subject_dn=7f19e605e988, &issuer_dn=7f19e605e978, &cipher=7f19e605e980)
[Thr 139749210060544] <<- SapSSLGetPeerInfo(sssl_hdl=7f19c0016b50)==SAP_O_K
[Thr 139749210060544]     out: cert_len = <no cert>
[Thr 139749210060544]     out: cipher   = "TLS_RSA_WITH_AES128_CBC_SHA"
[Thr 139749210060544]服务器配置的密码套件:“TLS\u ECDHE\u RSA\u带AES128\u GCM\u SHA256:TLS\u ECDHE\u RSA\u带AES256\u GCM\u SHA384:T
[Thr 139749210060544]2018年2月5日星期一11:09:34
[Thr 139749210060544]客户提供的密码套件:“TLS_RSA_WITH_AES256_CBC_SHA:TLS_RSA_WITH_AES128_CBC_SHA:TLS_RSA_WITH_RC4_128_S”
[Thr 139749210060544]没有客户端证书
[Thr 139749210060544]新会话(TLSv1.2,TLS_RSA_与_AES128_CBC_SHA)
[Thr 139749210060544]新SSL会话ID的HexDump{&buf=7f19c001306c,buf_len=32}
[Thr 139749210060544]00000:3e 2d 9e fb b6 f3 bf 63 fb 49 27 75 f3 d8 24 c7>-…c.I'u。
[Thr 139749210060544]00010:90 85 bb ed 5e 39 d6 cc 15 27 25 04 fe 29 44 3f....9.'%。)D
[Thr 139749210060544]SAPSLISIONSTARTFIN(sssl_hdl=7f19c0016b50)=SAP_O_K
[Thr 139749210060544]输入/输出:状态=“新SSL会话,TLSv1.2,TLS_RSA_,带AES128_CBC_SHA,**无客户端证书”**
[Thr 139749210060544]SapSSLGetPeerInfo(sssl_hdl=7f19c0016b50,&cert=7f19e605e990,&cert_len=7f19e605e99c,
[Thr 139749210060544]&主题(dn=7f19e605e988,&发行人(dn=7f19e605e978,&密码=7f19e605e980)

[Thr 139749210060544]我找到了问题所在。我正在生成的证书不是用于向服务器进行身份验证的有效证书

我如何知道它们是否有效?

刚刚使用下面的行启用了java调试

System.setProperty(“javax.net.debug”、“all”)
并在gatling最初启动时查看调试行。我看到所有对我可疑的东西都是空的

keyStore is : C:/Program Files/Java/jdk1.8.0_111/jre/lib/security/vthaduri
keyStore type is : jks
keyStore provider is : 
init keystore
init keymanager of type SunX509
trustStore is: C:\Program Files\Java\jdk1.8.0_111\jre\lib\security\cacerts
trustStore type is : jks
trustStore provider is : 
使用javax.net.ssl[仅用于调试目的]

我还使用了
javax.net.ssl
而不是
gatling.http.ssl
来设置信任库和密钥库

最后
.disableClientSharing

val httpBuilder: HttpProtocolBuilder = http
      .disableClientSharing
      .baseURL(AppConfig.getRuntimeConfig("endpoints." + environment + ".sap"))
      .connectionHeader("Keep-Alive")
      .acceptHeader("*/*")
      .acceptEncodingHeader("gzip, deflate")

后来我按照galting正确配置了所有内容。

知道这里出了什么问题吗?看起来客户端证书没有发送。任何一个知道加特林的身体帮助都被取消了。更多信息