簡體   English   中英

SSLHandshakeException:PKIX 路徑構建失敗

[英]SSLHandshakeException: PKIX path building failed

我一直在嘗試調試這個錯誤,但沒有運氣。

本質上,我正在通過我的應用程序聯系外部應用程序。 連接建立良好,應用程序通過回調 URL 聯系我的應用程序,然后我需要向外部應用程序發送最終驗證。 由於 SSLHandShajeException,這最后一步失敗了。

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX 路徑構建失敗:sun.security.provider.certpath.SunCertPathBuilderException:無法找到請求目標的有效認證路徑

我查看了可能的原因,並按照以下步驟創建了一個包含外部應用程序證書的信任庫:

  • 從瀏覽器下載證書鏈
  • 創建信任庫

keytool -import -v -trustcacerts -alias mycert -file x_my_cert_location_x -keystore truststore

  • 在我的 setenv 文件中添加上述信任
  • 重新啟動我的 tomcat 實例。

這並沒有解決問題。

我還在cacert文件中添加了cert,server.xml文件中的connector也是一樣的,如下:

 <Connector port="${catalina.port.https}" server="Apache" protocol="HTTP/1.1" SSLEnabled="true" scheme="https" secure="true" sslProtocol="TLS" clientAuth="false" connectionTimeout="20000" compression="on" compressionMinSize="200" compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml" enableLookups="false" URIEncoding="UTF-8" keystoreFile="my_store_location" keystorePass="myPwd"/>

在 SSL 中調試,我可以看到:

> %% Invalidated: [Session-15, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256]
> http-nio-8080-exec-9, SEND TLSv1.2 ALERT: fatal, description =
> certificate_unknown http-nio-8080-exec-9, WRITE: TLSv1.2 Alert, length
> = 2 [Raw write]: length = 7 0000: 15 03 03 00 02 02 2E ....... http-nio-8080-exec-9, called closeSocket() http-nio-8080-exec-9,
> handling exception: 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

這對我來說沒有任何意義。 我的應用程序在 java 1.8.242 上。 請問對此有什么建議嗎?

該錯誤表明您缺少嘗試訪問的站點的證書。 所以..

  • 使用-Djavax.net.debug=ALL啟動您的 java/tomcat。 在日志中,您應該看到這樣的行(我去掉了時間戳等):

     trustStore is: {your-cacerts-file} trustStore type is: pkcs12 trustStore provider is: the last modified time is: Tue Feb 02 18:29:33 GMT 2021 Reload the trust store Reload trust Reloaded {x} trust certs adding as trusted certificates ( {then you get a big dump of all {x} certs.}

    這樣你就可以確定你的 cacerts 是否真的被閱讀了。

  • 如果您的文件確實被 Tomcat 讀取,那么編寫您自己的小型 Java 程序,該程序使用您的 cacerts 文件(使用 -Djavax.net.ssl.trustStore={path-to-my-file})和上面使用的相同調試參數。 您應該會在您添加的證書中看到它。 然后從那里調試,也許重新發布這個較小的案例。 這不是完整的答案,但至少您會在某種程度上隔離問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM