Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用NSURLConnection处理自签名证书_Objective C_Ssl_Nsurlconnection - Fatal编程技术网

Objective c 使用NSURLConnection处理自签名证书

Objective c 使用NSURLConnection处理自签名证书,objective-c,ssl,nsurlconnection,Objective C,Ssl,Nsurlconnection,我希望允许使用NSURLConnection的自签名证书,前提是主机位于受信任列表中 我看到很多人都在做这样的事情: - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { if ([protectionSpace.authenticationMethod isEqualToString:

我希望允许使用NSURLConnection的自签名证书,前提是主机位于受信任列表中

我看到很多人都在做这样的事情:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        if (allowSelfSignedCertForThisHost) {
            NSLog(@"Allowing self signed!");
            return YES;
        }
    }
    return NO;
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        if ([trustedHosts containsObject:challenge.protectionSpace.host]) {
            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
        }
    }
    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

但是,,我想知道为什么您会调用
useCredential:forAuthenticationChallenge
,但之后也会调用
继续使用outCredentialforAuthenticationChallenge

只需在带有
iPhone配置实用程序
Apple Configurator

的设备上添加该证书,这是不可行的-它是由我正在连接到@Will,请下载并安装。你不需要它的私钥。只要证书就足够了。是否有任何代码更改来识别此自定义证书?这似乎更简单、更安全。一旦安装了自定义证书,是否需要通过编程执行任何操作来识别此证书?@Will,无需任何操作。如果您在Safari中打开您的链接,它还将显示证书是可信的。