【发布时间】:2012-08-10 01:58:25
【问题描述】:
我使用 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 连接到他们的网络服务。为此,我知道我需要在 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 是从我的浏览器中导出的,客户端私钥为PKCS,服务器证书为x509 Cert PKCS#7 w/ Chain'. Then opened them up in Portecle and exported them both asJKS` 文件。
假设 Java 代码是合法的,我如何确定我已正确创建了 keystore 和 truststore?
非常感谢。
【问题讨论】: