The WebView
control on android, does it support SSL?
I am trying to load a web page that uses a trusted ssl certificate but the WebView
is just white.
Any suggestions?
Using SSL in an Android app is easy, however ensuring that the connection is actually secure is a different matter. A man-in-the-middle attack can be carried out using several methods including ARP cache poisoning and DNS spoofing.
Mobile devices and the micro browsers that are installed on them support our SSL certificates if the server-side installation has been performed correct. The usual reason for lack of mobile support is the non-installation of the intermediate certificate, which is critical to completing the chain of trust.
The Secure Sockets Layer (SSL)—now technically known as Transport Layer Security (TLS)—is a common building block for encrypted communications between clients and servers. It's possible that an application might use SSL incorrectly such that malicious entities may be able to intercept an app's data over the network.
Not an expert, just what i could find on the web. from what I understand, the WebView does indeed support ssl, however, the blank screen is an indication that the WebView does not believe that the certificate is valid. This may happen with a certificate that is self-signed or a from a root auth that is not set up in android (perfectly valid cert does not validate). In any case, if you are using froyo or better you can try something like:
import android.webkit.WebView; import android.webkit.WebViewClient; import android.webkit.SslErrorHandler; import android.net.http.SslError; ... engine = (WebView) findViewById(R.id.my_webview); engine.setWebViewClient(new WebViewClient() { @Override public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } });
To properly handle SSL certificate validationoogle play according to updated Security Policy, Change your code to invoke SslErrorHandler.proceed() whenever the certificate presented by the server meets your expectations, and invoke SslErrorHandler.cancel() otherwise.
For example, I add an alert dialog to make user have confirmed and seems Google no longer shows warning.
@Override public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) { final AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); String message = "SSL Certificate error."; switch (error.getPrimaryError()) { case SslError.SSL_UNTRUSTED: message = "The certificate authority is not trusted."; break; case SslError.SSL_EXPIRED: message = "The certificate has expired."; break; case SslError.SSL_IDMISMATCH: message = "The certificate Hostname mismatch."; break; case SslError.SSL_NOTYETVALID: message = "The certificate is not yet valid."; break; } message += " Do you want to continue anyway?"; builder.setTitle("SSL Certificate Error"); builder.setMessage(message); builder.setPositiveButton("continue", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.proceed(); } }); builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.cancel(); } }); final AlertDialog dialog = builder.create(); dialog.show(); }
After this changes it will not show warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With