开发者

iOS 4.3 extractIdentityAndTrust linking error

I'm having a problem using extractIdentityAndTrust in iOS and getting the following linking error. I'm just trying to follow the code from the 'Certificate,Key and trust programming guide' and have a PKCS#12 certificate in the bundle.

"_extractIdentityAndTrust", reference from: [cryptoViewController viewDidLoad] in cryptoViewController.o Symbol(s) not found Collect2: Id returneed 1 exit status

I've the following code in the project;

    - (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];



}

and the following declaration in the header file;

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

Has anyone got any advice?


I'm not sure, but it seams that this method is not available on iOS.
Anyway the proper way to get the identity and certificates from a p12 file is:

  1. Use the SecPKCS12Import() function to import the p12 data.
    This will return an NSArray containing NSDictionary objects.
  2. The identity is stored within the dictionary under the key 'kSecImportItemIdentity'
  3. An NSArray of certificates is stored under 'kSecImportItemCertChain'

The things get a little bit complicated if you have multiple identities in your p12 file. Then you need to have some logic on how to choose the right one. But for start just get the dictionary at index 0 from the array returned at step 1 ;-)

Regards, Pece

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜