使用 HTTPS 连接到 Web 服务时 Android SSL 握手失败

Posted

技术标签:

【中文标题】使用 HTTPS 连接到 Web 服务时 Android SSL 握手失败【英文标题】:Android SSL Handshake Failed when connecting to a web service using HTTPS 【发布时间】:2016-06-10 04:21:03 【问题描述】:

我的 android 应用程序连接到我服务器上的网络服务。昨天一切正常,但今天我得到了错误。

我没有对网络服务和应用程序进行任何更改。我怀疑我的服务器有问题,但不知道从哪里开始。

我在 Android 5 和 Android 6 设备上都对其进行了测试。

这是错误:

HTTPClient: (TiHttpClient-3) [1136,1136] HTTP Error (javax.net.ssl.SSLHandshakeException): Handshake failed
[ERROR] :  TiHTTPClient: javax.net.ssl.SSLHandshakeException: Handshake failed
[ERROR] :  TiHTTPClient:    at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:396)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.http.SocketConnector.connectTls(SocketConnector.java:103)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.Connection.connect(Connection.java:143)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:185)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:341)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:437)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:388)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getHeaders(HttpURLConnectionImpl.java:150)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getHeaderField(HttpURLConnectionImpl.java:194)
[ERROR] :  TiHTTPClient:    at java.net.URLConnection.getHeaderFieldInt(URLConnection.java:543)
[ERROR] :  TiHTTPClient:    at java.net.URLConnection.getContentLength(URLConnection.java:315)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getContentLength(DelegatingHttpsURLConnection.java:146)
[ERROR] :  TiHTTPClient:    at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getContentLength(HttpsURLConnectionImpl.java)
[ERROR] :  TiHTTPClient:    at ti.modules.titanium.network.TiHTTPClient.handleResponse(TiHTTPClient.java:159)
[ERROR] :  TiHTTPClient:    at ti.modules.titanium.network.TiHTTPClient.access$1200(TiHTTPClient.java:85)
[ERROR] :  TiHTTPClient:    at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1207)
[ERROR] :  TiHTTPClient:    at java.lang.Thread.run(Thread.java:818)
[ERROR] :  TiHTTPClient:    Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
[ERROR] :  TiHTTPClient:        ... 20 more
[ERROR] :  TiHTTPClient:        Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
[ERROR] :  TiHTTPClient:            ... 20 more
[ERROR] :  TiHTTPClient:        Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xaef13100: Failure in SSL library, usually a protocol error
[ERROR] :  TiHTTPClient: error:100c5410:SSL routines:ssl3_read_bytes:SSLV3_ALERT_HANDSHAKE_FAILURE (external/boringssl/src/ssl/s3_pkt.c:972 0x9defc240:0x00000001)
[ERROR] :  TiHTTPClient: error:100c009f:SSL routines:ssl3_get_server_hello:HANDSHAKE_FAILURE_ON_CLIENT_HELLO
[ERROR] :  TiHTTPClient:            at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
[ERROR] :  TiHTTPClient:            at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
[ERROR] :  TiHTTPClient:            ... 19 more
[ERROR] :  TiHTTPClient:    Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xaef13100: Failure in SSL library, usually a protocol error
[ERROR] :  TiHTTPClient: error:100c5410:SSL routines:ssl3_read_bytes:SSLV3_ALERT_HANDSHAKE_FAILURE (external/boringssl/src/ssl/s3_pkt.c:972 0x9defc240:0x00000001)
[ERROR] :  TiHTTPClient: error:100c009f:SSL routines:ssl3_get_server_hello:HANDSHAKE_FAILURE_ON_CLIENT_HELLO (external/boringssl/src/ssl/s3_clnt.c:750 0xab1e350f:0x00000000)
[ERROR] :  TiHTTPClient:        at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
[ERROR] :  TiHTTPClient:        at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
[ERROR] :  TiHTTPClient:        ... 19 more
[ERROR] :  TiHTTPClient: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xaef13100: Failure in SSL library, usually a protocol error
[ERROR] :  TiHTTPClient: error:100c5410:SSL routines:ssl3_read_bytes:SSLV3_ALERT_HANDSHAKE_FAILURE (external/boringssl/src/ssl/s3_pkt.c:972 0x9defc240:0x00000001)
[ERROR] :  TiHTTPClient: error:100c009f:SSL routines:ssl3_get_server_hello:HANDSHAKE_FAILURE_ON_CLIENT_HELLO (external/boringssl/src/ssl/s3_clnt.c:750 0xab1e350f:0x00000000)
[ERROR] :  TiHTTPClient:    at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
[ERROR] :  TiHTTPClient:    at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
[ERROR] :  TiHTTPClient:    ... 19 more

非常感谢任何指针。谢谢。

【问题讨论】:

只需检查您的证书有效期是否已过期。或者假设如果您在应用程序中使用自签名证书。但是,服务器端使用授权证书意味着,可能会出现这种类型的错误。 【参考方案1】:

您应该检查您的证书是否有问题 你可以在这里找到更多信息http://developer.android.com/training/articles/security-ssl.html#UnknownCa

【讨论】:

以上是关于使用 HTTPS 连接到 Web 服务时 Android SSL 握手失败的主要内容,如果未能解决你的问题,请参考以下文章

我可以在 JavaFX 中将自签名证书添加到我的 WebEngine 以连接到 https Web 服务器吗?

如何使用节点 js/Oauth 连接到交换 Web 服务

在 asp.net 中,客户端连接到生产服务器时 Web 服务端点不正确

.NET 客户端连接到 ssl Web API

使用 ODBC 从 Web 服务器连接到 MS Access 数据库时找不到数据源名称

使用?wsdl URI查询将LinqPad连接到WCF Web服务