Skip to content

Commit b245611

Browse files
Revert "Replace NSCoding with NSSecureCoding (#7831)" (#7863)
This reverts commit 34c4bdb.
1 parent aeeb015 commit b245611

10 files changed

+73
-81
lines changed

FirebaseMessaging/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 2021-04 -- v7.11.0
22
- [changed] Refactor Messaging to internally not depending on InstanceID, but can co-exist. Will remove InstanceID dependency in the next Firebase breaking change. (#7814)
3-
- [changed] Replaced NSCoding with NSSecureCoding. (#7831)
43

54
# 2021-02 -- v7.7.0
65
- [fixed] Fixed an issue in which, when checking storage size before writing to disk, the client was checking document folders that were no longer used. (#7480)

FirebaseMessaging/Sources/FIRMessagingCode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ typedef NS_ENUM(NSInteger, FIRMessagingMessageCode) {
220220
kFIRMessagingMessageCodeTokenManagerAPNSChangedTokenInvalidated = 34011,
221221
kFIRMessagingMessageCodeTokenManagerInvalidateStaleToken = 34012,
222222
// FIRMessagingTokenStore.m
223-
// DO NOT USE 35002 - 35013
223+
// DO NOT USE 15002 - 15013
224224
kFIRMessagingMessageCodeTokenStore000 = 35000,
225225
kFIRMessagingMessageCodeTokenStore001 = 35001,
226-
kFIRMessagingMessageCodeTokenStoreUnarchivingTokenInfo = 35015,
227-
kFIRMessagingMessageCodeTokenStoreArchiveError = 35016,
226+
kFIRMessagingMessageCodeTokenStoreExceptionUnarchivingTokenInfo = 35015,
227+
228228
// DO NOT USE 16000, 18004
229229

230230
// FIRMessagingUtilities.m

FirebaseMessaging/Sources/Token/FIRMessagingAPNSInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
2222
* Represents an APNS device token and whether its environment is for sandbox.
2323
* It can read from and write to an NSDictionary for simple serialization.
2424
*/
25-
@interface FIRMessagingAPNSInfo : NSObject <NSSecureCoding, NSCopying>
25+
@interface FIRMessagingAPNSInfo : NSObject <NSCoding, NSCopying>
2626

2727
/// The APNs device token, provided by the OS to the application delegate
2828
@property(nonatomic, readonly, copy) NSData *deviceToken;

FirebaseMessaging/Sources/Token/FIRMessagingAPNSInfo.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ - (id)copyWithZone:(NSZone *)zone {
6868
return clone;
6969
}
7070

71-
#pragma mark - NSSecureCoding
72-
73-
+ (BOOL)supportsSecureCoding {
74-
return YES;
75-
}
71+
#pragma mark - NSCoding
7672

7773
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
7874
id deviceToken = [aDecoder decodeObjectForKey:kFIRInstanceIDAPNSInfoTokenKey];

FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
2525
* associated with it. It can read from and write to an NSDictionary object, for
2626
* simple serialization.
2727
*/
28-
@interface FIRMessagingTokenInfo : NSObject <NSSecureCoding>
28+
@interface FIRMessagingTokenInfo : NSObject <NSCoding>
2929

3030
/// The authorized entity (also known as Sender ID), associated with the token.
3131
@property(nonatomic, readonly, copy) NSString *authorizedEntity;

FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.m

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.h"
1818

19-
#import <GoogleUtilities/GULSecureCoding.h>
2019
#import "FirebaseMessaging/Sources/FIRMessagingConstants.h"
2120
#import "FirebaseMessaging/Sources/FIRMessagingLogger.h"
2221
#import "FirebaseMessaging/Sources/FIRMessagingUtilities.h"
@@ -120,11 +119,7 @@ - (BOOL)isDefaultToken {
120119
return [self.scope isEqualToString:kFIRMessagingDefaultTokenScope];
121120
}
122121

123-
#pragma mark - NSSecureCoding
124-
125-
+ (BOOL)supportsSecureCoding {
126-
return YES;
127-
}
122+
#pragma mark - NSCoding
128123

129124
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
130125
// These value cannot be nil
@@ -145,6 +140,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
145140
}
146141

147142
// These values are nullable, so only fail the decode if the type does not match
143+
148144
id appVersion = [aDecoder decodeObjectForKey:kFIRInstanceIDAppVersionKey];
149145
if (appVersion && ![appVersion isKindOfClass:[NSString class]]) {
150146
return nil;
@@ -162,15 +158,19 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
162158

163159
FIRMessagingAPNSInfo *APNSInfo = nil;
164160
if (rawAPNSInfo) {
165-
NSError *error;
166-
APNSInfo = [GULSecureCoding
167-
unarchivedObjectOfClasses:[NSSet setWithObjects:FIRMessagingAPNSInfo.class, nil]
168-
fromData:rawAPNSInfo
169-
error:&error];
170-
if (error) {
171-
FIRMessagingLoggerDebug(
172-
kFIRMessagingMessageCodeTokenInfoBadAPNSInfo,
173-
@"Could not parse raw APNS Info while parsing unarchived token info: %@", error);
161+
// TODO(chliangGoogle: Use the new API and secureCoding protocol.
162+
@try {
163+
[NSKeyedUnarchiver setClass:[FIRMessagingAPNSInfo class]
164+
forClassName:@"FIRInstanceIDAPNSInfo"];
165+
#pragma clang diagnostic push
166+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
167+
APNSInfo = [NSKeyedUnarchiver unarchiveObjectWithData:rawAPNSInfo];
168+
#pragma clang diagnostic pop
169+
} @catch (NSException *exception) {
170+
FIRMessagingLoggerInfo(kFIRMessagingMessageCodeTokenInfoBadAPNSInfo,
171+
@"Could not parse raw APNS Info while parsing archived token info.");
172+
APNSInfo = nil;
173+
} @finally {
174174
}
175175
}
176176

@@ -200,15 +200,15 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
200200
[aCoder encodeObject:self.firebaseAppID forKey:kFIRInstanceIDFirebaseAppIDKey];
201201
NSData *rawAPNSInfo;
202202
if (self.APNSInfo) {
203-
NSError *error;
204-
rawAPNSInfo = [GULSecureCoding archivedDataWithRootObject:self.APNSInfo error:&error];
205-
if (error) {
206-
FIRMessagingLoggerDebug(
207-
kFIRMessagingMessageCodeTokenInfoBadAPNSInfo,
208-
@"Could not parse raw APNS Info while parsing archived token info: %@", error);
209-
}
203+
// TODO(chliangGoogle: Use the new API and secureCoding protocol.
204+
[NSKeyedArchiver setClassName:@"FIRInstanceIDAPNSInfo" forClass:[FIRMessagingAPNSInfo class]];
205+
#pragma clang diagnostic push
206+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
207+
rawAPNSInfo = [NSKeyedArchiver archivedDataWithRootObject:self.APNSInfo];
208+
#pragma clang diagnostic pop
209+
210+
[aCoder encodeObject:rawAPNSInfo forKey:kFIRInstanceIDAPNSInfoKey];
210211
}
211-
[aCoder encodeObject:[rawAPNSInfo copy] forKey:kFIRInstanceIDAPNSInfoKey];
212212
[aCoder encodeObject:self.cacheTime forKey:kFIRInstanceIDCacheTimeKey];
213213
}
214214

FirebaseMessaging/Sources/Token/FIRMessagingTokenStore.m

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenStore.h"
1818

19-
#import <GoogleUtilities/GULSecureCoding.h>
2019
#import "FirebaseMessaging/Sources/FIRMessagingConstants.h"
2120
#import "FirebaseMessaging/Sources/FIRMessagingLogger.h"
2221
#import "FirebaseMessaging/Sources/FIRMessagingUtilities.h"
@@ -88,18 +87,21 @@ + (nullable FIRMessagingTokenInfo *)tokenInfoFromKeychainItem:(NSData *)item {
8887
// NOTE: Passing in nil to unarchiveObjectWithData will result in an iOS error logged
8988
// in the console on iOS 10 and below. Avoid by checking item.data's existence.
9089
if (item) {
91-
NSError *unarchiverError;
92-
tokenInfo = [GULSecureCoding
93-
unarchivedObjectOfClasses:[NSSet
94-
setWithObjects:FIRMessagingTokenInfo.class, NSDate.class, nil]
95-
fromData:item
96-
error:&unarchiverError];
97-
if (unarchiverError) {
98-
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeTokenStoreUnarchivingTokenInfo,
90+
// TODO(chliangGoogle: Use the new API and secureCoding protocol.
91+
@try {
92+
#pragma clang diagnostic push
93+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
94+
[NSKeyedUnarchiver setClass:[FIRMessagingTokenInfo class]
95+
forClassName:@"FIRInstanceIDTokenInfo"];
96+
tokenInfo = [NSKeyedUnarchiver unarchiveObjectWithData:item];
97+
#pragma clang diagnostic pop
98+
99+
} @catch (NSException *exception) {
100+
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeTokenStoreExceptionUnarchivingTokenInfo,
99101
@"Unable to parse token info from Keychain item; item was in an "
100-
@"invalid format %@",
101-
unarchiverError);
102+
@"invalid format");
102103
tokenInfo = nil;
104+
} @finally {
103105
}
104106
}
105107
return tokenInfo;
@@ -113,13 +115,13 @@ - (void)saveTokenInfo:(FIRMessagingTokenInfo *)tokenInfo
113115
handler:(void (^)(NSError *))handler { // Keep the cachetime up-to-date.
114116
tokenInfo.cacheTime = [NSDate date];
115117
// Always write to the Keychain, so that the cacheTime is up-to-date.
116-
NSError *archiverError;
117-
NSData *tokenInfoData = [GULSecureCoding archivedDataWithRootObject:tokenInfo
118-
error:&archiverError];
119-
if (archiverError) {
120-
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeTokenStoreArchiveError,
121-
@"Failed to archive token info: %@", archiverError);
122-
}
118+
NSData *tokenInfoData;
119+
// TODO(chliangGoogle: Use the new API and secureCoding protocol.
120+
[NSKeyedArchiver setClassName:@"FIRInstanceIDTokenInfo" forClass:[FIRMessagingTokenInfo class]];
121+
#pragma clang diagnostic push
122+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
123+
tokenInfoData = [NSKeyedArchiver archivedDataWithRootObject:tokenInfo];
124+
#pragma clang diagnostic pop
123125
NSString *account = FIRMessagingAppIdentifier();
124126
NSString *service = [[self class] serviceKeyForAuthorizedEntity:tokenInfo.authorizedEntity
125127
scope:tokenInfo.scope];
@@ -128,15 +130,14 @@ - (void)saveTokenInfo:(FIRMessagingTokenInfo *)tokenInfo
128130

129131
- (void)saveTokenInfoInCache:(FIRMessagingTokenInfo *)tokenInfo {
130132
tokenInfo.cacheTime = [NSDate date];
133+
// TODO(chliangGoogle): Use the new API and secureCoding protocol.
131134
// Always write to the Keychain, so that the cacheTime is up-to-date.
132-
NSError *archiverError;
133-
NSData *tokenInfoData = [GULSecureCoding archivedDataWithRootObject:tokenInfo
134-
error:&archiverError];
135-
if (archiverError) {
136-
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeTokenStoreArchiveError,
137-
@"Failed to archive token info: %@", archiverError);
138-
}
139-
135+
NSData *tokenInfoData;
136+
[NSKeyedArchiver setClassName:@"FIRInstanceIDTokenInfo" forClass:[FIRMessagingTokenInfo class]];
137+
#pragma clang diagnostic push
138+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
139+
tokenInfoData = [NSKeyedArchiver archivedDataWithRootObject:tokenInfo];
140+
#pragma clang diagnostic pop
140141
NSString *account = FIRMessagingAppIdentifier();
141142
NSString *service = [[self class] serviceKeyForAuthorizedEntity:tokenInfo.authorizedEntity
142143
scope:tokenInfo.scope];

FirebaseMessaging/Tests/UnitTests/FIRMessagingAPNSInfoTest.m

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import <XCTest/XCTest.h>
1818

19-
#import <GoogleUtilities/GULSecureCoding.h>
2019
#import "FirebaseMessaging/Sources/FIRMessagingConstants.h"
2120
#import "FirebaseMessaging/Sources/Token/FIRMessagingAPNSInfo.h"
2221

@@ -77,13 +76,11 @@ - (void)testAPNSInfoEncodingAndDecoding {
7776
};
7877
FIRMessagingAPNSInfo *info =
7978
[[FIRMessagingAPNSInfo alloc] initWithTokenOptionsDictionary:validDictionary];
80-
NSError *error;
81-
NSData *archive = [GULSecureCoding archivedDataWithRootObject:info error:&error];
82-
NSError *unarchiveError;
83-
FIRMessagingAPNSInfo *restoredInfo = [GULSecureCoding
84-
unarchivedObjectOfClasses:[NSSet setWithObjects:FIRMessagingAPNSInfo.class, nil]
85-
fromData:archive
86-
error:&unarchiveError];
79+
#pragma clang diagnostic push
80+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
81+
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:info];
82+
FIRMessagingAPNSInfo *restoredInfo = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
83+
#pragma clang diagnostic pop
8784
XCTAssertEqualObjects(info.deviceToken, restoredInfo.deviceToken);
8885
XCTAssertEqual(info.sandbox, restoredInfo.sandbox);
8986
}

FirebaseMessaging/Tests/UnitTests/FIRMessagingAuthKeychainTest.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
#if !TARGET_OS_MACCATALYST && !SWIFT_PACKAGE
1919
// Skip keychain tests on Catalyst and swift package
2020

21-
#import <GoogleUtilities/GULSecureCoding.h>
2221
#import <XCTest/XCTest.h>
22+
#import "OCMock.h"
23+
2324
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeychain.h"
2425
#import "FirebaseMessaging/Sources/Token/FIRMessagingCheckinPreferences.h"
2526
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.h"
26-
#import "OCMock.h"
2727

2828
static NSString *const kFIRMessagingTestKeychainId = @"com.google.iid-tests";
2929

@@ -406,8 +406,10 @@ - (NSData *)tokenDataWithAuthorizedEntity:(NSString *)authorizedEntity
406406
token:token
407407
appVersion:@"1.0"
408408
firebaseAppID:kFirebaseAppID];
409-
NSError *error;
410-
return [GULSecureCoding archivedDataWithRootObject:tokenInfo error:&error];
409+
#pragma clang diagnostic push
410+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
411+
return [NSKeyedArchiver archivedDataWithRootObject:tokenInfo];
412+
#pragma clang diagnostic pop
411413
}
412414
@end
413415

FirebaseMessaging/Tests/UnitTests/FIRMessagingTokenInfoTest.m

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.h"
1818

19-
#import <GoogleUtilities/GULSecureCoding.h>
2019
#import <XCTest/XCTest.h>
20+
2121
#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
2222
#import "FirebaseMessaging/Sources/FIRMessagingUtilities.h"
2323
#import "FirebaseMessaging/Sources/Token/FIRMessagingAPNSInfo.h"
@@ -76,14 +76,11 @@ - (void)tearDown {
7676
// yields the same values for all the fields.
7777
- (void)testTokenInfoEncodingAndDecoding {
7878
FIRMessagingTokenInfo *info = self.validTokenInfo;
79-
NSError *archiverError;
80-
NSData *archive = [GULSecureCoding archivedDataWithRootObject:info error:&archiverError];
81-
NSError *unarchiverError;
82-
FIRMessagingTokenInfo *restoredInfo =
83-
[GULSecureCoding unarchivedObjectOfClasses:[NSSet setWithObjects:FIRMessagingTokenInfo.class,
84-
NSDate.class, nil]
85-
fromData:archive
86-
error:&unarchiverError];
79+
#pragma clang diagnostic push
80+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
81+
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:info];
82+
FIRMessagingTokenInfo *restoredInfo = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
83+
#pragma clang diagnostic pop
8784
XCTAssertEqualObjects(restoredInfo.authorizedEntity, info.authorizedEntity);
8885
XCTAssertEqualObjects(restoredInfo.scope, info.scope);
8986
XCTAssertEqualObjects(restoredInfo.token, info.token);

0 commit comments

Comments
 (0)