简体   繁体   English

关于 SSL,cordova“发布”的行为与“调试”不同

[英]cordova "release" behaves differently to "debug" regarding SSL

I have very difficult and totally ungoogleable problem with cordova.我对cordova有非常困难且完全无法搜索的问题。

A program, working perfectly being compiled in --debug mode, ceases working after compilation in --release mode.--debug模式下完美编译的程序在--release模式下编译后停止工作。 I made sure the source is identical, and the effect is constant.我确保来源是相同的,并且效果是恒定的。

The only difference between --debug build and --release build is that the --release build fails to open any SSL connections . --debug build 和--release build 之间的唯一区别是--release build 无法打开任何 SSL 连接

This problem is localized very narrow, in my case it is the following line:这个问题的范围很窄,就我而言,它是以下几行:

Socket = new WebSocket('wss://376.su/');

a friend of mine has reported the same error occurrence in the line:我的一个朋友在行中报告了同样的错误:

<img src="https://blabla" />;

UPD: the problem is solved see the answers. UPD:问题已解决,请参阅答案。

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)我从 Thawte 获得的 SSL 证书(尽管成本很高)未被 Android 5.1.1 识别为有效证书(同时被所有桌面浏览器识别)

  2. The --debug flag in cordova build simply ignores certificate "errors" (silently). cordova build--debug标志只是忽略证书“错误”(静默)。

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:找到方法定义 ( onReceivedSslError ) 和以下条件:

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

This is what makes --debug and --release different.这就是--debug--release不同之处。 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.下次向项目添加平台时,不要忘记忽略这些准错误。

Issue问题

Android does not recognise the certificate authority (CA) of that certificate. Android 无法识别该证书的证书颁发机构 (CA)。 It is a common issue, specially with older devices, and it affects every device every time a new CA appears.这是一个常见问题,特别是对于较旧的设备,每次出现新 CA 时都会影响每个设备。

Solutions解决方案

A. Configure intermediate certificates. A. 配置中间证书。

Look for a detailed setup for your platform.寻找适合您平台的详细设置。 Here are some examples:这里有些例子:

You can read more about it in this Q&A at StackExchange's Unix .你可以在 StackExchange's Unix 的这个问答中阅读更多关于它的信息

B. Use the trust hierarchy chaining certs. B. 使用信任层次链接证书。

Taking advantage of the trust hierarchy feature, you can chain certs.利用信任层次结构功能,您可以链接证书。

You can leverage the effort using a tool like: https://whatsmychaincert.com/您可以使用以下工具来利用这项工作: https : //whatsmychaincert.com/

Or you can do it by yourself, as it is just a concatenation of text files (certs):或者您可以自己完成,因为它只是文本文件(证书)的串联:

Example steps for Linux / macOS Linux / macOS 的示例步骤

  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.这样,您将首先发送您的 CA 证书,以确保设备您的域证书之前信任您的 CA。

    If you have separated certs, this shell command does the trick:如果你有单独的证书,这个 shell 命令可以解决问题:

     $ 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:或者,如果您有一个ca-bundle文件,即证书的串联,只需运行:

     $ cat authority.ca-bundle your_domain.cert >> your_domain_bundle.cert
  2. Add that your_domain_bundle.cert to the server.your_domain_bundle.cert添加到服务器。

Problem solved for any ssl protocol, https , wss , etc.解决了任何 ssl 协议、 httpswss等的问题。

I had the same problem but the main source isn't the code SystemWebViewClient.java.我有同样的问题,但主要来源不是代码 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.实际上,主要来源是您尝试访问的 https 站点缺少 Cordova 连接到安全站点所需的证书颁发机构 (CA)。 Actually I'm using Siberian CMS which is built over Ionic/Cordova.实际上,我正在使用基于 Ionic/Cordova 构建的 Siberian CMS。

You can check the site with https://www.sslshopper.com/ssl-checker.html#hostname=您可以使用https://www.sslshopper.com/ssl-checker.html#hostname=检查该站点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 eclipse中的自定义Android构建脚本,在没有蚂蚁的情况下进行发布和调试的行为有所不同 - Custom Android build script in eclipse that behaves differently for release and debug without ant 发布 APK 的行为与使用 Future 类型进行调试的行为不同<dynamic>不是 FutureOr 的子类型<Response>错误 - Release APK behaves differently than debug with type Future<dynamic> is not a subtype of FutureOr<Response> error otto eventbus for android在发布版本中表现不同 - otto eventbus for android behaves differently in release build GridView在模拟器上的行为有所不同,并发布了apk - GridView behaves differently on Emulator and release apk Cordova Camera Error在发行中但未在调试中 - Cordova Camera Error in release but not in debug 有关发布和调试证书指纹的查询 - query regarding release and debug certificate fingerprint cordova build --debug 和 --release 之间的区别 - Difference between cordova build --debug and --release POS应用程序的打印机方法调用在发布和调试环境中的行为有所不同 - Printer method calls for a POS app behave differently for release and debug environment 如何迫使Cordova模拟发行版APK,而不是调试APK? - How to force Cordova to emulate release apk, rather than debug apk? GridView在手机和仿真器上的行为有所不同 - GridView Behaves Differently on phone and Emulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM