1

.p12 証明書から読み取る次のコードがあり、証明書データを認証チャレンジに渡したい:

- (SecIdentityRef)getClientCertificate {
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"fest" ofType:@"p12"];
if(!thePath)
    return NULL;
NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath] ;
CFDataRef inPKCS12Data = (CFDataRef)CFBridgingRetain(PKCS12Data);
CFStringRef password = CFSTR("fest");
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { password };
CFDictionaryRef optionsDictionary = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
OSStatus ret = SecPKCS12Import(inPKCS12Data, optionsDictionary, &items);
if (ret != errSecSuccess)
{
    // TODO: handle error.
    NSLog(@"-> SecPKCS12Import error (%ld)", ret);
}
CFRelease(optionsDictionary);

CFDictionaryRef identityDict = CFArrayGetValueAtIndex(items, 0);
SecIdentityRef identityApp = nil;
if(!identityDict)
    return nil;
identityApp = (SecIdentityRef)CFDictionaryGetValue(identityDict, kSecImportItemIdentity);

SecIdentityRef      identity;
SecCertificateRef   cert;
OSStatus            err;
CFStringRef         certName;

identity = identityApp;
assert( (identity != NULL) && (CFGetTypeID(identity) == SecIdentityGetTypeID()) );

cert = NULL;
err = SecIdentityCopyCertificate(identity, &cert);
assert(err == noErr);
assert(cert != NULL);

certName = SecCertificateCopySubjectSummary(cert);
assert(certName != NULL);

NSLog(@"%@" , (id) CFBridgingRelease(certName));
//NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:(id)CFBridgingRelease(certName),@"USERID",nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"UserInfoReceived" object:nil];

//CFRelease(cert);
//CFRelease(certName);
return identityApp;
_identities = [[NSMutableArray alloc] initWithArray:(__bridge NSArray *)(items)];
_certs = [[NSMutableArray alloc] initWithArray:(__bridge NSArray *)(cert)];

}

最後に、項目 CFArrayRef を ID 配列に割り当てたいと思います。しかし、うまくいきません。誰かアイデアはありますか?

ありがとう!

4

1 に答える 1

0

CFArrayRef は NSArray * に無料でブリッジされているため、そのようにキャストして可変コピーを作成できます。これを試して:

_identities = [(NSArray *)items mutableCopy];

于 2013-02-01T12:03:04.277 に答える