2011-08-05 44 views
1

我在使用iOS中的extractIdentityAndTrust時出現問題,並且得到以下鏈接錯誤。我只是試圖遵循「證書,密鑰和信任編程指南」中的代碼,並且在捆綁包中具有PKCS#12證書。iOS 4.3 extractIdentityAndTrust鏈接錯誤

「_extractIdentityAndTrust」,從參考: [cryptoViewController的viewDidLoad]在cryptoViewController.o 圖形符號沒有找到 Collect2:身份證returneed 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);

有沒有人有任何建議?

回答

0

我不確定,但它接縫說這種方法在iOS上不可用。
反正正確的方式來獲得一個P12文件的標識和證書是:

  1. 使用SecPKCS12Import()函數導入P12數據。
    這將返回一個包含NSDictionary對象的NSArray。
  2. 身份被存儲在項下的字典中「kSecImportItemIdentity」
  3. 的證書NSArray的是根據「kSecImportItemCertChain」

的事情存儲得到,如果你在你的P12多重身份有點複雜文件。那麼你需要有一些關於如何選擇正確的邏輯。但是,開始時只需從第1步返回的數組索引0獲取字典;-)

Regards, Pece