1. webview SSL Verification
@ Override
Public void onreceivedsslerror (webview view, sslerrorhandler handler,
Sslerror error ){
Super. onreceivedsslerror (view, handler, error );
// Handler. Cancel (); the default processing method. The webview becomes a blank page.
// Handlemessage (Message MSG); other processing
Handler. Proceed ();
}
2. httpclient SSL Verification
Private Static httpclient getnewhttpclient (){
// Return an httpclient configured to accept all SSL certificates
Try {
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", mysslsocketfactory
. Getsslsocketfactory (), 443 ));
Clientconnectionmanager CCM = new threadsafeclientconnmanager (
Params, registry );
// Httpclient = new
// Org. Apache. http. impl. Client. contentencodinghttpclient (CCM,
// Params); // throws eofexception in 4.1.1 (fixed in 4.1.2 ?)
Defaulthttpclient httpclient = new defaulthttpclient (CCM, Params );
// Httpclient. addresponseinterceptor (New
// Gziphttpresponseinterceptor ());
Return httpclient;
} Catch (ioexception e ){
Apputils. logd ("couldnt set up SSL properly ");
Return new defaulthttpclient ();
}
}
Mysslsocketfactory
Import java. Io. ioexception;
Import java.net. Socket;
Import java.net. unknownhostexception;
Import java. Security. keymanagementexception;
Import java. Security. keystore;
Import java. Security. keystoreexception;
Import java. Security. nosuchalgorithmexception;
Import java. Security. unrecoverablekeyexception;
Import java. Security. cert. certificateexception;
Import java. Security. cert. x509certificate;
Import javax.net. SSL. sslcontext;
Import javax.net. SSL. trustmanager;
Import javax.net. SSL. x509trustmanager;
Import org. Apache. http. Conn. SSL. sslsocketfactory;
Public class mysslsocketfactory extends sslsocketfactory
{
Private Static mysslsocketfactory instance;
Private Final sslcontext = sslcontext. getinstance ("TLS ");
Public static mysslsocketfactory getsslsocketfactory () throws ioexception
{
If (instance = NULL)
{
Try
{
Keystore truststore = keystore. getinstance (keystore. getdefaulttype ());
Truststore. Load (null, null );
Instance = new mysslsocketfactory (truststore );
Instance. sethostnameverifier (sslsocketfactory. allow_all_hostname_verifier );
}
Catch (certificateexception E)
{
Throw new ioexception ("couldnt set up SSL properly", e );
}
Catch (keystoreexception E)
{
Throw new ioexception ("couldnt set up SSL properly", e );
}
Catch (nosuchalgorithmexception E)
{
Throw new ioexception ("couldnt set up SSL properly", e );
}
Catch (keymanagementexception E)
{
Throw new ioexception ("couldnt set up SSL properly", e );
}
Catch (unrecoverablekeyexception E)
{
Throw new ioexception ("couldnt set up SSL properly", e );
}
}
Return instance;
}
Private mysslsocketfactory (keystore truststore) throws nosuchalgorithmexception, keymanagementexception, keystoreexception, unrecoverablekeyexception
{
Super (truststore );
Trustmanager TM = new x509trustmanager ()
{
Public void checkclienttrusted (x509certificate [] Chain, string authtype) throws certificateexception
{
// Accept
}
Public void checkservertrusted (x509certificate [] Chain, string authtype) throws certificateexception
{
// Accept
}
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 ();
}
}