Skip to content

Commit f7bd716

Browse files
authored
Merge pull request #677 from AzureAD/oldalton/keyed_unarchiver_hotfix
Keyed unarchiver hotfix for 11.2.x iOS versions
2 parents ebef0d8 + f9111d5 commit f7bd716

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

IdentityCore/src/cache/token/MSIDLegacyTokenCacheItem.m

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,6 @@ - (instancetype)initWithCoder:(NSCoder *)coder
124124
self.cachedAt = [coder decodeObjectOfClass:[NSDate class] forKey:@"cachedAt"];
125125
self.familyId = [coder decodeObjectOfClass:[NSString class] forKey:@"familyId"];
126126

127-
// We support all bplist types in "additionalServer" property.
128-
NSMutableDictionary *additionalServer = [[coder decodePropertyListForKey:@"additionalServer"] mutableCopy];
129-
self.extendedExpiresOn = additionalServer[MSID_EXTENDED_EXPIRES_ON_CACHE_KEY];
130-
[additionalServer removeObjectForKey:MSID_EXTENDED_EXPIRES_ON_CACHE_KEY];
131-
self.speInfo = additionalServer[MSID_SPE_INFO_CACHE_KEY];
132-
[additionalServer removeObjectForKey:MSID_SPE_INFO_CACHE_KEY];
133-
if (additionalServer.count)
134-
{
135-
self.additionalInfo = additionalServer;
136-
}
137-
138127
self.accessToken = [coder decodeObjectOfClass:[NSString class] forKey:@"accessToken"];
139128
self.refreshToken = [coder decodeObjectOfClass:[NSString class] forKey:@"refreshToken"];
140129
self.secret = self.accessToken ? self.accessToken : self.refreshToken;
@@ -154,6 +143,18 @@ - (instancetype)initWithCoder:(NSCoder *)coder
154143

155144
self.enrollmentId = [coder decodeObjectOfClass:[NSString class] forKey:@"enrollmentId"];
156145
self.applicationIdentifier = [coder decodeObjectOfClass:[NSString class] forKey:@"applicationIdentifier"];
146+
147+
NSSet *classes = [NSSet setWithObjects:[NSDictionary class], [NSDate class], [NSString class], [NSURL class], [NSNumber class], nil];
148+
NSMutableDictionary *additionalServer = [[coder decodeObjectOfClasses:classes forKey:@"additionalServer"] mutableCopy];
149+
self.extendedExpiresOn = additionalServer[MSID_EXTENDED_EXPIRES_ON_CACHE_KEY];
150+
[additionalServer removeObjectForKey:MSID_EXTENDED_EXPIRES_ON_CACHE_KEY];
151+
self.speInfo = additionalServer[MSID_SPE_INFO_CACHE_KEY];
152+
[additionalServer removeObjectForKey:MSID_SPE_INFO_CACHE_KEY];
153+
if (additionalServer.count)
154+
{
155+
self.additionalInfo = additionalServer;
156+
}
157+
157158
return self;
158159
}
159160

IdentityCore/tests/MSIDLegacyTokenCacheItemTests.m

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#import "MSIDLegacyTokenCacheItem.h"
2626
#import "MSIDClientInfo.h"
2727
#import "NSDictionary+MSIDTestUtil.h"
28+
#import "NSKeyedUnarchiver+MSIDExtensions.h"
2829

2930
@interface MSIDLegacyTokenCacheItemTests : XCTestCase
3031

@@ -65,7 +66,10 @@ - (void)testKeyedArchivingSingleResourceToken_whenAllFieldsSet_shouldReturnSameT
6566

6667
XCTAssertNotNil(data);
6768

68-
MSIDLegacyTokenCacheItem *newItem = [NSKeyedUnarchiver unarchiveObjectWithData:data];
69+
NSKeyedUnarchiver *unarchiver = [NSKeyedUnarchiver msidCreateForReadingFromData:data error:nil];
70+
XCTAssertNotNil(unarchiver);
71+
72+
MSIDLegacyTokenCacheItem *newItem = [unarchiver decodeObjectOfClass:[MSIDLegacyTokenCacheItem class] forKey:NSKeyedArchiveRootObjectKey];
6973

7074
XCTAssertNotNil(newItem);
7175
XCTAssertEqualObjects(newItem.accessToken, @"at");
@@ -113,14 +117,21 @@ - (void)testKeyedArchivingAccessToken_whenAllFieldsSet_shouldReturnSameTokenOnDe
113117
cacheItem.cachedAt = cachedAt;
114118
cacheItem.homeAccountId = @"uid.utid";
115119
cacheItem.speInfo = @"2";
116-
NSDictionary *additionalInfo = @{@"test": @"test"};
120+
NSDictionary *additionalInfo = @{@"scope": @"user_impersonation",
121+
@"correlation_id": @"97c58ae8-bf7e-438f-8710-2ad89c69ec1c",
122+
@"ext_expires_on": [NSDate date],
123+
@"not_before": @1580181520,
124+
@"url": [NSURL URLWithString:@"https://login.microsoftonline.com/common/oauth2/token"] };
117125
cacheItem.additionalInfo = additionalInfo;
118126

119127
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:cacheItem];
120128

121129
XCTAssertNotNil(data);
122130

123-
MSIDLegacyTokenCacheItem *newItem = [NSKeyedUnarchiver unarchiveObjectWithData:data];
131+
NSKeyedUnarchiver *unarchiver = [NSKeyedUnarchiver msidCreateForReadingFromData:data error:nil];
132+
XCTAssertNotNil(unarchiver);
133+
134+
MSIDLegacyTokenCacheItem *newItem = [unarchiver decodeObjectOfClass:[MSIDLegacyTokenCacheItem class] forKey:NSKeyedArchiveRootObjectKey];
124135

125136
XCTAssertNotNil(newItem);
126137
XCTAssertEqualObjects(newItem.accessToken, @"at");
@@ -174,7 +185,10 @@ - (void)testKeyedArchivingRefreshToken_whenAllFieldsSet_shouldReturnSameTokenOnD
174185

175186
XCTAssertNotNil(data);
176187

177-
MSIDLegacyTokenCacheItem *newItem = [NSKeyedUnarchiver unarchiveObjectWithData:data];
188+
NSKeyedUnarchiver *unarchiver = [NSKeyedUnarchiver msidCreateForReadingFromData:data error:nil];
189+
XCTAssertNotNil(unarchiver);
190+
191+
MSIDLegacyTokenCacheItem *newItem = [unarchiver decodeObjectOfClass:[MSIDLegacyTokenCacheItem class] forKey:NSKeyedArchiveRootObjectKey];
178192

179193
XCTAssertNotNil(newItem);
180194
XCTAssertEqualObjects(newItem.refreshToken, @"rt");

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 1.3.5-hotfix2
2+
---------
3+
* [Broker patch] Keyed unarchiver deserialization fix for iOS 11.2
4+
15
Version 1.3.5-hotfix1
26
----------
37
* [Broker patch] Fixed account lookups and validation with the same email (#669)

0 commit comments

Comments
 (0)