8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

崩溃的 _dispatch_sync_f SecTrustGetCertificateAtIndex 身份验证挑战 iOS

Gen 3月前

62 0

有人能帮我理解一下这种罕见且随机的崩溃吗?有没有办法修复此问题而不会重现?线程 0 名称:线程 0 崩溃:0 libdispatch.dylib

有人能帮我理解一下这种罕见且随机的崩溃吗?有没有办法修复这个问题而不让它重现?

Thread 0 name:
Thread 0 Crashed:
0   libdispatch.dylib               0x00000001b2d7e538 _dispatch_sync_f + 4 (queue.c:1898)
1   Security                        0x00000001b372d0d8 SecTrustGetCertificateAtIndex + 244 (SecTrust.c:0)
2   PK9                             0x0000000102d63124 __61+[CertificateUtils certificatesFromTrust:options:completion:]_block_invoke + 88 (CertificateUtils.m:201)
3   CoreFoundation                  0x00000001aadb51b8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28 (CFRunLoop.c:1805)
4   CoreFoundation                  0x00000001aadb39ac __CFRunLoopDoBlocks + 356 (CFRunLoop.c:1847)
5   CoreFoundation                  0x00000001aadb1888 __CFRunLoopRun + 812 (CFRunLoop.c:2953)
6   CoreFoundation                  0x00000001aadb1478 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   GraphicsServices                0x00000001ee30a4f8 GSEventRunModal + 164 (GSEvent.c:2196)
8   UIKitCore                       0x00000001ad1db360 -[UIApplication _run] + 888 (UIApplication.m:3685)
9   UIKitCore                       0x00000001ad1da99c UIApplicationMain + 340 (UIApplication.m:5270)
10  PK9                             0x0000000102e5dfe8 main + 68 (main.m:15)
11  dyld                            0x00000001cdae9dcc start + 2240 (dyldMain.cpp:1269)

发生崩溃的函数:

+ (void)certificatesFromTrust:(SecTrustRef)trust options:(CertificateOptions)options completion:(void (^)(NSArray *))completion
{
    if (trust == NULL) {
        completion(nil);
    }
    else {
        // trust needs to be evaluated prior to attempting to retrieve the certs
        CFIndex count = SecTrustGetCertificateCount(trust);
        
        [self evaluateTrust:trust completion:^(OSStatus status, SecTrustResultType result) {
            NSMutableArray *certs = [NSMutableArray arrayWithCapacity:(NSInteger)count];
            
            for (CFIndex i = 0; i < count; i++) {
                SecCertificateRef cert = SecTrustGetCertificateAtIndex(trust, i);
                if (cert != NULL) {
                    // Extract certificate data
                    NSData *certData = CFBridgingRelease(SecCertificateCopyData(cert));
                    
                    if (certData != nil && (options & CertificateOptionsRemoveRootCertificates) && count > 1) {
                        // We were told to strip all anchor certificates, so only keep this one if it's issued by someone else (and not the only cert, i.e. self-signed)
                        const unsigned char *certDataBytes = (const unsigned char *)[certData bytes];
                        X509 *x509Cert = d2i_X509(NULL, &certDataBytes, [certData length]);
                        NSString *subjectCN = X509CertificateGetCommonName(X509_get_subject_name(x509Cert));
                        NSString *issuerCN = X509CertificateGetCommonName(X509_get_issuer_name(x509Cert));
                        X509_free(x509Cert);
                        
                        if ([subjectCN isEqualToString:issuerCN]) {
                            certData = nil; // do not add root certificates
                        }
                    }
                    
                    if (certData != nil) {
                        // create a copy of the certificate and add it to the array transferring ownership to ARC
                        cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)(certData));
                        [certs addObject:CFBridgingRelease(cert)];
                    }
                }
            }
            
            completion(certs);
        }];
    }
}
帖子版权声明 1、本帖标题:崩溃的 _dispatch_sync_f SecTrustGetCertificateAtIndex 身份验证挑战 iOS
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由Gen在本站《objective-c》版块原创发布, 转载请注明出处!
最新回复 (0)
  • 经过一番挖掘,我发现 XCTest 在 -only-testing MyTarget/MyClass/myTest 传递时调用测试的方式不同。更具体地说, 当在中指定单个测试时,不会调用 XCTestCase.defaultTestSuite -only-testing .

    继承自( -only-testing 当然 NSObject.instancesRespondToSelector:aSelector: 发送消息 XCTestCase 来检查它是否可以运行传入的测试 NSObject 。这似乎是一个很好的 defaultTestSuite 手动调用的钩子点,它反过来会调用 testInvocations ,它会生成测试方法并将其混入到 ParametrizedTests 类中。

    我的 LandmarksTests 课程缺少该选择器的覆盖。在我将其添加到我的 ParametrizedTests 课程后:

    
    + (BOOL)instancesRespondToSelector:(SEL)aSelector {
      [self defaultTestSuite]; // calls testInvocations
      BOOL result = [super instancesRespondToSelector:aSelector];
      return true;
    }
    

    它开始正常工作了!

    这是最终文件,可以复制粘贴到 ParametrizedTests.m 内的 LandmarksUITests ,并且可以正常工作!

    @import XCTest;
    @import ObjectiveC.runtime;
    
    @interface ParametrizedTests : XCTestCase
    @end
    
    @implementation ParametrizedTests
    
    + (BOOL)instancesRespondToSelector:(SEL)aSelector {
      [self defaultTestSuite]; // calls testInvocations
      BOOL result = [super instancesRespondToSelector:aSelector];
      return true;
    }
    
    + (NSArray<NSInvocation *> *)testInvocations {
      NSLog(@"testInvocations() called");
    
      /* Prepare dummy input */
      __block NSMutableArray<NSString *> *dartTestFiles = [[NSMutableArray alloc] init];
      [dartTestFiles addObject:@"example_test"];
      [dartTestFiles addObject:@"permissions_location_test"];
      [dartTestFiles addObject:@"permissions_many_test"];
    
      NSMutableArray<NSInvocation *> *invocations = [[NSMutableArray alloc] init];
    
      NSLog(@"Before the loop, %lu elements in the array", (unsigned long)dartTestFiles.count);
    
      for (int i = 0; i < dartTestFiles.count; i++) {
        /* Step 1 */
    
        NSString *name = dartTestFiles[i];
    
        void (^anonymousFunc)(ParametrizedTests *) = ^(ParametrizedTests *instance) {
          NSLog(@"anonymousFunc called!");
        };
    
        IMP implementation = imp_implementationWithBlock(anonymousFunc);
        NSString *selectorStr = [NSString stringWithFormat:@"%@", name];
        SEL selector = NSSelectorFromString(selectorStr);
        class_addMethod(self, selector, implementation, "v@:");
    
        /* Step 2 */
    
        NSMethodSignature *signature = [self instanceMethodSignatureForSelector:selector];
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
        invocation.selector = selector;
    
        NSLog(@"RunnerUITests.testInvocations(): selectorStr = %@", selectorStr);
    
        [invocations addObject:invocation];
      }
    
      NSLog(@"After the loop");
    
      return invocations;
    }
    
    @end
    

    也可以看看:

    • Quick 框架如何覆盖此方法
返回
作者最近主题: