Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Web View on Android support SSL?

Tags:

android

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?

like image 982
Filip Ekberg Avatar asked May 12 '11 12:05

Filip Ekberg


People also ask

Does Android use SSL?

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.

Why is SSL not working on mobile?

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.

What is SSL in Android Architecture?

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.


2 Answers

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();     } }); 
like image 63
chris Avatar answered Sep 18 '22 21:09

chris


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.

like image 39
Anant Shah Avatar answered Sep 18 '22 21:09

Anant Shah