Hi,
I am using SecKeyCreateSignature to sign the data. It works for most users but for some iOS 13 users we are getting following error:
Error Domain=CryptoTokenKit Code=-2 "Failed to get externalizedContext from LAContext" UserInfo={NSLocalizedDescription=Failed to get externalizedContext from LAContext}
The error is only happening on iOS 13 devices and happens intermittently. I have copied the relevant code below:
-(NSData*) signData:(NSString*) textData withAuthenticator:(SANDKSecurityDeviceAuthenticator) auth andUID:(NSString*) userID error:(NSInteger*) errorCode {
Authenticator *authenticator = [AuthenticatorManager getAuthenticator:auth];
// Get private key selected for signing
NSString *alias = [NSString stringWithFormat:@"%@%@", userID,authenticator.type];
SecKeyRef privateKey = (SecKeyRef)[authenticator getPrivateKeyRef:alias];
// Generate digest
NSData* dataToSign = [textData dataUsingEncoding:NSUTF8StringEncoding];
NSData* hashedDataToSign = [HashUtils hasData:dataToSign withAlgorithm:SANDKSecurityDevice_SHA_256 andError:NULL];
NSData* signature = nil;
CFErrorRef error = NULL;
signature = (NSData*) CFBridgingRelease(SecKeyCreateSignature(privateKey,
kSecKeyAlgorithmECDSASignatureDigestX962SHA256,
(__bridge CFDataRef)hashedDataToSign,
&error));
if (!signature) {
NSError *err = CFBridgingRelease(error);
*errorCode = err.code;
}
return signature;
}
I would appreciate if someone can provide any insight on the issue.
Thanks.