Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

SSL Errors causes WebView to show blank page - Android #34

Closed
Iyashu5040 opened this issue Jul 24, 2013 · 5 comments
Closed

SSL Errors causes WebView to show blank page - Android #34

Iyashu5040 opened this issue Jul 24, 2013 · 5 comments
Assignees
Milestone

Comments

@Iyashu5040
Copy link

Gingerbread does not see Facebook's security certificate as valid, and any SSL error in a webview causes it to stop loading the page. Unfortunately, GB still runs on a large amount of devices out there. The solution to this problem is the following: Override the OnReceivedSSLError method of the WebViewClient as such

    public override void OnReceivedSslError(WebView view, SslErrorHandler handler,SslError error)
    {
    handler.Proceed();
    }

I've tested this and it allows the Facebook login page to display correctly on GB devices. I know it's not very secure, I'm working on a more fine tuned version which I'll post if I get it working.

@Iyashu5040
Copy link
Author

I've tweaked the solution, it now presents the user with an error message and prompts them to continue or cancel. (Tested working on an HTC Desire running CyanogenMod 7.2.0.1 - Android 2.3.7)

public override void OnReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
            {
                AlertDialog.Builder builder = new AlertDialog.Builder(this.activity);
                AlertDialog ad = builder.Create();
                string message = "Certificate error.";
                switch (error.PrimaryError)
                {
                    case SslErrorType.Untrusted:
                        message = "Certificate is untrusted."; break;
                    case SslErrorType.Expired:
                        message = "Certificate has expired."; break;
                    case SslErrorType.Idmismatch:
                        message = "Certificate ID is mismatched."; break;
                    case SslErrorType.Notyetvalid:
                        message = "Certificate is not yet valid."; break;
                }
                message += " Do you want to continue anyway?";
                ad.SetTitle("SSL Certificate Error");
                ad.SetMessage(message);
                ad.SetButton("OK", (sender, args) =>
                                       {
                                           handler.Proceed();
                                       });
                ad.SetButton2("Cancel", (sender, args) =>
                                            {
                                                handler.Cancel();
                                                activity.Finish();
                                            });
                ad.SetIcon(Android.Resource.Drawable.IcDialogAlert);
                ad.Show();
            }

@ghost ghost assigned ermau Aug 8, 2013
@ermau
Copy link
Member

ermau commented Aug 8, 2013

Does the sample produce the same error? I haven't been able to reproduce the issue on a GB simulator.

@ermau ermau closed this as completed in 748feaa Aug 20, 2013
@mdmota
Copy link

mdmota commented Dec 2, 2019

And for iOS? I need a solution

@Iyashu5040
Copy link
Author

And for iOS? I need a solution

This issue was very specific to Android, relating to trusted SSL root certificates back in 2013. Any iOS issue is definitely unrelated to this. You should log a separate issue or look around for a solution to your problem on StackOverflow.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants