cordova “release” behaves differently to “debug” regarding SSL

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 06:58:28

Problem

I have identified the exact source of the problem and i have found the perfect solution. It turned out to be a superposition of two separate issues each of which is seriously misleading:

  1. My SSL certificate from Thawte (despite its cost) is not recognized by Android 5.1.1 as a valid one (while being recognized by all desktop browsers)

  2. The --debug flag in cordova build simply ignores certificate "errors" (silently).

Solution

Go to your project's directory and find the following file:

platforms/android/CordovaLib/src/org/apache/cordova/engine/SystemWebViewClient.java

Locate the method definition (onReceivedSslError) and the following condition:

(appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0

This is what makes --debug and --release different. In order to ignore certificate "errors" the following code should be executed:

handler.proceed();
return;

This file persists through the build process. Don't forget to ignore those quasi-errors next time you add a platform to your project.

Android does not recognise the certificate authority (CA) of that certificate. It is a common issue, specially with older devices, and it affects every device every time a new CA appears.

A possible solution is to take advantage of the trust hierarchy:

  1. Concat the authority's certs with your cert.

    That way you'll send your CA's certificates first to ensure that the device trust your CA before your domain's certificate.

    If you have separated certs, this shell command does the trick:

    $ cat authority1.cert authority2.cert authority3.cert your_domain.cert >> your_domain_bundle.cert
    

    Or if you have a ca-bundle file, that is a concatenation of certificates, just run:

    $ cat authority.ca-bundle your_domain.cert >> your_domain_bundle.cert
    
  2. Add that your_domain_bundle.cert to the server.

Problem solved for https and wss.

I had the same problem but the main source isn't the code SystemWebViewClient.java. Your post helped me a lot to find the exact source. Actually the main source is that the https site you are trying to reach is missing the certificate authority (CA) that is needed by Cordova to connect to a secured site. Actually I'm using Siberian CMS which is built over Ionic/Cordova.

You can check the site with https://www.sslshopper.com/ssl-checker.html#hostname=

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!