Post not yet marked as solved
Post marked as unsolved with 3 replies, 427 views
Hello,
I created A ECC key in Secure Enclave. Then, when I tried to use SecItemCopyMatching to read the private key, it takes more than 8 seconds to read it on an iphoneX 14.6 device.
However, other phones, with the same model and same IOS version, do not have this phenomenon.
Only this particular phone.
Please advise the possible issue that causes this problem. Thank you.
Below is my code:
+(NSDictionary*)privateKeyQuery:(NSString*)labeled
{
return @{
(__bridge id)kSecClass:(__bridge id)kSecClassKey,
(__bridge id)kSecAttrKeyClass:(__bridge id)kSecAttrKeyClassPrivate,
(__bridge id)kSecAttrLabel:labeled,
(__bridge id)kSecReturnRef:(__bridge id)kCFBooleanTrue
};
}
+(SecKeyRef)getKey:(NSDictionary*)query
{
CFTypeRef raw=nil;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &raw);
if (status == errSecSuccess && raw)
{
return (__bridge SecKeyRef)(CFBridgingRelease(raw));
}
else{
SELog(@"IO- Could not get key for status=%@",@(status));
return nil;
}
}
+(PublicKey*)getPublicKey:(NSString*)labeled
{
NSDictionary *query=[self privateKeyQuery:labeled];
SecKeyRef underlying=[self getKey:query];
if (underlying) {
if (@available(iOS 10.3, *)) {
SecKeyRef publickeyRef=SecKeyCopyPublicKey(underlying);
if (publickeyRef) {
return [[PublicKey alloc] initWithUnderlying:(__bridge SecKeyRef)(CFBridgingRelease(publickeyRef))];
}
else
{
return nil;
}
} else {
// Fallback on earlier versions
return nil;
}
}
else
{
return nil;
}
}