1

我正在尝试使用以下插件对 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。

任何的想法?

谢谢!

4

1 回答 1

1

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

于 2016-10-15T20:37:02.517 回答