certificate
에 p12-format
이 있는데 정보를 얻고 싶습니다.스레드 1 : EXC_BAD_ACCESS (코드 = 1, 주소 = 0x10) 오류
I가 나는 다음과 같은 라인
SecIdentityRef identity = nil;
SecTrustRef trust = nil;
NSData *certPath = [[NSData alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"p12"]];
CFDataRef certData = (__bridge_retained CFDataRef)(certPath);
[self extractIdentityAndTrust:certData withIdentity:&identity withTrust:&trust withPassword:CFSTR("")];
NSString* summaryString = [self copySummaryString:&identity];
NSLog(@"%@", summaryString);
에하지만 내 기능 copySummaryString
나는 내 viewDidLoad
이 두 메소드를 호출
-(OSStatus)extractIdentityAndTrust: (CFDataRef) inPKCS12Data withIdentity:(SecIdentityRef *) outIdentity withTrust:(SecTrustRef *) outTrust withPassword:(CFStringRef) keyPassword
{
OSStatus securityError = errSecSuccess;
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { keyPassword };
CFDictionaryRef optionsDictionary = NULL;
optionsDictionary = CFDictionaryCreate(NULL, keys, values, (keyPassword ? 1 : 0), NULL, NULL);
CFArrayRef items = NULL;
securityError = SecPKCS12Import(inPKCS12Data, optionsDictionary, &items);
if(securityError == 0)
{
CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0);
const void *tempIdentity = NULL;
tempIdentity = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemIdentity);
CFRetain(tempIdentity);
*outIdentity = (SecIdentityRef)tempIdentity;
const void *tempTrust = NULL;
tempTrust = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemTrust);
CFRetain(tempTrust);
*outTrust = (SecTrustRef)tempTrust;
}
if(optionsDictionary) CFRelease(optionsDictionary);
if(items) CFRelease(items);
return securityError;
}
및
-(NSString *)copySummaryString:(SecIdentityRef *) identity
{
// Get the certificate from the identity.
SecCertificateRef myReturnedCertificate = NULL;
OSStatus status = SecIdentityCopyCertificate (*identity, &myReturnedCertificate);
if(status)
{
NSLog(@"SecIdentityCopyCertificate failed.\n");
return NULL;
}
CFStringRef certSummary = SecCertificateCopySubjectSummary(myReturnedCertificate);
NSString* summaryString = [[NSString alloc] initWithString:(__bridge NSString *)certSummary];
CFRelease(certSummary);
return summaryString;
}
다음과 같은 두 가지 기능 다음 줄에서 오류가 발생했습니다
OSStatus status = SecIdentityCopyCertificate (*identity, &myReturnedCertificate);
좋은 예가 하나도 없습니다. 어떻게이 함수를 올바르게 호출 할 수 있습니까? 왜이 오류가 발생하며이 오류는 무엇을 의미합니까?
나는 또한 https://stackoverflow.com/a/20913426/5629933, https://stackoverflow.com/a/19219932/5629933 또는 Custom Certificate in iOS App과 같은 게시물을 발견했습니다.
나는 Apple의 설명서를 https://developer.apple.com/library/ios/documentation/Security/Conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html#//apple_ref/doc/uid/TP40001358-CH208-SW13에서 읽었지만별로 도움이되지 않습니다.