Titanium – “此服务器的证书无效。您可能正在连接到假装为DOMAIN.COM的服务器”

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

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

此服务器的证书无效。 您可能正在连接到假装为DOMAIN.COM的服务器

我已尝试过其他安全域名,它运行正常。 我正在使用Ti.Network.createHTTPClient来创建我的连接。 有没有人对这个问题有任何想法? 这里有什么我想念的吗?

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

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

 // 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(); 

我找到了为什么在我的情况下连接被拒绝的原因。 问题是我没有连接godaddy给出的两个cert文件,这在浏览器上似乎不是问题,但是打破了应用程序的信任链。 更正该部分修复了问题,使用:

 cat gd_bundle-g1-g2.crt >> my_server.crt 

创建完整的crt文件。

注意:第一个证书文件可以在Godaddy的网站上下载,但在下载crt文件时也会附加。