title: OpenSSLSocketImpl.getSession crash
body: <p>on some devices i get the crash below:</p>
  
  <p>// the crash info </p>
  
  <blockquote>
    <p>SIGABRT</p>
    
    <h1>00    pc 00041300    /system/lib/libc.so (tgkill+12) [armeabi-v7a::1b317667710e940729198acd09513c97]</h1>
    
    <h1>01    pc 000401b5    /system/lib/libc.so (pthread_kill+32) [armeabi-v7a::1b317667710e940729198acd09513c97]</h1>
    
    <h1>02    pc 0001c893    /system/lib/libc.so (raise+10) [armeabi-v7a::1b317667710e940729198acd09513c97]</h1>
    
    <h1>03    pc 00019af1    /system/lib/libc.so (__libc_android_abort+34) [armeabi-v7a::1b317667710e940729198acd09513c97]</h1>
    
    <h1>04    pc 000176b8    /system/lib/libc.so (abort+4) [armeabi-v7a::1b317667710e940729198acd09513c97]</h1>
    
    <h1>05    pc 0001b553    /system/lib/libc.so (__libc_fatal+16) [armeabi-v7a::1b317667710e940729198acd09513c97]</h1>
    
    <h1>06    pc 0001b56b    /system/lib/libc.so (__fortify_chk_fail+18) [armeabi-v7a::1b317667710e940729198acd09513c97]</h1>
    
    <h1>07    pc 00046315    /system/lib/libc.so (__FD_SET_chk+24) [armeabi-v7a::1b317667710e940729198acd09513c97]</h1>
    
    <h1>08    pc 000092f5    /system/lib/libjavacrypto.so [armeabi-v7a::3bdb8758762753b0649e6940a3fc1a62] java:</h1>
    
    <p>com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
    com.android.org.conscrypt.OpenSSLSocketImpl.waitForHandshake(OpenSSLSocketImpl.java:629)
    com.android.org.conscrypt.OpenSSLSocketImpl.getSession(OpenSSLSocketImpl.java:793)
    com.thirdparty.afinal.utils.HttpsHelper$a.createSocket(SourceFile:786)
    org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:170)
    org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
    org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
    org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366)
    org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:596)
    org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:517)
    com.thirdparty.afinal.f.c.a(SourceFile:80)
    com.thirdparty.afinal.f.c.b(SourceFile:117)
    com.thirdparty.afinal.c.d$2.call(SourceFile:146)
    java.util.concurrent.FutureTask.run(FutureTask.java:237)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    java.lang.Thread.run(Thread.java:833)</p>
  </blockquote>
  
  <p>//the code is as below</p>
  
  <p>private static final class MySSLSocketFactory extends SSLSocketFactory {</p>
  
  <pre><code>    private KeyStore mKeystore;
  
      public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException,
              KeyManagementException, KeyStoreException, UnrecoverableKeyException {
          super(truststore);
          mKeystore = truststore;
      }
  
      final static HostnameVerifier hostnameVerifier = new StrictHostnameVerifier();
  
      @SuppressLint("NewApi")
      @Override
      public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
  
          if (autoClose) {
              socket.close();
          }
  
          SSLCertificateSocketFactory sslSocketFactory =
                  (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0);
          try {
              sslSocketFactory.setTrustManagers(new TrustManager[] { new MyX509TrustManager(mKeystore)});
          } catch (NoSuchAlgorithmException e) {
              e.printStackTrace();
          } catch (KeyStoreException e) {
              e.printStackTrace();
          }
          @SuppressLint("SSLCertificateSocketFactoryCreateSocket")
          SSLSocket ssl = (SSLSocket)sslSocketFactory.createSocket(InetAddress.getByName(host), port);
  
  
          if (socket instanceof SSLSocket) {
              if (Build.VERSION.SDK_INT &lt;= Build.VERSION_CODES.KITKAT_WATCH
                      &amp;&amp; Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN) {
                  ssl.setEnabledProtocols(ssl.getSupportedProtocols());
              }
          }
  
          sslSocketFactory.setHostname(ssl, host);
  
          SSLSession session = ssl.getSession();
          if (!hostnameVerifier.verify(host, session)){
              throw new SSLPeerUnverifiedException("Cannot verify hostname: " + host + " peer=" + session.getPeerHost());
          }
  
          return ssl;
      }
  }
  </code></pre>