Android OKHttp SSLPeerUnverifiedException / SSLHandshakeException

时间:2018-03-17 02:08:50

标签: android ssl https okhttp

我正在连接google例如:(https://finance.google.com/finance?q=NASDAQ%3AAAPL)和android okhttp客户端,但是它会抛出错误:

javax.net.ssl.SSLPeerUnverifiedException: Hostname www.google.com not verified:
        certificate: sha256/7ygD2cyU8sl30bjSfYs6WWBQ1IZVLiPNK04Tfzf5VPk=
        DN: CN=*.facebook.com,O=Facebook\, Inc.,L=Menlo Park,ST=California,C=US
        subjectAltNames: [*.facebook.com, *.xx.fbcdn.net, *.fbsbx.com, *.xz.fbcdn.net, *.facebook.net, *.xy.fbcdn.net, *.messenger.com, fb.com, *.fbcdn.net, *.fb.com, *.m.facebook.com, messenger.com, facebook.com]

2天后,我得到了

javax.net.ssl.SSLPeerUnverifiedException: Hostname www.google.com not verified:
    certificate: sha256/H7hNBz7v4J3Nf2Mj+xzmfoq5xJRS8cXC0gZO+LO06eA=
    DN: CN=syndication.twitter.com,OU=Twitter Security,O=Twitter\, Inc.,L=San Francisco,ST=California,C=US
    subjectAltNames: [syndication.twitter.com, cdn.syndication.twitter.com, syndication-o.twitter.com, syndication.twimg.com, cdn.syndication.twimg.com, syndication-o.twimg.com]
    at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:316)

我试过

builder.hostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });

但没有运气。

它也会抛出异常,如下所示:

javax.net.ssl.SSLHandshakeException: Connection closed by peer at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324) at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:302)

例外。

连接,它以前工作,但最近几天,如果失败,这些天谷歌服务器可能更新了什么?我该怎么办?

1 个答案:

答案 0 :(得分:2)

它似乎与我的代理相关。