Skip to content

Commit da87a45

Browse files
authored
Merge pull request #1170 from AzureAD/release/1.7.13
Release - 1.7.13
2 parents 2ae57da + 2246c2b commit da87a45

File tree

77 files changed

+1031
-618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1031
-618
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 36 additions & 36 deletions
Large diffs are not rendered by default.

IdentityCore/src/MSIDBrokerConstants.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,8 @@ extern NSString * _Nonnull const MSID_SSO_NONCE_QUERY_PARAM_KEY;
8282
extern NSString * _Nonnull const MSID_BROKER_MDM_ID_KEY;
8383
extern NSString * _Nonnull const MSID_ENROLLED_USER_OBJECT_ID_KEY;
8484
extern NSString * _Nonnull const MSID_EXTRA_DEVICE_INFO_KEY;
85-
85+
extern NSString * _Nonnull const MSID_PRIMARY_REGISTRATION_UPN;
86+
extern NSString * _Nonnull const MSID_PRIMARY_REGISTRATION_DEVICE_ID;
87+
extern NSString * _Nonnull const MSID_PRIMARY_REGISTRATION_TENANT_ID;
88+
extern NSString * _Nonnull const MSID_PRIMARY_REGISTRATION_CLOUD;
89+
extern NSString * _Nonnull const MSID_PRIMARY_REGISTRATION_CERTIFICATE_THUMBPRINT;

IdentityCore/src/MSIDBrokerConstants.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@
7878
NSString *const MSID_BROKER_MDM_ID_KEY = @"mdm_id";
7979
NSString *const MSID_ENROLLED_USER_OBJECT_ID_KEY = @"object_id";
8080
NSString *const MSID_EXTRA_DEVICE_INFO_KEY = @"extraDeviceInfo";
81+
NSString *const MSID_PRIMARY_REGISTRATION_UPN = @"primary_registration_metadata_upn";
82+
NSString *const MSID_PRIMARY_REGISTRATION_DEVICE_ID = @"primary_registration_metadata_device_id";
83+
NSString *const MSID_PRIMARY_REGISTRATION_TENANT_ID = @"primary_registration_metadata_tenant_id";
84+
NSString *const MSID_PRIMARY_REGISTRATION_CLOUD = @"primary_registration_metadata_cloud_host";
85+
NSString *const MSID_PRIMARY_REGISTRATION_CERTIFICATE_THUMBPRINT = @"primary_registration_metadata_certificate_thumbprint";

IdentityCore/src/broker_operation/request/MSIDBrokerOperationGetDeviceInfoRequest.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ @implementation MSIDBrokerOperationGetDeviceInfoRequest
2929

3030
+ (void)load
3131
{
32-
if (@available(iOS 13.0, *))
33-
{
34-
[MSIDJsonSerializableFactory registerClass:self forClassType:self.operation];
35-
}
32+
[MSIDJsonSerializableFactory registerClass:self forClassType:self.operation];
3633
}
3734

3835
#pragma mark - MSIDBrokerOperationRequest

IdentityCore/src/broker_operation/request/interactive_token_request/MSIDBrokerOperationInteractiveTokenRequest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ @implementation MSIDBrokerOperationInteractiveTokenRequest
3434

3535
+ (void)load
3636
{
37-
if (@available(iOS 13.0, macOS 10.15, *))
37+
if (@available(macOS 10.15, *))
3838
{
3939
[MSIDJsonSerializableFactory registerClass:self forClassType:self.operation];
4040
}
@@ -64,7 +64,7 @@ + (instancetype)tokenRequestWithParameters:(MSIDInteractiveTokenRequestParameter
6464

6565
+ (NSString *)operation
6666
{
67-
if (@available(iOS 13.0, macOS 10.15, *))
67+
if (@available(macOS 10.15, *))
6868
{
6969
return ASAuthorizationOperationLogin;
7070
}

IdentityCore/src/broker_operation/request/silent_token_request/MSIDBrokerOperationSilentTokenRequest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ @implementation MSIDBrokerOperationSilentTokenRequest
4040

4141
+ (void)load
4242
{
43-
if (@available(iOS 13.0, macOS 10.15, *))
43+
if (@available(macOS 10.15, *))
4444
{
4545
[MSIDJsonSerializableFactory registerClass:self forClassType:self.operation];
4646
}
@@ -63,7 +63,7 @@ + (instancetype)tokenRequestWithParameters:(MSIDRequestParameters *)parameters
6363

6464
+ (NSString *)operation
6565
{
66-
if (@available(iOS 13.0, macOS 10.15, *))
66+
if (@available(macOS 10.15, *))
6767
{
6868
return ASAuthorizationOperationRefresh;
6969
}

IdentityCore/src/broker_operation/response/MSIDBrokerNativeAppOperationResponse.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#import "MSIDBrokerOperationResponse.h"
2727

2828
@class MSIDDeviceInfo;
29+
#if !EXCLUDE_FROM_MSALCPP
30+
@class MSIDLastRequestTelemetry;
31+
#endif
2932

3033
extern NSString * _Nonnull const MSID_BROKER_OPERATION_RESPONSE_TYPE_JSON_KEY;
3134

@@ -43,11 +46,21 @@ NS_ASSUME_NONNULL_BEGIN
4346
@property (nonatomic, class, readonly) NSNumber *defaultHttpStatusCode;
4447
@property (nonatomic, nullable) NSDictionary *httpHeaders;
4548
@property (nonatomic) NSString *httpVersion;
49+
@property (nonatomic) NSDate *responseGenerationTimeStamp;
50+
@property (nonatomic) NSDate *requestReceivedTimeStamp;
4651

4752
- (instancetype)initWithDeviceInfo:(MSIDDeviceInfo *)deviceInfo;
4853
- (instancetype)init NS_UNAVAILABLE;
4954
+ (instancetype)new NS_UNAVAILABLE;
5055

56+
#if !EXCLUDE_FROM_MSALCPP
57+
58+
- (void)trackPerfTelemetryWithLastRequest:(MSIDLastRequestTelemetry *)telemetry
59+
requestStartDate:(NSDate *)requestStartDate
60+
telemetryType:(NSString *)telemetryType;
61+
62+
#endif
63+
5164

5265
@end
5366

IdentityCore/src/broker_operation/response/MSIDBrokerNativeAppOperationResponse.m

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@
3535
#import "MSIDJsonSerializableTypes.h"
3636
#import "MSIDJsonSerializableFactory.h"
3737
#import "MSIDJsonSerializer.h"
38+
#import "NSDate+MSIDExtensions.h"
39+
#if !EXCLUDE_FROM_MSALCPP
40+
#import "MSIDLastRequestTelemetry.h"
41+
#endif
3842

3943
NSString *const MSID_BROKER_OPERATION_JSON_KEY = @"operation";
4044
NSString *const MSID_BROKER_OPERATION_RESULT_JSON_KEY = @"success";
4145
NSString *const MSID_BROKER_OPERATION_RESPONSE_TYPE_JSON_KEY = @"operation_response_type";
4246
NSString *const MSID_BROKER_APP_VERSION_JSON_KEY = @"client_app_version";
47+
NSString *const MSID_BROKER_RESPONSE_GENERATION_TIMESTAMP = @"response_gen_timestamp";
48+
NSString *const MSID_BROKER_REQUEST_RECEIVED_TIMESTAMP = @"request_received_timestamp";
4349

4450
@implementation MSIDBrokerNativeAppOperationResponse
4551

@@ -99,6 +105,8 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError **)er
99105
_success = [json[MSID_BROKER_OPERATION_RESULT_JSON_KEY] boolValue];
100106
_clientAppVersion = [json msidStringObjectForKey:MSID_BROKER_APP_VERSION_JSON_KEY];
101107
_deviceInfo = [[MSIDDeviceInfo alloc] initWithJSONDictionary:json error:error];
108+
_responseGenerationTimeStamp = [NSDate msidDateFromTimeStamp:json[MSID_BROKER_RESPONSE_GENERATION_TIMESTAMP]];
109+
_requestReceivedTimeStamp = [NSDate msidDateFromTimeStamp:json[MSID_BROKER_REQUEST_RECEIVED_TIMESTAMP]];
102110
}
103111

104112
return self;
@@ -117,12 +125,39 @@ - (NSDictionary *)jsonDictionary
117125
json[MSID_BROKER_OPERATION_RESULT_JSON_KEY] = [@(self.success) stringValue];
118126
json[MSID_BROKER_OPERATION_RESPONSE_TYPE_JSON_KEY] = self.class.responseType;
119127
json[MSID_BROKER_APP_VERSION_JSON_KEY] = self.clientAppVersion;
128+
json[MSID_BROKER_RESPONSE_GENERATION_TIMESTAMP] = [self.responseGenerationTimeStamp msidDateToFractionalTimestamp:10];
129+
json[MSID_BROKER_REQUEST_RECEIVED_TIMESTAMP] = [self.requestReceivedTimeStamp msidDateToFractionalTimestamp:10];
120130

121131
NSDictionary *deviceInfoJson = [self.deviceInfo jsonDictionary];
122132
if (deviceInfoJson) [json addEntriesFromDictionary:deviceInfoJson];
123133

124134
return json;
125135
}
126136

137+
#if !EXCLUDE_FROM_MSALCPP
138+
139+
- (void)trackPerfTelemetryWithLastRequest:(MSIDLastRequestTelemetry *)telemetry
140+
requestStartDate:(NSDate *)requestStartDate
141+
telemetryType:(NSString *)telemetryType
142+
{
143+
if (!requestStartDate)
144+
{
145+
MSID_LOG_WITH_CTX(MSIDLogLevelError, nil, @"trackPerfTelemetryWithLastRequest called with nil request start date");
146+
return;
147+
}
148+
149+
NSDate *responseDate = [NSDate date];
150+
NSTimeInterval totalTime = [responseDate timeIntervalSinceDate:requestStartDate];
151+
NSTimeInterval ipcRequestTime = self.requestReceivedTimeStamp ? [self.requestReceivedTimeStamp timeIntervalSinceDate:requestStartDate] : 0;
152+
NSTimeInterval ipcResponseTime = self.responseGenerationTimeStamp ? [responseDate timeIntervalSinceDate:self.responseGenerationTimeStamp] : 0;
153+
154+
[telemetry trackSSOExtensionPerformanceWithType:telemetryType
155+
totalPerfNumber:totalTime
156+
ipcRequestPerfNumber:ipcRequestTime
157+
ipcResponsePerfNumber:ipcResponseTime];
158+
}
159+
160+
#endif
161+
127162
@end
128163

IdentityCore/src/cache/crypto/MSIDAssymetricKeyKeychainGenerator.m

Lines changed: 54 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -134,46 +134,40 @@ - (MSIDAssymetricKeyPair *)readOrGenerateKeyPairForAttributes:(MSIDAssymetricKey
134134
- (MSIDAssymetricKeyPair *)readKeyPairForAttributes:(MSIDAssymetricKeyLookupAttributes *)attributes
135135
error:(NSError **)error
136136
{
137-
if (@available(iOS 10.0, macOS 10.12, *))
137+
138+
if ([NSString msidIsStringNilOrBlank:attributes.privateKeyIdentifier])
138139
{
139-
if ([NSString msidIsStringNilOrBlank:attributes.privateKeyIdentifier])
140-
{
141-
[self logAndFillError:@"Invalid key lookup attributes provided" status:kNoStatus error:error];
142-
return nil;
143-
}
144-
145-
NSDictionary *privateKeyDict = [self keyAttributesWithQueryDictionary:[attributes privateKeyAttributes] error:error];
146-
if (!privateKeyDict)
147-
{
148-
return nil;
149-
}
150-
151-
SecKeyRef privateKeyRef = (__bridge SecKeyRef)privateKeyDict[(__bridge id)kSecValueRef];
152-
if (!privateKeyRef)
153-
{
154-
[self logAndFillError:@"Failed to query private key reference from keychain." status:kNoStatus error:error];
155-
return nil;
156-
}
157-
158-
SecKeyRef publicKeyRef = SecKeyCopyPublicKey(privateKeyRef);
159-
if (!publicKeyRef)
160-
{
161-
[self logAndFillError:@"Failed to copy public key from private key." status:kNoStatus error:error];
162-
return nil;
163-
}
164-
165-
MSIDAssymetricKeyPair *keypair = [[MSIDAssymetricKeyPair alloc] initWithPrivateKey:privateKeyRef
166-
publicKey:publicKeyRef
167-
privateKeyDict:privateKeyDict];
168-
169-
CFRelease(publicKeyRef);
170-
return keypair;
140+
[self logAndFillError:@"Invalid key lookup attributes provided" status:kNoStatus error:error];
141+
return nil;
142+
}
143+
144+
NSDictionary *privateKeyDict = [self keyAttributesWithQueryDictionary:[attributes privateKeyAttributes] error:error];
145+
if (!privateKeyDict)
146+
{
147+
return nil;
171148
}
172-
else
149+
150+
SecKeyRef privateKeyRef = (__bridge SecKeyRef)privateKeyDict[(__bridge id)kSecValueRef];
151+
if (!privateKeyRef)
173152
{
174-
[self logAndFillError:@"Failed to generate asymmetric key pair due to unsupported iOS/OSX platform." status:kNoStatus error:error];
153+
[self logAndFillError:@"Failed to query private key reference from keychain." status:kNoStatus error:error];
175154
return nil;
176155
}
156+
157+
SecKeyRef publicKeyRef = SecKeyCopyPublicKey(privateKeyRef);
158+
if (!publicKeyRef)
159+
{
160+
[self logAndFillError:@"Failed to copy public key from private key." status:kNoStatus error:error];
161+
return nil;
162+
}
163+
164+
MSIDAssymetricKeyPair *keypair = [[MSIDAssymetricKeyPair alloc] initWithPrivateKey:privateKeyRef
165+
publicKey:publicKeyRef
166+
privateKeyDict:privateKeyDict];
167+
168+
CFRelease(publicKeyRef);
169+
return keypair;
170+
177171
}
178172

179173
#pragma mark - Cleanup
@@ -237,43 +231,36 @@ - (MSIDAssymetricKeyPair *)generateEphemeralKeyPair:(NSError **)error
237231
- (MSIDAssymetricKeyPair *)generateKeyPairForKeyDict:(NSDictionary *)attributes
238232
error:(NSError **)error
239233
{
240-
if (@available(iOS 10.0, macOS 10.12, *))
234+
CFErrorRef keyGenerationError = NULL;
235+
SecKeyRef privateKeyRef = SecKeyCreateRandomKey((__bridge CFDictionaryRef)attributes, &keyGenerationError);
236+
237+
if (!privateKeyRef)
241238
{
242-
CFErrorRef keyGenerationError = NULL;
243-
SecKeyRef privateKeyRef = SecKeyCreateRandomKey((__bridge CFDictionaryRef)attributes, &keyGenerationError);
244-
245-
if (!privateKeyRef)
246-
{
247-
NSError *keyError = CFBridgingRelease(keyGenerationError);
248-
[self logAndFillError:@"Failed to generate private key." status:(int)keyError.code error:error];
249-
return nil;
250-
}
251-
252-
SecKeyRef publicKeyRef = SecKeyCopyPublicKey(privateKeyRef);
253-
if (!publicKeyRef)
254-
{
255-
[self logAndFillError:@"Failed to copy public key from private key." status:kNoStatus error:error];
256-
CFRelease(privateKeyRef);
257-
return nil;
258-
}
259-
260-
/*
261-
Setting creationDate to nil here intentionally as it is only needed for cpp code.
262-
CreationDate will be initialized using lazy loading once it is queried for the first time on key pair object.
263-
*/
264-
265-
MSIDAssymetricKeyPair *keyPair = [[MSIDAssymetricKeyPair alloc] initWithPrivateKey:privateKeyRef publicKey:publicKeyRef privateKeyDict:attributes];
266-
267-
if (privateKeyRef) CFRelease(privateKeyRef);
268-
if (publicKeyRef) CFRelease(publicKeyRef);
269-
270-
return keyPair;
239+
NSError *keyError = CFBridgingRelease(keyGenerationError);
240+
[self logAndFillError:@"Failed to generate private key." status:(int)keyError.code error:error];
241+
return nil;
271242
}
272-
else
243+
244+
SecKeyRef publicKeyRef = SecKeyCopyPublicKey(privateKeyRef);
245+
if (!publicKeyRef)
273246
{
274-
[self logAndFillError:@"Failed to generate asymmetric key pair due to unsupported iOS/OSX platform." status:kNoStatus error:error];
247+
[self logAndFillError:@"Failed to copy public key from private key." status:kNoStatus error:error];
248+
CFRelease(privateKeyRef);
275249
return nil;
276250
}
251+
252+
/*
253+
Setting creationDate to nil here intentionally as it is only needed for cpp code.
254+
CreationDate will be initialized using lazy loading once it is queried for the first time on key pair object.
255+
*/
256+
257+
MSIDAssymetricKeyPair *keyPair = [[MSIDAssymetricKeyPair alloc] initWithPrivateKey:privateKeyRef publicKey:publicKeyRef privateKeyDict:attributes];
258+
259+
if (privateKeyRef) CFRelease(privateKeyRef);
260+
if (publicKeyRef) CFRelease(publicKeyRef);
261+
262+
return keyPair;
263+
277264
}
278265

279266
#pragma mark - Platform

IdentityCore/src/cache/crypto/MSIDAssymetricKeyPair.m

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,13 @@ - (NSData *)keyData
196196
if (!_keyData)
197197
{
198198
CFErrorRef keyExtractionError = NULL;
199-
if (@available(iOS 10.0, macOS 10.12, *))
200-
{
201-
_keyData = (NSData *)CFBridgingRelease(SecKeyCopyExternalRepresentation(self.publicKeyRef, &keyExtractionError));
202-
203-
if (!_keyData)
204-
{
205-
NSError *error = CFBridgingRelease(keyExtractionError);
206-
MSID_LOG_WITH_CTX(MSIDLogLevelError, nil, @"Failed to read data from key ref %@", error);
207-
return nil;
208-
}
209-
}
210-
else
199+
_keyData = (NSData *)CFBridgingRelease(SecKeyCopyExternalRepresentation(self.publicKeyRef, &keyExtractionError));
200+
201+
if (!_keyData)
211202
{
212-
MSID_LOG_WITH_CTX(MSIDLogLevelError, nil, @"Unable to extract key data from SecKeyRef due to unsupported platform");
203+
NSError *error = CFBridgingRelease(keyExtractionError);
204+
MSID_LOG_WITH_CTX(MSIDLogLevelError, nil, @"Failed to read data from key ref %@", error);
205+
return nil;
213206
}
214207
}
215208

@@ -226,14 +219,7 @@ - (nullable NSData *)decrypt:(nonnull NSString *)encryptedMessageString
226219
return nil;
227220
}
228221

229-
if (@available(iOS 10.0, macOS 10.12, *))
230-
{
231-
return [encryptedMessage msidDecryptedDataWithAlgorithm:kSecKeyAlgorithmRSAEncryptionOAEPSHA1 privateKey:self.privateKeyRef];
232-
}
233-
else
234-
{
235-
return nil;
236-
}
222+
return [encryptedMessage msidDecryptedDataWithAlgorithm:kSecKeyAlgorithmRSAEncryptionOAEPSHA1 privateKey:self.privateKeyRef];
237223
}
238224

239225
- (NSString *)signData:(NSString *)message

0 commit comments

Comments
 (0)