SSLPeerUnverifiedException with httpClient

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 16:04:45

The trust manager instance created by your code does not seem to be used anywhere, and the KeyStore instance does not seem to contain any trust material.

Instead of doing all that you should simply leverage functionality of SSLSocketFactory.

TrustStrategy easyStrategy = new TrustStrategy() {
    public boolean isTrusted(X509Certificate[] chain, String authType)
            throws CertificateException {
        // eh, why not?
        return true;
    }
};
SSLSocketFactory sf = new SSLSocketFactory(easyStrategy);

Thanks that made it, resolved by using the following code:

HttpClient client = null;
    TrustStrategy easyStrategy = new TrustStrategy() {

        @Override
        public boolean isTrusted(X509Certificate[] certificate, String authType)
                throws CertificateException {
            return true;
        }
    };
    try {

        SSLSocketFactory sf = new SSLSocketFactory(easyStrategy,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("https", 8443, sf));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(registry);
        client = new DefaultHttpClient(ccm);

    } catch (KeyManagementException e1) {
        e1.printStackTrace();
    } catch (UnrecoverableKeyException e1) {
        e1.printStackTrace();
    } catch (NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    } catch (KeyStoreException e1) {
        e1.printStackTrace();
    }

In my particular case, the system time on my device was set in the past.

Thanks to this page for pointing out the seemingly obvious... :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!