Skip to content

Commit 377ece4

Browse files
authored
Merge pull request #1588 from AzureAD/hotfix/1.15.2
Hotfix/1.15.2
2 parents 4ba6789 + 5ead676 commit 377ece4

File tree

10 files changed

+64
-103
lines changed

10 files changed

+64
-103
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,6 @@
741741
728209D026FEA0F600B5F018 /* MSIDKeyOperationUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 728209CF26FEA0F600B5F018 /* MSIDKeyOperationUtil.m */; };
742742
728209D126FEA0F600B5F018 /* MSIDKeyOperationUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 728209CF26FEA0F600B5F018 /* MSIDKeyOperationUtil.m */; };
743743
728209D62702AF8900B5F018 /* MSIDBackgroundTaskManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 728209D32702AE9300B5F018 /* MSIDBackgroundTaskManagerTests.m */; };
744-
728ABACC2E5A3B4E00FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 728ABACB2E5A3B2800FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.h */; };
745-
728ABACE2E5A41A800FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ABACD2E5A418F00FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.m */; };
746-
728ABACF2E5A41A800FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ABACD2E5A418F00FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.m */; };
747744
728D9E4628245DD7001D990F /* MSIDTestSecureEnclaveKeyPairGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 728D9E4528245DD7001D990F /* MSIDTestSecureEnclaveKeyPairGenerator.m */; };
748745
728D9E4728245DD7001D990F /* MSIDTestSecureEnclaveKeyPairGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 728D9E4528245DD7001D990F /* MSIDTestSecureEnclaveKeyPairGenerator.m */; };
749746
728D9E492824A323001D990F /* MSIDPkeyAuthHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 23CA0C5E220A68D400768729 /* MSIDPkeyAuthHelperTests.m */; };
@@ -2657,8 +2654,6 @@
26572654
728209CD26FEA0D800B5F018 /* MSIDKeyOperationUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDKeyOperationUtil.h; sourceTree = "<group>"; };
26582655
728209CF26FEA0F600B5F018 /* MSIDKeyOperationUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDKeyOperationUtil.m; sourceTree = "<group>"; };
26592656
728209D32702AE9300B5F018 /* MSIDBackgroundTaskManagerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBackgroundTaskManagerTests.m; sourceTree = "<group>"; };
2660-
728ABACB2E5A3B2800FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MSIDWPJKeyPairWithCert+TransportKey.h"; sourceTree = "<group>"; };
2661-
728ABACD2E5A418F00FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MSIDWPJKeyPairWithCert+TransportKey.m"; sourceTree = "<group>"; };
26622657
728D9E4528245DD7001D990F /* MSIDTestSecureEnclaveKeyPairGenerator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDTestSecureEnclaveKeyPairGenerator.m; sourceTree = "<group>"; };
26632658
728D9E4828247D4C001D990F /* MSIDTestSecureEnclaveKeyPairGenerator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDTestSecureEnclaveKeyPairGenerator.h; sourceTree = "<group>"; };
26642659
729357E72DD810C70001D03C /* MSIDNonceTokenRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDNonceTokenRequest.h; sourceTree = "<group>"; };
@@ -5176,8 +5171,6 @@
51765171
B2C0747E246B70DC0008D701 /* crypto */ = {
51775172
isa = PBXGroup;
51785173
children = (
5179-
728ABACD2E5A418F00FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.m */,
5180-
728ABACB2E5A3B2800FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.h */,
51815174
B27893792470CAF200627C28 /* mac */,
51825175
B2C0748E246B71470008D701 /* MSIDAssymetricKeyGenerating.h */,
51835176
B2C07490246B735B0008D701 /* MSIDAssymetricKeyKeychainGenerator.h */,
@@ -6138,7 +6131,6 @@
61386131
A07EB427259D0C6B00783943 /* MSIDThrottlingService.h in Headers */,
61396132
9658103120C7E1180025F4A4 /* MSIDWebviewResponse.h in Headers */,
61406133
1E707FDF2407335700716148 /* MSIDBrokerNativeAppOperationResponse.h in Headers */,
6141-
728ABACC2E5A3B4E00FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.h in Headers */,
61426134
B28BDA7F217E964B003E5670 /* MSIDB2CTokenResponse.h in Headers */,
61436135
96B8D57D20946D2600E3F4A6 /* MSIDPkce.h in Headers */,
61446136
B286B9912389DC47007833AD /* MSIDIndividualClaimRequest.h in Headers */,
@@ -7385,7 +7377,6 @@
73857377
23C8981A2C892A3800071482 /* MSIDBrowserNativeMessageGetSupportedContractsResponse.m in Sources */,
73867378
B286B9992389DC9D007833AD /* MSIDSSOExtensionSilentTokenRequest.m in Sources */,
73877379
B2C7089921991D0000D917B8 /* MSIDAADV2BrokerResponse.m in Sources */,
7388-
728ABACE2E5A41A800FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.m in Sources */,
73897380
B20E3CB61FC4FE400029C097 /* MSIDOAuth2Constants.m in Sources */,
73907381
B2BE924D21A2331A00F5AB8C /* MSIDTelemetryAuthorityValidationEvent.m in Sources */,
73917382
B2807FF9204CAFDF00944D89 /* MSIDHelpers.m in Sources */,
@@ -8091,7 +8082,6 @@
80918082
239E3BBF23E1004F00F7A50A /* MSIDClientSDKType.m in Sources */,
80928083
23B39ABD209BD47D000AA905 /* MSIDB2CAuthorityResolver.m in Sources */,
80938084
B2F671E92467A34400649855 /* MSIDAuthorizationCodeResult.m in Sources */,
8094-
728ABACF2E5A41A800FCE434 /* MSIDWPJKeyPairWithCert+TransportKey.m in Sources */,
80958085
23C10A9F2B40D9350063D97C /* MSIDBrowserNativeMessageSignOutResponse.m in Sources */,
80968086
23FB5C2B225517AA002BF1EB /* MSIDIndividualClaimRequestAdditionalInfo.m in Sources */,
80978087
1E707FDD2406FA9200716148 /* MSIDBrokerBrowserOperationResponse.m in Sources */,

IdentityCore/src/MSIDConstants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,6 @@ extern NSString * _Nonnull const MSID_FLIGHT_IGNORE_COOKIES_IN_DUNA_RESUME;
230230
*/
231231
extern NSString * _Nonnull const MSID_FLIGHT_DISABLE_REMOVE_ACCOUNT_ARTIFACTS;
232232

233+
extern NSString * _Nonnull const MSID_FLIGHT_ENABLE_QUERYING_STK;
234+
233235
#define METHODANDLINE [NSString stringWithFormat:@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__]

IdentityCore/src/MSIDConstants.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,7 @@
9494
// Making the flight string short to avoid legacy broker url size limit
9595
NSString *const MSID_FLIGHT_DISABLE_REMOVE_ACCOUNT_ARTIFACTS = @"disable_rm_metadata";
9696

97+
NSString *const MSID_FLIGHT_ENABLE_QUERYING_STK = @"enable_querying_stk";
98+
9799

98100
#define METHODANDLINE [NSString stringWithFormat:@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__]

IdentityCore/src/cache/crypto/MSIDWPJKeyPairWithCert+TransportKey.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

IdentityCore/src/cache/crypto/MSIDWPJKeyPairWithCert+TransportKey.m

Lines changed: 0 additions & 49 deletions
This file was deleted.

IdentityCore/src/cache/crypto/MSIDWPJKeyPairWithCert.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ typedef NS_ENUM(NSInteger, MSIDWPJKeychainAccessGroup)
6363
certificate:(SecCertificateRef)certificate
6464
certificateIssuer:(nullable NSString *)issuer;
6565

66+
- (nullable instancetype)initializePrivateTransportKeyRef:(SecKeyRef)privateTransportKeyRef;
6667
@end
6768

6869
NS_ASSUME_NONNULL_END

IdentityCore/src/cache/crypto/MSIDWPJKeyPairWithCert.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ @interface MSIDWPJKeyPairWithCert()
3333
@property (nonatomic) NSString *certificateSubject;
3434
@property (nonatomic) NSString *certificateIssuer;
3535
@property (nonatomic) SecKeyRef privateKeyRef;
36+
@property (nonatomic) SecKeyRef privateTransportKeyRef;
3637

3738
@end
3839

@@ -88,6 +89,30 @@ - (nullable instancetype)initWithPrivateKey:(SecKeyRef)privateKey
8889
return self;
8990
}
9091

92+
- (nullable instancetype)initializePrivateTransportKeyRef:(nonnull SecKeyRef)privateTransportKeyRef
93+
{
94+
if (self && privateTransportKeyRef)
95+
{
96+
if (_privateTransportKeyRef != privateTransportKeyRef)
97+
{
98+
if (_privateTransportKeyRef)
99+
{
100+
CFReleaseNull(_privateTransportKeyRef);
101+
_privateTransportKeyRef = NULL;
102+
}
103+
104+
_privateTransportKeyRef = privateTransportKeyRef;
105+
106+
if (_privateTransportKeyRef)
107+
{
108+
CFRetain(_privateTransportKeyRef);
109+
}
110+
}
111+
}
112+
return self;
113+
}
114+
115+
91116
- (void)dealloc
92117
{
93118
if (_certificateRef)

IdentityCore/src/workplacejoin/MSIDWorkPlaceJoinUtilBase.m

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
#import "MSIDWorkPlaceJoinConstants.h"
2828
#import "MSIDWPJKeyPairWithCert.h"
2929
#import "MSIDWPJMetadata.h"
30-
#import "MSIDWPJKeyPairWithCert+TransportKey.h"
30+
#import "MSIDFlightManager.h"
31+
#import "MSIDConstants.h"
3132

3233
static NSString *kWPJPrivateKeyIdentifier = @"com.microsoft.workplacejoin.privatekey\0";
3334
static NSString *kECPrivateKeyTagSuffix = @"-EC";
@@ -381,13 +382,21 @@ + (MSIDWPJKeyPairWithCert *)getWPJKeysWithTenantId:(__unused NSString *)tenantId
381382
{
382383
defaultKeys.keyChainVersion = MSIDWPJKeychainAccessGroupV2;
383384
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, context, @"Returning EC private device key from default registration.");
384-
// Query the session transport key only for iOS.
385-
// 1P apps use transport key to decrypt ECDH JWE responses when redeeming bound regular refresh tokens
386-
id keyType = privateKeyAttributes[(__bridge id)kSecAttrKeyType];
387-
if (keyType && [keyType isEqual: (__bridge id)kSecAttrKeyTypeECSECPrimeRandom])
385+
#if TARGET_OS_IPHONE
386+
bool isQueryingEnabledViaFlight = [MSIDFlightManager.sharedInstance boolForKey:MSID_FLIGHT_ENABLE_QUERYING_STK];
387+
if (isQueryingEnabledViaFlight)
388388
{
389-
defaultKeys.privateTransportKeyRef = [self getSessionTransportKeyRefFromSecureEnclaveForTenantId:tenantId context:context];
389+
// Query the session transport key only for iOS.
390+
// 1P apps use transport key to decrypt ECDH JWE responses when redeeming bound regular refresh tokens
391+
id keyType = privateKeyAttributes[(__bridge id)kSecAttrKeyType];
392+
if (keyType && [keyType isEqual: (__bridge id)kSecAttrKeyTypeECSECPrimeRandom])
393+
{
394+
[self setSessionTransportKeyRefFromSecureEnclaveForTenantId:tenantId
395+
keyPairWithCert:defaultKeys
396+
context:context];
397+
}
390398
}
399+
#endif
391400
return defaultKeys;
392401
}
393402

@@ -501,14 +510,15 @@ + (MSIDWPJMetadata *)readWPJMetadataWithSharedAccessGroup:(NSString *)sharedAcce
501510
return nil;
502511
}
503512

504-
+ (SecKeyRef)getSessionTransportKeyRefFromSecureEnclaveForTenantId:(NSString *)tenantId context:(id<MSIDRequestContext>)context
513+
+ (void)setSessionTransportKeyRefFromSecureEnclaveForTenantId:(NSString *)tenantId
514+
keyPairWithCert:(MSIDWPJKeyPairWithCert *)keyPairWithCert
515+
context:(id<MSIDRequestContext>)context
505516
{
506-
SecKeyRef transportKeyRef = nil;
507517
#if TARGET_OS_IPHONE
518+
SecKeyRef transportKeyRef = nil;
508519
if (!tenantId)
509520
{
510521
MSID_LOG_WITH_CTX(MSIDLogLevelError, context, @"No tenantId provided to read secure enclave session transport key.");
511-
return nil;
512522
}
513523
NSString *teamId = [[MSIDKeychainUtil sharedInstance] teamId];
514524
NSString *defaultSharedAccessGroup = [NSString stringWithFormat:@"%@.com.microsoft.workplacejoin.v2", teamId];
@@ -531,7 +541,6 @@ + (SecKeyRef)getSessionTransportKeyRefFromSecureEnclaveForTenantId:(NSString *)t
531541
if (status != errSecSuccess)
532542
{
533543
MSID_LOG_WITH_CTX(MSIDLogLevelError, context, @"Failed to find secure enclave session transport private key with status %ld", (long)status);
534-
return nil;
535544
}
536545

537546
NSDictionary *privateKeyDict = CFBridgingRelease(privateKeyCFDict); // -1 privateKeyCFDict
@@ -543,9 +552,9 @@ + (SecKeyRef)getSessionTransportKeyRefFromSecureEnclaveForTenantId:(NSString *)t
543552
}
544553
else
545554
{
555+
[keyPairWithCert initializePrivateTransportKeyRef:transportKeyRef];
546556
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, context, @"Found secure enclave private session transport key ref in keychain.");
547557
}
548558
#endif
549-
return transportKeyRef;
550559
}
551560
@end

IdentityCore/tests/MSIDWorkPlaceJoinUtilTests.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#import "MSIDTestSwizzle.h"
3434
#import "MSIDWorkPlaceJoinUtilBase+Internal.h"
3535
#import "MSIDWPJMetadata.h"
36+
#import "MSIDFlightManager.h"
37+
#import "MSIDFlightManagerMockProvider.h"
38+
#import "MSIDConstants.h"
3639

3740
@interface MSIDWorkPlaceJoinUtilTests : XCTestCase
3841
@property (nonatomic) MSIDTestSecureEnclaveKeyPairGenerator *eccKeyGenerator;
@@ -67,6 +70,7 @@ - (void)setUp
6770
// Setting use iOS style keychain to true by default. Set it to NO in test cases that require ACL.
6871
self.useIosStyleKeychain = YES;
6972
self.tenantId = NSUUID.UUID.UUIDString;
73+
[self mockFlightValues];
7074
#if TARGET_OS_OSX
7175
self.useIosStyleKeychain = NO;
7276
#endif
@@ -848,4 +852,11 @@ - (void)insertEccStkKeyForTenantIdentifier:(NSString *)tenantIdentifier
848852
privateKeyTag:stkTag
849853
accessGroup:keychainGroup];
850854
}
855+
856+
- (void)mockFlightValues
857+
{
858+
MSIDFlightManagerMockProvider *flightProvider = [MSIDFlightManagerMockProvider new];
859+
flightProvider.boolForKeyContainer = @{ MSID_FLIGHT_ENABLE_QUERYING_STK: @YES };
860+
MSIDFlightManager.sharedInstance.flightProvider = flightProvider;
861+
}
851862
@end

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Version 1.15.2
2+
* Feature flag gating STK querying and getting rid of category for its setter. (#1586)
3+
14
Version 1.15.1
25
Allow cookies in duna resume request #1574
36

0 commit comments

Comments
 (0)