Skip to content

Commit 25fcae9

Browse files
authored
[AppCheck] Fix AppCheck interference for apps using ARCore and Firebase (#12191)
1 parent 5fba1e7 commit 25fcae9

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

FirebaseAppCheck/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 10.19.1
2+
- [fixed] Fix bug in apps using both AppCheck and ARCore where AppCheck
3+
unnecessarily tries to create tokens for the ARCore SDK. This results in
4+
noisy logs containing harmless attestation errors.
5+
16
# 10.18.0
27
- [changed] Extracted core `FirebaseAppCheck` functionality into a new
38
[`AppCheckCore`](https://github.com/google/app-check) dependency. (#12067)

FirebaseCore/Sources/FIRComponentContainer.m

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import "FirebaseCore/Extension/FIRComponent.h"
2121
#import "FirebaseCore/Extension/FIRLibrary.h"
2222
#import "FirebaseCore/Extension/FIRLogger.h"
23+
#import "FirebaseCore/Extension/FIROptionsInternal.h"
2324

2425
NS_ASSUME_NONNULL_BEGIN
2526

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

6364
- (instancetype)initWithApp:(FIRApp *)app {
64-
return [self initWithApp:app registrants:sFIRComponentRegistrants];
65+
NSMutableSet<Class> *componentRegistrants = sFIRComponentRegistrants;
66+
// If the app being created is for the ARCore SDK, remove the App Check
67+
// component (if it exists) since it does not support App Check.
68+
if ([self isAppForARCore:app]) {
69+
Class klass = NSClassFromString(@"FIRAppCheckComponent");
70+
if (klass && [sFIRComponentRegistrants containsObject:klass]) {
71+
componentRegistrants = [componentRegistrants mutableCopy];
72+
[componentRegistrants removeObject:klass];
73+
}
74+
}
75+
76+
return [self initWithApp:app registrants:componentRegistrants];
6577
}
6678

6779
- (instancetype)initWithApp:(FIRApp *)app registrants:(NSMutableSet<Class> *)allRegistrants {
@@ -214,6 +226,26 @@ - (void)removeAllComponents {
214226
}
215227
}
216228

229+
#pragma mark - Helpers
230+
231+
- (BOOL)isAppForARCore:(FIRApp *)app {
232+
// First, check if the app name matches that of the one used by ARCore.
233+
if ([app.name isEqualToString:@"ARCoreFIRApp"]) {
234+
// Second, check if the app's gcmSenderID matches that of ARCore. This
235+
// prevents false positives in the unlikely event a 3P Firebase app is
236+
// named `ARCoreFIRApp`.
237+
const char *p1 = "406756";
238+
const char *p2 = "893798";
239+
const char gcmSenderIDKey[27] = {p1[0], p2[0], p1[1], p2[1], p1[2], p2[2], p1[3],
240+
p2[3], p1[4], p2[4], p1[5], p2[5], p1[6], p2[6],
241+
p1[7], p2[7], p1[8], p2[8], p1[9], p2[9], p1[10],
242+
p2[10], p1[11], p2[11], p1[12], p2[12], '\0'};
243+
NSString *gcmSenderID = [NSString stringWithUTF8String:gcmSenderIDKey];
244+
return [app.options.GCMSenderID isEqualToString:gcmSenderID];
245+
}
246+
return NO;
247+
}
248+
217249
@end
218250

219251
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)