{"action":"created","issue":{"url":"https://api.github.com/repos/square/okhttp/issues/2323","repository_url":"https://api.github.com/repos/square/okhttp","labels_url":"https://api.github.com/repos/square/okhttp/issues/2323/labels{/name}","comments_url":"https://api.github.com/repos/square/okhttp/issues/2323/comments","events_url":"https://api.github.com/repos/square/okhttp/issues/2323/events","html_url":"https://github.com/square/okhttp/issues/2323","id":131971721,"number":2323,"title":"Unable to extract the trust manager","user":{"login":"AlexLardschneider","id":10795750,"avatar_url":"https://avatars.githubusercontent.com/u/10795750?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexLardschneider","html_url":"https://github.com/AlexLardschneider","followers_url":"https://api.github.com/users/AlexLardschneider/followers","following_url":"https://api.github.com/users/AlexLardschneider/following{/other_user}","gists_url":"https://api.github.com/users/AlexLardschneider/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexLardschneider/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexLardschneider/subscriptions","organizations_url":"https://api.github.com/users/AlexLardschneider/orgs","repos_url":"https://api.github.com/users/AlexLardschneider/repos","events_url":"https://api.github.com/users/AlexLardschneider/events{/privacy}","received_events_url":"https://api.github.com/users/AlexLardschneider/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/square/okhttp/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":47,"created_at":"2016-02-07T14:23:56Z","updated_at":"2016-04-08T06:08:12Z","closed_at":"2016-02-08T00:53:47Z","body":"Hi,\r\nafter upgrading from OkHttp 3.0.1 to 3.1.0 I get the following stack trace and crash after calling build() to create a OkHttpClient.\r\n\r\n```\r\njava.lang.IllegalStateException: Unable to extract the trust manager on okhttp3.internal.Platform$Android@1d8cf999, sslSocketFactory is class com.google.android.gms.org.conscrypt.KitKatPlatformOpenSSLSocketAdapterFactory\r\n                                                                        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:187)\r\n                                                                        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:60)\r\n                                                                        at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:719)\r\n```\r\n\r\nThis issue was not present in 3.0.1.\r\n\r\nHere's where the crash happens:\r\n```\r\nOkHttpClient.Builder builder = new OkHttpClient.Builder()\r\n                    .connectTimeout(10, TimeUnit.SECONDS)\r\n                    .writeTimeout(10, TimeUnit.SECONDS)\r\n                    .readTimeout(30, TimeUnit.SECONDS);\r\n\r\n            OkHttpClient client = builder.build();\r\n```"},"comment":{"url":"https://api.github.com/repos/square/okhttp/issues/comments/207231855","html_url":"https://github.com/square/okhttp/issues/2323#issuecomment-207231855","issue_url":"https://api.github.com/repos/square/okhttp/issues/2323","id":207231855,"user":{"login":"rogerhu","id":326857,"avatar_url":"https://avatars.githubusercontent.com/u/326857?v=3","gravatar_id":"","url":"https://api.github.com/users/rogerhu","html_url":"https://github.com/rogerhu","followers_url":"https://api.github.com/users/rogerhu/followers","following_url":"https://api.github.com/users/rogerhu/following{/other_user}","gists_url":"https://api.github.com/users/rogerhu/gists{/gist_id}","starred_url":"https://api.github.com/users/rogerhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rogerhu/subscriptions","organizations_url":"https://api.github.com/users/rogerhu/orgs","repos_url":"https://api.github.com/users/rogerhu/repos","events_url":"https://api.github.com/users/rogerhu/events{/privacy}","received_events_url":"https://api.github.com/users/rogerhu/received_events","type":"User","site_admin":false},"created_at":"2016-04-08T06:08:12Z","updated_at":"2016-04-08T06:08:12Z","body":"The 2nd problem is currently if you want to pass an SSL session cache, you have to pass in a SSL Socket factory:\r\n\r\n```\r\nOkHttpClient.Builder builder = new OkHttpClient.Builder();\r\nbuilder.sslSocketFactory(SSLCertificateSocketFactory.getDefault(socketOperationTimeout, sslSessionCache));\r\n```\r\n\r\nBut even for stock Android `SSLCertificateSocketFactory` relies on `com.android.org.conscrypt.OpenSSLContextImpl` so the trust manager code fails looking for `sun.security.ssl.SSLContextImpl`.\r\n\r\nIt turns out the Parse Android SDK, which includes OkHttp2, can't be upgraded until we get to 3.3.0. \r\nI attempted to do so just now and ran into the issue here.  https://github.com/ParsePlatform/Parse-SDK-Android/pull/435/files#r58793351\r\n\r\nI can get around the issue by using the snapshot version and implementing the code to get the default trust manager:\r\n\r\n```java\r\n\r\n  private X509TrustManager systemDefaultTrustManager() {\r\n    try {\r\n      TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(\r\n              TrustManagerFactory.getDefaultAlgorithm());\r\n      trustManagerFactory.init((KeyStore) null);\r\n      TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();\r\n      if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {\r\n        throw new IllegalStateException(\"Unexpected default trust managers:\"\r\n                + Arrays.toString(trustManagers));\r\n      }\r\n      return (X509TrustManager) trustManagers[0];\r\n    } catch (GeneralSecurityException e) {\r\n      throw new AssertionError(); // The system has no TLS. Just give up.\r\n    }\r\n  }\r\n```\r\n\r\nAnd then later:\r\n\r\n```java\r\nbuilder.sslSocketFactory(SSLCertificateSocketFactory.getDefault(socketOperationTimeout, sslSessionCache), systemDefaultTrustManager());\r\n```\r\n\r\nSo waiting for the 3.3.0 release before Parse's Android SDK implementation can be bumped to use OkHttp3. :)"}}