Skip to content

Commit 9db4c91

Browse files
authored
Merge pull request #1522 from AzureAD/ameyapat/generate-jwe-crypto-from-stk
Add method to generate jwe crypto from a given EC key
2 parents bd128ad + b86a2b7 commit 9db4c91

File tree

9 files changed

+606
-0
lines changed

9 files changed

+606
-0
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@
724724
6E4F659324D48B630070CA36 /* MSIDSymmetricKeyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E4F659024D48B120070CA36 /* MSIDSymmetricKeyTests.m */; };
725725
6E4F659424D48B6D0070CA36 /* MSIDSymmetricKeyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E4F659024D48B120070CA36 /* MSIDSymmetricKeyTests.m */; };
726726
720AC2A72550D4FB00B2C7C8 /* MSIDAppExtensionUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 720AC2A62550D4FB00B2C7C8 /* MSIDAppExtensionUtil.m */; };
727+
720B5B4E2DD573C300318FE5 /* MSIDJWECrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = 720B5B4D2DD573A400318FE5 /* MSIDJWECrypto.h */; };
728+
720B5B502DD577C700318FE5 /* MSIDJWECrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = 720B5B4F2DD577C100318FE5 /* MSIDJWECrypto.m */; };
729+
720B5B512DD577C700318FE5 /* MSIDJWECrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = 720B5B4F2DD577C100318FE5 /* MSIDJWECrypto.m */; };
730+
720B5B532DD57C5700318FE5 /* MSIDEcdhApv.h in Headers */ = {isa = PBXBuildFile; fileRef = 720B5B522DD57C3700318FE5 /* MSIDEcdhApv.h */; };
731+
720B5B552DD57D6800318FE5 /* MSIDEcdhApv.m in Sources */ = {isa = PBXBuildFile; fileRef = 720B5B542DD57D6600318FE5 /* MSIDEcdhApv.m */; };
732+
720B5B562DD57D6800318FE5 /* MSIDEcdhApv.m in Sources */ = {isa = PBXBuildFile; fileRef = 720B5B542DD57D6600318FE5 /* MSIDEcdhApv.m */; };
733+
720B5B582DD58A7F00318FE5 /* MSIDJWECryptoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 720B5B572DD58A6A00318FE5 /* MSIDJWECryptoTests.m */; };
734+
720B5B592DD58A7F00318FE5 /* MSIDJWECryptoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 720B5B572DD58A6A00318FE5 /* MSIDJWECryptoTests.m */; };
727735
72371CEB27051CC200EF5475 /* MSIDKeyOperationUtilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 72371CEA27051CC200EF5475 /* MSIDKeyOperationUtilTest.m */; };
728736
728209C326FA9C9A00B5F018 /* MSIDBackgroundTaskData.m in Sources */ = {isa = PBXBuildFile; fileRef = 728209C226FA9C9A00B5F018 /* MSIDBackgroundTaskData.m */; };
729737
728209C926FE94D800B5F018 /* MSIDJwtAlgorithm.m in Sources */ = {isa = PBXBuildFile; fileRef = 728209C826FE94D800B5F018 /* MSIDJwtAlgorithm.m */; };
@@ -2633,6 +2641,11 @@
26332641
6E4F658D24D4883A0070CA36 /* MSIDSymmetricKey.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDSymmetricKey.m; sourceTree = "<group>"; };
26342642
6E4F659024D48B120070CA36 /* MSIDSymmetricKeyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDSymmetricKeyTests.m; sourceTree = "<group>"; };
26352643
720AC2A62550D4FB00B2C7C8 /* MSIDAppExtensionUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDAppExtensionUtil.m; sourceTree = "<group>"; };
2644+
720B5B4D2DD573A400318FE5 /* MSIDJWECrypto.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDJWECrypto.h; sourceTree = "<group>"; };
2645+
720B5B4F2DD577C100318FE5 /* MSIDJWECrypto.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDJWECrypto.m; sourceTree = "<group>"; };
2646+
720B5B522DD57C3700318FE5 /* MSIDEcdhApv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDEcdhApv.h; sourceTree = "<group>"; };
2647+
720B5B542DD57D6600318FE5 /* MSIDEcdhApv.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDEcdhApv.m; sourceTree = "<group>"; };
2648+
720B5B572DD58A6A00318FE5 /* MSIDJWECryptoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDJWECryptoTests.m; sourceTree = "<group>"; };
26362649
72371CEA27051CC200EF5475 /* MSIDKeyOperationUtilTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDKeyOperationUtilTest.m; sourceTree = "<group>"; };
26372650
728209C126FA9C9A00B5F018 /* MSIDBackgroundTaskData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDBackgroundTaskData.h; sourceTree = "<group>"; };
26382651
728209C226FA9C9A00B5F018 /* MSIDBackgroundTaskData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBackgroundTaskData.m; sourceTree = "<group>"; };
@@ -5085,6 +5098,11 @@
50855098
B2AF1D29218BCDEF0080C1A0 /* requests */ = {
50865099
isa = PBXGroup;
50875100
children = (
5101+
5102+
720B5B542DD57D6600318FE5 /* MSIDEcdhApv.m */,
5103+
720B5B522DD57C3700318FE5 /* MSIDEcdhApv.h */,
5104+
720B5B4F2DD577C100318FE5 /* MSIDJWECrypto.m */,
5105+
720B5B4D2DD573A400318FE5 /* MSIDJWECrypto.h */,
50885106
729357E92DD810CD0001D03C /* MSIDNonceTokenRequest.m */,
50895107
729357E72DD810C70001D03C /* MSIDNonceTokenRequest.h */,
50905108
B2C708A0219A55CB00D917B8 /* sdk */,
@@ -5693,6 +5711,7 @@
56935711
D6DA89731FBA6A4E004C56C7 /* tests */ = {
56945712
isa = PBXGroup;
56955713
children = (
5714+
720B5B572DD58A6A00318FE5 /* MSIDJWECryptoTests.m */,
56965715
729357F22DDBD3F60001D03C /* MSIDNonceTokenRequestTest.m */,
56975716
A0410E4F25E88B5E004D80FD /* MSIDThrottlingMetaDataTest.m */,
56985717
A0410E1925E87E1A004D80FD /* MSIDThrottlingModelNonRecoverableServerError.m */,
@@ -6087,6 +6106,7 @@
60876106
583BFCA724D87BA40035B901 /* MSIDRedirectUri.h in Headers */,
60886107
B223B0A022ADD87A00FB8713 /* MSIDExtendedCacheItemSerializing.h in Headers */,
60896108
B286B9932389DC64007833AD /* MSIDBrokerResponseHandler+Internal.h in Headers */,
6109+
720B5B4E2DD573C300318FE5 /* MSIDJWECrypto.h in Headers */,
60906110
D6D9A4531FBD3FB800EFA430 /* NSURL+MSIDExtensions.h in Headers */,
60916111
8878C63029DCA0E8002F5F4B /* MSIDCIAMTokenResponse.h in Headers */,
60926112
233E96E22265279B007FCE2A /* MSIDTelemetryDefaultEvent.h in Headers */,
@@ -6351,6 +6371,7 @@
63516371
B286B9AD2389DD5A007833AD /* MSIDChallengeHandler.h in Headers */,
63526372
238E19CB2086FC87004DF483 /* MSIDUrlRequestSerializer.h in Headers */,
63536373
233E96F322652C5B007FCE2A /* MSIDTelemetryEventsObserving.h in Headers */,
6374+
720B5B532DD57C5700318FE5 /* MSIDEcdhApv.h in Headers */,
63546375
237F8F2F2D5166FE0095F164 /* MSIDFlightManager.h in Headers */,
63556376
96F21B1A20A65187002B87C3 /* MSIDWebviewInteracting.h in Headers */,
63566377
2A59B42D2D776F3400304FB1 /* MSIDXpcConfiguration.h in Headers */,
@@ -7159,6 +7180,7 @@
71597180
B20E3CB21FC4FA550029C097 /* MSIDVersion.m in Sources */,
71607181
236AAFCA2A61EE6C00AD6C6E /* MSIDBrowserNativeMessageGetCookiesRequestTests.m in Sources */,
71617182
B287C4CE26A132FA004303F1 /* MSIDSSOExtensionRequestDelegateTests.m in Sources */,
7183+
720B5B582DD58A7F00318FE5 /* MSIDJWECryptoTests.m in Sources */,
71627184
B29A36BB20AFAB0200427B63 /* MSIDDefaultAccessorSSOIntegrationTests.m in Sources */,
71637185
B2DD4B3820A922170047A66E /* MSIDDefaultAccountCacheQueryTests.m in Sources */,
71647186
B2936F4A20AA8E1F0050C585 /* MSIDCacheItemJsonSerializerTests.m in Sources */,
@@ -7438,6 +7460,7 @@
74387460
B26CEB042367B3B9009E6E54 /* MSIDSystemWebViewControllerFactory.m in Sources */,
74397461
609E74BE228CA5CA005E3FED /* MSIDAccountMetadataCacheAccessor.m in Sources */,
74407462
B48FC0312D726A66007B80DB /* MSIDBrokerFlightProvider.m in Sources */,
7463+
720B5B512DD577C700318FE5 /* MSIDJWECrypto.m in Sources */,
74417464
23B018C42356D51200207FEC /* NSDictionary+MSIDQueryItems.m in Sources */,
74427465
2394F2042D4894FF00E44F6E /* MSIDWebUpgradeRegOperation.m in Sources */,
74437466
B2C708AE219A612A00D917B8 /* MSIDDefaultBrokerTokenRequest.m in Sources */,
@@ -7526,6 +7549,7 @@
75267549
B26CEADF2365311E009E6E54 /* MSIDMacLegacyCachePersistenceHandler.m in Sources */,
75277550
A0C7DEC425D4C8B600F5B5B6 /* MSIDThrottlingModel429.m in Sources */,
75287551
23B39AC8209BF9F2000AA905 /* MSIDOpenIdConfigurationInfoRequest.m in Sources */,
7552+
720B5B552DD57D6800318FE5 /* MSIDEcdhApv.m in Sources */,
75297553
589BDB1B2718BC2200BF3799 /* MSIDBrokerOperationGetSsoCookiesRequest.m in Sources */,
75307554
23D7447A2097B2DA00210C51 /* MSIDAADV1AuthorizationCodeRequest.m in Sources */,
75317555
B21786A223A710A000839CE8 /* MSIDSSOExtensionGetAccountsRequest.m in Sources */,
@@ -7622,6 +7646,7 @@
76227646
B21B4082297786A3002607C8 /* MSIDBrokerOperationBrowserTokenRequestTests.m in Sources */,
76237647
B252913C2096698100E78695 /* MSIDAADIdTokenClaimsFactoryTests.m in Sources */,
76247648
B2DD5B98204756580084313F /* MSIDAccountTypeTests.m in Sources */,
7649+
720B5B592DD58A7F00318FE5 /* MSIDJWECryptoTests.m in Sources */,
76257650
B41163B729BAC20000E64619 /* MSIDAADOAuthEmbeddedWebviewControllerTests.m in Sources */,
76267651
B431B5242AF040450020CD3D /* MSIDBrokerOperationPasskeyAssertionRequestTests.m in Sources */,
76277652
23419F5E23973AAD00EA78C5 /* MSIDBrokerOperationRequestTests.m in Sources */,
@@ -7927,6 +7952,7 @@
79277952
2308476C207D6D500024CE7C /* NSData+MSIDExtensions.m in Sources */,
79287953
A0C7DE8425D46D7000F5B5B6 /* MSIDThrottlingModelFactory.m in Sources */,
79297954
B229841829AA8C2F0005F83D /* MSIDWebViewPlatformParams.m in Sources */,
7955+
720B5B562DD57D6800318FE5 /* MSIDEcdhApv.m in Sources */,
79307956
B2BE924721A2279A00F5AB8C /* MSIDTelemetryBrokerEvent.m in Sources */,
79317957
9641B52A1FCF3F3A00AFA0EC /* MSIDKeyedArchiverSerializer.m in Sources */,
79327958
B2E2A934239239F800BA2EA3 /* MSIDSSOExtensionOperationRequestDelegate.m in Sources */,
@@ -8099,6 +8125,7 @@
80998125
A0E540BD25CB62270016E167 /* MSIDThrottlingService.m in Sources */,
81008126
23AE9DB82148529A00B285F3 /* NSError+MSIDExtensions.m in Sources */,
81018127
23AD4A33237E298C0094B87E /* NSBundle+MSIDExtensions.m in Sources */,
8128+
720B5B502DD577C700318FE5 /* MSIDJWECrypto.m in Sources */,
81028129
23AE9DA4213A159C00B285F3 /* MSIDAADOpenIdConfigurationInfoResponseSerializer.m in Sources */,
81038130
B2C708222195285300D917B8 /* MSIDLegacyBrokerTokenRequest.m in Sources */,
81048131
B2C07487246B711B0008D701 /* MSIDAssymetricKeyLookupAttributes.m in Sources */,

IdentityCore/src/MSIDJwtAlgorithm.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,21 @@
2222
// THE SOFTWARE.
2323

2424
typedef NSString *const MSIDJwtAlgorithm NS_TYPED_ENUM;
25+
typedef NSString *const MSIDJwtParameterName NS_TYPED_ENUM;
26+
27+
// JWT key constants
28+
extern MSIDJwtParameterName const MSID_JWT_ALG; // Signing algorithm
29+
extern MSIDJwtParameterName const MSID_JWT_ENC; // Encryption algorithm
30+
extern MSIDJwtParameterName const MSID_JWT_APV; // This party's public key for key exchange.
31+
2532
// Asymmetric signature Algorithms values as defined in https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-algorithms-36#section-3.1
2633

2734
extern MSIDJwtAlgorithm const MSID_JWT_ALG_RS256; // RSASSA-PKCS-v1_5 using SHA-256
2835
extern MSIDJwtAlgorithm const MSID_JWT_ALG_ES256; // ECDSA using P-256 and SHA-256
36+
37+
38+
// Encryption Algorithms
39+
extern MSIDJwtAlgorithm const MSID_JWT_ALG_A256GCM; // AES GCM using 256-bit key
40+
41+
// Key exchange Algorithms
42+
extern MSIDJwtAlgorithm const MSID_JWT_ALG_ECDH; // Key Agreement with Elliptic Curve Diffie-Hellman

IdentityCore/src/MSIDJwtAlgorithm.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@
2525

2626
MSIDJwtAlgorithm MSID_JWT_ALG_RS256 = @"RS256";
2727
MSIDJwtAlgorithm MSID_JWT_ALG_ES256 = @"ES256";
28+
MSIDJwtAlgorithm MSID_JWT_ALG_A256GCM = @"A256GCM";
29+
MSIDJwtAlgorithm MSID_JWT_ALG_ECDH = @"ECDH-ES";
30+
31+
MSIDJwtParameterName MSID_JWT_ALG = @"alg";
32+
MSIDJwtParameterName MSID_JWT_ENC = @"enc";
33+
MSIDJwtParameterName MSID_JWT_APV = @"apv";
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
NS_ASSUME_NONNULL_BEGIN
26+
/// The PartyVInfo for ECDH key agreement (APV)
27+
/// Format for APV: <Prefix length> | <Prefix> | <Public key length> | <Public key> | <Nonce length> | <Nonce>
28+
@interface MSIDEcdhApv : NSObject
29+
30+
- (instancetype)init NS_UNAVAILABLE;
31+
+ (instancetype)new NS_UNAVAILABLE;
32+
33+
@property (nonatomic, readonly) NSString *APV;
34+
@property (nonatomic, readonly) NSData *nonce;
35+
@property (nonatomic, readonly) NSString *apvPrefix;
36+
@property (nonatomic, readonly) SecKeyRef publicKey;
37+
38+
// Format for APV: <Prefix length> | <Prefix> | <Public key length> | <Public key> | <Nonce length> | <Nonce>
39+
- (nullable instancetype)initWithKey:(SecKeyRef)publicKey
40+
apvPrefix:(NSString *)prefix
41+
context:(id<MSIDRequestContext> _Nullable)context
42+
error:(NSError * _Nullable __autoreleasing *)error;
43+
44+
@end
45+
NS_ASSUME_NONNULL_END
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
#import "MSIDEcdhApv.h"
26+
#import "NSData+MSIDExtensions.h"
27+
28+
@implementation MSIDEcdhApv
29+
30+
const NSUInteger kExpectedECP256KeyLength = 65;
31+
32+
- (instancetype)initWithKey:(SecKeyRef)publicKey
33+
apvPrefix:(NSString *)apvPrefix
34+
context:(id<MSIDRequestContext> _Nullable)context
35+
error:(NSError * _Nullable __autoreleasing *)error
36+
{
37+
if (publicKey == NULL)
38+
{
39+
if (error) *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInternal, @"Public STK provided is not defined.", nil, nil, nil, context.correlationId, nil, NO);
40+
return nil;
41+
}
42+
43+
if ([NSString msidIsStringNilOrBlank:apvPrefix])
44+
{
45+
if (error) *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInternal, @"APV prefix is not defined. A prefix must be provided to determine calling application type.", nil, nil, nil, context.correlationId, nil, NO);
46+
return nil;
47+
}
48+
49+
CFErrorRef errorRef = NULL;
50+
CFDictionaryRef attributes = SecKeyCopyAttributes(publicKey);
51+
CFStringRef keyType = CFDictionaryGetValue(attributes, kSecAttrKeyType);
52+
CFStringRef keyClass = CFDictionaryGetValue(attributes, kSecAttrKeyClass);
53+
54+
BOOL isECPrivateKey = (keyType == kSecAttrKeyTypeECSECPrimeRandom) && (keyClass == kSecAttrKeyClassPrivate);
55+
56+
if (attributes) CFRelease(attributes);
57+
NSData *stkData = CFBridgingRelease(SecKeyCopyExternalRepresentation(publicKey, NULL));
58+
if (isECPrivateKey || !stkData)
59+
{
60+
if (error) *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInternal, @"Supplied key should be a public EC key. Could not export EC key data.", nil, nil, CFBridgingRelease(errorRef), context.correlationId, nil, NO);
61+
return nil;
62+
}
63+
64+
if (stkData.length != kExpectedECP256KeyLength)
65+
{
66+
if (error) *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInternal, @"Supplied key is not a EC P-256 key.", nil, nil, nil, context.correlationId, nil, NO);
67+
return nil;
68+
}
69+
70+
NSMutableData *data = [NSMutableData new];
71+
72+
int prefixLen = (int)apvPrefix.length;
73+
NSData *prefixLenData = [NSData dataWithBytes:&prefixLen length:sizeof(prefixLen)];
74+
[data appendData:prefixLenData];
75+
[data appendData:[apvPrefix dataUsingEncoding:NSUTF8StringEncoding]];
76+
77+
int stkLen = (int)stkData.length;
78+
NSData *stkLenData = [NSData dataWithBytes:&stkLen length:sizeof(stkLen)];
79+
[data appendData:stkLenData];
80+
[data appendData:stkData];
81+
82+
NSData *nonceData = [[NSUUID UUID].UUIDString dataUsingEncoding:NSASCIIStringEncoding];
83+
int nonceLen = (int)nonceData.length;
84+
NSData *nonceLenData = [NSData dataWithBytes:&nonceLen length:sizeof(nonceLen)];
85+
[data appendData:nonceLenData];
86+
[data appendData:nonceData];
87+
88+
NSString *apvString = [data msidBase64UrlEncodedString];
89+
self = [super init];
90+
if (self)
91+
{
92+
_publicKey = publicKey;
93+
_apvPrefix = apvPrefix;
94+
_nonce = nonceData;
95+
_APV = apvString;
96+
}
97+
return self;
98+
}
99+
100+
@end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
@class MSIDEcdhApv;
26+
NS_ASSUME_NONNULL_BEGIN
27+
@interface MSIDJWECrypto : NSObject
28+
29+
/// JWE response encryption algorithm
30+
@property (nonatomic, readonly) NSString *encryptionAlgorithm;
31+
/// Key exchange algorithm
32+
@property (nonatomic, readonly) NSString *keyExchangeAlgorithm;
33+
/// APV . Contains this party's public key for key exchange.
34+
@property (nonatomic, readonly) MSIDEcdhApv *apv;
35+
36+
- (instancetype)init NS_UNAVAILABLE;
37+
+ (instancetype)new NS_UNAVAILABLE;
38+
- (nullable instancetype)initWithKeyExchangeAlg:(NSString *)keyExchangeAlgorithm
39+
encryptionAlgorithm:(NSString *)encryptionAlgorithm
40+
apv:(MSIDEcdhApv *)apv
41+
context:(_Nullable id<MSIDRequestContext>)context
42+
error:(NSError * _Nullable __autoreleasing *)error;
43+
44+
- (NSString *)urlEncodedJweCrypto;
45+
- (NSDictionary *)jweCryptoDictionary;
46+
@end
47+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)