Hey,
I need seriously help with apple security framework.
i got p12 data which i load as SecKeyRef to decode encoded data recevied from the server.
the decoding works great.
my main goal is to extract the expiration data of the certifcate and in case the private key is expired - raise an exception.
i'm trying to extract the expiration data from the SecKeyRef but not sure how to do that.. i read all the documentation on the security framework but still coudln't manage..
attached also my question which i post on Stackoverflow.
http://stackoverflow.com/questions/32548710/ios-security-framework-p12-and-expeiration-date
Here is my code which load the p12 data. if anyone can show me how to validate the expiration date and raise an exception it will be very helpful 🙂
-(BOOL)setP12Data:(NSData*)data pass:(NSString*)pass {
NSMutableDictionary * options = [[NSMutableDictionary alloc] init];
SecKeyRef privateKeyRef = NULL;
/
[options setObject:pass forKey:(__bridge id)kSecImportExportPassphrase];
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
OSStatus securityError = SecPKCS12Import((__bridge CFDataRef) data,
(__bridge CFDictionaryRef)options, &items);
if (securityError == noErr && CFArrayGetCount(items) > 0) {
CFDictionaryRef identityDict = CFArrayGetValueAtIndex(items, 0);
SecIdentityRef identityApp =
(SecIdentityRef)CFDictionaryGetValue(identityDict,
kSecImportItemIdentity);
securityError = SecIdentityCopyPrivateKey(identityApp, &privateKeyRef);
if (securityError != noErr) {
privateKeyRef = NULL;
}
}
/
CFRelease(items);
self.privateKeyRef = privateKeyRef;
return privateKeyRef != nil;
}
Thanks!