簡體   English   中英

iOS 4.3 extractIdentityAndTrust鏈接錯誤

[英]iOS 4.3 extractIdentityAndTrust linking error

我在iOS中使用extractIdentityAndTrust時遇到問題,並遇到以下鏈接錯誤。 我只是在嘗試遵循“證書,密鑰和信任編程指南”中的代碼,並在軟件包中包含PKCS#12證書。

“ _extractIdentityAndTrust”,引用來自:cryptoViewController.o中的[cryptoViewController viewDidLoad] o找不到符號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(PKCS12Data中的CFDataRef,SecIdentityRef * outIdentity,SecTrustRef * outTrust);

有沒有人得到任何建議?

我不確定,但是它暗示此方法在iOS上不可用。
無論如何,從p12文件中獲取身份和證書的正確方法是:

  1. 使用SecPKCS12Import()函數導入p12數據。
    這將返回一個包含NSDictionary對象的NSArray。
  2. 身份存儲在字典中的鍵“ kSecImportItemIdentity”下
  3. NSArray證書存儲在“ kSecImportItemCertChain”下

如果您在p12文件中有多個身份,事情會變得有些復雜。 然后,您需要對如何選擇正確的邏輯有所了解。 但首先,只需從步驟1返回的數組中獲得索引0處的字典即可;-)

問候,佩斯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM