HTTPS 与 NSURLConnection - NSURLErrorServerCertificateUntrusted

发布于 2024-08-08 20:22:37 字数 483 浏览 2 评论 0原文

我有一个可以通过 http 连接良好的应用程序。尝试 https 时,我收到错误消息,指出根证书不受信任。我找到了我的站点证书、其 CA 证书和 CA 根证书的 URL,并通过 Safari 将它们添加到手机中。现在,当我进入首选项 ->一般->个人资料 我可以看到我所有的证书,一直到链上。每张证书上都有一个未签名的红色标签。当我连接时,我仍然收到 NSURLErrorServerCertificateUntrusted 错误。我正在考虑下一步该去哪里。

任何帮助都会很棒。唯一可能影响此问题的事情是我正在连接到一个奇怪的端口。所以我的网址是 www.domain.com:port。端口号是否会导致证书-域名不匹配?

现在我已经使用 iPhone 配置实用程序将配置文件添加到手机中。它有我的根证书、ca 证书和站点证书。手机上的个人资料显示已验证。在详细信息中我可以看到我的三张证书。但是当我尝试连接时,我仍然收到不受信任的证书错误。有什么建议吗?

只是想看看其他人是否可以提供帮助?

I have an application that connects fine over http. When trying https I got the error that says that the root cert is not trusted. I found URLs for my site certificate, its CA certificate, and the CA's root certificate and have added them through Safari to the phone. Now when I go to Preferences -> General -> Profiles I can see all my certificates that go all the way up the chain. There is a red unsigned label on each certificate. Still when I connect I get the NSURLErrorServerCertificateUntrusted error. I'm trying to figure where to go next.

Any help would be great. The only other thing that may affect this, is that I am connecting to an odd port. So my url is www.domain.com:port. Does the port number create a certificate - domain name mismatch?

Now I have used the iPhone Configuration Utility to add a configuration profile to the phone. It has my root certificate, ca certificate, and site certificate. The profile on the phone says its verified. In the details I can see my three certificates. But when I try to connect, I still get the untrusted certificate error. Any suggestions?

Just trying to see if anyone else can help on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-08-15 20:22:37

有一个受支持的 API,用于在 NSURLConnection 加载期间忽略错误的证书。为此,只需将类似的内容添加到您的 NSURLConnection 委托中:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
  return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
    if (... user allows connection despite bad certificate ...)
      [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

  [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

请注意,connection:didReceiveAuthenticationChallenge: 可以在(很长时间)之后(在必要时向用户显示对话框等之后)将其消息发送到challenge.sender。

There is a supported API for ignoring bad certificates during NSURLConnection loads. To do so, simply add something like this to your NSURLConnection delegate:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
  return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
    if (... user allows connection despite bad certificate ...)
      [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

  [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

Note that connection:didReceiveAuthenticationChallenge: can send its message to challenge.sender (much) later, after presenting a dialog box to the user if necessary, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文