Skip to content

Commit ca76c18

Browse files
committed
replace OLM SHA256 with the native one
1 parent ac77e9a commit ca76c18

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

MatrixSDK/Crypto/CrossSigning/MXCrossSigningTools.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
#import "MXCrossSigningKey.h"
20-
2119
NS_ASSUME_NONNULL_BEGIN
2220

2321

MatrixSDK/Crypto/CrossSigning/MXCrossSigningTools.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
#import "MXCrossSigningTools.h"
1818

19-
#import "MXCryptoTools.h"
20-
#import "MXKey.h"
21-
#import "MXCryptoConstants.h"
22-
#import "MXBase64Tools.h"
23-
2419
#pragma mark - Constants
2520

2621
NSString *const MXCrossSigningToolsErrorDomain = @"org.matrix.sdk.crosssigning.tools";

MatrixSDK/IdentityServer/MXIdentityServerRestClient.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "MXIdentityServerRestClient.h"
1818

1919
#import <AFNetworking/AFNetworking.h>
20+
#import <CommonCrypto/CommonDigest.h>
2021

2122
#import "MXHTTPClient.h"
2223
#import "MXError.h"
@@ -385,6 +386,17 @@ - (MXHTTPOperation*)lookup3pids:(NSArray<NSArray<NSString*>*> *)threepids
385386
hashedTreePid = [NSString stringWithFormat:@"%@ %@", threepid, medium];
386387
break;
387388
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+
}
388400
break;
389401
default:
390402
break;
@@ -473,6 +485,20 @@ - (MXHTTPOperation*)lookup3pids:(NSArray<NSArray<NSString*>*> *)threepids
473485

474486
}
475487

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+
476502
#pragma mark Establishing associations
477503

478504
- (MXHTTPOperation*)requestEmailValidation:(NSString*)email

0 commit comments

Comments
 (0)