iOS 4.3 extractIdentityAndTrust链接错误

时间:2011-08-05 08:40:28

标签: iphone

我在iOS中使用extractIdentityAndTrust时遇到问题,并且遇到以下链接错误。我只是想遵循“证书,密钥和信任编程指南”中的代码,并在捆绑包中获得PKCS#12证书。

“_ extractIdentityAndTrust”,参考自: cryptoViewController.o中的[cryptoViewController viewDidLoad] 未找到符号 Collect2:Id返回1退出状态

我在项目中有以下代码;

    - (void)viewDidLoad {
   [super viewDidLoad];


       NSString *thePath = [[NSBundle mainBundle]
                                                pathForResource:@"iphone-cert" ofType:@"p12"];
   NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath];
   CFDataRef inPKCS12Data = (CFDataRef)PKCS12Data;
       CFDataRef inPKCS12Data1 = (CFDataRef)PKCS12Data;

       OSStatus status = noErr;
   SecIdentityRef myIdentity;
       SecIdentityRef *outIdentity;
       SecTrustRef *outTrust;
   SecTrustRef myTrust;
   status = extractIdentityAndTrust(
                                    inPKCS12Data1,
                                    &myIdentity,
                                    &myTrust);

       if (status != 0)
       {

       }

       SecTrustResultType trustResult;

       if (status == noErr)
       {
       status = SecTrustEvaluate(myTrust, &trustResult);
       }

       if (trustResult == kSecTrustResultRecoverableTrustFailure)
       {

   }


       OSStatus extractIdentityAndTrust(CFDataRef inPKCS12Data,
                                                                        SecIdentityRef *outIdentity,
                                                                        SecTrustRef *outTrust);

               OSStatus securityError = errSecSuccess;


               CFStringRef password = CFSTR("Password");
               const void *keys[] =   { kSecImportExportPassphrase };
               const void *values[] = { password };
               CFDictionaryRef optionsDictionary = CFDictionaryCreate(
                                                                                                                          NULL, keys,
                                                                                                                          values, 1,
                                                                                                                          NULL, NULL);


               CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
           CFDataRef inPKCS12Data2 = (CFDataRef)PKCS12Data;
               securityError = SecPKCS12Import(inPKCS12Data2,
                                                                               optionsDictionary,
                                                                               &items);



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



               if (optionsDictionary)
                       CFRelease(optionsDictionary);
               [PKCS12Data release];
       }


       //Next part

       SecCertificateRef myReturnedCertificate = NULL;
       SecIdentityRef myReturnedIdentity;

   status = SecIdentityCopyCertificate (myReturnedIdentity,
                                                                                &myReturnedCertificate);

   CFStringRef certSummary = SecCertificateCopySubjectSummary
       (myReturnedCertificate);

   NSString* summaryString = [[NSString alloc]
                                                          initWithString:(NSString*)certSummary];  //

   NSLog(@"%@", summaryString);
       [summaryString release];



}

以及头文件中的以下声明;

OSStatus extractIdentityAndTrust(CFDataRef inPKCS12Data, SecIdentityRef * outIdentity,SecTrustRef * outTrust);

有人有任何建议吗?

1 个答案:

答案 0 :(得分:0)

我不确定,但是这个方法在iOS上无法使用 无论如何,从p12文件获取身份和证书的正确方法是:

  1. 使用 SecPKCS12Import()功能导入p12数据。
    这将返回包含NSDictionary对象的NSArray。
  2. 标识存储在字典“kSecImportItemIdentity”
  3. 下的字典中
  4. NSArray证书存储在'kSecImportItemCertChain'
  5. 如果你的p12文件中有多个身份,事情会变得有点复杂。那么你需要有一些关于如何选择正确的逻辑。但是为了开始,只需从步骤1返回的数组中获取索引0处的字典; - )

    此致 PECE