Skip to content

[AppCheck] Fix AppCheck interference for apps using ARCore and Firebase #12191

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

Merged
merged 3 commits into from
Dec 13, 2023
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
5 changes: 5 additions & 0 deletions FirebaseAppCheck/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 10.19.1
- [fixed] Fix bug in apps using both AppCheck and ARCore where AppCheck
unnecessarily tries to create tokens for the ARCore SDK. This results in
noisy logs containing harmless attestation errors.

# 10.18.0
- [changed] Extracted core `FirebaseAppCheck` functionality into a new
[`AppCheckCore`](https://github.com/google/app-check) dependency. (#12067)
Expand Down
34 changes: 33 additions & 1 deletion FirebaseCore/Sources/FIRComponentContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#import "FirebaseCore/Extension/FIRComponent.h"
#import "FirebaseCore/Extension/FIRLibrary.h"
#import "FirebaseCore/Extension/FIRLogger.h"
#import "FirebaseCore/Extension/FIROptionsInternal.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -61,7 +62,18 @@ + (void)registerAsComponentRegistrant:(Class<FIRLibrary>)klass
#pragma mark - Internal Initialization

- (instancetype)initWithApp:(FIRApp *)app {
return [self initWithApp:app registrants:sFIRComponentRegistrants];
NSMutableSet<Class> *componentRegistrants = sFIRComponentRegistrants;
// If the app being created is for the ARCore SDK, remove the App Check
// component (if it exists) since it does not support App Check.
if ([self isAppForARCore:app]) {
Class klass = NSClassFromString(@"FIRAppCheckComponent");
if (klass && [sFIRComponentRegistrants containsObject:klass]) {
componentRegistrants = [componentRegistrants mutableCopy];
[componentRegistrants removeObject:klass];
}
}

return [self initWithApp:app registrants:componentRegistrants];
}

- (instancetype)initWithApp:(FIRApp *)app registrants:(NSMutableSet<Class> *)allRegistrants {
Expand Down Expand Up @@ -214,6 +226,26 @@ - (void)removeAllComponents {
}
}

#pragma mark - Helpers

- (BOOL)isAppForARCore:(FIRApp *)app {
// First, check if the app name matches that of the one used by ARCore.
if ([app.name isEqualToString:@"ARCoreFIRApp"]) {
// Second, check if the app's gcmSenderID matches that of ARCore. This
// prevents false positives in the unlikely event a 3P Firebase app is
// named `ARCoreFIRApp`.
const char *p1 = "406756";
const char *p2 = "893798";
const char gcmSenderIDKey[27] = {p1[0], p2[0], p1[1], p2[1], p1[2], p2[2], p1[3],
p2[3], p1[4], p2[4], p1[5], p2[5], p1[6], p2[6],
p1[7], p2[7], p1[8], p2[8], p1[9], p2[9], p1[10],
p2[10], p1[11], p2[11], p1[12], p2[12], '\0'};
NSString *gcmSenderID = [NSString stringWithUTF8String:gcmSenderIDKey];
return [app.options.GCMSenderID isEqualToString:gcmSenderID];
}
return NO;
}

@end

NS_ASSUME_NONNULL_END