【问题标题】:SSLPeerUnverifiedException: peer not authenticatedSSLPeerUnverifiedException:对等体未通过身份验证
【发布时间】:2012-10-18 18:43:40
【问题描述】:

又是 SSLPeerUnverified 的沉闷问题,但我没有使用自签名证书。 我尝试使用 https 连接到主机。此主机具有正确的证书,Firefox 和 HttpsUrlConnection 都没有任何问题。 但是尝试使用 HttpClient 进行连接时,我得到了可怕的异常。

有什么线索吗?或者提示在哪里可以看得更近?

谢谢!

编辑:调试输出

main,处理异常:

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

main,getSession() 中的 IOException:

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 httpclient


    【解决方案1】:

    您似乎需要将证书导入您的 JVM 正在使用的可信密钥库中。如果您没有在应用程序中使用其他受信任的密钥库,则这将是“cacerts”。

    您可以在“How to Fix 'SSLPeerUnverifiedException: peer not authenticated' Exception in Groovy / Java ”上按照分步指南进行操作。

    短版:

    1. 运行以下命令,将$ADDRESS替换为网址,减去“https://”:

      echo -n | openssl s_client -connect $ADDRESS:443 | \
        sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/$ADDRESS.cert
      
    2. 运行以下命令,将 $ALIAS 替换为密钥的短名称,将 $ADDRESS 替换为上面的证书名称,将 $PATH 替换为 JRE 中 cacerts 的路径。

       sudo keytool -importcert -alias "$ALIAS" -file /tmp/$ADDRESS.cert \
         -keystore $PATH/cacerts -storepass changeit
      

    【讨论】:

    • 2 天的痛苦以这个答案结束。投票给好人。
    【解决方案2】:

    之前的回答链接失效了,所以我附上:

    https://blogs.oracle.com/java-platform-group/entry/self_signed_certificates_for_a

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      相关资源
      最近更新 更多