Android SSL validation does not work below Android5.0
<p>I'm using Okhttp as my network utility now. I found a strange issue that I can't verify ssl connection(under dev) on devices below Android 5.0, the log printed <code>SSL handshake aborted</code>, which does not exist over API21. </p>

<p>Following is the code:</p>

<pre><code>public class CertificationUtils {

public static X509TrustManager x509TrustManager;

public static SSLContext sslContext = null;

public static HostnameVerifier DO_NOT_VERIFY;

public static void init(){

    x509TrustManager = new X509TrustManager() {
        @Override
        public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {

        }

        @Override
        public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {

        }

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            X509Certificate[] x509Certificates = new X509Certificate[0];
            return x509Certificates;
        }

    };

    try {
        sslContext = SSLContext.getInstance("SSL");

        sslContext.init(null, new TrustManager[]{x509TrustManager}, new SecureRandom());

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }

    DO_NOT_VERIFY = new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };

}
</code></pre>

<p>}</p>

<p>Okhttp side:</p>

<pre><code>CertificationUtils.init();

client = new OkHttpClient().newBuilder().connectTimeout(10, TimeUnit.SECONDS)
.sslSocketFactory(CertificationUtils.sslContext.getSocketFactory(), CertificationUtils.x509TrustManager)                     
.hostnameVerifier(CertificationUtils.DO_NOT_VERIFY).build();
</code></pre>

<p>Could anyone tell me what's wrong?</p>