From 4c72ef2a18b52502cca85d6fe53b67b82c7fce2a Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Wed, 23 Oct 2024 12:07:36 +0200 Subject: [PATCH 1/7] restored function --- .../Crypto/SecretStorage/MXSecretStorage.m | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m b/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m index 1f4bfcca6..3ffb6c6de 100644 --- a/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m +++ b/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m @@ -18,6 +18,7 @@ #import "MXSession.h" #import "MXTools.h" +#import "MXKeyBackupPassword.h" #import "MXRecoveryKey.h" #import "MXHkdfSha256.h" #import "MXAesHmacSha2.h" @@ -126,6 +127,104 @@ - (MXHTTPOperation*)createKeyWithKeyId:(nullable NSString*)keyId return operation; } +- (MXHTTPOperation*)createKeyWithKeyId:(nullable NSString*)keyId + keyName:(nullable NSString*)keyName + passphrase:(nullable NSString*)passphrase + success:(void (^)(MXSecretStorageKeyCreationInfo *keyCreationInfo))success + failure:(void (^)(NSError *error))failure +{ + MXLogDebug(@"[MXSecretStorage] createKeyWithKeyId: Creating new key with passphrase"); + keyId = keyId ?: [[NSUUID UUID] UUIDString]; + + MXHTTPOperation *operation = [MXHTTPOperation new]; + + MXWeakify(self); + dispatch_async(processingQueue, ^{ + MXStrongifyAndReturnIfNil(self); + + NSError *error; + + NSData *privateKey; + MXSecretStoragePassphrase *passphraseInfo; + + if (passphrase) + { + // Generate a private key from the passphrase + NSString *salt; + NSUInteger iterations; + privateKey = [MXKeyBackupPassword generatePrivateKeyWithPassword:passphrase + salt:&salt + iterations:&iterations + error:&error]; + if (!error) + { + passphraseInfo = [MXSecretStoragePassphrase new]; + passphraseInfo.algorithm = @"m.pbkdf2"; + passphraseInfo.salt = salt; + passphraseInfo.iterations = iterations; + } + } + else + { + OLMPkDecryption *decryption = [OLMPkDecryption new]; + [decryption generateKey:&error]; + privateKey = decryption.privateKey; + } + + if (error) + { + dispatch_async(dispatch_get_main_queue(), ^{ + MXLogDebug(@"[MXSecretStorage] createKeyWithKeyId: Failed to create a new key - %@", error); + failure(error); + }); + return; + } + + // Build iv and mac + MXEncryptedSecretContent *encryptedZeroString = [self encryptedZeroStringWithPrivateKey:privateKey iv:nil error:&error]; + if (error) + { + dispatch_async(dispatch_get_main_queue(), ^{ + MXLogDebug(@"[MXSecretStorage] createKeyWithKeyId: Failed to create a new key - %@", error); + failure(error); + }); + return; + } + + MXSecretStorageKeyContent *ssssKeyContent = [MXSecretStorageKeyContent new]; + ssssKeyContent.name = keyName; + ssssKeyContent.algorithm = MXSecretStorageKeyAlgorithm.aesHmacSha2; + ssssKeyContent.passphrase = passphraseInfo; + ssssKeyContent.iv = encryptedZeroString.iv; + ssssKeyContent.mac = encryptedZeroString.mac; + + NSString *accountDataId = [self storageKeyIdForKey:keyId]; + MXHTTPOperation *operation2 = [self setAccountData:ssssKeyContent.JSONDictionary forType:accountDataId success:^{ + + MXSecretStorageKeyCreationInfo *keyCreationInfo = [MXSecretStorageKeyCreationInfo new]; + keyCreationInfo.keyId = keyId; + keyCreationInfo.content = ssssKeyContent; + keyCreationInfo.privateKey = privateKey; + keyCreationInfo.recoveryKey = [MXRecoveryKey encode:privateKey]; + + dispatch_async(dispatch_get_main_queue(), ^{ + MXLogDebug(@"[MXSecretStorage] createKeyWithKeyId: Successfully created a new key"); + success(keyCreationInfo); + }); + + } failure:^(NSError *error) { + dispatch_async(dispatch_get_main_queue(), ^{ + MXLogDebug(@"[MXSecretStorage] createKeyWithKeyId: Failed to create a new key - %@", error); + failure(error); + }); + }]; + + [operation mutateTo:operation2]; + }); + + return operation; +} + - (MXHTTPOperation*)deleteKeyWithKeyId:(nullable NSString*)keyId success:(void (^)(void))success failure:(void (^)(NSError *error))failure From 34c66a0615173fb2d0252f8b9dc5d2650a58a847 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Tue, 12 Nov 2024 12:27:41 +0100 Subject: [PATCH 2/7] Prepare for new sprint From a826fd1831c3f519301a8fe13512ccdf8ca22835 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Thu, 14 Nov 2024 17:40:51 +0100 Subject: [PATCH 3/7] possible way to generate randomBytes --- MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m b/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m index 3ffb6c6de..014c15215 100644 --- a/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m +++ b/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m @@ -25,6 +25,7 @@ #import "MXBase64Tools.h" #import "MXEncryptedSecretContent.h" +#import #pragma mark - Constants @@ -166,9 +167,14 @@ - (MXHTTPOperation*)createKeyWithKeyId:(nullable NSString*)keyId } else { - OLMPkDecryption *decryption = [OLMPkDecryption new]; - [decryption generateKey:&error]; - privateKey = decryption.privateKey; + uint8_t randomBytes[32]; + OSStatus status = SecRandomCopyBytes(kSecRandomDefault, sizeof(randomBytes), randomBytes); + + if (status == errSecSuccess) { + privateKey = [NSData dataWithBytes:randomBytes length:sizeof(randomBytes)]; + } else { + MXLogDebug(@"Failed to generate random bytes with error: %d", (int)status); + } } if (error) From 4dfef2254e4ca26e3859750e3dcedc591416134f Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Thu, 14 Nov 2024 17:53:42 +0100 Subject: [PATCH 4/7] objc indentation --- MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m b/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m index 014c15215..69b2124d0 100644 --- a/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m +++ b/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m @@ -169,10 +169,13 @@ - (MXHTTPOperation*)createKeyWithKeyId:(nullable NSString*)keyId { uint8_t randomBytes[32]; OSStatus status = SecRandomCopyBytes(kSecRandomDefault, sizeof(randomBytes), randomBytes); - - if (status == errSecSuccess) { + + if (status == errSecSuccess) + { privateKey = [NSData dataWithBytes:randomBytes length:sizeof(randomBytes)]; - } else { + } + else + { MXLogDebug(@"Failed to generate random bytes with error: %d", (int)status); } } From cfd20629fa805e9684eae2a4679563517e362819 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:16:37 +0000 Subject: [PATCH 5/7] Use the stable endpoint when reporting rooms. (#1891) * Use the stable endpoint when reporting rooms. * Bump webrick --- Gemfile.lock | 2 +- MatrixSDK/MXRestClient.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d531aee81..d3dc824f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -275,7 +275,7 @@ GEM concurrent-ruby (~> 1.0) uber (0.1.0) unicode-display_width (2.5.0) - webrick (1.8.1) + webrick (1.9.0) word_wrap (1.0.0) xcode-install (2.8.1) claide (>= 0.9.1) diff --git a/MatrixSDK/MXRestClient.m b/MatrixSDK/MXRestClient.m index 2691d211f..c92cc7ce5 100644 --- a/MatrixSDK/MXRestClient.m +++ b/MatrixSDK/MXRestClient.m @@ -3103,7 +3103,7 @@ -(MXHTTPOperation *)reportRoom:(NSString *)roomId success:(void (^)(void))success failure:(void (^)(NSError *))failure { - NSString *path = [NSString stringWithFormat:@"%@/org.matrix.msc4151/rooms/%@/report", kMXAPIPrefixPathUnstable, roomId]; + NSString *path = [NSString stringWithFormat:@"%@/rooms/%@/report", kMXAPIPrefixPathV3, roomId]; NSDictionary *parameters = @{ @"reason": reason.length > 0 ? reason : @"" }; From beb27a32b1eabd0e91975f4567146853854fc2ed Mon Sep 17 00:00:00 2001 From: Doug Date: Tue, 10 Dec 2024 09:24:35 +0000 Subject: [PATCH 6/7] version++ --- CHANGES.md | 5 +++++ MatrixSDK.podspec | 2 +- MatrixSDK/MatrixSDKVersion.m | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index fdd2b1aa9..245d7e613 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## Changes in 0.27.17 (2024-12-10) + +No significant changes. + + ## Changes in 0.27.16 (2024-11-12) No significant changes. diff --git a/MatrixSDK.podspec b/MatrixSDK.podspec index 387453304..7fb8fb0e0 100644 --- a/MatrixSDK.podspec +++ b/MatrixSDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "MatrixSDK" - s.version = "0.27.16" + s.version = "0.27.17" s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)" s.description = <<-DESC diff --git a/MatrixSDK/MatrixSDKVersion.m b/MatrixSDK/MatrixSDKVersion.m index 808f922bb..dfaa60ec5 100644 --- a/MatrixSDK/MatrixSDKVersion.m +++ b/MatrixSDK/MatrixSDKVersion.m @@ -16,4 +16,4 @@ #import -NSString *const MatrixSDKVersion = @"0.27.16"; +NSString *const MatrixSDKVersion = @"0.27.17"; From de3f7a8be0dae6a5ed06588c6bbad8d5ba25ce7e Mon Sep 17 00:00:00 2001 From: Doug Date: Tue, 10 Dec 2024 10:06:18 +0000 Subject: [PATCH 7/7] finish version++ --- Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile.lock b/Podfile.lock index 86011bb53..187e72292 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -65,4 +65,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: a2fe7b4dcd95b04f52989dc47cded48c782c02a4 -COCOAPODS: 1.15.2 +COCOAPODS: 1.14.3