ios - 钛 - "The certificate for this server is invalid. You might be connecting to a server that is pretending to be DOMAIN.COM”

标签 ios ssl certificate titanium

我正在使用 Titanium Appcelerator 开发适用于 iOS 的应用程序。 我正在努力保护与我的服务器的连接。我购买了 UCC 证书来保护我的服务器(和其他网站)并安装了它。当我继续使用任何浏览器时,它会显示连接是安全的。

现在,当我尝试创建从应用程序到我的服务器的连接时,出现以下错误:

The certificate for this server is invalid. You might be connecting to a server that is pretending to be DOMAIN.COM

我试过其他安全域,效果很好。 我正在使用 Ti.Network.createHTTPClient 来创建我的连接。 有没有人知道这个问题?我在这里遗漏了什么吗?

最佳答案

您应该使用 securityManager 与安全网站进行通信。下面是来自 documentation 的简单示例.证书应作为 DER 二进制格式的 X.509 证书文件提供。

免责声明:appcelerator.https 模块是付费功能!

// Require in the module
var https = require('appcelerator.https'),
    securityManager,
    httpClient;

// Use the module to create a Security Manager that authenticates the specified URLs
securityManager = https.createX509CertificatePinningSecurityManager([
    {
        url: "https://dashboard.appcelerator.com",
        serverCertificate: "dashboard.appcelerator.com.der"
    },
    {
        url: "https://www.wellsfargo.com",
        serverCertificate: "wellsfargo.der"
    }
]);

// Create an HTTP client the same way you always have
// but pass in the optional Security Manager that was created previously.
httpClient = Ti.Network.createHTTPClient({
    onload: function(e) {
        Ti.API.info("Received text: " + this.responseText);
    },
    onerror: function(e) {
        Ti.API.error(e.error);
    },
    timeout : 5000,
    // Set this property before calling the `open` method. 
    securityManager: securityManager
});

// Prepare the HTTPS connection in the same way you always have
// and the Security Manager will authenticate all servers for
// which it was configured before any communication happens.
httpClient.open("GET", "https://dashboard.appcelerator.com");

// Send the request in the same way you always have.
// Throws a Security Exception if authentication fails.
httpClient.send();

关于ios - 钛 - "The certificate for this server is invalid. You might be connecting to a server that is pretending to be DOMAIN.COM”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32983099/

相关文章:

ios - 如何通过 AVCaptureVideoDataOutput() 和 AVCaptureSession() 快速录制视频

ssl - Windows 吊销证书(makecert、certmgr)

java - 将 PEM 转换为 PKCS7 (Java)

ios - UIImage 不使用 Swift 显示

ios - 如何快速访问存储在另一个应用程序中的声音文件?

ios - 自定义 UIPageViewController 手势识别器滚动行为

go - 使用golang和tls,如何将rawCerts [][]byte(传递给VerifyPeerCertificate)转换为x509.Certificate?

ssl - openssl 验证不使用 GeoTrust 证书

ruby-on-rails - 当我尝试使用 https 访问我的 Rails 站点时,为什么会出现 404 错误?

node.js - ACME - 使用 SAN 获取子域证书