Skip to content

Commit de3b856

Browse files
Mac OS FIS: use Firebase App ID as a suffix to Keychain service name Mac OS (#5603)
* FIS: use bundle ID as a prefix to Keychain service name on Mac OS * Remove "storage" from var name * Run ./scripts/style.sh * Use Firebase App ID as a suffix to Keychain service name on Mac OS
1 parent 39fb03c commit de3b856

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsIDController.m

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
NSTimeInterval const kFIRInstallationsTokenExpirationThreshold = 60 * 60; // 1 hour.
4646

47+
static NSString *const kKeychainService = @"com.firebase.FIRInstallations.installations";
48+
4749
@interface FIRInstallationsIDController ()
4850
@property(nonatomic, readonly) NSString *appID;
4951
@property(nonatomic, readonly) NSString *appName;
@@ -71,9 +73,9 @@ - (instancetype)initWithGoogleAppID:(NSString *)appID
7173
APIKey:(NSString *)APIKey
7274
projectID:(NSString *)projectID
7375
GCMSenderID:(NSString *)GCMSenderID
74-
accessGroup:(NSString *)accessGroup {
75-
GULKeychainStorage *secureStorage =
76-
[[GULKeychainStorage alloc] initWithService:@"com.firebase.FIRInstallations.installations"];
76+
accessGroup:(nullable NSString *)accessGroup {
77+
NSString *serviceName = [FIRInstallationsIDController keychainServiceWithAppID:appID];
78+
GULKeychainStorage *secureStorage = [[GULKeychainStorage alloc] initWithService:serviceName];
7779
FIRInstallationsStore *installationsStore =
7880
[[FIRInstallationsStore alloc] initWithSecureStorage:secureStorage accessGroup:accessGroup];
7981

@@ -456,4 +458,23 @@ - (BOOL)isDefaultApp {
456458
return [self.appName isEqualToString:kFIRDefaultAppName];
457459
}
458460

461+
#pragma mark - Keychain
462+
463+
+ (NSString *)keychainServiceWithAppID:(NSString *)appID {
464+
#if TARGET_OS_MACCATALYST || TARGET_OS_OSX
465+
// We need to keep service name unique per application on macOS.
466+
// Applications on macOS may request access to Keychain items stored by other applications. It
467+
// means that when the app looks up for a relevant Keychain item in the service scope it will
468+
// request user password to grant access to the Keychain if there are other Keychain items from
469+
// other applications stored under the same Keychain Service.
470+
return [kKeychainService stringByAppendingFormat:@".%@", appID];
471+
#else
472+
// Use a constant Keychain service for non-macOS because:
473+
// 1. Keychain items cannot be shared between apps until configured specifically so the service
474+
// name collisions are not a concern
475+
// 2. We don't want to change the service name to avoid doing a migration.
476+
return kKeychainService;
477+
#endif
478+
}
479+
459480
@end

0 commit comments

Comments
 (0)