![](/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.