Cordova SSL 固定错误 500:"There was an error with the request"

Cordova SSL pinning error 500: "There was an error with the request"

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

当我使用以下功能启用固定并执行 GET 时,它抛出错误 500:"There was an error with the request"。 (所有测试都使用检查器在 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 中的 debuggable 变量设置为 true。

<application android:debuggable="true">

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

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

有什么想法吗?

谢谢!

问题与证书格式无关。这是因为IP地址。如果您不使用主机名发送请求,则需要按照 here 所述使用 SubjectAltName (SAN) 创建证书。您必须将 IP 地址写为 alt_name。否则你会得到一个 "Hostname xxx.xxx.xxx.xxx not verified" 错误。