Titanium - “此服务器的证书无效。您可能正在连接到伪装成 DOMAIN.COM 的服务器”
Titanium - "The certificate for this server is invalid. You might be connecting to a server that is pretending to be DOMAIN.COM”
我正在使用 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();
我找到了连接被拒绝的原因。问题是我没有连接 godaddy 提供的两个证书文件,这在浏览器上似乎不是问题,但打破了应用程序的信任链。更正该部分解决了问题,使用:
cat gd_bundle-g1-g2.crt >> my_server.crt
创建完整的 crt 文件。
注意:第一个证书文件可在 Godaddy 的网站上下载,但在您下载 crt 文件时也会附加。
我正在使用 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();
我找到了连接被拒绝的原因。问题是我没有连接 godaddy 提供的两个证书文件,这在浏览器上似乎不是问题,但打破了应用程序的信任链。更正该部分解决了问题,使用:
cat gd_bundle-g1-g2.crt >> my_server.crt
创建完整的 crt 文件。
注意:第一个证书文件可在 Godaddy 的网站上下载,但在您下载 crt 文件时也会附加。