android - Safely fixing: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate -


there dozens of posts issue (javax.net.ssl.sslpeerunverifiedexception: no peer certificate) haven't found works me.

many posts (like this, , this) "solve" allowing certificates accepted but, of course, not solution other testing.

others seem quite localized , don't work me. hope has insight lack.

so, problem: i'm testing on server accessible through local network, connecting via https. making call need through browser works fine. no complaining certificates , if check certificates, looks good.

when try on android device, javax.net.ssl.sslpeerunverifiedexception: no peer certificate

here's code calls it:

stringbuilder builder = new stringbuilder(); builder.append( /* stuff goes here*/ );  httpget.setentity(new urlencodedformentity(namevaluepairs)); responsehandler<string> responsehandler = new basicresponsehandler();  // execute http post request. response body returned string httpclient httpclient = myactivity.gethttpclient(); httpget httpget = new httpget(builder.tostring());  string jsonresponse = httpclient.execute(httpget, responsehandler); //line causing exception 

my code myactivity.gethttpclient():

protected synchronized static httpclient gethttpclient(){     if (httpclient != null)         return httpclient;      httpparams httpparameters = new basichttpparams();     httpconnectionparams.setconnectiontimeout(httpparameters, timeout_connection);     httpconnectionparams.setsotimeout(httpparameters, timeout_socket);     httpprotocolparams.setversion(httpparameters, httpversion.http_1_1);      //thread safe in case various asynctasks try access concurrently     schemeregistry schemeregistry = new schemeregistry();     schemeregistry.register(new scheme("http", plainsocketfactory.getsocketfactory(), 80));     schemeregistry.register(new scheme("https", sslsocketfactory.getsocketfactory(), 443));     clientconnectionmanager cm = new threadsafeclientconnmanager(httpparameters, schemeregistry);      httpclient = new defaulthttpclient(cm, httpparameters);      cookiestore cookiestore = httpclient.getcookiestore();     httpcontext localcontext = new basichttpcontext();     localcontext.setattribute(clientcontext.cookie_store, cookiestore);      return httpclient; } 

any appreciated.

edit

also mention i've had other ssl issues app adding schemeregistry portion fixed me before.

edit 2

so far i've tested on android 3.1, need work on android 2.2+ regardless. tested on browser on android tab (android 3.1) , complains certificate. it's fine on pc browser, not on android browser or in app.

edit 3

turns out ios browser complains it. i'm starting think it's certificate chain issue described here (ssl certificate not trusted - on mobile only)

it turns out code fine , problem server not returning full certificate chain. more information see post , superuser post:

ssl certificate not trusted - on mobile only

https://superuser.com/questions/347588/how-do-ssl-chains-work


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -