{"action":"created","issue":{"url":"https://api.github.com/repos/koush/AndroidAsync/issues/393","labels_url":"https://api.github.com/repos/koush/AndroidAsync/issues/393/labels{/name}","comments_url":"https://api.github.com/repos/koush/AndroidAsync/issues/393/comments","events_url":"https://api.github.com/repos/koush/AndroidAsync/issues/393/events","html_url":"https://github.com/koush/AndroidAsync/issues/393","id":107019638,"number":393,"title":"SSL handshake fails with self signed certificate on Android 4.3 (and 4.2.2)","user":{"login":"nbrocard","id":1597414,"avatar_url":"https://avatars.githubusercontent.com/u/1597414?v=3","gravatar_id":"","url":"https://api.github.com/users/nbrocard","html_url":"https://github.com/nbrocard","followers_url":"https://api.github.com/users/nbrocard/followers","following_url":"https://api.github.com/users/nbrocard/following{/other_user}","gists_url":"https://api.github.com/users/nbrocard/gists{/gist_id}","starred_url":"https://api.github.com/users/nbrocard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbrocard/subscriptions","organizations_url":"https://api.github.com/users/nbrocard/orgs","repos_url":"https://api.github.com/users/nbrocard/repos","events_url":"https://api.github.com/users/nbrocard/events{/privacy}","received_events_url":"https://api.github.com/users/nbrocard/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-17T16:11:51Z","updated_at":"2015-10-20T08:18:00Z","closed_at":null,"body":"Hi,, when trying to connect to a HTTPS url with AndroidAsync, I get the following stacktrace :\r\n```java\r\n javax.net.ssl.SSLException: Fatal alert received handshake_failure\r\n at org.apache.harmony.xnet.provider.jsse.SSLEngineImpl.unwrap(SSLEngineImpl.java:485)\r\n at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:383)\r\n at com.koushikdutta.async.AsyncSSLSocketWrapper$5.onDataAvailable(AsyncSSLSocketWrapper.java:191)\r\n at com.koushikdutta.async.Util.emitAllData(Util.java:23)\r\n at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:146)\r\n at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:788)\r\n at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:626)\r\n at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:41)\r\n at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:568)\r\n```\r\n\r\nHere is the code I use :\r\n```java\r\n        SSLContext sslcontext = null;\r\n        TrustManager[] trustManagers = null;\r\n        try {\r\n            trustManagers = CertUtils.getTrustManagers(mContext);\r\n            sslcontext = SSLContext.getInstance(\"TLS\");\r\n            sslcontext.init(null, trustManagers, null);\r\n        } catch (NoSuchAlgorithmException | KeyManagementException | CertificateException | IOException | KeyStoreException e) {\r\n            e.printStackTrace();\r\n        }\r\n\r\n        AsyncHttpClient asyncHttpClient = AsyncHttpClient.getDefaultInstance();\r\n        asyncHttpClient.insertMiddleware(new ConscryptMiddleware(mContext, asyncHttpClient.getSSLSocketMiddleware()));\r\n        asyncHttpClient.getSSLSocketMiddleware().setSSLContext(sslcontext);\r\n        asyncHttpClient.getSSLSocketMiddleware().setTrustManagers(trustManagers);\r\n\r\n        asyncHttpClient.execute(\"https://url:443\", new HttpConnectCallback() {\r\n            @Override\r\n            public void onConnectCompleted(Exception ex, AsyncHttpResponse response) {\r\n                if (ex != null) {\r\n                    Log.e(\"AsyncTest\", \"exception ? \" + ex);\r\n                }\r\n                if (response != null) {\r\n                    Log.d(\"AsyncTest\", \"result : \" + response.code());\r\n                }\r\n\r\n            }\r\n        });\r\n```\r\nI load custom CA from assets. The SSL context I use here works when I try to connect using HttpsUrlConnection :\r\n\r\n```java\r\n        try {\r\n            URL url = new URL(\"https://url:443\");\r\n            final HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();\r\n            urlConnection.setSSLSocketFactory(sslcontext.getSocketFactory());\r\n            new Thread() {\r\n                @Override\r\n                public void run() {\r\n                    try {\r\n                        urlConnection.connect();\r\n                        InputStream inputStream = urlConnection.getInputStream();\r\n\r\n                        //read stream\r\n\r\n                    } catch (IOException e) {\r\n                        e.printStackTrace();\r\n                    }\r\n                }\r\n            }.start();\r\n        } catch (MalformedURLException e) {\r\n            e.printStackTrace();\r\n        } catch (IOException e) {\r\n            e.printStackTrace();\r\n        }\r\n```\r\n\r\nIt works on Android M preview 3, maybe because of conscrypt used by default ?"},"comment":{"url":"https://api.github.com/repos/koush/AndroidAsync/issues/comments/149473912","html_url":"https://github.com/koush/AndroidAsync/issues/393#issuecomment-149473912","issue_url":"https://api.github.com/repos/koush/AndroidAsync/issues/393","id":149473912,"user":{"login":"bleuf1sh","id":2596120,"avatar_url":"https://avatars.githubusercontent.com/u/2596120?v=3","gravatar_id":"","url":"https://api.github.com/users/bleuf1sh","html_url":"https://github.com/bleuf1sh","followers_url":"https://api.github.com/users/bleuf1sh/followers","following_url":"https://api.github.com/users/bleuf1sh/following{/other_user}","gists_url":"https://api.github.com/users/bleuf1sh/gists{/gist_id}","starred_url":"https://api.github.com/users/bleuf1sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleuf1sh/subscriptions","organizations_url":"https://api.github.com/users/bleuf1sh/orgs","repos_url":"https://api.github.com/users/bleuf1sh/repos","events_url":"https://api.github.com/users/bleuf1sh/events{/privacy}","received_events_url":"https://api.github.com/users/bleuf1sh/received_events","type":"User","site_admin":false},"created_at":"2015-10-20T08:18:00Z","updated_at":"2015-10-20T08:18:00Z","body":"I'm having the same issue on a Samsung Mega running 4.2.2\r\n```\r\n10-20 11:05:02.131: D/ExampleLogoutUtilsREQ(9413): (0 ms) https://stagingcdn.example.com/logout?l=en&cv=9999999&dl=en&os=a&sv=5&sid=MTsxOzUzZjllZWMyZGIxYTdkMWMwOGMyNGNlODs1OzJmYTdhYTZhOWM4NzZmMmRjOWM1OGNiMGEwODkyZjIxO2E0MzU1NjFkZTdiM2U3OWQ0NjZjZDNkNGZmNzEzZWQ0QQ%3D%3D: Executing request.\r\n10-20 11:05:02.141: D/ExampleLogoutUtilsREQ(9413): (6 ms) https://stagingcdn.example.com/logout?l=en&cv=9999999&dl=en&os=a&sv=5&sid=MTsxOzUzZjllZWMyZGIxYTdkMWMwOGMyNGNlODs1OzJmYTdhYTZhOWM4NzZmMmRjOWM1OGNiMGEwODkyZjIxO2E0MzU1NjFkZTdiM2U3OWQ0NjZjZDNkNGZmNzEzZWQ0QQ%3D%3D: Connecting socket\r\n10-20 11:05:02.451: V/ExampleLogoutUtilsREQ(9413): (314 ms) https://stagingcdn.example.com/logout?l=en&cv=9999999&dl=en&os=a&sv=5&sid=MTsxOzUzZjllZWMyZGIxYTdkMWMwOGMyNGNlODs1OzJmYTdhYTZhOWM4NzZmMmRjOWM1OGNiMGEwODkyZjIxO2E0MzU1NjFkZTdiM2U3OWQ0NjZjZDNkNGZmNzEzZWQ0QQ%3D%3D: socket connected\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413): (314 ms) https://stagingcdn.example.com/logout?l=en&cv=9999999&dl=en&os=a&sv=5&sid=MTsxOzUzZjllZWMyZGIxYTdkMWMwOGMyNGNlODs1OzJmYTdhYTZhOWM4NzZmMmRjOWM1OGNiMGEwODkyZjIxO2E0MzU1NjFkZTdiM2U3OWQ0NjZjZDNkNGZmNzEzZWQ0QQ%3D%3D: Connection error\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413): null\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413): javax.net.ssl.SSLException\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncSSLSocketWrapper$2.onCompleted(AsyncSSLSocketWrapper.java:106)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncNetworkSocket.reportClose(AsyncNetworkSocket.java:172)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncNetworkSocket.close(AsyncNetworkSocket.java:180)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncSSLSocketWrapper.report(AsyncSSLSocketWrapper.java:424)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncSSLSocketWrapper.access$100(AsyncSSLSocketWrapper.java:30)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncSSLSocketWrapper$5.onDataAvailable(AsyncSSLSocketWrapper.java:221)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.Util.emitAllData(Util.java:22)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:146)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:788)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:626)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:41)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:568)\r\n10-20 11:05:02.451: V/ExampleLogoutUtilsREQ(9413): (316 ms) https://stagingcdn.example.com/logout?l=en&cv=9999999&dl=en&os=a&sv=5&sid=MTsxOzUzZjllZWMyZGIxYTdkMWMwOGMyNGNlODs1OzJmYTdhYTZhOWM4NzZmMmRjOWM1OGNiMGEwODkyZjIxO2E0MzU1NjFkZTdiM2U3OWQ0NjZjZDNkNGZmNzEzZWQ0QQ%3D%3D: socket connected\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413): (316 ms) https://stagingcdn.example.com/logout?l=en&cv=9999999&dl=en&os=a&sv=5&sid=MTsxOzUzZjllZWMyZGIxYTdkMWMwOGMyNGNlODs1OzJmYTdhYTZhOWM4NzZmMmRjOWM1OGNiMGEwODkyZjIxO2E0MzU1NjFkZTdiM2U3OWQ0NjZjZDNkNGZmNzEzZWQ0QQ%3D%3D: Connection error\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413): Fatal alert received handshake_failure\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413): javax.net.ssl.SSLException: Fatal alert received handshake_failure\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at org.apache.harmony.xnet.provider.jsse.SSLEngineImpl.unwrap(SSLEngineImpl.java:485)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:383)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncSSLSocketWrapper$5.onDataAvailable(AsyncSSLSocketWrapper.java:191)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.Util.emitAllData(Util.java:22)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:146)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:788)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:626)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:41)\r\n10-20 11:05:02.451: E/ExampleLogoutUtilsREQ(9413):    at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:568)\r\n```"}}