From e4ef22044e5d64ea64df72795355241f90a59492 Mon Sep 17 00:00:00 2001 From: Andy Uhnak Date: Wed, 14 Dec 2022 16:14:32 +0000 Subject: [PATCH 1/2] Disable notifications for Crypto V2 --- MatrixSDK.xcodeproj/project.pbxproj | 42 ++++++++++-------- .../Crypto/MXDummyBackgroundCrypto.swift | 44 +++++++++++++++++++ .../Background/MXBackgroundSyncService.swift | 22 ++++------ ...EventDecryptionResult+DecryptedEvent.swift | 6 ++- changelog.d/pr-1662.change | 1 + 5 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 MatrixSDK/Background/Crypto/MXDummyBackgroundCrypto.swift create mode 100644 changelog.d/pr-1662.change diff --git a/MatrixSDK.xcodeproj/project.pbxproj b/MatrixSDK.xcodeproj/project.pbxproj index 36cbac0fa5..17f88ae338 100644 --- a/MatrixSDK.xcodeproj/project.pbxproj +++ b/MatrixSDK.xcodeproj/project.pbxproj @@ -872,7 +872,7 @@ B14EF1E32397E90400758AF0 /* MXCall.m in Sources */ = {isa = PBXBuildFile; fileRef = 3245A74D1AF7B2930001D8A7 /* MXCall.m */; }; B14EF1E42397E90400758AF0 /* MXWellknownIntegrations.m in Sources */ = {isa = PBXBuildFile; fileRef = 32CF439C2371AF9500907C56 /* MXWellknownIntegrations.m */; }; B14EF1E52397E90400758AF0 /* MXLoginPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 3275FD9B21A6B60B00B9C13D /* MXLoginPolicy.m */; }; - B14EF1E62397E90400758AF0 /* BuildFile in Sources */ = {isa = PBXBuildFile; }; + B14EF1E62397E90400758AF0 /* (null) in Sources */ = {isa = PBXBuildFile; }; B14EF1E72397E90400758AF0 /* MXRoomThirdPartyInvite.m in Sources */ = {isa = PBXBuildFile; fileRef = 327F8DB11C6112BA00581CA3 /* MXRoomThirdPartyInvite.m */; }; B14EF1E82397E90400758AF0 /* MXRoomPowerLevels.m in Sources */ = {isa = PBXBuildFile; fileRef = B17982F42119E4A2001FD722 /* MXRoomPowerLevels.m */; }; B14EF1E92397E90400758AF0 /* MXRealmMediaScanMapper.m in Sources */ = {isa = PBXBuildFile; fileRef = B146D4DE21A5AEF100D8C2C6 /* MXRealmMediaScanMapper.m */; }; @@ -929,7 +929,7 @@ B14EF21D2397E90400758AF0 /* MXEncryptedContentKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 021AFBA12179E91800742B2C /* MXEncryptedContentKey.m */; }; B14EF21E2397E90400758AF0 /* MXEventDecryptionResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 32F634AA1FC5E3470054EF49 /* MXEventDecryptionResult.m */; }; B14EF21F2397E90400758AF0 /* MXMyUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 327137261A24D50A00DB6757 /* MXMyUser.m */; }; - B14EF2202397E90400758AF0 /* BuildFile in Sources */ = {isa = PBXBuildFile; }; + B14EF2202397E90400758AF0 /* (null) in Sources */ = {isa = PBXBuildFile; }; B14EF2212397E90400758AF0 /* MX3PID.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6F935831E5B3BE600FC34BF /* MX3PID.swift */; }; B14EF2222397E90400758AF0 /* MXMediaScan.m in Sources */ = {isa = PBXBuildFile; fileRef = B146D47621A5950800D8C2C6 /* MXMediaScan.m */; }; B14EF2232397E90400758AF0 /* MXEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6F935861E5B3BE600FC34BF /* MXEvent.swift */; }; @@ -944,7 +944,7 @@ B14EF22C2397E90400758AF0 /* MXAccountData.m in Sources */ = {isa = PBXBuildFile; fileRef = 3264DB901CEC528D00B99881 /* MXAccountData.m */; }; B14EF22D2397E90400758AF0 /* MXRealmReactionCount.m in Sources */ = {isa = PBXBuildFile; fileRef = 32133018228B010C0070BA9B /* MXRealmReactionCount.m */; }; B14EF22E2397E90400758AF0 /* MXCryptoTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 3250E7C9220C913900736CB5 /* MXCryptoTools.m */; }; - B14EF22F2397E90400758AF0 /* BuildFile in Sources */ = {isa = PBXBuildFile; }; + B14EF22F2397E90400758AF0 /* (null) in Sources */ = {isa = PBXBuildFile; }; B14EF2302397E90400758AF0 /* MXDeviceListOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 322691311E5EF77D00966A6E /* MXDeviceListOperation.m */; }; B14EF2312397E90400758AF0 /* MX3PidAddSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D2CBFF23422462002BD8CA /* MX3PidAddSession.m */; }; B14EF2322397E90400758AF0 /* MXBugReportRestClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 3283F7771EAF30F700C1688C /* MXBugReportRestClient.m */; }; @@ -988,7 +988,7 @@ B14EF25B2397E90400758AF0 /* MXSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 320DFDD119DD99B60068622A /* MXSession.m */; }; B14EF25C2397E90400758AF0 /* MXRoomTombStoneContent.m in Sources */ = {isa = PBXBuildFile; fileRef = B17982EE2119E49F001FD722 /* MXRoomTombStoneContent.m */; }; B14EF25D2397E90400758AF0 /* MXImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C602B58D1F22A8D700B67D87 /* MXImage.swift */; }; - B14EF25E2397E90400758AF0 /* BuildFile in Sources */ = {isa = PBXBuildFile; }; + B14EF25E2397E90400758AF0 /* (null) in Sources */ = {isa = PBXBuildFile; }; B14EF25F2397E90400758AF0 /* MXServerNoticeContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 32954018216385F100E300FC /* MXServerNoticeContent.m */; }; B14EF2602397E90400758AF0 /* MXContentScanResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 02CAD434217DD12F0074700B /* MXContentScanResult.m */; }; B14EF2612397E90400758AF0 /* MXRealmAggregationsStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 32133014228AF4EF0070BA9B /* MXRealmAggregationsStore.m */; }; @@ -1026,7 +1026,7 @@ B14EF2822397E90400758AF0 /* MXDeviceList.m in Sources */ = {isa = PBXBuildFile; fileRef = 32637ED31E5B00400011E20D /* MXDeviceList.m */; }; B14EF2832397E90400758AF0 /* MXRoomCreateContent.m in Sources */ = {isa = PBXBuildFile; fileRef = B17982F22119E4A1001FD722 /* MXRoomCreateContent.m */; }; B14EF2842397E90400758AF0 /* MXUIKitBackgroundModeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 32A9E8231EF4026E0081358A /* MXUIKitBackgroundModeHandler.m */; }; - B14EF2852397E90400758AF0 /* BuildFile in Sources */ = {isa = PBXBuildFile; }; + B14EF2852397E90400758AF0 /* (null) in Sources */ = {isa = PBXBuildFile; }; B14EF2862397E90400758AF0 /* MXRealmMediaScanStore.m in Sources */ = {isa = PBXBuildFile; fileRef = B146D4F521A5BB9F00D8C2C6 /* MXRealmMediaScanStore.m */; }; B14EF2872397E90400758AF0 /* MXPusherData.m in Sources */ = {isa = PBXBuildFile; fileRef = 32999DE222DCD1AD004FF987 /* MXPusherData.m */; }; B14EF2882397E90400758AF0 /* MXOlmDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = 322A51C61D9BBD3C00C8536D /* MXOlmDevice.m */; }; @@ -1961,6 +1961,8 @@ ED8F1D352885B07500F897E7 /* MXCrossSigningInfoUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8F1D1628857FE600F897E7 /* MXCrossSigningInfoUnitTests.swift */; }; ED8F1D3B2885BB2D00F897E7 /* MXCryptoProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8F1D3A2885BB2D00F897E7 /* MXCryptoProtocols.swift */; }; ED8F1D3C2885BB2D00F897E7 /* MXCryptoProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8F1D3A2885BB2D00F897E7 /* MXCryptoProtocols.swift */; }; + ED96F2BA294A2E9A002DB8F6 /* MXDummyBackgroundCrypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED96F2B9294A2E9A002DB8F6 /* MXDummyBackgroundCrypto.swift */; }; + ED96F2BB294A2E9A002DB8F6 /* MXDummyBackgroundCrypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED96F2B9294A2E9A002DB8F6 /* MXDummyBackgroundCrypto.swift */; }; ED997856292E2877006B5248 /* MXSessionSyncProgressUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED997855292E2877006B5248 /* MXSessionSyncProgressUnitTests.swift */; }; ED997857292E2877006B5248 /* MXSessionSyncProgressUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED997855292E2877006B5248 /* MXSessionSyncProgressUnitTests.swift */; }; EDA2CDD628F5C4230088ACE7 /* MXQRCodeTransactionV2UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA2CDD528F5C4230088ACE7 /* MXQRCodeTransactionV2UnitTests.swift */; }; @@ -1969,10 +1971,10 @@ EDA69341290BA92E00223252 /* MXCryptoMachineUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA6933F290BA92E00223252 /* MXCryptoMachineUnitTests.swift */; }; EDAAC41928E2FCFE00DD89B5 /* MXCryptoSecretStoreV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDAAC41828E2FCFE00DD89B5 /* MXCryptoSecretStoreV2.swift */; }; EDAAC41A28E2FCFE00DD89B5 /* MXCryptoSecretStoreV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDAAC41828E2FCFE00DD89B5 /* MXCryptoSecretStoreV2.swift */; }; - EDAAC41C28E30F3C00DD89B5 /* BuildFile in Headers */ = {isa = PBXBuildFile; settings = {ATTRIBUTES = (Public, ); }; }; - EDAAC41D28E30F3C00DD89B5 /* BuildFile in Headers */ = {isa = PBXBuildFile; settings = {ATTRIBUTES = (Public, ); }; }; - EDAAC41F28E30F4C00DD89B5 /* BuildFile in Sources */ = {isa = PBXBuildFile; }; - EDAAC42028E30F4C00DD89B5 /* BuildFile in Sources */ = {isa = PBXBuildFile; }; + EDAAC41C28E30F3C00DD89B5 /* (null) in Headers */ = {isa = PBXBuildFile; settings = {ATTRIBUTES = (Public, ); }; }; + EDAAC41D28E30F3C00DD89B5 /* (null) in Headers */ = {isa = PBXBuildFile; settings = {ATTRIBUTES = (Public, ); }; }; + EDAAC41F28E30F4C00DD89B5 /* (null) in Sources */ = {isa = PBXBuildFile; }; + EDAAC42028E30F4C00DD89B5 /* (null) in Sources */ = {isa = PBXBuildFile; }; EDAAC42128E3174700DD89B5 /* MXCryptoSecretStore.h in Headers */ = {isa = PBXBuildFile; fileRef = EDAAC41228E2F86800DD89B5 /* MXCryptoSecretStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; EDAAC42228E3174700DD89B5 /* MXCryptoSecretStore.h in Headers */ = {isa = PBXBuildFile; fileRef = EDAAC41228E2F86800DD89B5 /* MXCryptoSecretStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; EDAAC42428E3177000DD89B5 /* MXRecoveryServiceDependencies.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDAAC42328E3177000DD89B5 /* MXRecoveryServiceDependencies.swift */; }; @@ -3099,6 +3101,7 @@ ED8F1D312885AC5700F897E7 /* Device+Stub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Device+Stub.swift"; sourceTree = ""; }; ED8F1D332885ADE200F897E7 /* MXCryptoProtocolStubs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoProtocolStubs.swift; sourceTree = ""; }; ED8F1D3A2885BB2D00F897E7 /* MXCryptoProtocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXCryptoProtocols.swift; sourceTree = ""; }; + ED96F2B9294A2E9A002DB8F6 /* MXDummyBackgroundCrypto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXDummyBackgroundCrypto.swift; sourceTree = ""; }; ED997855292E2877006B5248 /* MXSessionSyncProgressUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSessionSyncProgressUnitTests.swift; sourceTree = ""; }; EDA2CDD528F5C4230088ACE7 /* MXQRCodeTransactionV2UnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXQRCodeTransactionV2UnitTests.swift; sourceTree = ""; }; EDA6933F290BA92E00223252 /* MXCryptoMachineUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMachineUnitTests.swift; sourceTree = ""; }; @@ -5416,6 +5419,7 @@ ED4114E7292E496C00728459 /* MXBackgroundCrypto.swift */, ED4114EA292E498100728459 /* MXBackgroundCryptoV2.swift */, ED4114ED292E49C000728459 /* MXLegacyBackgroundCrypto.swift */, + ED96F2B9294A2E9A002DB8F6 /* MXDummyBackgroundCrypto.swift */, ); path = Crypto; sourceTree = ""; @@ -5764,7 +5768,7 @@ B146D47421A5945800D8C2C6 /* MXAntivirusScanStatus.h in Headers */, 322691361E5EFF8700966A6E /* MXDeviceListOperationsPool.h in Headers */, 3281E8B719E42DFE00976E1A /* MXJSONModel.h in Headers */, - EDAAC41C28E30F3C00DD89B5 /* BuildFile in Headers */, + EDAAC41C28E30F3C00DD89B5 /* (null) in Headers */, B135066127E9CB6400BD3276 /* MXBeaconInfo.h in Headers */, EC5C562827A36EDB0014CBE9 /* MXInReplyTo.h in Headers */, EC8A539325B1BC77004E0802 /* MXCallSessionDescription.h in Headers */, @@ -6388,7 +6392,7 @@ 324AAC7E2399143400380A66 /* MXKeyVerificationCancel.h in Headers */, ED01915528C64E0400ED3A69 /* MXRoomKeyEventContent.h in Headers */, B14EF3372397E90400758AF0 /* MXRoomTombStoneContent.h in Headers */, - EDAAC41D28E30F3C00DD89B5 /* BuildFile in Headers */, + EDAAC41D28E30F3C00DD89B5 /* (null) in Headers */, 3274538B23FD918800438328 /* MXKeyVerificationByToDeviceRequest.h in Headers */, B14EF3382397E90400758AF0 /* MXFilterObject.h in Headers */, B14EF3392397E90400758AF0 /* MXRealmReactionCount.h in Headers */, @@ -6997,6 +7001,7 @@ B19A30A0240424BD00FB6F35 /* MXQRCodeTransaction.m in Sources */, C63E78B01F26588000AC692F /* MXRoomPowerLevels.swift in Sources */, EC0B943F271DB68F00B4D440 /* MXVoidRoomSummaryStore.m in Sources */, + ED96F2BA294A2E9A002DB8F6 /* MXDummyBackgroundCrypto.swift in Sources */, EC383BA5253DE6C9002FBBE6 /* MXSyncResponseStore.swift in Sources */, 32CEEF4523AD2A6C0039BA98 /* MXCrossSigningKey.m in Sources */, 327E9AF02289C61100A98BC1 /* MXAggregations.m in Sources */, @@ -7133,7 +7138,7 @@ 324AAC73239913AD00380A66 /* MXKeyVerificationDone.m in Sources */, ED6DABFC28C7542800ECDCB6 /* MXRoomKeyInfoFactory.swift in Sources */, B11556EE230C45C600B2A2CF /* MXIdentityServerRestClient.swift in Sources */, - EDAAC41F28E30F4C00DD89B5 /* BuildFile in Sources */, + EDAAC41F28E30F4C00DD89B5 /* (null) in Sources */, 321CFDE722525A49004D31DF /* MXSASTransaction.m in Sources */, EDDBA7F0293F353900AD1480 /* MXToDevicePayload.swift in Sources */, 32720D9D222EAA6F0086FFF5 /* MXDiscoveredClientConfig.m in Sources */, @@ -7427,7 +7432,7 @@ EC1165B527107E330089FA56 /* MXStoreRoomListDataManager.swift in Sources */, 66836ABA27CFA17200515780 /* MXLiveEventListener.swift in Sources */, B14EF1E52397E90400758AF0 /* MXLoginPolicy.m in Sources */, - B14EF1E62397E90400758AF0 /* BuildFile in Sources */, + B14EF1E62397E90400758AF0 /* (null) in Sources */, B18D23F727ECF199004C4277 /* MXLocationService.swift in Sources */, EC60EDB5265CFE6200B39A4E /* MXRoomSyncEphemeral.m in Sources */, B14EF1E72397E90400758AF0 /* MXRoomThirdPartyInvite.m in Sources */, @@ -7567,7 +7572,7 @@ B14EF21F2397E90400758AF0 /* MXMyUser.m in Sources */, EDAAC42528E3177300DD89B5 /* MXRecoveryServiceDependencies.swift in Sources */, EC60EDAB265CFE3B00B39A4E /* MXRoomSyncTimeline.m in Sources */, - B14EF2202397E90400758AF0 /* BuildFile in Sources */, + B14EF2202397E90400758AF0 /* (null) in Sources */, ED647E3F292CE64400A47519 /* MXSessionSyncProgress.swift in Sources */, B14EF2212397E90400758AF0 /* MX3PID.swift in Sources */, 18121F79273E6E4100B68ADF /* PollBuilder.swift in Sources */, @@ -7605,7 +7610,7 @@ B18B0E6825FBDC3000E32151 /* MXSpace.swift in Sources */, B14EF22D2397E90400758AF0 /* MXRealmReactionCount.m in Sources */, B14EF22E2397E90400758AF0 /* MXCryptoTools.m in Sources */, - B14EF22F2397E90400758AF0 /* BuildFile in Sources */, + B14EF22F2397E90400758AF0 /* (null) in Sources */, B14EF2302397E90400758AF0 /* MXDeviceListOperation.m in Sources */, 32C78B6B256CFC4D008130B1 /* MXCryptoMigration.m in Sources */, ECDA763027B292B5000C48CF /* MXThreadModel.swift in Sources */, @@ -7643,6 +7648,7 @@ EC8A539625B1BC77004E0802 /* MXUserModel.m in Sources */, EC0B9440271DB68F00B4D440 /* MXVoidRoomSummaryStore.m in Sources */, B14EF2402397E90400758AF0 /* MXSessionEventListener.m in Sources */, + ED96F2BB294A2E9A002DB8F6 /* MXDummyBackgroundCrypto.swift in Sources */, EC8A53A625B1BC77004E0802 /* MXCallInviteEventContent.m in Sources */, ECD2899226EB3B3400F268CF /* MXRoomListDataFetcher.swift in Sources */, B18B0E5025FB783F00E32151 /* MXSpaceService.swift in Sources */, @@ -7718,7 +7724,7 @@ B14EF25C2397E90400758AF0 /* MXRoomTombStoneContent.m in Sources */, B1432B52282AB29A00737CA6 /* MXBeaconInfoSummaryAllRoomListener.swift in Sources */, B14EF25D2397E90400758AF0 /* MXImage.swift in Sources */, - B14EF25E2397E90400758AF0 /* BuildFile in Sources */, + B14EF25E2397E90400758AF0 /* (null) in Sources */, 32B090E3261F709B002924AA /* MXAsyncTaskQueue.swift in Sources */, B14EF25F2397E90400758AF0 /* MXServerNoticeContent.m in Sources */, B1F04B112811E7B600103EBE /* MXBeaconInfoSummaryMemoryStore.swift in Sources */, @@ -7779,7 +7785,7 @@ B14EF2772397E90400758AF0 /* MXDecryptionResult.m in Sources */, ED6DABFD28C7542800ECDCB6 /* MXRoomKeyInfoFactory.swift in Sources */, B14EF2782397E90400758AF0 /* MXTransactionCancelCode.m in Sources */, - EDAAC42028E30F4C00DD89B5 /* BuildFile in Sources */, + EDAAC42028E30F4C00DD89B5 /* (null) in Sources */, B14EF2792397E90400758AF0 /* MXEventListener.m in Sources */, EDDBA7F1293F353900AD1480 /* MXToDevicePayload.swift in Sources */, B1710B202613D01400A9B429 /* MXSpaceChildrenRequestParameters.swift in Sources */, @@ -7816,7 +7822,7 @@ EC60ED7E265CFCD100B39A4E /* MXDeviceListResponse.m in Sources */, 323F879025553D84009E9E67 /* MXTaskProfile.m in Sources */, B14EF2842397E90400758AF0 /* MXUIKitBackgroundModeHandler.m in Sources */, - B14EF2852397E90400758AF0 /* BuildFile in Sources */, + B14EF2852397E90400758AF0 /* (null) in Sources */, 32A9F8E1244720B10069C65B /* MXThrottler.m in Sources */, 3274538D23FD918800438328 /* MXKeyVerificationByToDeviceRequest.m in Sources */, 32CEEF5223B0AB030039BA98 /* MXCrossSigning.m in Sources */, diff --git a/MatrixSDK/Background/Crypto/MXDummyBackgroundCrypto.swift b/MatrixSDK/Background/Crypto/MXDummyBackgroundCrypto.swift new file mode 100644 index 0000000000..88b2ae65a5 --- /dev/null +++ b/MatrixSDK/Background/Crypto/MXDummyBackgroundCrypto.swift @@ -0,0 +1,44 @@ +// +// Copyright 2022 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 + +#if DEBUG + +/// Dummy implementation of background crypto that does nothing and is unable +/// to decrypt notification. +/// +/// Note: This is a temporary class to be used with foreground Crypto V2 which +/// is not currently multi-process safe and thus only one process can be +/// decrypting events. +class MXDummyBackgroundCrypto: MXBackgroundCrypto { + enum Error: Swift.Error { + case unableToDecrypt + } + + func handleSyncResponse(_ syncResponse: MXSyncResponse) { + } + + func canDecryptEvent(_ event: MXEvent) -> Bool { + false + } + + func decryptEvent(_ event: MXEvent) throws { + throw Error.unableToDecrypt + } +} + +#endif diff --git a/MatrixSDK/Background/MXBackgroundSyncService.swift b/MatrixSDK/Background/MXBackgroundSyncService.swift index 7f59136ccf..8695914aa3 100644 --- a/MatrixSDK/Background/MXBackgroundSyncService.swift +++ b/MatrixSDK/Background/MXBackgroundSyncService.swift @@ -81,20 +81,16 @@ public enum MXBackgroundSyncServiceError: Error { // We can flush any crypto data if our sync response store is empty let resetBackgroundCryptoStore = syncResponseStoreManager.syncToken() == nil - #if DEBUG - if MXSDKOptions.sharedInstance().enableCryptoV2 { - do { - crypto = try MXBackgroundCryptoV2(credentials: credentials, restClient: restClient) - } catch { - MXLog.failure("[MXBackgroundSyncService] init: Cannot initialize crypto v2", context: error) - crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore) + crypto = { + #if DEBUG + if MXSDKOptions.sharedInstance().enableCryptoV2 { + // Crypto V2 is currently unable to decrypt notifications due to single-process store, + // so it uses dummy background crypto that does not do anything. + return MXDummyBackgroundCrypto() } - } else { - crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore) - } - #else - crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore) - #endif + #endif + return MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore) + }() pushRulesManager = MXBackgroundPushRulesManager(withCredentials: credentials) if let accountData = syncResponseStoreManager.syncResponseStore.accountData { diff --git a/MatrixSDK/Crypto/CryptoMachine/MXEventDecryptionResult+DecryptedEvent.swift b/MatrixSDK/Crypto/CryptoMachine/MXEventDecryptionResult+DecryptedEvent.swift index 3b61745d1e..8dd25cd525 100644 --- a/MatrixSDK/Crypto/CryptoMachine/MXEventDecryptionResult+DecryptedEvent.swift +++ b/MatrixSDK/Crypto/CryptoMachine/MXEventDecryptionResult+DecryptedEvent.swift @@ -37,7 +37,11 @@ extension MXEventDecryptionResult { senderCurve25519Key = event.senderCurve25519Key claimedEd25519Key = event.claimedEd25519Key forwardingCurve25519KeyChain = event.forwardingCurve25519Chain - isUntrusted = event.verificationState == VerificationState.untrusted + + // `Untrusted` state from rust is currently ignored as it lacks "undecided" option, + // will be changed in a future PR into: + // isUntrusted = event.verificationState == VerificationState.untrusted + isUntrusted = false } } diff --git a/changelog.d/pr-1662.change b/changelog.d/pr-1662.change new file mode 100644 index 0000000000..c26f6b5a46 --- /dev/null +++ b/changelog.d/pr-1662.change @@ -0,0 +1 @@ +CryptoV2: Disable notification decryption From 95e8e83fc4064f0cfb085d2c428f1928cd82b203 Mon Sep 17 00:00:00 2001 From: Andy Uhnak Date: Wed, 14 Dec 2022 17:20:56 +0000 Subject: [PATCH 2/2] Do not post notification for transactions --- .../Verification/MXKeyVerificationManagerV2.swift | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/MatrixSDK/Crypto/Verification/MXKeyVerificationManagerV2.swift b/MatrixSDK/Crypto/Verification/MXKeyVerificationManagerV2.swift index 0b25954345..bd161a4b51 100644 --- a/MatrixSDK/Crypto/Verification/MXKeyVerificationManagerV2.swift +++ b/MatrixSDK/Crypto/Verification/MXKeyVerificationManagerV2.swift @@ -497,19 +497,6 @@ class MXKeyVerificationManagerV2: NSObject, MXKeyVerificationManager { private func addSasTransaction(for sas: SasProtocol, isIncoming: Bool) -> MXSASTransactionV2 { let transaction = MXSASTransactionV2(sas: sas, isIncoming: isIncoming, handler: handler) activeTransactions[transaction.transactionId] = transaction - if isIncoming { - NotificationCenter.default.post( - name: .MXKeyVerificationManagerNewTransaction, - object: self, - userInfo: [ - MXKeyVerificationManagerNotificationTransactionKey: transaction - ] - ) - NotificationCenter.default.post( - name: .MXKeyVerificationTransactionDidChange, - object: transaction - ) - } return transaction }