【问题标题】:Cordova SSL pinning error 500: "There was an error with the request"Cordova SSL 固定错误 500:“请求出错”
【发布时间】:2015-10-20 07:29:17
【问题描述】:

我正在尝试使用以下插件对 Cordova 5.3.3 和 Android 进行 SSL 固定: https://github.com/wymsee/cordova-HTTP

当我使用以下功能启用固定并执行 GET 时,它会抛出错误 500:“请求出现错误”。 (所有测试都使用检查器在 android 设备内完成)。

window.cordovaHTTP.enableSSLPinning(
    true,
    function(res) {console.log("SSL pinning: " + res)},
    function(err) {console.log("SSL pinning: " + err)}
);

window.cordovaHTTP.get(
    "https://95.85.12.4/test.json",
    {}, // optional params
    {}, // optional headers
    function(res) {console.log(res)},
    function(err) {console.log(err)}
);

如果我接受所有证书,则一切正常,因为我正在重叠固定配置。

window.cordovaHTTP.enableSSLPinning(
    true,
    function(res) {console.log("SSL pinning: " + res)},
    function(err) {console.log("SSL pinning: " + err)}
);

window.cordovaHTTP.acceptAllCerts(
    true,
    function(res) {console.log('Accept all certs: ' + res)},
    function(err) {console.log('Accept all certs: ' + err)}
);

window.cordovaHTTP.get(
    "https://95.85.12.4/test.json",
    {}, // optional params
    {}, // optional headers
    function(res) {console.log(res)},
    function(err) {console.log(err)}
);

我正在运行 NGINX 的服务器上进行此测试。 https://95.85.12.4/test.json

我将所有内容都列入白名单(仅用于测试目的)

<!-- Enable all requests, inline styles, and eval() -->
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

我还将 AndroidManifest.xml 中的可调试变量设置为 true。

<application android:debuggable="true">

我的证书是使用 DER 格式和 .cer 扩展名的自签名证书。 我用 openssl 检查了证书是否正确。 如果我在我的机器上安装证书,打开服务器 URL 没有问题 浏览器。

证书位于我的 Cordova 项目内的 /www/certificates 文件夹中。 我还添加了 .cer insinde /platforms/android/assets。

有什么想法吗?

谢谢!

【问题讨论】:

  • 虽然我的服务器中没有 DER 证书,但格式是 PEM。我检查了一下,NGINX 无法处理 DER 证书。也许这就是问题所在?

标签: android cordova ssl-certificate cordova-plugins pinning


【解决方案1】:

问题与证书格式无关。这是因为IP地址。如果您不使用主机名发送请求,则需要按照here 所述创建带有 SubjectAltName (SAN) 的证书。您必须将 IP 地址写为 alt_name。否则会出现“主机名 xxx.xxx.xxx.xxx 未验证”错误。

【讨论】:

    猜你喜欢
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 2014-10-15
    相关资源
    最近更新 更多