1

Can someone advise me on how to solve SSLHandshakeException in Android? See below the error I keep getting for this one URL that I am trying to access using HttpURLConnection object.

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$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.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

See the code of my method below

 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();
        }
    }
Abra
  • 19,142
  • 7
  • 29
  • 41
MIike Eps
  • 421
  • 7
  • 24
  • Something is wrong with the server. As you have not posted the URL you use we can't help you on this problem. – Robert Jan 07 '20 at 19:23
  • 1
    if faced this issue in the phone with Android 9 or above, and your URL starts with **http://** instead of **https://**, try to add this line in your **manifest.xml** `android:usesCleartextTraffic="true"`. – Mouaad Abdelghafour AITALI Jan 07 '20 at 19:36
  • Perhaps this will help: [Javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: Failure in SSL library, usually a protocol error](https://stackoverflow.com/questions/29916962/javax-net-ssl-sslhandshakeexception-javax-net-ssl-sslprotocolexception-ssl-han) – Abra Jan 07 '20 at 19:41
  • `TLSV1_ALERT_PROTOCOL_VERSION`: This is the actual reason. In this case, it probably means the server doesn't like the TLS version the client is offering. Perhaps the server requires TLS 1.2, and the device is too old to support it. – greeble31 Jan 07 '20 at 20:29
  • @Robert the url is "https://www2.fundsforngos.org/feed/". android:usesCleartextTraffic="true" is already included in the manifest and the device is running Android P or Android 9 – MIike Eps Jan 07 '20 at 21:05
  • Any code suggestions on how to resolve this TSL issue as I am unable to make changes to the server – MIike Eps Jan 07 '20 at 21:10
  • 1
    According to [SSL Server Test](https://www.ssllabs.com/ssltest/analyze.html?d=www2.fundsforngos.org&s=104.20.75.101&hideResults=on), this server only supports TLS 1.3. – greeble31 Jan 07 '20 at 21:30
  • Any suggestions on how I can read data from this site using the Android app as a client – MIike Eps Jan 08 '20 at 05:52
  • TLS 1.3 requires Android 10. For older versions there seems to be the possibility to use 3rd party libraries. See for example this question and the answers: https://stackoverflow.com/q/55539513/150978 – Robert Jan 08 '20 at 08:24
  • @Robert thanks but the link you provided has no solution. I changed the API version of my application to 29 (10) but the issue persists. Kindly advice – MIike Eps Jan 08 '20 at 10:28
  • The solution marker of StackOverflow is usually useless, therefore you have to check the answers yourself and from my understanding this answer is a solution: https://stackoverflow.com/a/59346159/150978 You have to check for yourself if it really works. Of course you still have to change your code to use OkHttp. – Robert Jan 08 '20 at 10:34
  • i just changed my code to use OkHttp and it still returned Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x78ce6709c8: Failure in SSL library, error – MIike Eps Jan 08 '20 at 11:09

1 Answers1

1

I can't take any credit for this article but this will show you what packages need to be installed to fix the TLS/SSLv3 issue.

The other thing that you may need to do is add

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

to your AndroidManifest.xml, which is something that I needed to do during unit tests.

WeezyKrush
  • 464
  • 5
  • 11