Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clientDataHash to App Attest failure reasons #50

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions AppCheckCore/Sources/Core/Errors/GACAppCheckErrorUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#import <DeviceCheck/DeviceCheck.h>

#import <GoogleUtilities/GULAppEnvironmentUtil.h>
#import <GoogleUtilities/GULKeychainUtils.h>

#import "AppCheckCore/Sources/Core/Errors/GACAppCheckHTTPError.h"
Expand Down Expand Up @@ -139,8 +140,11 @@ + (NSError *)appAttestAttestKeyFailedWithError:(NSError *)error
NSString *failureReason =
[NSString stringWithFormat:@"Failed to attest the validity of the generated cryptographic "
@"key (`attestKey:clientDataHash:completionHandler:`); "
@"keyId.length = %lu, clientDataHash.length = %lu; %@.",
(unsigned long)keyId.length, (unsigned long)clientDataHash.length,
@"keyId.length = %lu, clientDataHash = %@, systemVersion = %@; "
@"%@.",
(unsigned long)keyId.length,
[clientDataHash base64EncodedStringWithOptions:0],
[GULAppEnvironmentUtil systemVersion],
[self errorDescriptionWithDeviceCheckError:error]];
// TODO(#31): Add a new error code for this case (e.g., GACAppCheckAppAttestAttestKeyFailed).
return [self appCheckErrorWithCode:GACAppCheckErrorCodeUnknown
Expand All @@ -154,8 +158,10 @@ + (NSError *)appAttestGenerateAssertionFailedWithError:(NSError *)error
NSString *failureReason = [NSString
stringWithFormat:@"Failed to create a block of data that demonstrates the legitimacy of the "
@"app instance (`generateAssertion:clientDataHash:completionHandler:`); "
@"keyId.length = %lu, clientDataHash.length = %lu; %@.",
(unsigned long)keyId.length, (unsigned long)clientDataHash.length,
@"keyId.length = %lu, clientDataHash = %@, systemVersion = %@; %@.",
(unsigned long)keyId.length,
[clientDataHash base64EncodedStringWithOptions:0],
[GULAppEnvironmentUtil systemVersion],
[self errorDescriptionWithDeviceCheckError:error]];
// TODO(#31): Add error code for this case (e.g., GACAppCheckAppAttestGenerateAssertionFailed).
return [self appCheckErrorWithCode:GACAppCheckErrorCodeUnknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,14 @@ - (void)testGetToken_WhenKeyRegisteredAndGenerateAssertionError {
[NSError errorWithDomain:@"testGetToken_WhenKeyRegisteredAndGenerateAssertionError"
code:0
userInfo:nil];

NSMutableData *statementForAssertion = [storedArtifact mutableCopy];
[statementForAssertion appendData:self.randomChallenge];
NSData *clientDataHash = [GACAppCheckCryptoUtils sha256HashFromData:[statementForAssertion copy]];
NSError *expectedError =
[GACAppCheckErrorUtil appAttestGenerateAssertionFailedWithError:generateAssertionError
keyId:existingKeyID
clientDataHash:self.randomChallengeHash];
clientDataHash:clientDataHash];
id completionBlockArg = [OCMArg invokeBlockWithArgs:[NSNull null], generateAssertionError, nil];
OCMExpect([self.mockAppAttestService
generateAssertion:existingKeyID
Expand Down
Loading