[英]HTTPS url with port number not working on iOS
我在包含端口號的 HTTPS url 上發送一個簡單的 GET 請求。 網址看起來像這樣
https://example.com:8080/v1/base
這在 Android 和任何瀏覽器上都可以完美運行……甚至 curl。 但是,我在 iOS 上收到此錯誤。 如果我從上面的 URL 中刪除端口號,這工作得很好!
錯誤:錯誤域=NSURLErrorDomain 代碼=-1202 “此服務器的證書無效。您可能正在連接到一個偽裝成“example.com”的服務器,這可能會使您的機密信息處於危險之中。 UserInfo=0xa694c50 {NSErrorFailingURLStringKey= https://example.com:8080/v1/base , NSLocalizedRecoverySuggestion=您是否仍要連接到服務器?, NSErrorFailingURLKey= https://example.com:8080/api/v1/base , NSLocalizedDescription=此服務器的證書無效。 您可能正在連接到一個偽裝成“example.com”的服務器,這可能會使您的機密信息處於危險之中。, NSUnderlyingError=0xa2410a0 “該服務器的證書無效。您可能正在連接到一個偽裝成是“example.com”,這可能會使您的機密信息處於危險之中。”,NSURLErrorFailingURLPeerTrustErrorKey=}
SSL 證書由 DigiCert 頒發。 服務器后端是 node v0.10.15 和 iOS SDK v6.1
知道我在這里缺少什么嗎?
添加requestCert: true
& CA 證書解決了這個問題
var https = require('https'), // module for https
fs = require('fs'); // required to read certs and keys
var options = {
key: fs.readFileSync('ssl/server.key'),
cert: fs.readFileSync('ssl/server.crt'),
ca: fs.readFileSync('ssl/ca.crt'),
requestCert: true,
rejectUnauthorized: false
};
https.createServer(options, function (req, res) {
if (req.client.authorized) {
res.writeHead(200, {"Content-Type": "application/json"});
res.end('{"status":"approved"}');
} else {
res.writeHead(401, {"Content-Type": "application/json"});
res.end('{"status":"denied"}');
}
}).listen(443);
您是否包括除您自己之外的任何其他父 CA 證書?
另外,如果您使用 8080 或 443 以外的端口,它是否有效? 如果您監聽 443 並明確嘗試請求https://example.com:443/v1/base
是否有效?
var fs = require('fs');
var httpsOpt = {
key : fs.readFileSync('ssl.plain.key').toString(),
cert : fs.readFileSync('ssl.crt').toString(),
ca:[fs.readFileSync('ca.pem').toString(),
fs.readFileSync('sub.class1.server.ca.pem').toString()],
};
https.createServer(httpsOpt, app)
.listen('8080', function(){
console.log('Listening on 8080')
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.