2011-08-05 22 views
1

iOSでextractIdentityAndTrustを使用していて、次のリンクエラーが発生しました。私は '証明書、鍵、信頼プログラミングガイド'のコードに従っていて、バンドルにPKCS#12証明書を持っています。iOS 4.3 extractIdentityAndTrustリンクエラー

"_extractIdentityAndTrust" は、から参照: collect2は見出されないcryptoViewController.o における[cryptoViewControllerのviewDidLoad】シンボル(S):Idがreturneed 1終了ステータス

Iプロジェクトで次のコードをしました。

- (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ファイルからのIDと証明書を取得するための適切な方法は次のとおりです。

  1. は、P12のデータをインポートするSecPKCS12Import()機能を使用してください。
    これは、NSDictionaryオブジェクトを含むNSArrayを返します。
  2. アイデンティティがキーの下に辞書内に格納された証明書の「kSecImportItemIdentity」
  3. アンNSArrayのは、あなたのP12で複数のIDを持っている場合は、物事は少し複雑になります「kSecImportItemCertChain」

の下に格納されていますファイル。次に、正しいものを選択する方法についていくつかの論理を持つ必要があります。しかし、スタートのためのステップ1 ;-)

よろしく、 ペツェ

で返されたばかり配列からインデックス0の辞書を取得
関連する問題