web-dev-qa-db-ja.com

iOSで「TIC SSL信頼エラー」を修正する方法

Webサービスを使用してアプリケーションにログインしようとしたとき。 plist-fileも次のように設定します

enter image description here

次のエラーが表示されました。このエラーはコンソールに表示されます

TIC SSL Trust Error [5:0x1c017fbc0]: 3:0
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
Task <E0C414FF-98C7-4E6B-876F-B9006465C8FD>.<1> HTTP load failed (error code: -1200 [3:-9802]
7
IKKA

次のコードは私のために機能します。 NSURLSessionDelegate(didReceiveChallenge)のデリゲートメソッドを実装しました

NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:Nil];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
                    //Handle the response
   }];
[task resume];

// NSURLSessionDelegate method

  - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{

      if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
        if([challenge.protectionSpace.Host isEqualToString:@"yourdomain.com"]){
          NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
      completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
    }
  }
}
4
IKKA

IKKA-Swift 4.2バージョンでの回答

extension CustomViewController: URLSessionDelegate {
    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate) {
            completionHandler(.rejectProtectionSpace, nil)
        }
        if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
            let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
            completionHandler(.useCredential, credential)
        }
    }
}
4

これはAppdelegate.mに入力できます

コードは次のとおりです。

@implementation NSURLRequest(DataController)
   + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)Host{
   return YES;
}  
2
张轶铭

Swift 5.1

クラスはURLSessionDelegateに準拠し、「didReceive Challenge」機能を実装する必要があります。

これらのApple開発者ページは問題を示しており、この問題を安全に修正する方法に関する多くの洞察を提供します。

認証チャレンジの処理

手動サーバー信頼認証の実行

開発環境またはQA環境でこの問題を修正する方法の例を次に示します。

func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    #if DEBUG
    if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
        if challenge.protectionSpace.Host == "YourTrustedDevOrQaDomain" {
            // At this point you can prevent a domain that is pretending to be a trusted domain by challenging the user to present some credentials or a security mechanism for authentication. 
            if let serverTrust = challenge.protectionSpace.serverTrust {
                let credential = URLCredential(trust: serverTrust)
                completionHandler(URLSession.AuthChallengeDisposition.useCredential, credential)
            }
        }
    }
    #endif
}
0
Ramin

Apple開発者ドキュメント。

sslはiOS 11を変更します https://forums.developer.Apple.com/thread/80197

証明書ビューアには、より具体的なメッセージングもあります。以下のスクリーンショットでは、特定の信頼エラーに対して警告が表示されていることがわかります。この場合、SHA-1で署名されているため、「この証明書は検証できません(弱いダイジェストアルゴリズム)」というエラーが表示されます。

場合によっては、サーバーに接続し、テスト目的でコマンドを発行すると便利です。一般的なインターネットプロトコル(HTTP、SMTP、NNTPなど)では、telnetツールを使用してこれを行うことができます。ただし、プロトコルがTLSを使用している場合、これは機能しません。その場合、最適なオプションはopensslツールのs_clientサブコマンドです。リスト1は、このツールを使用して手動でコンテンツを取得する方法を示しています(HTTPSはポート443を使用することに注意してください)。

リスト1 openssl s_clientの使用

$ openssl s_client -connect www.Apple.com:443
CONNECTED(00000003)
[...]
GET / HTTP/1.1
Host: www.Apple.com

HTTP/1.1 200 OK
Server: Apache/2.2.3 (Oracle)
Content-Length: 9464
Content-Type: text/html; charset=UTF-8
ntCoent-Length: 9516
Cache-Control: max-age=47
Expires: Mon, 25 Jun 2012 16:18:24 GMT
Date: Mon, 25 Jun 2012 16:17:37 GMT
Connection: keep-alive

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
[...]
</html>
closed
$

S_clientサブコマンドは、多くの便利なデバッグオプションをサポートしています。例えば:

-cert引数を指定して、クライアント証明書要求に応答させることができます。 -showcertsオプションを指定して、サーバーが提供する証明書の完全なリストを取得できます。 -debugおよび-msgオプションは、低レベルのデバッグ機能を有効にします。これらのオプションの詳細については、manページを参照してください。

0
BuLB JoBs