Skip to content

Commit 131e539

Browse files
authored
Revert "Use secure encoding for messaging's pending topics (#4826)" (#4829)
This reverts commit b7fec9e.
1 parent b7fec9e commit 131e539

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

Firebase/Messaging/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
- [added] Firebase Pod support for watchOS: `pod 'Firebase/Messaging'` in addition to `pod 'FirebaseMessaging'`. (#4807)
33
- [fixed] Fix FIRMessagingExtensionHelper crash in unit tests when `attachment == nil`. (#4689)
44
- [fixed] Fix FIRMessagingRmqManager crash when database is removed. This only happens when device has a corrupted database file. (#4771)
5-
- [fixed] Use secure encoding for messaging's pending topics objects. (#3686)
65

76
# 2020-01 -- v 4.2.0
87
- [added] Added watchOS support for Firebase Messaging. This enables FCM push notification function on watch only app or independent watch app. (#4016)

Firebase/Messaging/FIRMessagingPendingTopicsList.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
3030
* topics is unique, as it doesn't make sense to apply the same action to the same topic
3131
* repeatedly; the result would be the same as the first time.
3232
*/
33-
@interface FIRMessagingTopicBatch : NSObject <NSSecureCoding>
33+
@interface FIRMessagingTopicBatch : NSObject <NSCoding>
3434

3535
@property(nonatomic, readonly, assign) FIRMessagingTopicAction action;
3636
@property(nonatomic, readonly, copy) NSMutableSet <NSString *> *topics;
@@ -101,7 +101,7 @@ NS_ASSUME_NONNULL_BEGIN
101101
*
102102
* @see FIRMessagingPendingTopicsListDelegate
103103
*/
104-
@interface FIRMessagingPendingTopicsList : NSObject <NSSecureCoding>
104+
@interface FIRMessagingPendingTopicsList : NSObject <NSCoding>
105105

106106
@property(nonatomic, weak) NSObject <FIRMessagingPendingTopicsListDelegate> *delegate;
107107

Firebase/Messaging/FIRMessagingPendingTopicsList.m

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,15 @@ - (instancetype)initWithAction:(FIRMessagingTopicAction)action {
4848
return self;
4949
}
5050

51-
#pragma mark NSSecureCoding
52-
53-
+ (BOOL)supportsSecureCoding {
54-
return YES;
55-
}
51+
#pragma mark NSCoding
5652

5753
- (void)encodeWithCoder:(NSCoder *)aCoder {
5854
[aCoder encodeInteger:self.action forKey:kPendingTopicBatchActionKey];
5955
[aCoder encodeObject:self.topics forKey:kPendingTopicBatchTopicsKey];
6056
}
6157

6258
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
59+
6360
// Ensure that our integer -> enum casting is safe
6461
NSInteger actionRawValue = [aDecoder decodeIntegerForKey:kPendingTopicBatchActionKey];
6562
FIRMessagingTopicAction action = FIRMessagingTopicActionSubscribe;
@@ -68,7 +65,10 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder {
6865
}
6966

7067
if (self = [self initWithAction:action]) {
71-
_topics = [aDecoder decodeObjectOfClass:[NSSet class] forKey:kPendingTopicBatchTopicsKey];
68+
NSSet *topics = [aDecoder decodeObjectForKey:kPendingTopicBatchTopicsKey];
69+
if ([topics isKindOfClass:[NSSet class]]) {
70+
_topics = [topics mutableCopy];
71+
}
7272
_topicHandlers = [NSMutableDictionary dictionary];
7373
}
7474
return self;
@@ -109,22 +109,20 @@ + (void)pruneTopicBatches:(NSMutableArray <FIRMessagingTopicBatch *> *)topicBatc
109109
}
110110
}
111111

112-
#pragma mark NSSecureCoding
113-
114-
+ (BOOL)supportsSecureCoding {
115-
return YES;
116-
}
112+
#pragma mark NSCoding
117113

118114
- (void)encodeWithCoder:(NSCoder *)aCoder {
119115
[aCoder encodeObject:[NSDate date] forKey:kPendingTopicsTimestampEncodingKey];
120116
[aCoder encodeObject:self.topicBatches forKey:kPendingBatchesEncodingKey];
121117
}
122118

123119
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
120+
124121
if (self = [self init]) {
125-
_archiveDate = [aDecoder decodeObjectOfClass:[NSDate class] forKey:kPendingTopicsTimestampEncodingKey];
126-
_topicBatches = [aDecoder decodeObjectOfClass:[NSMutableArray<FIRMessagingTopicBatch *> class] forKey:kPendingBatchesEncodingKey];
127-
if (_topicBatches) {
122+
_archiveDate = [aDecoder decodeObjectForKey:kPendingTopicsTimestampEncodingKey];
123+
NSArray *archivedBatches = [aDecoder decodeObjectForKey:kPendingBatchesEncodingKey];
124+
if (archivedBatches) {
125+
_topicBatches = [archivedBatches mutableCopy];
128126
[FIRMessagingPendingTopicsList pruneTopicBatches:_topicBatches];
129127
}
130128
_topicsInFlight = [NSMutableSet set];

Firebase/Messaging/FIRMessagingPubSub.m

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,10 @@ - (BOOL)pendingTopicsListCanRequestTopicUpdates:(FIRMessagingPendingTopicsList *
183183

184184
- (void)archivePendingTopicsList:(FIRMessagingPendingTopicsList *)topicsList {
185185
GULUserDefaults *defaults = [GULUserDefaults standardUserDefaults];
186-
187-
NSData *pendingData;
188-
if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *)) {
189-
NSError *error;
190-
pendingData = [NSKeyedArchiver archivedDataWithRootObject:topicsList requiringSecureCoding:YES error:&error];
191-
} else {
192-
pendingData = [NSKeyedArchiver archivedDataWithRootObject:topicsList];
193-
}
186+
#pragma clang diagnostic push
187+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
188+
NSData *pendingData = [NSKeyedArchiver archivedDataWithRootObject:topicsList];
189+
#pragma clang diagnostic pop
194190
[defaults setObject:pendingData forKey:kPendingSubscriptionsListKey];
195191
[defaults synchronize];
196192
}
@@ -199,17 +195,16 @@ - (void)restorePendingTopicsList {
199195
GULUserDefaults *defaults = [GULUserDefaults standardUserDefaults];
200196
NSData *pendingData = [defaults objectForKey:kPendingSubscriptionsListKey];
201197
FIRMessagingPendingTopicsList *subscriptions;
202-
if (pendingData) {
203-
if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *)) {
204-
NSError *error;
205-
subscriptions = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSData class] fromData:pendingData error:&error];
206-
} else {
207-
@try {
208-
subscriptions = [NSKeyedUnarchiver unarchiveObjectWithData:pendingData];
209-
} @catch (NSException *exception) {
210-
// Nothing we can do, just continue as if we don't have pending subscriptions
211-
}
198+
@try {
199+
if (pendingData) {
200+
#pragma clang diagnostic push
201+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
202+
subscriptions = [NSKeyedUnarchiver unarchiveObjectWithData:pendingData];
203+
#pragma clang diagnostic pop
212204
}
205+
} @catch (NSException *exception) {
206+
// Nothing we can do, just continue as if we don't have pending subscriptions
207+
} @finally {
213208
if (subscriptions) {
214209
self.pendingTopicUpdates = subscriptions;
215210
} else {

0 commit comments

Comments
 (0)