Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion FirebaseInstallations.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Pod::Spec.new do |s|
s.framework = 'Security'
s.dependency 'FirebaseCore', '~> 6.6'
s.dependency 'PromisesObjC', '~> 1.2'
s.dependency 'GoogleUtilities/UserDefaults', '~> 6.5'
s.dependency 'GoogleUtilities/Environment', '~> 6.6'
s.dependency 'GoogleUtilities/UserDefaults', '~> 6.6'

preprocessor_definitions = 'FIRInstallations_LIB_VERSION=' + String(s.version)
if ENV['FIS_ALLOWS_INCOMPATIBLE_IID_VERSION'] && ENV['FIS_ALLOWS_INCOMPATIBLE_IID_VERSION'] == '1' then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#import "FBLPromises.h"
#endif

#import <GoogleUtilities/GULKeychainUtils.h>

#import "FIRInstallationsErrorUtil.h"
#import "FIRInstallationsKeychainUtils.h"

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

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

NSMutableDictionary *keychainQuery = [self IIDDefaultTokenDataKeychainQuery];
NSError *error;
NSData *data = [FIRInstallationsKeychainUtils getItemWithQuery:keychainQuery error:&error];
NSData *data = [GULKeychainUtils getItemWithQuery:keychainQuery error:&error];

if (data) {
[resultPromise fulfill:data];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#endif

#import <FirebaseCore/FIRAppInternal.h>
#import <GoogleUtilities/GULKeychainStorage.h>

#import "FIRInstallationsAPIService.h"
#import "FIRInstallationsErrorUtil.h"
Expand All @@ -32,7 +33,6 @@
#import "FIRInstallationsLogger.h"
#import "FIRInstallationsSingleOperationPromiseCache.h"
#import "FIRInstallationsStore.h"
#import "FIRSecureStorage.h"

#import "FIRInstallationsHTTPError.h"
#import "FIRInstallationsStoredAuthToken.h"
Expand Down Expand Up @@ -72,7 +72,8 @@ - (instancetype)initWithGoogleAppID:(NSString *)appID
projectID:(NSString *)projectID
GCMSenderID:(NSString *)GCMSenderID
accessGroup:(NSString *)accessGroup {
FIRSecureStorage *secureStorage = [[FIRSecureStorage alloc] init];
GULKeychainStorage *secureStorage =
[[GULKeychainStorage alloc] initWithService:@"com.firebase.FIRInstallations.installations"];
FIRInstallationsStore *installationsStore =
[[FIRInstallationsStore alloc] initWithSecureStorage:secureStorage accessGroup:accessGroup];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@class FBLPromise<ValueType>;
@class FIRInstallationsItem;
@class FIRSecureStorage;
@class GULKeychainStorage;

NS_ASSUME_NONNULL_BEGIN

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@
#import "FBLPromises.h"
#endif

#import <GoogleUtilities/GULKeychainStorage.h>

#import "FIRInstallationsErrorUtil.h"
#import "FIRInstallationsItem.h"
#import "FIRInstallationsStoredItem.h"
#import "FIRSecureStorage.h"

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

@interface FIRInstallationsStore ()
@property(nonatomic, readonly) FIRSecureStorage *secureStorage;
@property(nonatomic, readonly) GULKeychainStorage *secureStorage;
@property(nonatomic, readonly, nullable) NSString *accessGroup;
@property(nonatomic, readonly) dispatch_queue_t queue;
@property(nonatomic, readonly) GULUserDefaults *userDefaults;
@end

@implementation FIRInstallationsStore

- (instancetype)initWithSecureStorage:(FIRSecureStorage *)storage
- (instancetype)initWithSecureStorage:(GULKeychainStorage *)storage
accessGroup:(NSString *)accessGroup {
self = [super init];
if (self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

#import <OCMock/OCMock.h>

#import <GoogleUtilities/GULKeychainStorage.h>
#import <GoogleUtilities/GULUserDefaults.h>

#import "FBLPromise+Testing.h"
#import "FIRInstallationsErrorUtil.h"
#import "FIRInstallationsItem+Tests.h"
#import "FIRInstallationsItem.h"
#import "FIRInstallationsStore.h"
#import "FIRInstallationsStoredItem.h"
#import "FIRSecureStorage.h"

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

- (void)setUp {
self.accessGroup = @"accessGroup";
self.mockSecureStorage = OCMClassMock([FIRSecureStorage class]);
self.mockSecureStorage = OCMClassMock([GULKeychainStorage class]);
self.store = [[FIRInstallationsStore alloc] initWithSecureStorage:self.mockSecureStorage
accessGroup:self.accessGroup];

Expand Down
4 changes: 3 additions & 1 deletion GoogleUtilities.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GoogleUtilities'
s.version = '6.5.2'
s.version = '6.6.0'
s.summary = 'Google Utilities for iOS (plus community support for macOS and tvOS)'

s.description = <<-DESC
Expand Down Expand Up @@ -34,6 +34,8 @@ other Google CocoaPods. They're not intended for direct public usage.
es.source_files = 'GoogleUtilities/Environment/**/*.[mh]'
es.public_header_files = 'GoogleUtilities/Environment/**/*.h'
es.private_header_files = 'GoogleUtilities/Environment/**/*.h'

es.dependency 'PromisesObjC', '~> 1.2'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate from this review - but are we comfortable allowing minor version updates of Promises. It might be safer to lock to patch version updates ...

end

s.subspec 'Logger' do |ls|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
NS_ASSUME_NONNULL_BEGIN

/// The class provides a convenient abstraction on top of the iOS Keychain API to save data.
@interface FIRSecureStorage : NSObject
@interface GULKeychainStorage : NSObject

- (instancetype)init NS_UNAVAILABLE;

/** Initializes the keychain storage with Keychain Service name.
* @param service A Keychain Service name that will be used to store and retrieve objects. See also
* `kSecAttrService`.
*/
- (instancetype)initWithService:(NSString *)service;

/**
* Get an object by key.
Expand Down
61 changes: 61 additions & 0 deletions GoogleUtilities/Environment/Public/GULKeychainUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2019 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

FOUNDATION_EXPORT NSString *const kGULKeychainUtilsErrorDomain;

/// Helper functions to access Keychain.
@interface GULKeychainUtils : NSObject

/** Fetches a keychain item data matching to the provided query.
* @param query A dictionary with Keychain query parameters. See docs for `SecItemCopyMatching` for
* details.
* @param outError A pointer to `NSError` instance or `NULL`. The instance at `outError` will be
* assigned with an error if there is.
* @returns Data for the first Keychain Item matching the provided query or `nil` if there is not
* such an item (`outError` will be `nil` in this case) or an error occurred.
*/
+ (nullable NSData *)getItemWithQuery:(NSDictionary *)query
error:(NSError *_Nullable *_Nullable)outError;

/** Stores data to a Keychain Item matching to the provided query. An existing Keychain Item
* matching the query parameters will be updated or a new will be created.
* @param item A Keychain Item data to store.
* @param query A dictionary with Keychain query parameters. See docs for `SecItemAdd` and
* `SecItemUpdate` for details.
* @param outError A pointer to `NSError` instance or `NULL`. The instance at `outError` will be
* assigned with an error if there is.
* @returns `YES` when data was successfully stored, `NO` otherwise.
*/
+ (BOOL)setItem:(NSData *)item
withQuery:(NSDictionary *)query
error:(NSError *_Nullable *_Nullable)outError;

/** Removes a Keychain Item matching to the provided query.
* @param query A dictionary with Keychain query parameters. See docs for `SecItemDelete` for
* details.
* @param outError A pointer to `NSError` instance or `NULL`. The instance at `outError` will be
* assigned with an error if there is.
* @returns `YES` if the item was removed successfully or doesn't exist, `NO` otherwise.
*/
+ (BOOL)removeItemWithQuery:(NSDictionary *)query error:(NSError *_Nullable *_Nullable)outError;

@end

NS_ASSUME_NONNULL_END
Loading