![](/img/trans.png)
[英]Mutual Authentication(Two-Way TLS/SSL) with cloud residing KeyStores and TrustStores(Secret Manager) -Spring boot
[英]Mutual SSL - getting the key/truststores in the proper formats
我使用OpenSSL生成了CSR:
openssl req -out MyCompanyCsr.csr -new -newkey rsa:2048 -nodes -keyout MyCompanyPrivateKey.key
因此,开始时,我们有:
- MyCompanyPrivateKey.key
- MyCompanyCsr.csr
然后,我将其发送给我们的集成合作伙伴,该合作伙伴回复了3个文件:
- PartnerIntermediateCa.crt
- PartnerRootCa.crt
- MyCompanyCsr.crt
现在,我需要使用相互SSL连接到他们的Web服务。 为此,我知道我需要在我的SSLSocketFactory中为JAXB设置信任库和密钥库。
我正在使用以下方法在Java中实例化密钥库和信任库:
KeyStore trustStore = KeyStore.getInstance("JKS");
InputStream tsis = ClassLoader.getSystemResourceAsStream(trustStorePath);
trustStore.load(tsis, "mypassword".toCharArray());
tsis.close();
KeyStore keyStore = KeyStore.getInstance("JKS");
InputStream ksis = ClassLoader.getSystemResourceAsStream(keyStorePath);
keyStore.load(ksis, "mypassword".toCharArray());
if (ksis != null) {
ksis.close();
}
TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(trustStore);
KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, "mypassword".toCharArray());
但是,尝试在连接服务器时使用此代码会引发SSLHandshakeException
并显示消息http.client.failed
:
com.sun.xml.ws.client.ClientTransportException: HTTP transport error:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
我使用的keystore
和truststore
keystore
是从浏览器中导出的,其中客户端私钥作为PKCS
,服务器证书作为x509 Cert PKCS#7 w/ Chain'. Then opened them up in Portecle and exported them both as
x509 Cert PKCS#7 w/ Chain'. Then opened them up in Portecle and exported them both as
JKS`文件。
假设Java代码是合法的,如何确定正确创建了keystore
和truststore
keystore
?
非常感谢。
我终于想通了。 我使用了FireFox和Portecle 。
在浏览器中安装服务器证书和私钥。
注意:一个总是令人困惑的地方:就Portecle / Java而言,“ truststore”和“ keystore”都是密钥库 。 唯一的不同是, 我们在客户端中用作密钥库的密钥将具有除公共证书之外的私有密钥。
使用服务器证书构建的TrustStore:
另存为ffTestServerCert.crt
通过以下方法在Portecle中打开:检查菜单>检查证书>选择ffTestServerCert.crt
另存为.pem文件在磁盘上(例如,说我有caCert1.pem,caCert2.pem,caCert3.pem)
在Portecle中创建新的密钥库:File> New Keystore> JKS
对要导入的任何其他证书重复上述步骤(我全部完成了3个)。
在Portecle中保存密钥库:
恭喜,这是有效的truststore 。
使用私钥和服务器证书构建的KeyStore:
应该说它们已导出,请单击“确定”。
在Portecle中打开钥匙
输入上面选择的密码
使用Portecle转换为JKS
password
的内部 password
。 打好
保存密钥库 :
已完成
现在,您已经具有正确配置的clientTrustStore.jks和clientKeyStore.jks用于验证客户端。
要查看如何现在使用它们的示例,您可以签出: 具有双向SSL的SOAP-如何发送凭据?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.