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

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

Gen 3月前

63 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)
  • 我的 SDK 需要另一个 SDK,我有它的 .h 文件 (xdjaalg.h)。当我仅使用 xdjaalg.h 文件编译动态库时,出现错误:ld: 未定义的符号:。所以我必须链接 xdjaalg.a,但我没有

    我的 SDK 需要另一个 SDK,我有它的.h 文件(xdjaalg.h)。当我仅使用 xdjaalg.h 文件编译我的动态库时,出现错误: ld: Undefined symbols: 。所以我必须链接 xdjaalg.a,但我没有将 xdjaalg.a 编译到我的 SDK 中。

    当我将选项更改为时 Mach-O Type Static Library 一切 Build Settings 顺利。但我想使用动态库。

    有什么方法可以使动态库像系统框架那样仅使用头文件进行编译。

    我也很好奇为什么系统框架没有这个限制,我只是导入系统头文件 UIKit.h ,它可以很好地编译(无论是动态还是静态)。但是 xdjaalg.h 构建失败 ld: Undefined symbols:

  • 我有一个 NSString *htmlString,它在 HTML 中显示一个按钮来打开 Telegram。我曾尝试加入 Telegram

    我有一个 NSString *htmlString 在 HTML 中显示按钮来打开 Telegram。

    我已尝试过 <a href='https://t.me/*********official' class='btn btn-success btn-block'>Join on Telegram</a> 但这只是直接在应用程序中打开。

    我的第二个理论是尝试 <a href='window.open('https://t.me/*********official')' class='btn btn-success btn-block'>Join on Telegram</a> 相同的结果。如何在 Safari 中使用 Objective-C htmlString 打开此链接,而不是直接在应用程序中打开?

  • 我有一个应用需要在其 XCTestCase 子类中动态生成测试方法。我使用 +(NSArray *)testInvocations 在运行时动态生成测试方法...

    我有一个应用程序需要在其 XCTestCase 子类中动态生成测试方法。我使用 +(NSArray<NSInvocation*>*)testInvocations 以下(虚拟)名称在运行时动态生成测试方法: example_test , permissions_location_test permissions_many_test 。下面是简化的、可直接粘贴到 Xcode 中的代码。

    @import XCTest;
    @import ObjectiveC.runtime;
    
    @interface ParametrizedTests : XCTestCase
    @end
    
    @implementation ParametrizedTests
    + (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
    

    我可以使用以下方法同时运行所有这些测试:

    xcodebuild test \
      -scheme Landmarks \
      -destination 'platform=iOS Simulator,name=iPhone 15'
    

    摘自上述命令的标准输出:

    Test Suite 'Selected tests' passed at 2023-11-16 13:44:59.148.
         Executed 3 tests, with 0 failures (0 unexpected) in 0.246 (0.248) seconds
    

    问题

    我现在面临的问题是,我无法使用 标志选择仅运行一个测试 xcodebuild -only-testing 例如:

    xcodebuild test \
      -scheme Landmarks \
      -destination 'platform=iOS Simulator,name=iPhone 15' \
      -only-testing 'LandmarksUITests/ParametrizedTests/example_test'
    

    不起作用-没有执行任何测试:

    Test Suite 'ParametrizedTests' passed at 2023-11-16 13:45:58.472.
         Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds
    

    我也尝试过这样做:

    xcodebuild test \
      -scheme Landmarks \
      -destination 'platform=iOS Simulator,name=iPhone 15' \
      -only-testing 'LandmarksUITests/ParametrizedTests/testInvocations'
    

    但结果是一样的。

    所以问题是: 如何使用 -only-testing 选项选择测试子集(在运行时使用 testInvocations 动态生成)? 有可能吗?

  • 经过一番挖掘,我发现 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 框架如何覆盖此方法
返回
作者最近主题: