我是這個領域的新手......我最近遇到了一個問題......我想檢查來自服務器的SSL證書是否來自正確的服務器(我們自己的服務器),或者它來自任何惡意服務器......我如何實現這一目標?我使用NSURLConnection
代表方法connection:canAuthenticateAgainstProtectionSpace:
和connection:didReceiveAuthenticationChallenge:
。檢查SSL證書的身份
2
A
回答
3
在連接委託中使用以下代碼並將YOUR HOST
字符串替換爲您的真實主機。
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
{
if ([@"YOUR HOST" isEqualToString:challenge.protectionSpace.host])
{
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
forAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
0
對於iOS5的和更大的和失敗:
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
{
if ([@"xip.comcast.net" isEqualToString:challenge.protectionSpace.host] ||
[@"xip-staging.cim.comcast.net" isEqualToString:challenge.protectionSpace.host])
{
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
forAuthenticationChallenge:challenge];
}
else
{
[challenge.sender cancelAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
相關問題
- 1. SSL證書和身份驗證
- 2. 從小書籤檢查身份驗證
- 3. 身份證書
- 4. SSL身份驗證
- 5. NSMutableURLRequest檢查Https SSL證書驗證
- 6. iOS ssl證書驗證 - 無法驗證服務器身份
- 7. Facebook的身份驗證卷曲錯誤60:SSL證書
- 8. 集羣環境中的相互WCF證書身份驗證/ SSL
- 9. Android 4.0使用證書的Webview SSL身份驗證
- 10. 通過django中的ssl證書進行用戶身份驗證
- 11. PHP和X.509身份驗證 - 檢查證書頒發者
- 12. WSO2身份驗證證書
- 13. 身份驗證證書
- 14. PHP - 檢查請求的SSL證書
- 15. 檢查SSL證書的到期日期
- 16. 沒有SSL證書檢查的點子?
- 17. Asp.net身份驗證檢查
- 18. 如何支持SSL客戶端證書身份驗證?
- 19. php SSL客戶端證書身份驗證
- 20. 通過比較證書指紋進行SSL身份驗證?
- 21. Node.js SSL身份驗證
- 22. Android 4.0 SSL身份驗證
- 23. OAuth 2.0身份驗證SSL
- 24. Android SSL插座證書吊銷檢查
- 25. 檢查SSL證書到期日期
- 26. Android和SSL - 檢查證書有效性
- 27. 如何離線檢查SSL證書鏈?
- 28. 恢復SSL證書覆蓋檢查
- 29. Apache Camel ProducerTemplate忽略SSL證書檢查
- 30. 檢查自簽名證書(SSL,C#)