title: com.android.volley.error.NoConnectionError: javax.net.ssl.SSLHandshakeException: Handshake failed, Only in Nougat device
body: <p>App is working properly in devices having os version below Nougat.
  have given the certificate of the server (downloaded using firefox).</p>
  
  <p>EXCEPTION CAUSE : </p>
  
  <pre><code>Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xabad5f00: Failure in SSL library, usually a protocol error
  03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err:  error:10000410:SSL routines:OPENSSL_internal:SSLV3_ALERT_HANDSHAKE_FAILURE  (external/boringssl/src/ssl/s3_pkt.c:610 0xaba93a80:0x00000001)
   03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err:  error:1000009a:SSL routines:OPENSSL_internal:HANDSHAKE_FAILURE_ON_CLIENT_HELLO  (external/boringssl/src/ssl/s3_clnt.c:764 0xa7dc5912:0x00000000)
   03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err:     at  com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
    03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err:     at    com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java :357)
  03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err:            ... 17 more
   03-03 20:54:52.507 12993-12993/com.mummysocial W/System.err:   Caused by:  javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xabad5f00:  Failure in SSL library, usually a protocol error
    03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err:  error:1000043e:SSL routines:OPENSSL_internal:TLSV1_ALERT_INAPPROPRIATE_FALLBACK  (external/boringssl/src/ssl/s3_pkt.c:610 0xaba93a80:0x00000001)
    03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
  03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
  03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err:        ... 17 more
  03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0xabad5f00: Failure in SSL library, usually a protocol error
  03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err: error:1000043e:SSL routines:OPENSSL_internal:TLSV1_ALERT_INAPPROPRIATE_FALLBACK (external/boringssl/src/ssl/s3_pkt.c:610 0xaba93a80:0x00000001)
  03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
  03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
  03-03 20:54:52.508 12993-12993/com.mummysocial W/System.err:    ... 17 more
  </code></pre>
  
  <p>and followed this link from <a href="https://developer.android.com/training/articles/security-ssl.html" rel="nofollow noreferrer">Android developer site</a></p>
  
  <pre><code> private SSLSocketFactory getSSLSocketFactory()
          throws CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException, KeyManagementException {
      CertificateFactory cf = CertificateFactory.getInstance("X.509");
      InputStream caInput = getResources().openRawResource(R.raw.ms); // this cert file stored in \app\src\main\res\raw folder path
  
      Certificate ca = cf.generateCertificate(caInput);
      caInput.close();
      String keyStoreType = KeyStore.getDefaultType();
      KeyStore keyStore = KeyStore.getInstance(keyStoreType);
      keyStore.load(null, null);
      keyStore.setCertificateEntry("ca", ca);
  
      String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
      TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
      tmf.init(keyStore);
  
  
      //TrustManager[] wrappedTrustManagers = getWrappedTrustManagers(tmf.getTrustManagers());
  
      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(null, tmf.getTrustManagers(), null);
  
      return sslContext.getSocketFactory();
  }
  
  private HostnameVerifier getHostnameVerifier() {
      return new HostnameVerifier() {
          @Override
          public boolean verify(String hostname, SSLSession session) {
              return true;
          }
      };
  }
  </code></pre>
  
  <p>and created a varible of HurlStack and passing it to volley.init() method. </p>
  
  <pre><code>hurlStack = new HurlStack() {
          @Override
          protected HttpURLConnection createConnection(URL url) throws IOException {
              HttpsURLConnection httpsURLConnection = (HttpsURLConnection) super.createConnection(url);
              try {
                  httpsURLConnection.setSSLSocketFactory(getSSLSocketFactory());
                  httpsURLConnection.setHostnameVerifier(getHostnameVerifier());
              } catch (Exception e) {
                  e.printStackTrace();
              }
              return httpsURLConnection;
          }
      };
      MyVolley.init(this,hurlStack);
  </code></pre>
  
  <p>My init method looks something like this: </p>
  
  <pre><code> public static void init(Context context, HurlStack hurlStack) {
  
      if(mRequestQueue==null) {
          mRequestQueue = Volley.newRequestQueue(context,hurlStack);
      }
  }
  </code></pre>
  
  <p>I downloaded the certificate using the firefox. and in firefox it's mentioned: this certificate has been verified for the ssl client certification and ssl server certification and inside <code>getSSLSOcketFactory()</code> method am passing <code>SSLContext.getInstance("TLS")</code> &lt;-- dont know if it's due to this, (I tried changing this argument to "SSL", didn't work out.</p>