ios – willSendRequestForAuthenticationChallenge方法称为递归

ios – willSendRequestForAuthenticationChallenge方法称为递归,第1张

概述我正在使用iOS 10.我正在评估自签名证书,如下所示 -(void) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { NSURLProtectionSpace *protectionS 我正在使用iOS 10.我正在评估自签名证书,如下所示

-(voID) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {    NSURLProtectionSpace *protectionSpace = [challenge protectionSpace];    if ([protectionSpace authenticationMethod] == NSURLAuthenticationMethodServerTrust) {        SecTrustRef trust = [protectionSpace serverTrust];        SecPolicyRef policyOverrIDe = SecPolicyCreateSSL(true,(CFStringRef)@"HOSTname");        SecTrustSetPolicIEs(trust,policyOverrIDe);        CFMutableArrayRef certificates = CFArrayCreateMutable(kcfAllocatorDefault,&kcfTypeArrayCallBacks);        /* copy the certificates from the original trust object */        CFIndex count = SecTrustGetCertificateCount(trust);        CFIndex i=0;        for (i = 0; i < count; i++) {            SecCertificateRef item = SecTrustGetCertificateAtIndex(trust,i);            CFArrayAppendValue(certificates,item);        }        /* Create a new trust object */        SecTrustRef newtrust = NulL;        if (SecTrustCreateWithCertificates(certificates,policyOverrIDe,&newtrust) != errSecSuccess) {            /* Probably a good spot to log something. */            NSLog(@"Error in SecTrustCreateWithCertificates");            [connection cancel];            return;        }        CFRelease(policyOverrIDe);        /* Re-evaluate the trust policy. */        SecTrustResultType secresult = kSecTrustResultInvalID;        if (SecTrustEvaluate(trust,&secresult) != errSecSuccess) {            /* Trust evaluation Failed. */            [connection cancel];            // Perform other cleanup here,as needed.            return;        }        switch (secresult) {                //case kSecTrustResultInvalID:                //case kSecTrustResultRecoverableTrustFailure:            case kSecTrustResultUnspecifIEd: // The OS trusts this certificate implicitly.            case kSecTrustResultProceed: // The user explicitly told the OS to trust it.            {                NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];                [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];                return;            }            default: ;                /* It's somebody else's key. Fall through. */                [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge];                break;        }        /* The server sent a key other than the trusted key. */        [connection cancel];        // Perform other cleanup here,as needed.    }}

评估后的结果是’kSecTrustResultUnspecifIEd’,并且再次以递归方式调用相同的方法’willSendRequestForAuthenticationChallenge’.不确定为什么要递归调用该方法.让我知道代码的任何问题.

谢谢

解决方法 有几个解决方案,我认为最简单的解决方案是 here.总之,您需要检查[challenge prevIoUsFailureCount]以防止反复重新输入方法.

否则,从Apple api文档中,我会建议类似于this的东西,它使用不推荐的委托回调,但可能适合你.

总结

以上是内存溢出为你收集整理的ios – willSendRequestForAuthenticationChallenge方法称为递归全部内容,希望文章能够帮你解决ios – willSendRequestForAuthenticationChallenge方法称为递归所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1030924.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存