ssl - Handling certificate errors in Android Webview and clearing the certificate peferences -
i trying find proper way handle ssl certificate errors in android webview. goal provide way load pages ssl certificate errors, let user choose load page after warning him security any time tries load url certificate errors.
the closest solutions found in threads suggest overriding webviewclient following:
webview.setwebviewclient(new webviewclient() { @override public void onreceivedsslerror(final webview view, final sslerrorhandler handler, final sslerror error) { handler.proceed(); } });
however disables ssl in webview without user consent.
for reference here threads found solution:
android webview ssl 'security warning'
does web view on android support ssl?
android webview not loading https url
android webview client certificate
web view shows blank/white page after loading url when using wifi in android
unable load specific webpage on android webview
webview displays blank view links
android webview blocks redirect https http
ignore ssl certificate requests in webview
i went ahead , implemented different version prompts user:
webview.setwebviewclient(new webviewclient() { @override public void onreceivedsslerror(final webview view, final sslerrorhandler handler, final sslerror error) { //showing first confirmation dialog androidutils.showyesnodialog( //first confirmation message "warning - page not secure! sure want continue loading it?", //first confirmation "yes" option runnable new runnable() { @override public void run() { //showing second confirmation dialog androidutils.showyesnodialogwithresid( //second confirmation message "you chose load unsecure page, sure want that?", //second confirmation "yes" option runnable new runnable() { @override public void run() { //disregard error , proceed bad certificate anyways handler.proceed(); } }, //second confirmation "no" option runnable new runnable() { @override public void run() { //cancel loading page certificate error handler.cancel(); } } ); } }, //first confirmation "no" option runnable new runnable() { @override public void run() { //cancel loading page certificate error handler.cancel(); } }); } });
this implementation asks user twice if wants load page, if says yes twice, error disregarded , page loads, otherwise page loading canceled.
the first time url certificate error loads, webviewclient.onreceivedsslerror
called, if user proceeds certificate error , sslerrorhandler.proceed()
called, following times same url loads, webviewclient.onreceivedsslerror
never called again: killing app resets behavior.
i want webviewclient.onreceivedsslerror
called systematically when url certificate error loads, not first time. tried calling methods without success:
/** javadoc quote: clears ssl preferences table stored in response proceeding ssl certificate errors.*/ webview.clearsslpreferences(); //those other methods tried out of despair in case webview.clearformdata(); webview.clearcache(true); webview.clearhistory(); webview.clearmatches();
does know how make webview call webviewclient.onreceivedsslerror
more once same url, after sslerrorhandler.proceed()
has been called?
Comments
Post a Comment