我想連接到https
服務器,該服務器有self signed certificate
,但不修改我的客戶端代碼。告訴java客戶端代碼接受自簽名證書
我知道這個問題已被問了很多次,但我無法得到它的工作。下面是我做了什麼:
在Firefox中打開
https
服務器點擊上面的URL信息,那麼更多的信息,然後查看證書,則詳細信息,然後單擊導出。
選擇默認導出類型設置(
X.509 Certificate (PEM)
,保存爲certificate.crt
),並將其保存到磁盤。打開命令提示符,轉到客戶端代碼,這在我的情況是
c:\jdk-7u55-windows-x64\jre\bin
輸入以下命令使用的
java_home
文件夾:keytool -import -v -trustcacerts -alias server-alias -file C:\Downloads\certificate.crt -keystore cacerts.jks -keypass changeit -storepass changeit
我也嘗試過:
keytool -import -v -trustcacerts
-alias server-alias2 -file C:\Downloads\certificate.crt
-keystore keystore.jks
- 重啓客戶端應用程序
這一切之後,我仍然獲得了SSLHandshakeException
(無法找到有效的認證路徑請求的目標)。 全部例外日誌:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我不知道我做錯了什麼,還能做什麼或如何進一步調試。
您可以驗證證書是否已正確導入信任存儲區。使用以下命令列出信任存儲中的證書。 'keytool -list -keystore cacerts.jks' 也請追加與失敗相關的日誌。 – dammina
@dammina是的,列表命令顯示服務器別名是今天導入的。日誌只顯示SSLHandshakeException。我已添加完整的例外 – PeteSpo
http://stackoverflow.com/questions/9210514/unable-to-find-valid-certification-path-to-requested-target-error-even-after-c – dammina