Android SSLHandShakeException:Android 6.0.1上的Handschake失败

时间:2017-05-18 08:05:18

标签: android ssl sslhandshakeexception

由于执行请求的一周,我收到此SSLHandschakeException。一直在网上搜索,没有找到解决问题的方法。用于工作的代码,并且在没有更改的情况下停止工作。 SSL证书有效,可在浏览器中使用,也可在Android设备上使用。但不是在应用程序中。

我在带有Android 6.0.1的Nexus 5上运行该应用。该应用程序使用Volley来发出请求,这只是正常的事情。

最奇怪的是,当从设备中删除应用程序,而不是运行应用程序时,它可以正常工作。但那之后就没有了。

完整的堆栈跟踪:

com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: Handshake failed
      at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:151)
      at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
    Caused by: javax.net.ssl.SSLHandshakeException: Handshake failed
      at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:396)
      at com.android.okhttp.internal.http.SocketConnector.connectTls(SocketConnector.java:103)
      at com.android.okhttp.Connection.connect(Connection.java:143)
      at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:185)
      at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
      at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:341)
      at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
      at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
      at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:437)
      at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:388)
      at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:501)
      at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
      at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java)
      at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:110)
      at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
      at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 
    Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
      ... 16 more
      Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
        ... 16 more
      Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
        ... 16 more
      Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xab1e5c00: Failure in SSL library, usually a protocol error
    error:100c543e:SSL routines:ssl3_read_bytes:TLSV1_ALERT_INAPPROPRIATE_FALLBACK (external/boringssl/src/ssl/s3_pkt.c:972 0xab4705c0:0x00000001)
      at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
      at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
        ... 15 more
    Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xab1e5c00: Failure in SSL library, usually a protocol error
    error:100c543e:SSL routines:ssl3_read_bytes:TLSV1_ALERT_INAPPROPRIATE_FALLBACK (external/boringssl/src/ssl/s3_pkt.c:972 0xab4705c0:0x00000001)
      at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
      at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
      ... 15 more
    Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xab1e5c00: Failure in SSL library, usually a protocol error
    error:100c543e:SSL routines:ssl3_read_bytes:TLSV1_ALERT_INAPPROPRIATE_FALLBACK (external/boringssl/src/ssl/s3_pkt.c:972 0xab4705c0:0x00000001)
      at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
      at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
      ... 15 more
    Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xab1e5c00: Failure in SSL library, usually a protocol error
    error:100c5410:SSL routines:ssl3_read_bytes:SSLV3_ALERT_HANDSHAKE_FAILURE (external/boringssl/src/ssl/s3_pkt.c:972 0xab4705c0:0x00000001)
    error:100c009f:SSL routines:ssl3_get_server_hello:HANDSHAKE_FAILURE_ON_CLIENT_HELLO (external/boringssl/src/ssl/s3_clnt.c:750 0xab23259f:0x00000000)
      at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
      at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
      ... 15 more

1 个答案:

答案 0 :(得分:1)

如此处所述:https://github.com/square/okhttp/issues/1582#issuecomment-97104082

你可能处于以下情况之一:

  1.   

    您转到名为 https://example.com 的网站,最终会访问该网站   你似乎在 https://example.com ,但是给你一个    https://no-example.com 的证书。 OkHttp会正确地失败   连接。在像Chrome这样的浏览器中,您可以在控制台中看到警告   "这不是您认为的页面"

  2.   

    其他例外情况表明服务器提供了证书,   但它不受信任,因为根证书不在   客户端设备(或可能已过期)

  3. 您需要调试更多的SSL问题,可能是由于服务器上的证书配置错误或客户端上缺少/过期的证书。当您了解问题的位置时,您可以尝试使用与this类似的内容