无论如何要在OkHttp上修复此SSL握手错误?

时间:2017-11-14 19:57:08

标签: android okhttp okhttp3

这是用户获得的例外情况。我可以在手机上加载完全相同的URL。

11-14 14:22:10.007 16863 16948 W sy      : javax.net.ssl.SSLHandshakeException: Handshake failed
11-14 14:22:10.007 16863 16948 W sy      :  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:444)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:299)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:268)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
11-14 14:22:10.007 16863 16948 W sy      :  at okhttp3.RealCall.execute(RealCall.java:77)
11-14 14:22:10.007 16863 16948 W sy      :  at sy.a(MyCode.java:360)
11-14 14:22:10.007 16863 16948 W sy      :  at sy.service(MyCode.java:174)
11-14 14:22:10.007 16863 16948 W sy      :  at aoc.service(HttpServlet.java:848)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.Server.handle(Server.java:370)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
11-14 14:22:10.007 16863 16948 W sy      :  at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
11-14 14:22:10.007 16863 16948 W sy      :  at java.lang.Thread.run(Thread.java:762)
11-14 14:22:10.007 16863 16948 W sy      : Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0x6f64d25a00: Failure in SSL library, usually a protocol error
11-14 14:22:10.007 16863 16948 W sy      : error:10000410:SSL routines:OPENSSL_internal:SSLV3_ALERT_HANDSHAKE_FAILURE (external/boringssl/src/ssl/s3_pkt.c:641 0x6f5e670aa0:0x00000001)
11-14 14:22:10.007 16863 16948 W sy      : error:1000009a:SSL routines:OPENSSL_internal:HANDSHAKE_FAILURE_ON_CLIENT_HELLO (external/boringssl/src/ssl/s3_clnt.c:800 0x6fc1a7c2d7:0x00000000)
11-14 14:22:10.007 16863 16948 W sy      :  at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
11-14 14:22:10.007 16863 16948 W sy      :  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:364)
11-14 14:22:10.007 16863 16948 W sy      :  ... 43 more

是否可以以某种方式允许它工作?

感谢。

编辑:我已删除了TrustManager的代码,因为它向我指出它违反了Play商店政策。所以现在我只是想知道为什么我得到这个错误,如果用户可以做任何事情来解决它?奇怪的是,他能够在Chrome上加载相同的资源,甚至可以使用Android System WebView在我自己的应用上加载。只是无法在使用OkHttp的这段代码上加载它。我能够在任何地方加载它,即使是在那段代码上也是如此。

已移除的代码:

这就是我创建OkHttp客户端的方式: <击>     final TrustManager [] trustAllCerts = new TrustManager [] {                     new X509TrustManager(){                         @覆盖                         public void checkClientTrusted(java.security.cert.X509Certificate [] chain,String authType)抛出CertificateException {                         }

<击>
                    @Override
                    public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
                    }

                    @Override
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return new java.security.cert.X509Certificate[]{};
                    }
                }
        };
        // Install the all-trusting trust manager
        final SSLContext sslContext;
        try {
            sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
            final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
            builder.sslSocketFactory(sslSocketFactory);
            builder.hostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String s, SSLSession sslSession) {
                    return true;
                }
            });
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            Log.w(TAG, e);
        }

<击>

0 个答案:

没有答案