Android WebView setCertificate issues SSL problems

I have seen a lot of posts and information about SSL errors and I have stumbled upon one myself.

I am trying to access a web page through Android WebView with a GlobalSign CA BE certificate, and I get a not-trusted error.

  • Android: manual screen orientation without restarting the activity?
  • ActionBarSherlock with custom RelativeLayout does not show title text
  • Notification Icon with the new Firebase Cloud Messaging system
  • Intel's HAXM equivalent for AMD on Windows OS
  • How do I pass an object from one activity to another on Android?
  • Why suddenly I got the error “Unable to resolve target 'android-9' ”?
  • For most phones, it works fine to handle this, and just tell the handler to proceed.

    Some phones, however, end up getting a onReceivedError in the webview-client, telling it that it can’t establish contact with the server. This happens after it has gone through the onReceivedSslError and proceeded.

    I searched for descriptions and found a lot of descriptions involving HttpClient and either installing your own certificate or just tricking it into accepting all.

    However, since I was using WebView I thought I’d make use of WebView.setCertificate(SslCertificate crt) . I searched for discussions of this function, but did not find much/any info.

    I got a hold of the certificate that was said to be untrusted, and did this code:

         Certificate myCert = CertificateFactory.getInstance("X509").
         X509Certificate x509 = (X509Certificate) myCert;
         SslCertificate sslCert = new SslCertificate(x509);
        catch (CertificateException ex){

    With a .cer file containing this:


    It completed without exception, but I still got the same behaviour from my webview. First an SSL-error and then an error saying it could not communicate/load the page.

    If anyone has some info, has been able to get SSL working properly in WebView, or even just help in ways to debug this. I would greatly appreciate it.

    My head is also exploding a bit, because I’m not very experienced in SSL to begin with.

    *it’s a public key btw, nothing exciting 😉 (GlobalSign CA BE)

    some more info:
    the ssl exception:
    primary error: 3
    certificate: Issued to: CN=GlobalSign Domain Validation
    CA,O=GlobalSign nv-sa,OU=Domain Validation CA,C=BE;

    Issued by: CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE;

    error 3 is , SSL_UNTRUSTED

    I do however have a feeling that the setCertificate function, is not to add a trusted certificate for a missing root or similar, but instead to add a client certificate to identify with a server expecting one. Would be good with some more info on this function though, it seems a bit undocumented.

    I got the CA through running through a site called and downloading the cert from there.

    Related posts:

    android/iphone click to call in html
    How can I Subtract these lists faster?
    How does one Animate Layout properties of ViewGroups?
    Duplicate files at the same path inside the APK
    Android notifications actions without opening the app
    RelativeLayout weight
  • Android Bluetooth Example
  • Where is comprehensive documentation on Android's XML shapes?
  • Android two player game to be played in internet
  • ParseFile.cancel() not working - file keeps being downloaded
  • Handling gzipped content on Android
  • How can I get the MD5 fingerprint from Java's keytool, not only SHA-1?
  • 3 Solutions collect form web for “Android WebView setCertificate issues SSL problems”

    I tried to decode the certificate but it does not seem to be valid (actually I tested 2 distinct X509 implementations and both gave me an “incorrect encoding” error).

    Can you give more details on the SSL exception?

    I did not find much information about the setCertificate method. I think this method expects the server certificate. You should ensure that the certificate you decode is the end entity certificate and not a CA certificate.

    If you are using InMobi sdk, just update it to latest version and this warning will be fixed. More information here in Sohan’s answer


    If you have a WebClient which overrides the onReceivedSSLError() function and calls the handler.proceed() API, it can solve the certificate issue of error 3, I tested on Android 4.4 and 6.0.

    If you still get an errorCode(-1) in the function onReceivedError(), you need to check the server side implementation sometime, especially when you call the POST method instead of the GET method, because the server may return nothing if there is unexpected POST parameters.

    Good luck.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.