ios - Apple 证书对 PKCS7_verify 无效

标签 ios xcode openssl x509certificate

我下载AppleRootCertificate.cer现在我尝试检查我的应用内收据证书是否有效(与苹果一样)。

我像 apple 在他的 WWDS 视频中那样做。

    BIO *b_receipt = BIO_new_mem_buf((void *)[receipt bytes], (long)[receipt length]);
    BIO *b_x509 = BIO_new_mem_buf((void *)[certificateData bytes], (long)[certificateData length]);

    // Convert receipt data to PKCS #7 Representation
    PKCS7 * p7 = d2i_PKCS7_bio(b_receipt, NULL);

    // Create the certificate store for matching white Apple cerif.
    X509_STORE * store = X509_STORE_new();
    X509 * appleRootCA = d2i_X509_bio(b_x509, NULL);
    X509_STORE_add_cert(store, appleRootCA);

    // Verify the Signature

    BIO * b_receiptPayload = BIO_new(BIO_s_mem());
    int result = PKCS7_verify(p7, NULL, store, NULL, b_receiptPayload, 0);
    NSLog(@"Result == %i", result); 

但结果总是0而不是1。

我做错了什么?

最佳答案

按照#noloader 的建议,我使用 ERR_get_error() 打印错误。

当我得到:Error:0D0C50A1:lib(13):func(197):reason(161) 时,我用谷歌搜索并发现我需要在上面添加这一行:

 OpenSSL_add_all_algorithms();

这解决了我所有的问题:D

关于ios - Apple 证书对 PKCS7_verify 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22716149/

相关文章:

iphone - 如何以编程方式在 iPhone 中查找掉话?

iOS 10 错误多次记录导致应用程序挂起

iphone - 如何在每页的基础上更改导航栏的背景图像?

Ruby OpenSSL,打印发行者和 pem 文件的主题

ios - Creating an image format with an unknown type 是错误的 Objective-C Xcode 8

ios - 为 `UICollectionViewController` 带来一个 UIView 到前面

ios - SwiftUI - 使用 Toggle 隐藏列表项

xcode - 将 Mac 目标添加到 Xcode 中的 iOS 项目,现在为 'Error Starting Executable File'

openssl - 为什么openssl在OCSP协议(protocol)中发送CA证书

macos - 由于 "unknown message digest algorithm",curl 无法访问 github.com