2011-12-08 4 views
2

.p12 파일을 추출하여 내 서버에 대한 양방향 인증에 사용하려고합니다. 내가 컴파일하려고하면 몇 가지 링크 오류가 발생합니다. 오류는에 다스 려됩니다클라이언트 인증서 iOS

  • 이 _kSecImportExportPassphrase
  • _SecIdentityCopyCertificate
  • _kSecImportItemTrust
  • _SecPKCS12Import
  • _kSecImportItemIdentity 여기

내가 P12 파일을 추출하기 위해 사용하고 코드는 다음과 같습니다

 -(void)clientCert 
     { 
      NSString *path = [[NSBundle mainBundle] pathForResource:@"torbix" ofType:@"p12"]; 
      NSData *p12data = [NSData dataWithContentsOfFile:path]; 
      CFDataRef inP12data = (CFDataRef)p12data; 

      SecIdentityRef myIdentity; 
      SecTrustRef myTrust; 
      OSStatus status = extractIdentityAndTrust(inP12data, &myIdentity, &myTrust); 

      SecCertificateRef myCertificate; 
      SecIdentityCopyCertificate(myIdentity, &myCertificate); 
      const void *certs[] = { myCertificate }; 
      CFArrayRef certsArray = CFArrayCreate(NULL, certs, 1, NULL); 

     } 
     OSStatus extractIdentityAndTrust(CFDataRef inP12data, SecIdentityRef *identity, SecTrustRef *trust) 
     { 
      OSStatus securityError = errSecSuccess; 

      CFStringRef password = CFSTR("password"); 
      const void *keys[] = { kSecImportExportPassphrase }; 
      const void *values[] = { password }; 

      CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL); 

      CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL); 
      securityError = SecPKCS12Import(inP12data, options, &items); 

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

      if (options) { 
       CFRelease(options); 
      } 

     return securityError; 
    } 

왜 이러한 오류가 발생합니까?

+0

어떤 오류가 있으며 어떤 프레임 워크에 연결하고 있습니까? – Stripes

+0

내가 실험실에 다시있을 때 내일 더 체크 아웃 할 것이다! :) – Bewn

+0

이제 해결되었습니다! 해결책은 해결책입니다! :) – Bewn

답변

6

Security.framework을 프로젝트에 추가하십시오.

대상의 Xcode 4.2 이상에서 "빌드 단계"탭으로 이동하고 "라이브러리와 바이너리 라이브러리"를 클릭하고 "+"를 클릭하여 "Security.framework"를 추가하십시오.

enter image description here

+0

고마워요! 내일 다시 실험실로 돌아 가면해볼거야. (와이) – Bewn