views:

187

answers:

1

How to add security identity (certificate + private key) to iPhone keychain? I have .p12 file in application. I can get identity from it using SecPKCS12Import() but when i try to do the following:

NSMutableDictionary *secIdentityParams = [[NSMutableDictionary alloc] init];    
[secIdentityParams setObject:(id)kSecClassIdentity forKey:(id)kSecClass];
[secIdentityParams setObject:label forKey:(id)kSecAttrLabel];
[secIdentityParams setObject:(id)myIdentity forKey:(id)kSecValueRef];

status = SecItemAdd((CFDictionaryRef) secIdentityParams, NULL);

I am getting error = -25291 -> No trust results are available. What am I doing wrong?

+2  A: 

Just use 1 parameter in attributes dictionary to add identity to keychain:

NSMutableDictionary *secIdentityParams = [[NSMutableDictionary alloc] init];    
[secIdentityParams setObject:(id)myIdentity forKey:(id)kSecValueRef];
OSStatus status = SecItemAdd((CFDictionaryRef) secIdentityParams, NULL);
Dmitry Likhachev