我尝试使用以下插件使用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'">
我还将debuggable变量设置为AndroidManifest.xml为true。
<application android:debuggable="true">
我的证书是使用DER格式和.cer扩展名自签名的。 我用openssl检查证书是否正确。 如果我在我的机器上安装证书,打开服务器URL没问题 浏览器。
证书位于Cordova项目内的/ www / certificates文件夹中。 我还添加了.cer insinde / platforms / android / assets。
有什么想法吗?
谢谢!
答案 0 :(得分:1)
问题与证书格式无关。这是因为IP地址。如果您没有使用主机名发送请求,则需要使用描述为here的SubjectAltName(SAN)创建证书。您必须将IP地址写为alt_name。否则你得到一个&#34;主机名xxx.xxx.xxx.xxx未经验证&#34;错误。