![](/img/trans.png)
[英]How to fix xCode 4 linking error with CoreData (4.2 -> 4.3)
[英]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文件中獲取身份和證書的正確方法是:
如果您在p12文件中有多個身份,事情會變得有些復雜。 然后,您需要對如何選擇正確的邏輯有所了解。 但首先,只需從步驟1返回的數組中獲得索引0處的字典即可;-)
問候,佩斯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.