ssl - SSLHandshakeException Below Android 6.0 (marshmallow) -
error log.
sslhandshakeexception error log
only in marshmallow it's working fine else not working.
i getting sslhandshakeexception in android version work fine in marshmallow.
public defaulthttpclient getnewhttpclient() { try { keystore truststore = keystore.getinstance(keystore .getdefaulttype()); truststore.load(null, null); sslsocketfactory sf = new mysslsocketfactory(truststore); sf.sethostnameverifier(sslsocketfactory.allow_all_hostname_verifier); httpparams params = new basichttpparams(); httpconnectionparams.setconnectiontimeout(params, http_connection_timeout); httpconnectionparams.setsotimeout(params, http_so_timeout); httpprotocolparams.setversion(params, httpversion.http_1_1); httpprotocolparams.setcontentcharset(params, http.utf_8); schemeregistry registry = new schemeregistry(); registry.register(new scheme("http", plainsocketfactory .getsocketfactory(), 80)); registry.register(new scheme("https", sf, 443)); clientconnectionmanager ccm = new threadsafeclientconnmanager( params, registry); defaulthttpclient httpclient = new defaulthttpclient(ccm, params); return httpclient; } catch (exception e) { return new defaulthttpclient(); } }
public class mysslsocketfactory extends sslsocketfactory { sslcontext sslcontext = getsslcontext();
public mysslsocketfactory(keystore truststore) throws nosuchalgorithmexception, keymanagementexception, keystoreexception, unrecoverablekeyexception { super(truststore); trustmanager tm = new x509trustmanager() { public void checkclienttrusted(x509certificate[] chain, string authtype) throws certificateexception { } public void checkservertrusted(x509certificate[] chain, string authtype) throws certificateexception { } public x509certificate[] getacceptedissuers() { return null; } }; sslcontext.init(null, new trustmanager[] { tm }, null); } @override public socket createsocket(socket socket, string host, int port, boolean autoclose) throws ioexception, unknownhostexception { return sslcontext.getsocketfactory().createsocket(socket, host, port, autoclose); } @override public socket createsocket() throws ioexception { return sslcontext.getsocketfactory().createsocket(); } }
Comments
Post a Comment