2

I have a SSLHandshakeException using HttpsUrlConnection in Android 5.0 lollipop.

05-05 14:54:08.821  10855-11793/com.soonoo.mobilecampus E/INFO﹕ javax.net.ssl.SSLHandshakeException: Handshake failed
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
at com.android.okhttp.Connection.upgradeToTls(Connection.java:238)
at com.android.okhttp.Connection.connect(Connection.java:158)
at com.android.okhttp.Connection.connect(Connection.java:170)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:309)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:242)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:118)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:220)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
at com.soonoo.mobilecampus.User.login(User.java:72)
at com.soonoo.mobilecampus.LoginView$Login.doInBackground(LoginView.java:112)
at com.soonoo.mobilecampus.LoginView$Login.doInBackground(LoginView.java:84)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xaaaf8a00: Failure in SSL library, usually a protocol error
error:1407743E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert inappropriate fallback (external/openssl/ssl/s23_clnt.c:765 0xa9295b25:0x00000000)
        at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
        at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
        ... 19 more

I searched for solutions about solving SSLHandshakeException: Handshake failed however there are no appropriate solutions in web I think.(I tried almost every answers in StackOverflow, etc..)

Reading book about HTTP(http://shop.oreilly.com/product/9781565925090.do), I found that following things occur in the process of handshake

  1. Exchanging protocol version number
  2. Choosing cipher suites
  3. Authenticating server/client

Since Exception message only says Handshake failed, I'm confusing what should I do to fix it. So I want to know what's going wrong with my appication exactly.

Can I get more detailed exception messages?

soonoo
  • 867
  • 1
  • 10
  • 35
  • You need to enable full log level for HttpUrlConnection and try to debug SSL. http://stackoverflow.com/a/12339718/2802875 The reason why it shows just one message for several cases - security. Malefactor should know nothing about details of error. But you, as developer, should know all. So try to debug SSL connection. – Anton Holovin May 09 '15 at 12:24
  • There's a lot more that happens than that. Pre-master secret generation, session resumption, ... – user207421 May 09 '15 at 13:02
  • @EJP I found that `handshake failure` happens after `client hello` and there is no available cipher suites for server suite in `client hello`'s cipher suites list using Wireshark. So I used `HttpsURLConnection.setSSLSocketFactory()` with custom `SSLSocketFactory`(I added cipher suites which server can use using `setEnabledCipherSuites()`) However exception message says added cipher suite is not supported. Can you please give me some advice? – soonoo May 09 '15 at 16:02
  • I found a solution, thank you for every comments... – soonoo May 09 '15 at 16:47
  • @user3858358 What is your solution? Would please give me a hint? – Dog발자 Sep 16 '15 at 07:31
  • 1
    @Joshua I'm sorry it's late. In my case exception occurs since android 5.0 doesn't support server's cipher suite.(https://developer.android.com/intl/ko/about/versions/android-5.0-changes.html#ssl) I added cipher suites that server supports manually.(check cipher suites in https://www.ssllabs.com/ssltest/) – soonoo Sep 16 '15 at 15:18
  • @soonoo OMG. I didn't expect you answer quickly like this. Thanks very much!! – Dog발자 Sep 16 '15 at 15:57
  • Does the solution work with OkHttp? – IgorGanapolsky Oct 23 '15 at 15:57

0 Answers0