Skip to content

Commit 7bd8faa

Browse files
Move FIRSecureStorage to GoogleUtilities (#5329)
* FIRSecureStorage -> GULKeychainStorage: renamed and moved to GoogleUtilities * FIS updated to GULKeychainStorage * Run ./scripts/style.sh * Headers order * GULKeychainUtils API docs * GULKeychainStorage: require Keychain service name
1 parent 6c14c21 commit 7bd8faa

File tree

14 files changed

+222
-140
lines changed

14 files changed

+222
-140
lines changed

FirebaseInstallations.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Pod::Spec.new do |s|
3232
s.framework = 'Security'
3333
s.dependency 'FirebaseCore', '~> 6.6'
3434
s.dependency 'PromisesObjC', '~> 1.2'
35-
s.dependency 'GoogleUtilities/UserDefaults', '~> 6.5'
35+
s.dependency 'GoogleUtilities/Environment', '~> 6.6'
36+
s.dependency 'GoogleUtilities/UserDefaults', '~> 6.6'
3637

3738
preprocessor_definitions = 'FIRInstallations_LIB_VERSION=' + String(s.version)
3839
if ENV['FIS_ALLOWS_INCOMPATIBLE_IID_VERSION'] && ENV['FIS_ALLOWS_INCOMPATIBLE_IID_VERSION'] == '1' then

FirebaseInstallations/Source/Library/IIDMigration/FIRInstallationsIIDTokenStore.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#import "FBLPromises.h"
2323
#endif
2424

25+
#import <GoogleUtilities/GULKeychainUtils.h>
26+
2527
#import "FIRInstallationsErrorUtil.h"
26-
#import "FIRInstallationsKeychainUtils.h"
2728

2829
static NSString *const kFIRInstallationsIIDTokenKeychainId = @"com.google.iid-tokens";
2930

@@ -118,7 +119,7 @@ - (instancetype)initWithGCMSenderID:(NSString *)GCMSenderID {
118119

119120
NSMutableDictionary *keychainQuery = [self IIDDefaultTokenDataKeychainQuery];
120121
NSError *error;
121-
NSData *data = [FIRInstallationsKeychainUtils getItemWithQuery:keychainQuery error:&error];
122+
NSData *data = [GULKeychainUtils getItemWithQuery:keychainQuery error:&error];
122123

123124
if (data) {
124125
[resultPromise fulfill:data];

FirebaseInstallations/Source/Library/InstallationsIDController/FIRInstallationsIDController.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#endif
2424

2525
#import <FirebaseCore/FIRAppInternal.h>
26+
#import <GoogleUtilities/GULKeychainStorage.h>
2627

2728
#import "FIRInstallationsAPIService.h"
2829
#import "FIRInstallationsErrorUtil.h"
@@ -32,7 +33,6 @@
3233
#import "FIRInstallationsLogger.h"
3334
#import "FIRInstallationsSingleOperationPromiseCache.h"
3435
#import "FIRInstallationsStore.h"
35-
#import "FIRSecureStorage.h"
3636

3737
#import "FIRInstallationsHTTPError.h"
3838
#import "FIRInstallationsStoredAuthToken.h"
@@ -72,7 +72,8 @@ - (instancetype)initWithGoogleAppID:(NSString *)appID
7272
projectID:(NSString *)projectID
7373
GCMSenderID:(NSString *)GCMSenderID
7474
accessGroup:(NSString *)accessGroup {
75-
FIRSecureStorage *secureStorage = [[FIRSecureStorage alloc] init];
75+
GULKeychainStorage *secureStorage =
76+
[[GULKeychainStorage alloc] initWithService:@"com.firebase.FIRInstallations.installations"];
7677
FIRInstallationsStore *installationsStore =
7778
[[FIRInstallationsStore alloc] initWithSecureStorage:secureStorage accessGroup:accessGroup];
7879

FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStore.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
@class FBLPromise<ValueType>;
2020
@class FIRInstallationsItem;
21-
@class FIRSecureStorage;
21+
@class GULKeychainStorage;
2222

2323
NS_ASSUME_NONNULL_BEGIN
2424

@@ -33,7 +33,7 @@ extern NSString *const kFIRInstallationsStoreUserDefaultsID;
3333
* @param storage The secure storage to save installations data.
3434
* @param accessGroup The Keychain Access Group to store and request the installations data.
3535
*/
36-
- (instancetype)initWithSecureStorage:(FIRSecureStorage *)storage
36+
- (instancetype)initWithSecureStorage:(GULKeychainStorage *)storage
3737
accessGroup:(nullable NSString *)accessGroup;
3838

3939
/**

FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStore.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,24 @@
2424
#import "FBLPromises.h"
2525
#endif
2626

27+
#import <GoogleUtilities/GULKeychainStorage.h>
28+
2729
#import "FIRInstallationsErrorUtil.h"
2830
#import "FIRInstallationsItem.h"
2931
#import "FIRInstallationsStoredItem.h"
30-
#import "FIRSecureStorage.h"
3132

3233
NSString *const kFIRInstallationsStoreUserDefaultsID = @"com.firebase.FIRInstallations";
3334

3435
@interface FIRInstallationsStore ()
35-
@property(nonatomic, readonly) FIRSecureStorage *secureStorage;
36+
@property(nonatomic, readonly) GULKeychainStorage *secureStorage;
3637
@property(nonatomic, readonly, nullable) NSString *accessGroup;
3738
@property(nonatomic, readonly) dispatch_queue_t queue;
3839
@property(nonatomic, readonly) GULUserDefaults *userDefaults;
3940
@end
4041

4142
@implementation FIRInstallationsStore
4243

43-
- (instancetype)initWithSecureStorage:(FIRSecureStorage *)storage
44+
- (instancetype)initWithSecureStorage:(GULKeychainStorage *)storage
4445
accessGroup:(NSString *)accessGroup {
4546
self = [super init];
4647
if (self) {

FirebaseInstallations/Source/Tests/Unit/FIRInstallationsStoreTests.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919
#import <OCMock/OCMock.h>
2020

21+
#import <GoogleUtilities/GULKeychainStorage.h>
2122
#import <GoogleUtilities/GULUserDefaults.h>
23+
2224
#import "FBLPromise+Testing.h"
2325
#import "FIRInstallationsErrorUtil.h"
2426
#import "FIRInstallationsItem+Tests.h"
2527
#import "FIRInstallationsItem.h"
2628
#import "FIRInstallationsStore.h"
2729
#import "FIRInstallationsStoredItem.h"
28-
#import "FIRSecureStorage.h"
2930

3031
@interface FIRInstallationsStoreTests : XCTestCase
3132
@property(nonatomic) NSString *accessGroup;
@@ -38,7 +39,7 @@ @implementation FIRInstallationsStoreTests
3839

3940
- (void)setUp {
4041
self.accessGroup = @"accessGroup";
41-
self.mockSecureStorage = OCMClassMock([FIRSecureStorage class]);
42+
self.mockSecureStorage = OCMClassMock([GULKeychainStorage class]);
4243
self.store = [[FIRInstallationsStore alloc] initWithSecureStorage:self.mockSecureStorage
4344
accessGroup:self.accessGroup];
4445

GoogleUtilities.podspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'GoogleUtilities'
3-
s.version = '6.5.2'
3+
s.version = '6.6.0'
44
s.summary = 'Google Utilities for iOS (plus community support for macOS and tvOS)'
55

66
s.description = <<-DESC
@@ -34,6 +34,8 @@ other Google CocoaPods. They're not intended for direct public usage.
3434
es.source_files = 'GoogleUtilities/Environment/**/*.[mh]'
3535
es.public_header_files = 'GoogleUtilities/Environment/**/*.h'
3636
es.private_header_files = 'GoogleUtilities/Environment/**/*.h'
37+
38+
es.dependency 'PromisesObjC', '~> 1.2'
3739
end
3840

3941
s.subspec 'Logger' do |ls|

FirebaseInstallations/Source/Library/SecureStorage/FIRSecureStorage.h renamed to GoogleUtilities/Environment/Public/GULKeychainStorage.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
NS_ASSUME_NONNULL_BEGIN
2222

2323
/// The class provides a convenient abstraction on top of the iOS Keychain API to save data.
24-
@interface FIRSecureStorage : NSObject
24+
@interface GULKeychainStorage : NSObject
25+
26+
- (instancetype)init NS_UNAVAILABLE;
27+
28+
/** Initializes the keychain storage with Keychain Service name.
29+
* @param service A Keychain Service name that will be used to store and retrieve objects. See also
30+
* `kSecAttrService`.
31+
*/
32+
- (instancetype)initWithService:(NSString *)service;
2533

2634
/**
2735
* Get an object by key.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
NS_ASSUME_NONNULL_BEGIN
20+
21+
FOUNDATION_EXPORT NSString *const kGULKeychainUtilsErrorDomain;
22+
23+
/// Helper functions to access Keychain.
24+
@interface GULKeychainUtils : NSObject
25+
26+
/** Fetches a keychain item data matching to the provided query.
27+
* @param query A dictionary with Keychain query parameters. See docs for `SecItemCopyMatching` for
28+
* details.
29+
* @param outError A pointer to `NSError` instance or `NULL`. The instance at `outError` will be
30+
* assigned with an error if there is.
31+
* @returns Data for the first Keychain Item matching the provided query or `nil` if there is not
32+
* such an item (`outError` will be `nil` in this case) or an error occurred.
33+
*/
34+
+ (nullable NSData *)getItemWithQuery:(NSDictionary *)query
35+
error:(NSError *_Nullable *_Nullable)outError;
36+
37+
/** Stores data to a Keychain Item matching to the provided query. An existing Keychain Item
38+
* matching the query parameters will be updated or a new will be created.
39+
* @param item A Keychain Item data to store.
40+
* @param query A dictionary with Keychain query parameters. See docs for `SecItemAdd` and
41+
* `SecItemUpdate` for details.
42+
* @param outError A pointer to `NSError` instance or `NULL`. The instance at `outError` will be
43+
* assigned with an error if there is.
44+
* @returns `YES` when data was successfully stored, `NO` otherwise.
45+
*/
46+
+ (BOOL)setItem:(NSData *)item
47+
withQuery:(NSDictionary *)query
48+
error:(NSError *_Nullable *_Nullable)outError;
49+
50+
/** Removes a Keychain Item matching to the provided query.
51+
* @param query A dictionary with Keychain query parameters. See docs for `SecItemDelete` for
52+
* details.
53+
* @param outError A pointer to `NSError` instance or `NULL`. The instance at `outError` will be
54+
* assigned with an error if there is.
55+
* @returns `YES` if the item was removed successfully or doesn't exist, `NO` otherwise.
56+
*/
57+
+ (BOOL)removeItemWithQuery:(NSDictionary *)query error:(NSError *_Nullable *_Nullable)outError;
58+
59+
@end
60+
61+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)