Skip to content

Commit

Permalink
Apple: Fix #495: Use LAContext in authenticateUsingBiometry()
Browse files Browse the repository at this point in the history
  • Loading branch information
hvge committed Nov 2, 2022
1 parent 31b7028 commit 1f10f91
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 88 deletions.
2 changes: 2 additions & 0 deletions docs/Migration-from-1.6-to-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Version 1.7.3 increased minimum required iOS & tvOS deployment target to 11.0. S
- All asynchronous methods from `PowerAuthTokenStore` protocol now returns objects conforming to `PowerAuthOperationTask` and therefore the returned operation can be canceled directly.
- `PowerAuthTokenStore.cancelTask()` is now deprecated. You can cancel the returned asynchronous operation directly.
- `PowerAuthSDK.authenticateUsingBiometry()` is no longer available on tvOS platform (1.7.5+)
### Other changes
Expand Down
2 changes: 1 addition & 1 deletion proj-xcode/PowerAuth2/PowerAuthErrorConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

NSError * PA2MakeErrorInfo(NSInteger errorCode, NSString * message, NSDictionary * info)
{
NSMutableDictionary * mutableInfo = [info mutableCopy];
NSMutableDictionary * mutableInfo = info ? [info mutableCopy] : [NSMutableDictionary dictionary];
mutableInfo[NSLocalizedDescriptionKey] = PA2MakeDefaultErrorDescription(errorCode, message);
return [NSError errorWithDomain:PowerAuthErrorDomain code:errorCode userInfo:mutableInfo];
}
Expand Down
6 changes: 4 additions & 2 deletions proj-xcode/PowerAuth2/PowerAuthSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@
*/
- (void) authenticateUsingBiometryWithPrompt:(nonnull NSString *)prompt
callback:(nonnull void(^)(PowerAuthAuthentication * _Nullable authentication, NSError * _Nullable error))callback
NS_SWIFT_NAME(authenticateUsingBiometry(withPrompt:callback:));
NS_SWIFT_NAME(authenticateUsingBiometry(withPrompt:callback:))
API_UNAVAILABLE(tvos);

/** Prepare PowerAuthAuthentication object for future PowerAuth signature calculation with a biometry and possession factors involved.
Expand All @@ -539,7 +540,8 @@
*/
- (void) unlockBiometryKeysWithPrompt:(nonnull NSString*)prompt
withBlock:(nonnull void(^)(NSDictionary<NSString*, NSData*> * _Nullable keys, BOOL userCanceled))block
NS_SWIFT_NAME(unlockBiometryKeys(withPrompt:callback:));
NS_SWIFT_NAME(unlockBiometryKeys(withPrompt:callback:))
API_UNAVAILABLE(tvos);

/** Unlock all keys stored in a biometry related keychain and keeps them cached for the scope of the block.
Expand Down
261 changes: 180 additions & 81 deletions proj-xcode/PowerAuth2/PowerAuthSDK.m

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

NSError * PA2MakeErrorInfo(NSInteger errorCode, NSString * message, NSDictionary * info)
{
NSMutableDictionary * mutableInfo = [info mutableCopy];
NSMutableDictionary * mutableInfo = info ? [info mutableCopy] : [NSMutableDictionary dictionary];
mutableInfo[NSLocalizedDescriptionKey] = PA2MakeDefaultErrorDescription(errorCode, message);
return [NSError errorWithDomain:PowerAuthErrorDomain code:errorCode userInfo:mutableInfo];
}
Expand Down
2 changes: 1 addition & 1 deletion proj-xcode/PowerAuth2ForWatch/PowerAuthErrorConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

NSError * PA2MakeErrorInfo(NSInteger errorCode, NSString * message, NSDictionary * info)
{
NSMutableDictionary * mutableInfo = [info mutableCopy];
NSMutableDictionary * mutableInfo = info ? [info mutableCopy] : [NSMutableDictionary dictionary];
mutableInfo[NSLocalizedDescriptionKey] = PA2MakeDefaultErrorDescription(errorCode, message);
return [NSError errorWithDomain:PowerAuthErrorDomain code:errorCode userInfo:mutableInfo];
}
Expand Down
19 changes: 17 additions & 2 deletions proj-xcode/PowerAuth2IntegrationTests/PowerAuthSDKDefaultTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,12 @@ - (void) testCancelEnqueuedHttpOperation
- (void) testBiometrySignatureWhenNotConfigured
{
CHECK_TEST_CONFIG();

#if defined(PA2_BIOMETRY_SUPPORT)
BOOL supportsBiometry = YES;
#else
BOOL supportsBiometry = NO;
#endif

//
// This test validates that signing with biometry doesn't work when
Expand All @@ -1134,13 +1140,22 @@ - (void) testBiometrySignatureWhenNotConfigured
authentication = [PowerAuthAuthentication possessionWithBiometry];
header = [_sdk requestSignatureWithAuthentication:authentication method:@"POST" uriId:@"/some/uri/id" body:[NSData data] error:&error];
XCTAssertNil(header);
XCTAssertEqual(PowerAuthErrorCode_BiometryFailed, error.powerAuthErrorCode);
if (supportsBiometry) {
XCTAssertEqual(PowerAuthErrorCode_BiometryFailed, error.powerAuthErrorCode);
} else {
XCTAssertEqual(PowerAuthErrorCode_BiometryNotAvailable, error.powerAuthErrorCode);
}

error = nil;
authentication = [PowerAuthAuthentication possessionWithBiometryPrompt:@"Authenticate with biometry"];
header = [_sdk requestSignatureWithAuthentication:authentication method:@"POST" uriId:@"/some/uri/id" body:[NSData data] error:&error];
XCTAssertNil(header);
XCTAssertEqual(PowerAuthErrorCode_BiometryFailed, error.powerAuthErrorCode);

if (supportsBiometry) {
XCTAssertEqual(PowerAuthErrorCode_BiometryFailed, error.powerAuthErrorCode);
} else {
XCTAssertEqual(PowerAuthErrorCode_BiometryNotAvailable, error.powerAuthErrorCode);
}
}

#if defined(PA2_BIOMETRY_SUPPORT)
Expand Down

0 comments on commit 1f10f91

Please sign in to comment.