From e71773780c65b01cfccf1bb63e059c5ec574553f Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Thu, 12 Sep 2024 17:47:00 +0200 Subject: [PATCH 1/9] replaced OlmKit functions for content scanner with CryptoSDK functions --- MatrixSDK.xcodeproj/project.pbxproj | 6 +++ .../Data/MXContentScanEncryptedBody.h | 8 +-- .../Data/MXContentScanEncryptedBody.m | 11 ++-- MatrixSDK/ContentScan/MXScanManager.m | 17 +++++-- .../ContentScan/PKEncryptionHelper.swift | 50 +++++++++++++++++++ .../RoomEvent/MXRoomEventEncryption.swift | 3 +- .../CryptoMachine/MXCryptoMachine.swift | 3 +- .../Transactions/SAS/MXSASTransactionV2.swift | 2 + .../CryptoMachine/DecryptedEvent+Stub.swift | 1 + MatrixSDKTests/MXSelfSignedHomeserverTests.m | 2 +- Podfile | 4 +- Podfile.lock | 8 +-- 12 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 MatrixSDK/ContentScan/PKEncryptionHelper.swift diff --git a/MatrixSDK.xcodeproj/project.pbxproj b/MatrixSDK.xcodeproj/project.pbxproj index e24eca391a..734f247101 100644 --- a/MatrixSDK.xcodeproj/project.pbxproj +++ b/MatrixSDK.xcodeproj/project.pbxproj @@ -752,6 +752,8 @@ A780624F27B2CE74005780C0 /* FileManager+Backup.swift in Sources */ = {isa = PBXBuildFile; fileRef = A780624C27B2CE74005780C0 /* FileManager+Backup.swift */; }; A780625027B2CE74005780C0 /* FileManager+AppGroupContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A780624D27B2CE74005780C0 /* FileManager+AppGroupContainer.swift */; }; A780625127B2CE74005780C0 /* FileManager+AppGroupContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A780624D27B2CE74005780C0 /* FileManager+AppGroupContainer.swift */; }; + A7BB11982C933677002F7FA5 /* PKEncryptionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7BB11972C933677002F7FA5 /* PKEncryptionHelper.swift */; }; + A7BB11992C933677002F7FA5 /* PKEncryptionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7BB11972C933677002F7FA5 /* PKEncryptionHelper.swift */; }; A816247C25F60C7700A46F05 /* MXDeviceListOperationsPoolUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A816247B25F60C7700A46F05 /* MXDeviceListOperationsPoolUnitTests.swift */; }; A816248525F60D0300A46F05 /* MXDeviceListOperationsPoolUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A816247B25F60C7700A46F05 /* MXDeviceListOperationsPoolUnitTests.swift */; }; B105CD9D261E0B70006EB204 /* MXSpaceChildrenSummary.swift in Sources */ = {isa = PBXBuildFile; fileRef = B105CD9C261E0B70006EB204 /* MXSpaceChildrenSummary.swift */; }; @@ -2713,6 +2715,7 @@ A75CAD6B2A97970500F06072 /* MXWellKnownAuthentication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXWellKnownAuthentication.h; sourceTree = ""; }; A780624C27B2CE74005780C0 /* FileManager+Backup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FileManager+Backup.swift"; sourceTree = ""; }; A780624D27B2CE74005780C0 /* FileManager+AppGroupContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FileManager+AppGroupContainer.swift"; sourceTree = ""; }; + A7BB11972C933677002F7FA5 /* PKEncryptionHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKEncryptionHelper.swift; sourceTree = ""; }; A816247B25F60C7700A46F05 /* MXDeviceListOperationsPoolUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXDeviceListOperationsPoolUnitTests.swift; sourceTree = ""; }; B105CD9C261E0B70006EB204 /* MXSpaceChildrenSummary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSpaceChildrenSummary.swift; sourceTree = ""; }; B105CDD4261F54C8006EB204 /* MXSpaceChildContent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXSpaceChildContent.h; sourceTree = ""; }; @@ -3290,6 +3293,7 @@ 02CAD435217DD12F0074700B /* Data */, B146D50021A5C6D600D8C2C6 /* MXScanManager.h */, B146D50121A5C6D600D8C2C6 /* MXScanManager.m */, + A7BB11972C933677002F7FA5 /* PKEncryptionHelper.swift */, ); path = ContentScan; sourceTree = ""; @@ -7292,6 +7296,7 @@ EC8A53AF25B1BC77004E0802 /* MXCallAnswerEventContent.m in Sources */, B1432B51282AB29A00737CA6 /* MXBeaconInfoSummaryAllRoomListener.swift in Sources */, 32A30B191FB4813400C8309E /* MXIncomingRoomKeyRequestManager.m in Sources */, + A7BB11982C933677002F7FA5 /* PKEncryptionHelper.swift in Sources */, 323F3F9320D3F0C700D26D6A /* MXRoomEventFilter.m in Sources */, 3275FD9921A6B53300B9C13D /* MXLoginPolicyData.m in Sources */, EC1848C92686176D00865E16 /* MXiOSAudioOutputRouterDelegate.swift in Sources */, @@ -7964,6 +7969,7 @@ B14EF25C2397E90400758AF0 /* MXRoomTombStoneContent.m in Sources */, B1432B52282AB29A00737CA6 /* MXBeaconInfoSummaryAllRoomListener.swift in Sources */, B14EF25D2397E90400758AF0 /* MXImage.swift in Sources */, + A7BB11992C933677002F7FA5 /* PKEncryptionHelper.swift in Sources */, B14EF25E2397E90400758AF0 /* (null) in Sources */, 32B090E3261F709B002924AA /* MXAsyncTaskQueue.swift in Sources */, B14EF25F2397E90400758AF0 /* MXServerNoticeContent.m in Sources */, diff --git a/MatrixSDK/ContentScan/Data/MXContentScanEncryptedBody.h b/MatrixSDK/ContentScan/Data/MXContentScanEncryptedBody.h index fde999c287..e70ad201d4 100644 --- a/MatrixSDK/ContentScan/Data/MXContentScanEncryptedBody.h +++ b/MatrixSDK/ContentScan/Data/MXContentScanEncryptedBody.h @@ -16,7 +16,7 @@ #import "MXJSONModel.h" -@class OLMPkMessage; +@class PKMessageWrapper; /** `MXContentScanEncryptedBody` contains the encrypted body use to scan an encrypted content. @@ -39,11 +39,11 @@ @property (nonatomic) NSString *ephemeral; /** - Create a model instance from a OLMPkMessage instance. + Create a model instance from a PKMessageWrapper instance. - @param OLMPkMessage the encrypted message. + @param PKMessageWrapper the encrypted message. @return the newly created instance. */ -+ (id)modelFromOLMPkMessage:(OLMPkMessage *)OLMPkMessage; ++ (id)modelFromPKMessage:(PKMessageWrapper *)pkMessage; @end diff --git a/MatrixSDK/ContentScan/Data/MXContentScanEncryptedBody.m b/MatrixSDK/ContentScan/Data/MXContentScanEncryptedBody.m index 24815064ef..8160ecbe27 100644 --- a/MatrixSDK/ContentScan/Data/MXContentScanEncryptedBody.m +++ b/MatrixSDK/ContentScan/Data/MXContentScanEncryptedBody.m @@ -15,7 +15,8 @@ */ #import "MXContentScanEncryptedBody.h" -#import + +#import "MatrixSDKSwiftHeader.h" @implementation MXContentScanEncryptedBody @@ -31,14 +32,14 @@ + (id)modelFromJSON:(NSDictionary *)JSONDictionary return contentScanEncryptedBody; } -+ (id)modelFromOLMPkMessage:(OLMPkMessage *)OLMPkMessage ++ (id)modelFromPKMessage:(PKMessageWrapper *)pkMessage { MXContentScanEncryptedBody *contentScanEncryptedBody = [[MXContentScanEncryptedBody alloc] init]; if (contentScanEncryptedBody) { - contentScanEncryptedBody.ciphertext = OLMPkMessage.ciphertext; - contentScanEncryptedBody.mac = OLMPkMessage.mac; - contentScanEncryptedBody.ephemeral = OLMPkMessage.ephemeralKey; + contentScanEncryptedBody.ciphertext = pkMessage.ciphertext; + contentScanEncryptedBody.mac = pkMessage.mac; + contentScanEncryptedBody.ephemeral = pkMessage.ephemeralKey; } return contentScanEncryptedBody; } diff --git a/MatrixSDK/ContentScan/MXScanManager.m b/MatrixSDK/ContentScan/MXScanManager.m index 7f1dcdc70c..c37fb45381 100644 --- a/MatrixSDK/ContentScan/MXScanManager.m +++ b/MatrixSDK/ContentScan/MXScanManager.m @@ -15,7 +15,6 @@ */ #import "MXScanManager.h" -#import #import "MXMediaScanStore.h" #import "MXRealmMediaScanStore.h" @@ -29,6 +28,8 @@ #import "MXTools.h" #import "MXScanRealmFileProvider.h" +#import "MatrixSDKSwiftHeader.h" + #pragma mark - Defines & Constants NSString *const MXScanManagerEventScanDidChangeNotification = @"MXScanManagerEventScanDidChangeNotification"; @@ -331,11 +332,17 @@ - (void)encryptRequestBody:(nonnull NSDictionary *)requestBody completion:(void [self getAntivirusServerPublicKey:^(NSString * _Nullable publicKey) { if (publicKey.length) { - OLMPkEncryption *olmPkEncryption = [OLMPkEncryption new]; - [olmPkEncryption setRecipientKey:publicKey]; + NSString *message = [MXTools serialiseJSONObject:requestBody]; - OLMPkMessage *olmPkMessage = [olmPkEncryption encryptMessage:message error:nil]; - completion([MXContentScanEncryptedBody modelFromOLMPkMessage:olmPkMessage]); + PKMessageWrapper *pkMessage = [PKEncryptionHelper getPKMessage:message using:publicKey]; + if (pkMessage) + { + completion([MXContentScanEncryptedBody modelFromPKMessage:pkMessage]); + } + else + { + completion(nil); + } } else { diff --git a/MatrixSDK/ContentScan/PKEncryptionHelper.swift b/MatrixSDK/ContentScan/PKEncryptionHelper.swift new file mode 100644 index 0000000000..97704eac79 --- /dev/null +++ b/MatrixSDK/ContentScan/PKEncryptionHelper.swift @@ -0,0 +1,50 @@ +// +// Copyright 2024 The Matrix.org Foundation C.I.C +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation +import MatrixSDKCrypto + +@objc public class PKEncryptionHelper: NSObject { + @objc public static func getPKMessage(_ message: String, using publicKey: String) -> PKMessageWrapper? { + do { + let pkEncryption = try PkEncryption.fromBase64(key: publicKey) + return PKMessageWrapper(pkMessage: pkEncryption.encrypt(plaintext: message)) + } catch { + MXLog.error("[PKEncryptionHelper] failed to create pkEncryption", context: error) + return nil + } + } +} + +@objc public class PKMessageWrapper: NSObject { + private let pkMessage: PkMessage + + @objc public var ciphertext: String { + pkMessage.ciphertext + } + + @objc public var mac: String { + pkMessage.mac + } + + @objc public var ephemeralKey: String { + pkMessage.ephemeralKey + } + + fileprivate init(pkMessage: PkMessage) { + self.pkMessage = pkMessage + } +} diff --git a/MatrixSDK/Crypto/Algorithms/RoomEvent/MXRoomEventEncryption.swift b/MatrixSDK/Crypto/Algorithms/RoomEvent/MXRoomEventEncryption.swift index fe9fa93268..108fdc45a2 100644 --- a/MatrixSDK/Crypto/Algorithms/RoomEvent/MXRoomEventEncryption.swift +++ b/MatrixSDK/Crypto/Algorithms/RoomEvent/MXRoomEventEncryption.swift @@ -184,7 +184,8 @@ struct MXRoomEventEncryption: MXRoomEventEncrypting { rotationPeriodMsgs: UInt64(Self.keyRotationPeriodMsgs), // If not set, history visibility defaults to `joined` as the most restrictive setting historyVisibility: state.historyVisibility?.visibility ?? .joined, - onlyAllowTrustedDevices: onlyTrustedDevices(in: roomId) + onlyAllowTrustedDevices: onlyTrustedDevices(in: roomId), + errorOnVerifiedUserProblem: false ) } diff --git a/MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift b/MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift index effbd238bb..b2592c96d3 100644 --- a/MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift +++ b/MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift @@ -117,7 +117,8 @@ class MXCryptoMachine { } func invalidateCache() async { - await machine.clearCryptoCache() + // Not sure what is the new function for this +// await machine.clearCryptoCache() } // MARK: - Private diff --git a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransactionV2.swift b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransactionV2.swift index f1d42a68d9..bdcdcf9bff 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransactionV2.swift +++ b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransactionV2.swift @@ -172,6 +172,8 @@ extension MXSASTransactionV2: SasListener { humanReadable: cancelInfo.reason ) self.state = cancelInfo.cancelledByUs == true ? MXSASTransactionStateCancelledByMe : MXSASTransactionStateCancelled + case .created: + break } } } diff --git a/MatrixSDKTests/Crypto/CryptoMachine/DecryptedEvent+Stub.swift b/MatrixSDKTests/Crypto/CryptoMachine/DecryptedEvent+Stub.swift index 5c77c80896..81e476d9bf 100644 --- a/MatrixSDKTests/Crypto/CryptoMachine/DecryptedEvent+Stub.swift +++ b/MatrixSDKTests/Crypto/CryptoMachine/DecryptedEvent+Stub.swift @@ -28,6 +28,7 @@ extension DecryptedEvent { forwardingCurve25519Chain: [], shieldState: .init( color: .none, + code: nil, message: nil ) ) diff --git a/MatrixSDKTests/MXSelfSignedHomeserverTests.m b/MatrixSDKTests/MXSelfSignedHomeserverTests.m index 18efa1f801..b2689200e2 100644 --- a/MatrixSDKTests/MXSelfSignedHomeserverTests.m +++ b/MatrixSDKTests/MXSelfSignedHomeserverTests.m @@ -283,7 +283,7 @@ - (void)testMediaWithNotTrustedCertificate NSString *contentURL = event.content[@"url"]; XCTAssert(contentURL); - MXMediaManager *mediaManager = [[MXMediaManager alloc] initWithHomeServer:mxSession.matrixRestClient.homeserver]; + MXMediaManager *mediaManager = [[MXMediaManager alloc] initWithRestClient:mxSession.matrixRestClient]; XCTAssert(mediaManager); [mxSession close]; diff --git a/Podfile b/Podfile index c2b1b2bc06..a4bf99cc4e 100644 --- a/Podfile +++ b/Podfile @@ -1,3 +1,5 @@ +source 'https://cdn.cocoapods.org/' + # Uncomment this line to define a global platform for your project # Expose Objective-C frameworks to Swift @@ -16,7 +18,7 @@ abstract_target 'MatrixSDK' do pod 'Realm', '10.27.0' pod 'libbase58', '~> 0.1.4' - pod 'MatrixSDKCrypto', '0.4.2', :inhibit_warnings => true + pod 'MatrixSDKCrypto', '0.4.3', :inhibit_warnings => true target 'MatrixSDK-iOS' do platform :ios, '13.0' diff --git a/Podfile.lock b/Podfile.lock index 43b858befb..3041ea5cb6 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -16,7 +16,7 @@ PODS: - AFNetworking/NSURLSession - GZIP (1.3.2) - libbase58 (0.1.4) - - MatrixSDKCrypto (0.4.2) + - MatrixSDKCrypto (0.4.3) - OHHTTPStubs (9.1.0): - OHHTTPStubs/Default (= 9.1.0) - OHHTTPStubs/Core (9.1.0) @@ -44,7 +44,7 @@ DEPENDENCIES: - AFNetworking (~> 4.0.0) - GZIP (~> 1.3.0) - libbase58 (~> 0.1.4) - - MatrixSDKCrypto (= 0.4.2) + - MatrixSDKCrypto (= 0.4.3) - OHHTTPStubs (~> 9.1.0) - OLMKit (~> 3.2.5) - Realm (= 10.27.0) @@ -65,12 +65,12 @@ SPEC CHECKSUMS: AFNetworking: 3bd23d814e976cd148d7d44c3ab78017b744cd58 GZIP: 3c0abf794bfce8c7cb34ea05a1837752416c8868 libbase58: 7c040313537b8c44b6e2d15586af8e21f7354efd - MatrixSDKCrypto: 736069ee0a5ec12852ab3498bf2242acecc443fc + MatrixSDKCrypto: 27bee960e0e8b3a3039f3f3e93dd2ec88299c77e OHHTTPStubs: 90eac6d8f2c18317baeca36698523dc67c513831 OLMKit: da115f16582e47626616874e20f7bb92222c7a51 Realm: 9ca328bd7e700cc19703799785e37f77d1a130f2 SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82 -PODFILE CHECKSUM: 37ab0de0200808bcd3335a637e31736df60fc62e +PODFILE CHECKSUM: cb51affdced38356ae06d1eb0f8f4526e203e1cd COCOAPODS: 1.15.2 From c04c38edfcfddbd64f7bdeff8964f5fad213f81b Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Thu, 12 Sep 2024 18:02:37 +0200 Subject: [PATCH 2/9] update podspec --- MatrixSDK.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatrixSDK.podspec b/MatrixSDK.podspec index 3846cacff1..27bc69b3ed 100644 --- a/MatrixSDK.podspec +++ b/MatrixSDK.podspec @@ -45,7 +45,7 @@ Pod::Spec.new do |s| ss.dependency 'OLMKit', '~> 3.2.5' ss.dependency 'Realm', '10.27.0' ss.dependency 'libbase58', '~> 0.1.4' - ss.dependency 'MatrixSDKCrypto', '0.4.2', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true + ss.dependency 'MatrixSDKCrypto', '0.4.3', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true end s.subspec 'JingleCallStack' do |ss| From 278cf8b6ada8ea5cf64cc83605c4171539f87802 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Thu, 12 Sep 2024 20:15:57 +0200 Subject: [PATCH 3/9] simplified code --- MatrixSDK.xcodeproj/project.pbxproj | 12 +++++----- MatrixSDK/ContentScan/MXScanManager.m | 2 +- ...ionHelper.swift => PKMessageWrapper.swift} | 24 +++++++++---------- 3 files changed, 18 insertions(+), 20 deletions(-) rename MatrixSDK/ContentScan/{PKEncryptionHelper.swift => PKMessageWrapper.swift} (80%) diff --git a/MatrixSDK.xcodeproj/project.pbxproj b/MatrixSDK.xcodeproj/project.pbxproj index 734f247101..783a8dae9d 100644 --- a/MatrixSDK.xcodeproj/project.pbxproj +++ b/MatrixSDK.xcodeproj/project.pbxproj @@ -752,8 +752,8 @@ A780624F27B2CE74005780C0 /* FileManager+Backup.swift in Sources */ = {isa = PBXBuildFile; fileRef = A780624C27B2CE74005780C0 /* FileManager+Backup.swift */; }; A780625027B2CE74005780C0 /* FileManager+AppGroupContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A780624D27B2CE74005780C0 /* FileManager+AppGroupContainer.swift */; }; A780625127B2CE74005780C0 /* FileManager+AppGroupContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A780624D27B2CE74005780C0 /* FileManager+AppGroupContainer.swift */; }; - A7BB11982C933677002F7FA5 /* PKEncryptionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7BB11972C933677002F7FA5 /* PKEncryptionHelper.swift */; }; - A7BB11992C933677002F7FA5 /* PKEncryptionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7BB11972C933677002F7FA5 /* PKEncryptionHelper.swift */; }; + A7BB11982C933677002F7FA5 /* PKMessageWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7BB11972C933677002F7FA5 /* PKMessageWrapper.swift */; }; + A7BB11992C933677002F7FA5 /* PKMessageWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7BB11972C933677002F7FA5 /* PKMessageWrapper.swift */; }; A816247C25F60C7700A46F05 /* MXDeviceListOperationsPoolUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A816247B25F60C7700A46F05 /* MXDeviceListOperationsPoolUnitTests.swift */; }; A816248525F60D0300A46F05 /* MXDeviceListOperationsPoolUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A816247B25F60C7700A46F05 /* MXDeviceListOperationsPoolUnitTests.swift */; }; B105CD9D261E0B70006EB204 /* MXSpaceChildrenSummary.swift in Sources */ = {isa = PBXBuildFile; fileRef = B105CD9C261E0B70006EB204 /* MXSpaceChildrenSummary.swift */; }; @@ -2715,7 +2715,7 @@ A75CAD6B2A97970500F06072 /* MXWellKnownAuthentication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXWellKnownAuthentication.h; sourceTree = ""; }; A780624C27B2CE74005780C0 /* FileManager+Backup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FileManager+Backup.swift"; sourceTree = ""; }; A780624D27B2CE74005780C0 /* FileManager+AppGroupContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FileManager+AppGroupContainer.swift"; sourceTree = ""; }; - A7BB11972C933677002F7FA5 /* PKEncryptionHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKEncryptionHelper.swift; sourceTree = ""; }; + A7BB11972C933677002F7FA5 /* PKMessageWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKMessageWrapper.swift; sourceTree = ""; }; A816247B25F60C7700A46F05 /* MXDeviceListOperationsPoolUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXDeviceListOperationsPoolUnitTests.swift; sourceTree = ""; }; B105CD9C261E0B70006EB204 /* MXSpaceChildrenSummary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSpaceChildrenSummary.swift; sourceTree = ""; }; B105CDD4261F54C8006EB204 /* MXSpaceChildContent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXSpaceChildContent.h; sourceTree = ""; }; @@ -3293,7 +3293,7 @@ 02CAD435217DD12F0074700B /* Data */, B146D50021A5C6D600D8C2C6 /* MXScanManager.h */, B146D50121A5C6D600D8C2C6 /* MXScanManager.m */, - A7BB11972C933677002F7FA5 /* PKEncryptionHelper.swift */, + A7BB11972C933677002F7FA5 /* PKMessageWrapper.swift */, ); path = ContentScan; sourceTree = ""; @@ -7296,7 +7296,7 @@ EC8A53AF25B1BC77004E0802 /* MXCallAnswerEventContent.m in Sources */, B1432B51282AB29A00737CA6 /* MXBeaconInfoSummaryAllRoomListener.swift in Sources */, 32A30B191FB4813400C8309E /* MXIncomingRoomKeyRequestManager.m in Sources */, - A7BB11982C933677002F7FA5 /* PKEncryptionHelper.swift in Sources */, + A7BB11982C933677002F7FA5 /* PKMessageWrapper.swift in Sources */, 323F3F9320D3F0C700D26D6A /* MXRoomEventFilter.m in Sources */, 3275FD9921A6B53300B9C13D /* MXLoginPolicyData.m in Sources */, EC1848C92686176D00865E16 /* MXiOSAudioOutputRouterDelegate.swift in Sources */, @@ -7969,7 +7969,7 @@ B14EF25C2397E90400758AF0 /* MXRoomTombStoneContent.m in Sources */, B1432B52282AB29A00737CA6 /* MXBeaconInfoSummaryAllRoomListener.swift in Sources */, B14EF25D2397E90400758AF0 /* MXImage.swift in Sources */, - A7BB11992C933677002F7FA5 /* PKEncryptionHelper.swift in Sources */, + A7BB11992C933677002F7FA5 /* PKMessageWrapper.swift in Sources */, B14EF25E2397E90400758AF0 /* (null) in Sources */, 32B090E3261F709B002924AA /* MXAsyncTaskQueue.swift in Sources */, B14EF25F2397E90400758AF0 /* MXServerNoticeContent.m in Sources */, diff --git a/MatrixSDK/ContentScan/MXScanManager.m b/MatrixSDK/ContentScan/MXScanManager.m index c37fb45381..48ae47e780 100644 --- a/MatrixSDK/ContentScan/MXScanManager.m +++ b/MatrixSDK/ContentScan/MXScanManager.m @@ -334,7 +334,7 @@ - (void)encryptRequestBody:(nonnull NSDictionary *)requestBody completion:(void { NSString *message = [MXTools serialiseJSONObject:requestBody]; - PKMessageWrapper *pkMessage = [PKEncryptionHelper getPKMessage:message using:publicKey]; + PKMessageWrapper *pkMessage = [PKMessageWrapper encryptMessage:message usingKey:publicKey]; if (pkMessage) { completion([MXContentScanEncryptedBody modelFromPKMessage:pkMessage]); diff --git a/MatrixSDK/ContentScan/PKEncryptionHelper.swift b/MatrixSDK/ContentScan/PKMessageWrapper.swift similarity index 80% rename from MatrixSDK/ContentScan/PKEncryptionHelper.swift rename to MatrixSDK/ContentScan/PKMessageWrapper.swift index 97704eac79..05aa716b0f 100644 --- a/MatrixSDK/ContentScan/PKEncryptionHelper.swift +++ b/MatrixSDK/ContentScan/PKMessageWrapper.swift @@ -17,18 +17,6 @@ import Foundation import MatrixSDKCrypto -@objc public class PKEncryptionHelper: NSObject { - @objc public static func getPKMessage(_ message: String, using publicKey: String) -> PKMessageWrapper? { - do { - let pkEncryption = try PkEncryption.fromBase64(key: publicKey) - return PKMessageWrapper(pkMessage: pkEncryption.encrypt(plaintext: message)) - } catch { - MXLog.error("[PKEncryptionHelper] failed to create pkEncryption", context: error) - return nil - } - } -} - @objc public class PKMessageWrapper: NSObject { private let pkMessage: PkMessage @@ -43,8 +31,18 @@ import MatrixSDKCrypto @objc public var ephemeralKey: String { pkMessage.ephemeralKey } + + @objc public static func encryptMessage(_ message: String, usingKey key: String) -> PKMessageWrapper? { + do { + let pkEncryption = try PkEncryption.fromBase64(key: key) + return PKMessageWrapper(pkMessage: pkEncryption.encrypt(plaintext: message)) + } catch { + MXLog.error("[PKMessageWrapper] failed to create pkEncryption", context: error) + return nil + } + } - fileprivate init(pkMessage: PkMessage) { + private init(pkMessage: PkMessage) { self.pkMessage = pkMessage } } From d56aff1ae50dec578e8514feff848855f30660a8 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 13 Sep 2024 11:08:57 +0200 Subject: [PATCH 4/9] pr comments --- .github/workflows/ci-integration-tests.yml | 2 +- .github/workflows/ci-unit-tests.yml | 2 +- MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift | 5 ----- MatrixSDK/Crypto/MXCryptoV2.swift | 3 +-- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-integration-tests.yml b/.github/workflows/ci-integration-tests.yml index 590e2b3552..de719cb61d 100644 --- a/.github/workflows/ci-integration-tests.yml +++ b/.github/workflows/ci-integration-tests.yml @@ -80,7 +80,7 @@ jobs: with: name: report.junit path: build/test/report.junit - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: always() with: name: MatrixSDK-macOS.xcresult diff --git a/.github/workflows/ci-unit-tests.yml b/.github/workflows/ci-unit-tests.yml index 96e0c752f1..4dd14030fe 100644 --- a/.github/workflows/ci-unit-tests.yml +++ b/.github/workflows/ci-unit-tests.yml @@ -50,7 +50,7 @@ jobs: run: bundle exec fastlane test testplan:UnitTests # Store artifacts - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: report.html path: build/test/report.html diff --git a/MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift b/MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift index b2592c96d3..3b384051d0 100644 --- a/MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift +++ b/MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift @@ -116,11 +116,6 @@ class MXCryptoMachine { } } - func invalidateCache() async { - // Not sure what is the new function for this -// await machine.clearCryptoCache() - } - // MARK: - Private private static func createMachine(userId: String, deviceId: String, log: MXNamedLog) throws -> OlmMachine { diff --git a/MatrixSDK/Crypto/MXCryptoV2.swift b/MatrixSDK/Crypto/MXCryptoV2.swift index b7fdef4e9f..0619d0516d 100644 --- a/MatrixSDK/Crypto/MXCryptoV2.swift +++ b/MatrixSDK/Crypto/MXCryptoV2.swift @@ -724,8 +724,7 @@ class MXCryptoV2: NSObject, MXCrypto { func invalidateCache(_ done: @escaping () -> Void) { Task { - log.debug("Invalidating Olm Machine crypto store cache.") - await machine.invalidateCache() + // invalidating cache is not required for crypto v2 and is just here for conformance with the original crypto protocol await MainActor.run { done() } From 323027ed7a0fb5fa63f43b6525a3fd55149595bc Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 13 Sep 2024 11:11:47 +0200 Subject: [PATCH 5/9] workflow update --- .github/workflows/ci-integration-tests.yml | 4 ++-- .github/workflows/ci-unit-tests.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-integration-tests.yml b/.github/workflows/ci-integration-tests.yml index de719cb61d..cce33f1363 100644 --- a/.github/workflows/ci-integration-tests.yml +++ b/.github/workflows/ci-integration-tests.yml @@ -70,12 +70,12 @@ jobs: run: bundle exec fastlane test testplan:AllWorkingTests # Store artifacts - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: always() with: name: report.html path: build/test/report.html - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: always() with: name: report.junit diff --git a/.github/workflows/ci-unit-tests.yml b/.github/workflows/ci-unit-tests.yml index 4dd14030fe..7bdec19873 100644 --- a/.github/workflows/ci-unit-tests.yml +++ b/.github/workflows/ci-unit-tests.yml @@ -54,16 +54,16 @@ jobs: with: name: report.html path: build/test/report.html - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: report.junit path: build/test/report.junit - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: MatrixSDK-macOS.xcresult path: build/test/MatrixSDK-macOS.xcresult/ - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v2 with: token: ${{ secrets.CODECOV_TOKEN }} From aceec3d5a42da68f9170533f1457ab73fad0bc06 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 13 Sep 2024 11:33:52 +0200 Subject: [PATCH 6/9] update sas transaction --- .github/workflows/ci-unit-tests.yml | 2 +- .../Verification/Transactions/SAS/MXSASTransactionV2.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-unit-tests.yml b/.github/workflows/ci-unit-tests.yml index 7bdec19873..46ffea0046 100644 --- a/.github/workflows/ci-unit-tests.yml +++ b/.github/workflows/ci-unit-tests.yml @@ -64,6 +64,6 @@ jobs: path: build/test/MatrixSDK-macOS.xcresult/ - name: Upload coverage to Codecov - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransactionV2.swift b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransactionV2.swift index bdcdcf9bff..a196f87802 100644 --- a/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransactionV2.swift +++ b/MatrixSDK/Crypto/Verification/Transactions/SAS/MXSASTransactionV2.swift @@ -150,7 +150,7 @@ extension MXSASTransactionV2: SasListener { switch state { case .started: - self.state = isIncoming ? MXSASTransactionStateIncomingShowAccept : MXSASTransactionStateOutgoingWaitForPartnerToAccept + self.state = MXSASTransactionStateIncomingShowAccept case .accepted: self.state = MXSASTransactionStateWaitForPartnerKey case .keysExchanged(let emojis, let decimals): @@ -173,7 +173,7 @@ extension MXSASTransactionV2: SasListener { ) self.state = cancelInfo.cancelledByUs == true ? MXSASTransactionStateCancelledByMe : MXSASTransactionStateCancelled case .created: - break + self.state = MXSASTransactionStateOutgoingWaitForPartnerToAccept } } } From 1a3927f3663b598f9ed5c5bac4d2cf252e8a7767 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 13 Sep 2024 11:45:57 +0200 Subject: [PATCH 7/9] fixed a test --- .../Transactions/SAS/MXSASTransactionV2UnitTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MatrixSDKTests/Crypto/Verification/Transactions/SAS/MXSASTransactionV2UnitTests.swift b/MatrixSDKTests/Crypto/Verification/Transactions/SAS/MXSASTransactionV2UnitTests.swift index ad1ba7166f..a88bf42420 100644 --- a/MatrixSDKTests/Crypto/Verification/Transactions/SAS/MXSASTransactionV2UnitTests.swift +++ b/MatrixSDKTests/Crypto/Verification/Transactions/SAS/MXSASTransactionV2UnitTests.swift @@ -71,13 +71,13 @@ class MXSASTransactionV2UnitTests: XCTestCase { // MARK: - Test State - func test_startedState() { + func test_startedAndCreatedState() { let incoming = makeTransaction(isIncoming: true) incoming.onChange(state: .started) XCTAssertEqual(incoming.state, MXSASTransactionStateIncomingShowAccept) let outgoing = makeTransaction(isIncoming: false) - outgoing.onChange(state: .started) + outgoing.onChange(state: .created) XCTAssertEqual(outgoing.state, MXSASTransactionStateOutgoingWaitForPartnerToAccept) } From f4df1d5452583014884b1a3cbe53c1c82085440a Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Tue, 17 Sep 2024 13:47:46 +0200 Subject: [PATCH 8/9] 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 1121ef1302..ed2c9cb829 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## Changes in 0.27.14 (2024-09-17) + +No significant changes. + + ## Changes in 0.27.13 (2024-08-20) 🙌 Improvements diff --git a/MatrixSDK.podspec b/MatrixSDK.podspec index 27bc69b3ed..77d45aaa0a 100644 --- a/MatrixSDK.podspec +++ b/MatrixSDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "MatrixSDK" - s.version = "0.27.13" + s.version = "0.27.14" 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 c48d07bcaa..5ec5ca3e3b 100644 --- a/MatrixSDK/MatrixSDKVersion.m +++ b/MatrixSDK/MatrixSDKVersion.m @@ -16,4 +16,4 @@ #import -NSString *const MatrixSDKVersion = @"0.27.13"; +NSString *const MatrixSDKVersion = @"0.27.14"; From f149305d33415798b261b85deb77968551a26ddd Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Tue, 17 Sep 2024 14:20:51 +0200 Subject: [PATCH 9/9] finish version++