Code = -1200 "Произошла ошибка SSL, и невозможно установить безопасное соединение с сервером - PullRequest
0 голосов
/ 17 марта 2020

Я пытаюсь подключиться к серверу, который при открытии через браузер выдает клиенту предупреждающее сообщение для идентификации самого себя. найдите изображение здесь

Я использую тот же сертификат клиента для выполнить аутентификацию клиента через код swift, но я продолжаю получать вышеупомянутую ошибку. Я запустил диагностику ATS в терминале и соответственно изменил info.plist. Ниже приведен мой код.

func urlSession(_ session: URLSession,
                didReceive challenge: URLAuthenticationChallenge,
                completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {

    if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust,
        challenge.protectionSpace.host.contains("apple.com"),
        let serverTrust = challenge.protectionSpace.serverTrust {
                let credential = URLCredential(trust: serverTrust)
                challenge.sender?.use(credential, for: challenge)
                completionHandler(URLSession.AuthChallengeDisposition.useCredential, credential)
                return
    }else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate,
        challenge.protectionSpace.host.contains("apple.com") {
        // Pass apple_corporate_server_ca_1 certificate information here
                let path = Bundle.main.path(forResource: "Certificates", ofType: ".p12")
                let PKCS12Data = NSData(contentsOfFile: path!)
                let identityAndTrust = self.extractIdentity(certData: PKCS12Data!)
        let credential = URLCredential(identity: identityAndTrust.identity, certificates: (identityAndTrust.certArray as! [Any]), persistence: .forSession)
                completionHandler(URLSession.AuthChallengeDisposition.useCredential, credential)
                return}
    // Pinning failed, perform default handling
    completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)

}

И мой info.plist выглядит как dis.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>yourdomain.com</key>
        <dict>
            <key>NSExceptionMinimumTLSVersion</key>
            <string>TLSv1.0</string>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...