|
17 | 17 | #import "MXIdentityServerRestClient.h" |
18 | 18 |
|
19 | 19 | #import <AFNetworking/AFNetworking.h> |
| 20 | +#import <CommonCrypto/CommonDigest.h> |
20 | 21 |
|
21 | 22 | #import "MXHTTPClient.h" |
22 | 23 | #import "MXError.h" |
@@ -385,6 +386,17 @@ - (MXHTTPOperation*)lookup3pids:(NSArray<NSArray<NSString*>*> *)threepids |
385 | 386 | hashedTreePid = [NSString stringWithFormat:@"%@ %@", threepid, medium]; |
386 | 387 | break; |
387 | 388 | case MXIdentityServerHashAlgorithmSHA256: |
| 389 | + { |
| 390 | + NSString *threePidConcatenation = [NSString stringWithFormat:@"%@ %@ %@", threepid, medium, pepper]; |
| 391 | + |
| 392 | + // Hash the concatenated string using the helper method |
| 393 | + NSString *hashedSha256ThreePid = sha256(threePidConcatenation); |
| 394 | + |
| 395 | + // Convert hashed SHA-256 string to base64 URL |
| 396 | + hashedTreePid = [MXBase64Tools base64ToBase64Url:hashedSha256ThreePid]; |
| 397 | + |
| 398 | + threePidArrayByThreePidConcatHash[hashedTreePid] = threepidArray; |
| 399 | + } |
388 | 400 | break; |
389 | 401 | default: |
390 | 402 | break; |
@@ -473,6 +485,20 @@ - (MXHTTPOperation*)lookup3pids:(NSArray<NSArray<NSString*>*> *)threepids |
473 | 485 |
|
474 | 486 | } |
475 | 487 |
|
| 488 | +// Helper method to perform SHA256 hashing |
| 489 | +NSString *sha256(NSString *input) { |
| 490 | + const char *str = [input UTF8String]; |
| 491 | + unsigned char result[CC_SHA256_DIGEST_LENGTH]; |
| 492 | + CC_SHA256(str, (CC_LONG)strlen(str), result); |
| 493 | + |
| 494 | + NSMutableString *hash = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2]; |
| 495 | + for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) { |
| 496 | + [hash appendFormat:@"%02x", result[i]]; |
| 497 | + } |
| 498 | + |
| 499 | + return hash; |
| 500 | +} |
| 501 | + |
476 | 502 | #pragma mark Establishing associations |
477 | 503 |
|
478 | 504 | - (MXHTTPOperation*)requestEmailValidation:(NSString*)email |
|
0 commit comments