Android System.err: javax.net.ssl.SSLHandshakeException: 握手失败

Android System.err: javax.net.ssl.SSLHandshakeException: Handshake failed

有人可以告诉我如何解决 Android 中的 SSLHandshakeException 吗? 请参阅下面的错误,我一直在尝试使用 HttpURLConnection 对象访问这个 URL。

W/bile.allfundin: Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (light greylist, reflection)
W/bile.allfundin: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, linking)
W/bile.allfundin: Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, linking)
W/bile.allfundin: Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, JNI)
I/DynamiteModule: Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:21001
    Selected remote version of com.google.android.gms.ads.dynamite, version >= 21001
D/DynamitePackage: Instantiated singleton DynamitePackage.
    Instantiating com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl
I/Ads: Updating ad debug logging enablement.
V/NativeCrypto: SSL handshake aborted: ssl=0x78ce68f9c8: Failure in SSL library, usually a protocol error
    error:1000042e:SSL routines:OPENSSL_internal:TLSV1_ALERT_PROTOCOL_VERSION (third_party/openssl/boringssl/src/ssl/tls_record.cc:592 0x78ce688688:0x00000001)
W/bile.allfundin: Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (light greylist, linking)
W/bile.allfundin: Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (light greylist, linking)
    Accessing hidden method Ldalvik/system/CloseGuard;->close()V (light greylist, linking)
I/WebViewFactory: Loading com.android.chrome version 79.0.3945.93 (code 394509337)
I/WebViewFactory: SystemProperties GMSVERSION = 9_201910
    Get WebViewChromiumFactoryProviderForO
I/cr_LibraryLoader: Time to load native libraries: 5 ms
V/NativeCrypto: SSL handshake aborted: ssl=0x78ce68f9c8: Failure in SSL library, usually a protocol error
    error:1000042e:SSL routines:OPENSSL_internal:TLSV1_ALERT_PROTOCOL_VERSION (third_party/openssl/boringssl/src/ssl/tls_record.cc:592 0x78ce688688:0x00000001)
W/System.err: javax.net.ssl.SSLHandshakeException: Handshake failed
W/System.err:     at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@19831029@19.8.31 (100406-284611645):38)
        at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192)
        at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149)
        at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
        at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
        at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
W/System.err:     at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
        at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
        at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:244)
        at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
        at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:26)
        at com.techlinemobile.allfunding.utilities.NetworkUtils.getResponseFromHttpUrl(NetworkUtils.java:55)
        at com.techlinemobile.allfunding.MainActivity$scholarshipQueryTask.doInBackground(MainActivity.java:92)
W/System.err:     at com.techlinemobile.allfunding.MainActivity$scholarshipQueryTask.doInBackground(MainActivity.java:84)
        at android.os.AsyncTask.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x78ce68f9c8: Failure in SSL library, usually a protocol error
    error:1000042e:SSL routines:OPENSSL_internal:TLSV1_ALERT_PROTOCOL_VERSION (third_party/openssl/boringssl/src/ssl/tls_record.cc:592 0x78ce688688:0x00000001)
        at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
        at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms@19831029@19.8.31 (100406-284611645):6)
        at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@19831029@19.8.31 (100406-284611645):14)
        ... 22 more
I/chromium: [INFO:library_loader_hooks.cc(51)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader: Expected native library version number "79.0.3945.93", actual native library version number "79.0.3945.93"
W/cr_ChildProcLH: Create a new ChildConnectionAllocator with package name = com.android.chrome, sandboxed = true

看下面我方法的代码

 public static String getResponseFromHttpUrl(URL url) throws IOException {
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        try {
            InputStream in = urlConnection.getInputStream();
            Scanner scanner = new Scanner(in);
            scanner.useDelimiter("\A");

            boolean hasInput = scanner.hasNext();
            if (hasInput) {
                return scanner.next();
            } else {
                return null;
            }
        } finally {
            urlConnection.disconnect();
        }
    }

我不能把 this article 归功于我,但这会告诉你需要安装哪些软件包来解决 TLS/SSLv3 问题。

您可能需要做的另一件事是添加

<application
  android:usesCleartextTraffic="true"
  ...
>

给你的AndroidManifest.xml,这是我在单元测试期间需要做的事情。