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

Mac OS FIS: use Firebase App ID as a suffix to Keychain service name Mac OS #5603

Merged
merged 4 commits into from May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions FirebaseInstallations/Source/Library/FIRInstallations.m
Expand Up @@ -88,6 +88,7 @@ - (instancetype)initWitAppOptions:(FIROptions *)appOptions appName:(NSString *)a
APIKey:appOptions.APIKey
projectID:appOptions.projectID
GCMSenderID:appOptions.GCMSenderID
bundleID:appOptions.bundleID
accessGroup:appOptions.appGroupID];
return [self initWithAppOptions:appOptions
appName:appName
Expand Down
Expand Up @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
APIKey:(NSString *)APIKey
projectID:(NSString *)projectID
GCMSenderID:(NSString *)GCMSenderID
bundleID:(nullable NSString *)bundleID
accessGroup:(nullable NSString *)accessGroup;

- (FBLPromise<FIRInstallationsItem *> *)getInstallationItem;
Expand Down
Expand Up @@ -44,6 +44,8 @@

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

static NSString *const kStorageKeychainService = @"com.firebase.FIRInstallations.installations";
maksymmalyhin marked this conversation as resolved.
Show resolved Hide resolved

@interface FIRInstallationsIDController ()
@property(nonatomic, readonly) NSString *appID;
@property(nonatomic, readonly) NSString *appName;
Expand Down Expand Up @@ -71,9 +73,10 @@ - (instancetype)initWithGoogleAppID:(NSString *)appID
APIKey:(NSString *)APIKey
projectID:(NSString *)projectID
GCMSenderID:(NSString *)GCMSenderID
accessGroup:(NSString *)accessGroup {
GULKeychainStorage *secureStorage =
[[GULKeychainStorage alloc] initWithService:@"com.firebase.FIRInstallations.installations"];
bundleID:(NSString *)bundleID
accessGroup:(nullable NSString *)accessGroup {
NSString *serviceName = [FIRInstallationsIDController keychainServiceWithBundleID:bundleID];
GULKeychainStorage *secureStorage = [[GULKeychainStorage alloc] initWithService:serviceName];
FIRInstallationsStore *installationsStore =
[[FIRInstallationsStore alloc] initWithSecureStorage:secureStorage accessGroup:accessGroup];

Expand Down Expand Up @@ -456,4 +459,24 @@ - (BOOL)isDefaultApp {
return [self.appName isEqualToString:kFIRDefaultAppName];
}

#pragma mark - Keychain
maksymmalyhin marked this conversation as resolved.
Show resolved Hide resolved

+ (NSString *)keychainServiceWithBundleID:(nullable NSString *)bundleID {
#if TARGET_OS_MACCATALYST || TARGET_OS_OSX
// We need to keep service name unique per application on macOS if bundleID provided.
// Applications on macOS may request access to Keychain items stored by other applications. It
// means that when the app looks up for a relevant Keychain item in the service scope it will
// request user password to grant access to the Keychain if there are other Keychain items from
// other applications stored under the same Keychain Service.
maksymmalyhin marked this conversation as resolved.
Show resolved Hide resolved
return [bundleID stringByAppendingFormat:@".%@", kStorageKeychainService]
?: kStorageKeychainService;
#else
// Use a constant Keychain service for non-macOS because:
maksymmalyhin marked this conversation as resolved.
Show resolved Hide resolved
// 1. Keychain items cannot be shared between apps until configured specifically so the service
// name collisions are not a concern
// 2. We don't want to change the service name to avoid doing a migration.
return kStorageKeychainService;
#endif
}

@end
Expand Up @@ -102,6 +102,7 @@ - (void)testInitWhenProjectIDSetThenItIsPassedToAPIService {
APIKey:APIKey
projectID:projectID
GCMSenderID:@"sender-id"
bundleID:@"FIRInstallationsIDController"
accessGroup:nil];
XCTAssertNotNil(controller);

Expand All @@ -121,6 +122,7 @@ - (void)testInitWhenProjectIDIsNilThenGCMSenderIDIsPassedToAPIServiceAsProjectID
APIKey:APIKey
projectID:@""
GCMSenderID:GCMSenderID
bundleID:nil
accessGroup:nil];
XCTAssertNotNil(controller);

Expand Down