ios - https 使用自簽名憑證的問題
漂亮男人
漂亮男人 2017-05-02 09:38:04
0
1
938

對於https 使用自簽名證書,我有以下幾個問題:

1.網路上看的資料對於自簽名證書都需要在客戶端倒入證書,然後驗證證書的,如果不驗證證書,直接使用發過來的發過來的憑證進行通信有什麼風險和問題?

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    //1)获取trust object
    SecTrustRef trust = challenge.protectionSpace.serverTrust;
    NSURLCredential *cred = [NSURLCredential credentialForTrust:trust];
        [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
  }
  1. 我常在網路上看到這樣一段程式碼,你覺得這段程式碼是怎麼驗證的?

 NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
    __block NSURLCredential *credential = nil;
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        disposition = NSURLSessionAuthChallengeUseCredential;
        credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
    } else {
        disposition = NSURLSessionAuthChallengePerformDefaultHandling;
    }
    
    if (completionHandler) {
        completionHandler(disposition, credential);
    }
漂亮男人
漂亮男人

全部回覆(1)
曾经蜡笔没有小新

1、不驗證證書,直接請求都是有問題的哦
2、那邊是先判斷其證書伺服器是否可信的,然後再對證書做出相應的的處理方式。具體的可看 iOS HTTPs。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!