Java:在 Spring 引导中连接到服务时出现 SSLHandshake 异常
Java: SSLHandshake Exception while connecting to a service in Spring Boot
我正在开发 Apple Pay POC,在此过程中,我尝试使用休息服务,但很难通过 Java 代码连接到该服务器。
但是,下面的 curl 命令可以正常工作。
curl -v --cert publicCert.pem:srk --key privateKey.pem -H Content-type:application/json --request POST --data
{
"merchantIdentifier": "merchant.com.xxxx.srk-demos",
"displayName": "poc",
"initiative": "web",
"initiativeContext": "srk-demos.xxxx.com"
}
https://apple-pay-gateway-cert.apple.com/paymentservices/startSession
我得到的只是一个 merchant.p12
文件,我从中提取了 pem 格式的私钥和 public 证书。私钥的密码与p12文件相同,在本例中为srk
。
我正在使用 Spring 使用 RestTemplate
引导来使用该服务。将 mic.p12
直接导入到 jks。
并且,将 jks 放入我的 spring 启动应用程序的 resources
文件夹中。
并按照 Sasha Shpota for this relevant Whosebug question 方法中建议的代码通过代码加载此 jks,但在我的情况下它也不起作用。
对此有任何想法或建议,我们将不胜感激。我可以使用 java.lang.Runtime
class 调用上面的工作 curl
命令,但我认为这不是有效的 java 方法。
我正在使用 OpenJDK8
我关注了 this post,它对我有用。
已创建具有私钥的身份存储 + public 包含服务器证书的证书和信任存储。
我之前错过了什么?尝试使用以下代码片段加载 p12 文件
try(CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(yourLoadSSLFunction()).build()){
}
不应包含在 try with resources 中,而应像这样使用
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(yourLoadSSLFunction()).build()
RestTemplate restTemplate = new RestTemplate();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
restTemplate.setRequestFactory(requestFactory);
我正在开发 Apple Pay POC,在此过程中,我尝试使用休息服务,但很难通过 Java 代码连接到该服务器。
但是,下面的 curl 命令可以正常工作。
curl -v --cert publicCert.pem:srk --key privateKey.pem -H Content-type:application/json --request POST --data
{
"merchantIdentifier": "merchant.com.xxxx.srk-demos",
"displayName": "poc",
"initiative": "web",
"initiativeContext": "srk-demos.xxxx.com"
}
https://apple-pay-gateway-cert.apple.com/paymentservices/startSession
我得到的只是一个 merchant.p12
文件,我从中提取了 pem 格式的私钥和 public 证书。私钥的密码与p12文件相同,在本例中为srk
。
我正在使用 Spring 使用 RestTemplate
引导来使用该服务。将 mic.p12
直接导入到 jks。
并且,将 jks 放入我的 spring 启动应用程序的 resources
文件夹中。
并按照 Sasha Shpota for this relevant Whosebug question 方法中建议的代码通过代码加载此 jks,但在我的情况下它也不起作用。
对此有任何想法或建议,我们将不胜感激。我可以使用 java.lang.Runtime
class 调用上面的工作 curl
命令,但我认为这不是有效的 java 方法。
我正在使用 OpenJDK8
我关注了 this post,它对我有用。
已创建具有私钥的身份存储 + public 包含服务器证书的证书和信任存储。
我之前错过了什么?尝试使用以下代码片段加载 p12 文件
try(CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(yourLoadSSLFunction()).build()){
}
不应包含在 try with resources 中,而应像这样使用
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(yourLoadSSLFunction()).build()
RestTemplate restTemplate = new RestTemplate();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
restTemplate.setRequestFactory(requestFactory);