Skip to content

Commit 1054d6a

Browse files
Remove migration from legacy keychain (#5237)
1 parent 09e7b40 commit 1054d6a

File tree

6 files changed

+11
-120
lines changed

6 files changed

+11
-120
lines changed

Example/InstanceID/Tests/FIRInstanceIDCheckinStoreTest.m

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -191,62 +191,6 @@ - (void)testCheckinSaveSuccess {
191191
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
192192
}
193193

194-
// Write fake checkin data to legacy location, then test if migration worked.
195-
- (void)testCheckinMigrationMovesToNewLocationInKeychain {
196-
XCTestExpectation *checkinMigrationExpectation =
197-
[self expectationWithDescription:@"checkin migration should move to the new location"];
198-
// Create checkin store class.
199-
FIRInstanceIDBackupExcludedPlist *checkinPlist =
200-
[[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:kFakeCheckinPlistName
201-
subDirectory:kSubDirectoryName];
202-
203-
FIRInstanceIDFakeKeychain *fakeKeychain = [[FIRInstanceIDFakeKeychain alloc] init];
204-
FIRInstanceIDFakeKeychain *weakKeychain = fakeKeychain;
205-
206-
// Create fake checkin preferences object.
207-
FIRInstanceIDCheckinPreferences *preferences =
208-
[[FIRInstanceIDCheckinPreferences alloc] initWithDeviceID:kAuthID secretToken:kSecret];
209-
[preferences updateWithCheckinPlistContents:[[self class] newCheckinPlistPreferences]];
210-
211-
// Write checkin into legacy location in Fake keychain.
212-
NSString *checkinKeychainContent = [preferences checkinKeychainContent];
213-
NSData *data = [checkinKeychainContent dataUsingEncoding:NSUTF8StringEncoding];
214-
[fakeKeychain setData:data
215-
forService:kFIRInstanceIDLegacyCheckinKeychainService
216-
account:kFIRInstanceIDLegacyCheckinKeychainAccount
217-
handler:^(NSError *error) {
218-
XCTAssertNil(error);
219-
// Check that we saved it correctly to the legacy location.
220-
NSData *dataInLegacyLocation =
221-
[weakKeychain dataForService:kFIRInstanceIDLegacyCheckinKeychainService
222-
account:kFIRInstanceIDLegacyCheckinKeychainAccount];
223-
XCTAssertNotNil(dataInLegacyLocation);
224-
225-
FIRInstanceIDCheckinStore *checkinStore =
226-
[[FIRInstanceIDCheckinStore alloc] initWithCheckinPlist:checkinPlist
227-
keychain:weakKeychain];
228-
// Perform migration.
229-
[checkinStore migrateCheckinItemIfNeeded];
230-
231-
// Ensure the item is no longer in the old location.
232-
dataInLegacyLocation =
233-
[weakKeychain dataForService:kFIRInstanceIDLegacyCheckinKeychainService
234-
account:kFIRInstanceIDLegacyCheckinKeychainAccount];
235-
XCTAssertNil(dataInLegacyLocation);
236-
// Check that it exists in the new location.
237-
NSData *dataInMigratedLocation =
238-
[weakKeychain dataForService:kFIRInstanceIDCheckinKeychainService
239-
account:checkinStore.bundleIdentifierForKeychainAccount];
240-
XCTAssertNotNil(dataInMigratedLocation);
241-
// Ensure that the data is the same as what we originally saved.
242-
XCTAssertEqualObjects(dataInMigratedLocation, data);
243-
244-
[checkinMigrationExpectation fulfill];
245-
}];
246-
247-
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
248-
}
249-
250194
#pragma mark - Private Helpers
251195

252196
- (BOOL)savePreferencesToPlist:(NSDictionary *)preferences {

Example/InstanceID/Tests/FIRInstanceIDStoreTest.m

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,6 @@ - (void)testResetCredentialsWithFreshInstall {
229229
OCMVerifyAll(_mockCheckinStore);
230230
}
231231

232-
- (void)testResetCredentialsWithoutFreshInstall {
233-
FIRInstanceIDCheckinPreferences *checkinPreferences =
234-
[[FIRInstanceIDCheckinPreferences alloc] initWithDeviceID:kAuthID secretToken:kSecret];
235-
// Expect migration happens if it's not a fresh install.
236-
[[_mockCheckinStore expect] migrateCheckinItemIfNeeded];
237-
// Always setting up stub after expect.
238-
OCMStub([_mockCheckinStore cachedCheckinPreferences]).andReturn(checkinPreferences);
239-
// Mock plist exists, meaning this is not a fresh install.
240-
OCMStub([_mockCheckinStore hasCheckinPlist]).andReturn(YES);
241-
242-
[_mockInstanceIDStore resetCredentialsIfNeeded];
243-
OCMVerifyAll(_mockCheckinStore);
244-
}
245-
246232
- (void)testResetCredentialsWithNoCachedCheckin {
247233
id niceMockCheckinStore = [OCMockObject niceMockForClass:[FIRInstanceIDCheckinStore class]];
248234
[[niceMockCheckinStore reject]

Firebase/InstanceID/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2020-03 -- 4.3.3
2+
- [fixed] Fixed provisioning profile location for catalyst. (#5048)
3+
- [changed] Remove obsolete logic to improve performance and reduce keychain operations. (#5211, #5237)
4+
15
# 2020-02 -- 4.3.2
26
- [changed] Removed unused files (#4881).
37

Firebase/InstanceID/FIRInstanceIDCheckinStore.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
// These values exposed for testing
2424
extern NSString *const kFIRInstanceIDCheckinKeychainService;
25-
extern NSString *const kFIRInstanceIDLegacyCheckinKeychainAccount;
26-
extern NSString *const kFIRInstanceIDLegacyCheckinKeychainService;
2725

2826
/**
2927
* Checkin preferences backing store.
@@ -95,14 +93,4 @@ extern NSString *const kFIRInstanceIDLegacyCheckinKeychainService;
9593
*/
9694
- (FIRInstanceIDCheckinPreferences *)cachedCheckinPreferences;
9795

98-
/**
99-
* Migrate the checkin item from old service/account to the new one.
100-
* The new account is dynamic as it uses bundle ID.
101-
* This is to ensure checkin is not shared across apps, but still the same
102-
* if app has used GCM before.
103-
* This call should only happen once.
104-
*
105-
*/
106-
- (void)migrateCheckinItemIfNeeded;
107-
10896
@end

Firebase/InstanceID/FIRInstanceIDCheckinStore.m

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
static NSString *const kFIRInstanceIDCheckinKeychainGeneric = @"com.google.iid";
3030

3131
NSString *const kFIRInstanceIDCheckinKeychainService = @"com.google.iid.checkin";
32-
NSString *const kFIRInstanceIDLegacyCheckinKeychainAccount = @"com.google.iid.checkin-account";
33-
NSString *const kFIRInstanceIDLegacyCheckinKeychainService = @"com.google.iid.checkin-service";
3432

3533
@interface FIRInstanceIDCheckinStore ()
3634

@@ -152,19 +150,11 @@ - (void)removeCheckinPreferencesWithHandler:(void (^)(NSError *error))handler {
152150
FIRInstanceIDLoggerDebug(kFIRInstanceIDMessageCodeCheckinStoreCheckinPlistDeleted,
153151
@"Deleted checkin plist file.");
154152
// Remove deviceID and secret from Keychain
155-
[self.keychain
156-
removeItemsMatchingService:kFIRInstanceIDCheckinKeychainService
157-
account:self.bundleIdentifierForKeychainAccount
158-
handler:^(NSError *error) {
159-
// Try to remove from old location as well because migration
160-
// is no longer needed. Consider this is either a fresh install
161-
// or an identity wipe.
162-
[self.keychain
163-
removeItemsMatchingService:kFIRInstanceIDLegacyCheckinKeychainService
164-
account:kFIRInstanceIDLegacyCheckinKeychainAccount
165-
handler:nil];
166-
handler(error);
167-
}];
153+
[self.keychain removeItemsMatchingService:kFIRInstanceIDCheckinKeychainService
154+
account:self.bundleIdentifierForKeychainAccount
155+
handler:^(NSError *error) {
156+
handler(error);
157+
}];
168158
}
169159

170160
- (FIRInstanceIDCheckinPreferences *)cachedCheckinPreferences {
@@ -201,23 +191,4 @@ - (FIRInstanceIDCheckinPreferences *)cachedCheckinPreferences {
201191
return checkinPreferences;
202192
}
203193

204-
- (void)migrateCheckinItemIfNeeded {
205-
// Check for checkin in the old location, using the legacy keys
206-
// Query the keychain for deviceID and secret
207-
NSData *dataInOldLocation =
208-
[self.keychain dataForService:kFIRInstanceIDLegacyCheckinKeychainService
209-
account:kFIRInstanceIDLegacyCheckinKeychainAccount];
210-
if (dataInOldLocation) {
211-
// Save to new location
212-
[self.keychain setData:dataInOldLocation
213-
forService:kFIRInstanceIDCheckinKeychainService
214-
account:self.bundleIdentifierForKeychainAccount
215-
handler:nil];
216-
// Remove from old location
217-
[self.keychain removeItemsMatchingService:kFIRInstanceIDLegacyCheckinKeychainService
218-
account:kFIRInstanceIDLegacyCheckinKeychainAccount
219-
handler:nil];
220-
}
221-
}
222-
223194
@end

Firebase/InstanceID/FIRInstanceIDStore.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,11 @@ - (void)resetCredentialsIfNeeded {
140140
BOOL checkinPlistExists = [self.checkinStore hasCheckinPlist];
141141
// Checkin info existed in backup excluded plist. Should not be a fresh install.
142142
if (checkinPlistExists) {
143-
// FCM user can still have the old version of checkin, migration should only happen once.
144-
[self.checkinStore migrateCheckinItemIfNeeded];
145143
return;
146144
}
147145

148-
// reset checkin in keychain if a fresh install.
149-
// set the old checkin preferences to unregister pre-registered tokens
146+
// Resets checkin in keychain if a fresh install.
147+
// Keychain can still exist even if app is uninstalled.
150148
FIRInstanceIDCheckinPreferences *oldCheckinPreferences =
151149
[self.checkinStore cachedCheckinPreferences];
152150

0 commit comments

Comments
 (0)