【问题标题】:Client certificates iOS客户端证书 iOS
【发布时间】:2011-12-08 09:38:28
【问题描述】:

我正在尝试提取 .p12 文件并将其用于针对我自己的服务器的双向身份验证。当我试图编译时,我得到了一些链接错误。错误指的是:

  • _kSecImportExportPassphrase
  • _SecIdentityCopyCertificate
  • _kSecImportItemTrust
  • _SecPKCS12Import
  • _kSecImportItemIdentity

这是我用来提取 p12 文件的代码:

        -(void)clientCert   
        {
            NSString *path = [[NSBundle mainBundle] pathForResource:@"torbix" ofType:@"p12"];
            NSData *p12data = [NSData dataWithContentsOfFile:path];
            CFDataRef inP12data = (CFDataRef)p12data;

            SecIdentityRef myIdentity;
            SecTrustRef myTrust;
            OSStatus status = extractIdentityAndTrust(inP12data, &myIdentity, &myTrust);

            SecCertificateRef myCertificate;
            SecIdentityCopyCertificate(myIdentity, &myCertificate);
            const void *certs[] = { myCertificate };
            CFArrayRef certsArray = CFArrayCreate(NULL, certs, 1, NULL);

        }
        OSStatus extractIdentityAndTrust(CFDataRef inP12data, SecIdentityRef *identity, SecTrustRef *trust)
        {
            OSStatus securityError = errSecSuccess;

            CFStringRef password = CFSTR("password");
            const void *keys[] = { kSecImportExportPassphrase };
            const void *values[] = { password };

            CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);

            CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
            securityError = SecPKCS12Import(inP12data, options, &items);

            if (securityError == 0) {
                CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex(items, 0);
                const void *tempIdentity = NULL;
                tempIdentity = CFDictionaryGetValue(myIdentityAndTrust, kSecImportItemIdentity);
                *identity = (SecIdentityRef)tempIdentity;
                const void *tempTrust = NULL;
                tempTrust = CFDictionaryGetValue(myIdentityAndTrust, kSecImportItemTrust);
                *trust = (SecTrustRef)tempTrust;
            }

            if (options) {
                CFRelease(options);
            }

        return securityError;
    }

为什么会出现这些错误?

【问题讨论】:

  • 有哪些错误以及您链接到哪些框架?
  • 明天我回到实验室时会检查更多! :)
  • 现在解决了!答案就在答案中! :)

标签: iphone objective-c ios linker


【解决方案1】:

Security.framework 添加到您的项目中。

在目标中的 Xcode 4.2+ 中,转到“Build Phases”选项卡,“Link BinariesWith Libraries”,单击“+”并添加“Security.framework”。

【讨论】:

  • 谢谢!明天我回实验室试试。 (Y)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-09
  • 2015-09-06
  • 2020-05-17
  • 1970-01-01
  • 2017-01-02
  • 2016-01-27
  • 2017-06-08
相关资源
最近更新 更多