android - How to Handle SSL certification validation in proper way? -


hello application live , using "https" protocol. google play team throws warning below.

"your app(s) listed @ end of email use unsafe implementation of interface x509trustmanager. specifically, implementation ignores ssl certificate validation errors when establishing https connection remote host, thereby making app vulnerable man-in-the-middle attacks. attacker read transmitted data (such login credentials) , change data transmitted on https connection. if have more 20 affected apps in account, please check developer console full list.

to handle ssl certificate validation, change code in checkservertrusted method of custom x509trustmanager interface raise either certificateexception or illegalargumentexception whenever certificate presented server not meet expectations. google play block publishing of new apps or updates containing unsafe implementation of interface x509trustmanager."

in project using custom http client handle https instead default httpclient. code below.

    public static httpclient getnewhttpclient() {             try             {                 keystore truststore = keystore.getinstance(keystore.getdefaulttype());                 truststore.load(null, null);                  mysslsocketfactory sf = new mysslsocketfactory(truststore);                 sf.sethostnameverifier(sslsocketfactory.allow_all_hostname_verifier);                  httpparams params = new basichttpparams();                 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);                  return new defaulthttpclient(ccm, params);             }             catch (exception e)             {                 return new defaulthttpclient();             }         }  public static class mysslsocketfactory extends sslsocketfactory {         sslcontext sslcontext = sslcontext.getinstance("tls");          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();         }     } 

how overcome problem? hoping favorable answers.

now have posted code concerned, difficult see part of quoted message don't understand.

the fix remove trustmanager part of code altogether, root , branch, , use default one, , deal whatever problems may arise in proper way, adjusting contents of truststore trust certificates need trust aren't trusted default. if any, there shouldn't be.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -