android – 使用超过3g时找不到证书路径的信任锚,但在WiFi上工作正常

android – 使用超过3g时找不到证书路径的信任锚,但在WiFi上工作正常,第1张

概述我的 android项目正在使用api 15.我使用HttpsURLConnection类通过https连接到服务器.一切都可以正常通过WiFi,但如果我关闭WiFi并运行超过3克我得到以下内容: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for 我的 android项目正在使用API 15.我使用httpsURLConnection类通过https连接到服务器.一切都可以正常通过WiFi,但如果我关闭WiFi并运行超过3克我得到以下内容:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValIDatorException: Trust anchor for certification path not found.       at org.apache.harmony.xnet.provIDer.Jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:413)   at org.apache.harmony.xnet.provIDer.Jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:257)       at libcore.net.http.httpconnection.setupSecureSocket(httpconnection.java:210)   at libcore.net.http.httpsURLConnectionImpl$httpsEngine.makeSslConnection(httpsURLConnectionImpl.java:477)   at libcore.net.http.httpsURLConnectionImpl$httpsEngine.connect(httpsURLConnectionImpl.java:432)   at libcore.net.http.httpEngine.sendSocketRequest(httpEngine.java:282)   at libcore.net.http.httpEngine.sendRequest(httpEngine.java:232)       at libcore.net.http.httpURLConnectionImpl.connect(httpURLConnectionImpl.java:80)   at libcore.net.http.httpURLConnectionImpl.getoutputStream(httpURLConnectionImpl.java:188)       at libcore.net.http.httpsURLConnectionImpl.getoutputStream(httpsURLConnectionImpl.java:280)

如果我做错了什么,为什么它会通过WiFi工作?

这里有更多信息.

如果我使用openssl查看服务器证书信息,

echo | openssl s_clIEnt -connect myserver.com:443

返回服务器级自签名证书,而

echo | openssl s_clIEnt -connect myserver.com:443 -servername myserver.com

返回“正确”的证书.我的服务器上有多个vhost,每个都有自己的rAPIdssl发布的证书,所以我认为这意味着我需要使用支持TLS的客户端.至少这是我对启动时Apache日志中看到的消息的解释:

name-based SSL virtual hosts only work for clIEnts with TLS server name indication support

如果到目前为止我是正确的,这是否意味着我的移动3G网络可能与TLS搞砸了或者我还应该做些什么呢?

我可以通过继承DefaulthttpClIEnt并导入包含服务器自签名证书的密钥库来获得超过3g的工作,但这绝对不是我的首选选项.

解决方法 添加-servername选项只是在ClIEnt Hello消息中设置Server name Indication字段,这有助于我们在目标主机包含许多证书时选择正确的证书,就像您的情况一样.但是,它与问题无关.

在SSL握手期间,证书以主题/发行者对的形式提供,形成证书链.

即Google.com证书链看起来像这样:

openssl s_clIEnt -connect Google.com:443CONNECTED(00000003)depth=2 C = US,O = GeoTrust Inc.,CN = GeoTrust Global CAverify error:num=20:unable to get local issuer certificateverify return:0---Certificate chain 0 s:/C=US/ST=California/L=Mountain VIEw/O=Google Inc/CN=*.Google.com   i:/C=US/O=Google Inc/CN=Google Internet Authority G2 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority---

收到后,客户端会尝试从下到上验证链中的所有发卡行(根).如果客户端无法验证根证书,则会显示“未找到证书路径的信任锚”消息.

因此,回到WiFi / 3G问题,可能您的移动网络的DNS无法解析证书链中某个中间发行人的地址.

更新:

您可以将发卡机构的证书放入APK,并通过代码中的TrustManager添加.这种方法可以克服接入网络限制(如果有的话).

总结

以上是内存溢出为你收集整理的android – 使用超过3g时找不到证书路径的信任锚,但在WiFi上工作正常全部内容,希望文章能够帮你解决android – 使用超过3g时找不到证书路径的信任锚,但在WiFi上工作正常所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1135438.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存