diff --git a/.github/workflows/ci-crypto-tests.yml b/.github/workflows/ci-crypto-tests.yml deleted file mode 100644 index 60bc264fa3..0000000000 --- a/.github/workflows/ci-crypto-tests.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: Crypto Tests CI - -on: - # Triggers the workflow on any pull request and push to develop - push: - branches: [ develop ] - pull_request: - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - crypto-tests: - name: Crypto Tests with Synapse - runs-on: macos-11 - - concurrency: - # When running on develop, use the sha to allow all runs of this workflow to run concurrently. - # Otherwise only allow a single run of this workflow on each branch, automatically cancelling older runs. - group: ${{ github.ref == 'refs/heads/develop' && format('crypto-develop-{0}', github.sha) || format('crypto-{0}', github.ref) }} - cancel-in-progress: true - - steps: - - uses: actions/checkout@v2 - - # Cache for python env for Synapse - - name: Set up Python 3.8 - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- - # Cache for Xcode env - - uses: actions/cache@v2 - with: - path: Pods - key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} - restore-keys: | - ${{ runner.os }}-pods- - - uses: actions/cache@v2 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems- - - name: Start synapse server - uses: michaelkaye/setup-matrix-synapse@v1.0.3 - with: - uploadLogs: true - httpPort: 8080 - disableRateLimiting: true - - - name: Bundle install - run: | - bundle config path vendor/bundle - bundle install --jobs 4 --retry 3 - # Main step - - name: Crypto tests - run: bundle exec fastlane test testplan:CryptoTests - - # Store artifacts - - uses: actions/upload-artifact@v2 - if: always() - with: - name: report.html - path: build/test/report.html - - uses: actions/upload-artifact@v2 - if: always() - with: - name: report.junit - path: build/test/report.junit - - uses: actions/upload-artifact@v2 - if: always() - with: - name: MatrixSDK-macOS.xcresult - path: build/test/MatrixSDK-macOS.xcresult/ - - # Upload coverage - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 diff --git a/CHANGES.md b/CHANGES.md index 8412d19900..3a4ee02e7c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,16 @@ +## Changes in 0.26.10 (2023-05-16) + +🙌 Improvements + +- Crypto: Enable Crypto SDK by default ([#1770](https://github.com/matrix-org/matrix-ios-sdk/pull/1770)) +- Crypto: Deprecate MXLegacyCrypto ([#1772](https://github.com/matrix-org/matrix-ios-sdk/pull/1772)) + +🐛 Bugfixes + +- Poll: Refreshing the poll when receiving pollEnd can break the chronological order in the store. ([#1776](https://github.com/matrix-org/matrix-ios-sdk/pull/1776)) +- Fix breadcrumb list not updating when leaving a room. Contributed by @JanNikGra. ([#1777](https://github.com/vector-im/element-ios/issues/1777)) + + ## Changes in 0.26.9 (2023-04-18) 🐛 Bugfixes diff --git a/MatrixSDK.podspec b/MatrixSDK.podspec index ecd9a2d63b..d86d3500a5 100644 --- a/MatrixSDK.podspec +++ b/MatrixSDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "MatrixSDK" - s.version = "0.26.9" + s.version = "0.26.10" s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)" s.description = <<-DESC diff --git a/MatrixSDK.xcodeproj/project.pbxproj b/MatrixSDK.xcodeproj/project.pbxproj index 7e94b2d397..643661e11e 100644 --- a/MatrixSDK.xcodeproj/project.pbxproj +++ b/MatrixSDK.xcodeproj/project.pbxproj @@ -414,7 +414,6 @@ 3291DC8423DF52E20009732F /* MXRoomCreationParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 3291DC8123DF52E10009732F /* MXRoomCreationParameters.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3291DC8523DF52E20009732F /* MXRoomCreationParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 3291DC8223DF52E10009732F /* MXRoomCreationParameters.m */; }; 3291DC8623DF52E20009732F /* MXRoomCreationParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 3291DC8223DF52E10009732F /* MXRoomCreationParameters.m */; }; - 32935F61216FA49D00A1BC24 /* MXCurve25519KeyBackupTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32935F60216FA49D00A1BC24 /* MXCurve25519KeyBackupTests.m */; }; 3293C700214BBA4F009B3DDB /* MXPeekingRoomSummary.h in Headers */ = {isa = PBXBuildFile; fileRef = 3293C6FE214BBA4F009B3DDB /* MXPeekingRoomSummary.h */; }; 3293C701214BBA4F009B3DDB /* MXPeekingRoomSummary.m in Sources */ = {isa = PBXBuildFile; fileRef = 3293C6FF214BBA4F009B3DDB /* MXPeekingRoomSummary.m */; }; 3294FD9D22F321B0007F1E60 /* MXServiceTermsRestClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 3294FD9922F321B0007F1E60 /* MXServiceTermsRestClient.m */; }; @@ -876,7 +875,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 */; }; @@ -933,7 +932,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 */; }; @@ -948,7 +947,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 */; }; @@ -992,7 +991,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 */; }; @@ -1030,7 +1029,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 */; }; @@ -1354,7 +1353,6 @@ B1E09A1D2397FCE90057C069 /* MXCryptoKeyVerificationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 329E808E22512DF500A48C3A /* MXCryptoKeyVerificationTests.m */; }; B1E09A1E2397FCE90057C069 /* MXCryptoShareTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 322D01C322492B0700150C68 /* MXCryptoShareTests.m */; }; B1E09A1F2397FCE90057C069 /* MXAutoDiscoveryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32720DA1222EB5650086FFF5 /* MXAutoDiscoveryTests.m */; }; - B1E09A202397FCE90057C069 /* MXCurve25519KeyBackupTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32935F60216FA49D00A1BC24 /* MXCurve25519KeyBackupTests.m */; }; B1E09A212397FCE90057C069 /* DirectRoomTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32C03CB52123076F00D92712 /* DirectRoomTests.m */; }; B1E09A222397FCE90057C069 /* MXRoomSummaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 320E1BC01E0AD674009635F5 /* MXRoomSummaryTests.m */; }; B1E09A242397FCE90057C069 /* MXPeekingRoomTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32E226A81D081CE200E6CA54 /* MXPeekingRoomTests.m */; }; @@ -1886,8 +1884,8 @@ ED558069296F0361003443E3 /* MXCryptoMigrationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED558067296F0361003443E3 /* MXCryptoMigrationStore.swift */; }; ED55806D296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806C296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift */; }; ED55806E296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806C296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift */; }; - ED558070296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift */; }; - ED558071296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift */; }; + ED558070296F1BEE003443E3 /* MXCryptoMigrationV2UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2UnitTests.swift */; }; + ED558071296F1BEE003443E3 /* MXCryptoMigrationV2UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2UnitTests.swift */; }; ED5580732970265A003443E3 /* MXCryptoSDKLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED5580722970265A003443E3 /* MXCryptoSDKLogger.swift */; }; ED5580742970265A003443E3 /* MXCryptoSDKLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED5580722970265A003443E3 /* MXCryptoSDKLogger.swift */; }; ED55807629709943003443E3 /* MatrixSDKTestsE2EData.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55807529709943003443E3 /* MatrixSDKTestsE2EData.swift */; }; @@ -2003,14 +2001,30 @@ ED997857292E2877006B5248 /* MXSessionStartupProgressUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED997855292E2877006B5248 /* MXSessionStartupProgressUnitTests.swift */; }; EDA2CDD628F5C4230088ACE7 /* MXQRCodeTransactionV2UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA2CDD528F5C4230088ACE7 /* MXQRCodeTransactionV2UnitTests.swift */; }; EDA2CDD728F5C4230088ACE7 /* MXQRCodeTransactionV2UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA2CDD528F5C4230088ACE7 /* MXQRCodeTransactionV2UnitTests.swift */; }; + EDA40A0529E9D6BE00C0CAB9 /* MXKeyProviderStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA40A0429E9D6BE00C0CAB9 /* MXKeyProviderStub.swift */; }; + EDA40A0629E9D6BE00C0CAB9 /* MXKeyProviderStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA40A0429E9D6BE00C0CAB9 /* MXKeyProviderStub.swift */; }; + EDA40A0F29E9E2BF00C0CAB9 /* legacy_version2_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0829E9E2BF00C0CAB9 /* legacy_version2_account.realm */; }; + EDA40A1029E9E2BF00C0CAB9 /* legacy_version2_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0829E9E2BF00C0CAB9 /* legacy_version2_account.realm */; }; + EDA40A1129E9E2BF00C0CAB9 /* legacy_verified_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0929E9E2BF00C0CAB9 /* legacy_verified_account.realm */; }; + EDA40A1229E9E2BF00C0CAB9 /* legacy_verified_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0929E9E2BF00C0CAB9 /* legacy_verified_account.realm */; }; + EDA40A1329E9E2BF00C0CAB9 /* legacy_unverified_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0A29E9E2BF00C0CAB9 /* legacy_unverified_account.realm */; }; + EDA40A1429E9E2BF00C0CAB9 /* legacy_unverified_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0A29E9E2BF00C0CAB9 /* legacy_unverified_account.realm */; }; + EDA40A1529E9E2BF00C0CAB9 /* legacy_deprecated3_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0B29E9E2BF00C0CAB9 /* legacy_deprecated3_account.realm */; }; + EDA40A1629E9E2BF00C0CAB9 /* legacy_deprecated3_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0B29E9E2BF00C0CAB9 /* legacy_deprecated3_account.realm */; }; + EDA40A1729E9E2BF00C0CAB9 /* legacy_deprecated1_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0C29E9E2BF00C0CAB9 /* legacy_deprecated1_account.realm */; }; + EDA40A1829E9E2BF00C0CAB9 /* legacy_deprecated1_account.realm in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0C29E9E2BF00C0CAB9 /* legacy_deprecated1_account.realm */; }; + EDA40A1929E9E2BF00C0CAB9 /* archived_encrypted_event in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0D29E9E2BF00C0CAB9 /* archived_encrypted_event */; }; + EDA40A1A29E9E2BF00C0CAB9 /* archived_encrypted_event in Resources */ = {isa = PBXBuildFile; fileRef = EDA40A0D29E9E2BF00C0CAB9 /* archived_encrypted_event */; }; + EDA40A1B29E9E2BF00C0CAB9 /* LegacyRealmStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA40A0E29E9E2BF00C0CAB9 /* LegacyRealmStore.swift */; }; + EDA40A1C29E9E2BF00C0CAB9 /* LegacyRealmStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA40A0E29E9E2BF00C0CAB9 /* LegacyRealmStore.swift */; }; EDA69340290BA92E00223252 /* MXCryptoMachineUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA6933F290BA92E00223252 /* MXCryptoMachineUnitTests.swift */; }; 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 */; }; @@ -2025,14 +2039,10 @@ EDBCF337281A8ABE00ED5044 /* MXSharedHistoryKeyService.h in Headers */ = {isa = PBXBuildFile; fileRef = EDBCF335281A8AB900ED5044 /* MXSharedHistoryKeyService.h */; settings = {ATTRIBUTES = (Public, ); }; }; EDBCF339281A8D3D00ED5044 /* MXSharedHistoryKeyService.m in Sources */ = {isa = PBXBuildFile; fileRef = EDBCF338281A8D3D00ED5044 /* MXSharedHistoryKeyService.m */; }; EDBCF33A281A8D3D00ED5044 /* MXSharedHistoryKeyService.m in Sources */ = {isa = PBXBuildFile; fileRef = EDBCF338281A8D3D00ED5044 /* MXSharedHistoryKeyService.m */; }; - EDC2A0E628369E740039F3D6 /* CryptoTests.xctestplan in Resources */ = {isa = PBXBuildFile; fileRef = EDC2A0E528369E740039F3D6 /* CryptoTests.xctestplan */; }; - EDC2A0E728369E740039F3D6 /* CryptoTests.xctestplan in Resources */ = {isa = PBXBuildFile; fileRef = EDC2A0E528369E740039F3D6 /* CryptoTests.xctestplan */; }; EDC8C4082968A993003792C5 /* MXKeysQueryScheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC8C4072968A993003792C5 /* MXKeysQueryScheduler.swift */; }; EDC8C4092968A993003792C5 /* MXKeysQueryScheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC8C4072968A993003792C5 /* MXKeysQueryScheduler.swift */; }; EDC8C40D2968C37E003792C5 /* MXKeysQuerySchedulerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */; }; EDC8C40E2968C37F003792C5 /* MXKeysQuerySchedulerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */; }; - EDCAD251299BF7F40088B4DA /* MXCryptoV2Feature.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCAD250299BF7F40088B4DA /* MXCryptoV2Feature.swift */; }; - EDCAD252299BF7F40088B4DA /* MXCryptoV2Feature.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCAD250299BF7F40088B4DA /* MXCryptoV2Feature.swift */; }; EDCB65E22912AB0C00F55D4D /* MXRoomEventDecryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */; }; EDCB65E32912AB0C00F55D4D /* MXRoomEventDecryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */; }; EDCF802D2941FF220059E774 /* MXCryptoMigrationV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCF802C2941FF220059E774 /* MXCryptoMigrationV2.swift */; }; @@ -2057,8 +2067,8 @@ EDD7B74929CB3F1B00548AB4 /* MXCrossSigningInfo_v1 in Resources */ = {isa = PBXBuildFile; fileRef = EDD7B74629CB3F1B00548AB4 /* MXCrossSigningInfo_v1 */; }; EDD7B74A29CB3F1B00548AB4 /* MXCrossSigningInfo_v0 in Resources */ = {isa = PBXBuildFile; fileRef = EDD7B74729CB3F1B00548AB4 /* MXCrossSigningInfo_v0 */; }; EDD7B74B29CB3F1B00548AB4 /* MXCrossSigningInfo_v0 in Resources */ = {isa = PBXBuildFile; fileRef = EDD7B74729CB3F1B00548AB4 /* MXCrossSigningInfo_v0 */; }; - EDDB07CA297EE0A7005249A6 /* MXCryptoV2FactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryTests.swift */; }; - EDDB07CB297EE0A7005249A6 /* MXCryptoV2FactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryTests.swift */; }; + EDDB07CA297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift */; }; + EDDB07CB297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift */; }; EDDBA7F0293F353900AD1480 /* MXToDevicePayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDBA7EF293F353900AD1480 /* MXToDevicePayload.swift */; }; EDDBA7F1293F353900AD1480 /* MXToDevicePayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDBA7EF293F353900AD1480 /* MXToDevicePayload.swift */; }; EDDD90C82901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDDD90C72901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift */; }; @@ -2451,7 +2461,6 @@ 3291D4D31A68FFEB00C3BA41 /* MXFileRoomStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXFileRoomStore.m; sourceTree = ""; }; 3291DC8123DF52E10009732F /* MXRoomCreationParameters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXRoomCreationParameters.h; sourceTree = ""; }; 3291DC8223DF52E10009732F /* MXRoomCreationParameters.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXRoomCreationParameters.m; sourceTree = ""; }; - 32935F60216FA49D00A1BC24 /* MXCurve25519KeyBackupTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXCurve25519KeyBackupTests.m; sourceTree = ""; }; 3293C6FE214BBA4F009B3DDB /* MXPeekingRoomSummary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXPeekingRoomSummary.h; sourceTree = ""; }; 3293C6FF214BBA4F009B3DDB /* MXPeekingRoomSummary.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXPeekingRoomSummary.m; sourceTree = ""; }; 3294FD9922F321B0007F1E60 /* MXServiceTermsRestClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXServiceTermsRestClient.m; sourceTree = ""; }; @@ -3117,7 +3126,7 @@ ED555F58298BB27200C5BD63 /* MXKeysQueryResponseUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXKeysQueryResponseUnitTests.swift; sourceTree = ""; }; ED558067296F0361003443E3 /* MXCryptoMigrationStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationStore.swift; sourceTree = ""; }; ED55806C296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationStoreUnitTests.swift; sourceTree = ""; }; - ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationV2Tests.swift; sourceTree = ""; }; + ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2UnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationV2UnitTests.swift; sourceTree = ""; }; ED5580722970265A003443E3 /* MXCryptoSDKLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoSDKLogger.swift; sourceTree = ""; }; ED55807529709943003443E3 /* MatrixSDKTestsE2EData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixSDKTestsE2EData.swift; sourceTree = ""; }; ED5580782970A879003443E3 /* MatrixSDKTestsData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixSDKTestsData.swift; sourceTree = ""; }; @@ -3176,6 +3185,14 @@ ED8F1D3A2885BB2D00F897E7 /* MXCryptoProtocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXCryptoProtocols.swift; sourceTree = ""; }; ED997855292E2877006B5248 /* MXSessionStartupProgressUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSessionStartupProgressUnitTests.swift; sourceTree = ""; }; EDA2CDD528F5C4230088ACE7 /* MXQRCodeTransactionV2UnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXQRCodeTransactionV2UnitTests.swift; sourceTree = ""; }; + EDA40A0429E9D6BE00C0CAB9 /* MXKeyProviderStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXKeyProviderStub.swift; sourceTree = ""; }; + EDA40A0829E9E2BF00C0CAB9 /* legacy_version2_account.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = legacy_version2_account.realm; sourceTree = ""; }; + EDA40A0929E9E2BF00C0CAB9 /* legacy_verified_account.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = legacy_verified_account.realm; sourceTree = ""; }; + EDA40A0A29E9E2BF00C0CAB9 /* legacy_unverified_account.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = legacy_unverified_account.realm; sourceTree = ""; }; + EDA40A0B29E9E2BF00C0CAB9 /* legacy_deprecated3_account.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = legacy_deprecated3_account.realm; sourceTree = ""; }; + EDA40A0C29E9E2BF00C0CAB9 /* legacy_deprecated1_account.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = legacy_deprecated1_account.realm; sourceTree = ""; }; + EDA40A0D29E9E2BF00C0CAB9 /* archived_encrypted_event */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = archived_encrypted_event; sourceTree = ""; }; + EDA40A0E29E9E2BF00C0CAB9 /* LegacyRealmStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LegacyRealmStore.swift; sourceTree = ""; }; EDA6933F290BA92E00223252 /* MXCryptoMachineUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMachineUnitTests.swift; sourceTree = ""; }; EDAAC41228E2F86800DD89B5 /* MXCryptoSecretStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXCryptoSecretStore.h; sourceTree = ""; }; EDAAC41828E2FCFE00DD89B5 /* MXCryptoSecretStoreV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoSecretStoreV2.swift; sourceTree = ""; }; @@ -3185,10 +3202,8 @@ EDB4209827DF842F0036AF39 /* MXEventFixtures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXEventFixtures.swift; sourceTree = ""; }; EDBCF335281A8AB900ED5044 /* MXSharedHistoryKeyService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXSharedHistoryKeyService.h; sourceTree = ""; }; EDBCF338281A8D3D00ED5044 /* MXSharedHistoryKeyService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXSharedHistoryKeyService.m; sourceTree = ""; }; - EDC2A0E528369E740039F3D6 /* CryptoTests.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CryptoTests.xctestplan; sourceTree = ""; }; EDC8C4072968A993003792C5 /* MXKeysQueryScheduler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXKeysQueryScheduler.swift; sourceTree = ""; }; EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXKeysQuerySchedulerUnitTests.swift; sourceTree = ""; }; - EDCAD250299BF7F40088B4DA /* MXCryptoV2Feature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoV2Feature.swift; sourceTree = ""; }; EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXRoomEventDecryption.swift; sourceTree = ""; }; EDCF802C2941FF220059E774 /* MXCryptoMigrationV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationV2.swift; sourceTree = ""; }; EDD4197D28DCAA5F007F3757 /* MXNativeKeyBackupEngine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXNativeKeyBackupEngine.h; sourceTree = ""; }; @@ -3201,7 +3216,7 @@ EDD578EB2881C38C006739DD /* MXCrossSigningV2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXCrossSigningV2.swift; sourceTree = ""; }; EDD7B74629CB3F1B00548AB4 /* MXCrossSigningInfo_v1 */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = MXCrossSigningInfo_v1; sourceTree = ""; }; EDD7B74729CB3F1B00548AB4 /* MXCrossSigningInfo_v0 */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = MXCrossSigningInfo_v0; sourceTree = ""; }; - EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoV2FactoryTests.swift; sourceTree = ""; }; + EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoV2FactoryUnitTests.swift; sourceTree = ""; }; EDDBA7EF293F353900AD1480 /* MXToDevicePayload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXToDevicePayload.swift; sourceTree = ""; }; EDDD90C72901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MXLegacyCrypto+LegacyCrossSigning.swift"; sourceTree = ""; }; EDE1B13A28B7BEAB000DEEE8 /* MXCrossSigningV2UnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCrossSigningV2UnitTests.swift; sourceTree = ""; }; @@ -3546,7 +3561,6 @@ 322A51B41D9AB15900C8536D /* MXCrypto.h */, 322A51B51D9AB15900C8536D /* MXCrypto.m */, ED47CB6C28523995004FD755 /* MXCryptoV2.swift */, - EDCAD250299BF7F40088B4DA /* MXCryptoV2Feature.swift */, ED5EF151297AB33E00A5ADDA /* MXCryptoV2Factory.swift */, 325D1C251DFECE0D0070B8BF /* MXCrypto_Private.h */, 322A51C51D9BBD3C00C8536D /* MXOlmDevice.h */, @@ -4117,7 +4131,6 @@ 326277F0288BC219009A0508 /* AllWorkingTests.xctestplan */, 3298ABD52637FA3100E40B06 /* AllTests.xctestplan */, 3209682F26396385005D64ED /* AllTestsWithSanitizers.xctestplan */, - EDC2A0E528369E740039F3D6 /* CryptoTests.xctestplan */, 3298ABDC2637FB1900E40B06 /* UnitTests.xctestplan */, 3209683026396385005D64ED /* UnitTestsWithSanitizers.xctestplan */, ); @@ -4376,7 +4389,6 @@ 324DD2BA246C3ADE00377005 /* MXCryptoSecretStorageTests.m */, 322D01C322492B0700150C68 /* MXCryptoShareTests.m */, 322A51D71D9E846800C8536D /* MXCryptoTests.m */, - 32935F60216FA49D00A1BC24 /* MXCurve25519KeyBackupTests.m */, 3A7B8CFD267FCD9B00D9DD96 /* MXDehydrationTests.m */, 3281E89D19E299C000976E1A /* MXErrorUnitTests.m */, B146D4FC21A5C0BC00D8C2C6 /* MXEventScanStoreUnitTests.m */, @@ -5443,7 +5455,7 @@ ED5C95CD2833E85600843D82 /* MXOlmDeviceUnitTests.swift */, ED825F8E29014EDA006A614E /* MXSession+LegacyCrypto.swift */, EDDD90C72901611600B760E0 /* MXLegacyCrypto+LegacyCrossSigning.swift */, - EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryTests.swift */, + EDDB07C9297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift */, ); path = Crypto; sourceTree = ""; @@ -5499,6 +5511,7 @@ ED8F1D312885AC5700F897E7 /* Device+Stub.swift */, ED1FE90A2912E13A0046F722 /* DecryptedEvent+Stub.swift */, EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */, + EDA40A0429E9D6BE00C0CAB9 /* MXKeyProviderStub.swift */, ); path = CryptoMachine; sourceTree = ""; @@ -5577,8 +5590,9 @@ ED55806A296F0E18003443E3 /* Migration */ = { isa = PBXGroup; children = ( + EDA40A0729E9E2BF00C0CAB9 /* LegacyRealmStore */, ED55806B296F0E1D003443E3 /* Data */, - ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift */, + ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2UnitTests.swift */, ); path = Migration; sourceTree = ""; @@ -5789,6 +5803,20 @@ path = Trust; sourceTree = ""; }; + EDA40A0729E9E2BF00C0CAB9 /* LegacyRealmStore */ = { + isa = PBXGroup; + children = ( + EDA40A0829E9E2BF00C0CAB9 /* legacy_version2_account.realm */, + EDA40A0929E9E2BF00C0CAB9 /* legacy_verified_account.realm */, + EDA40A0A29E9E2BF00C0CAB9 /* legacy_unverified_account.realm */, + EDA40A0B29E9E2BF00C0CAB9 /* legacy_deprecated3_account.realm */, + EDA40A0C29E9E2BF00C0CAB9 /* legacy_deprecated1_account.realm */, + EDA40A0D29E9E2BF00C0CAB9 /* archived_encrypted_event */, + EDA40A0E29E9E2BF00C0CAB9 /* LegacyRealmStore.swift */, + ); + path = LegacyRealmStore; + sourceTree = ""; + }; EDB4208E27DF76C60036AF39 /* Data */ = { isa = PBXGroup; children = ( @@ -5932,7 +5960,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 */, @@ -6556,7 +6584,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 */, @@ -6766,7 +6794,6 @@ 3209683326396385005D64ED /* UnitTestsWithSanitizers.xctestplan in Resources */, 3298ABDD2637FB1900E40B06 /* UnitTests.xctestplan in Resources */, 3209683126396385005D64ED /* AllTestsWithSanitizers.xctestplan in Resources */, - EDC2A0E628369E740039F3D6 /* CryptoTests.xctestplan in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -6774,7 +6801,13 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + EDA40A1529E9E2BF00C0CAB9 /* legacy_deprecated3_account.realm in Resources */, + EDA40A1729E9E2BF00C0CAB9 /* legacy_deprecated1_account.realm in Resources */, + EDA40A1329E9E2BF00C0CAB9 /* legacy_unverified_account.realm in Resources */, EDD7B74A29CB3F1B00548AB4 /* MXCrossSigningInfo_v0 in Resources */, + EDA40A1929E9E2BF00C0CAB9 /* archived_encrypted_event in Resources */, + EDA40A0F29E9E2BF00C0CAB9 /* legacy_version2_account.realm in Resources */, + EDA40A1129E9E2BF00C0CAB9 /* legacy_verified_account.realm in Resources */, EDD7B74829CB3F1B00548AB4 /* MXCrossSigningInfo_v1 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -6788,7 +6821,6 @@ 3209683426396385005D64ED /* UnitTestsWithSanitizers.xctestplan in Resources */, 3298ABDE2637FB1900E40B06 /* UnitTests.xctestplan in Resources */, 3209683226396385005D64ED /* AllTestsWithSanitizers.xctestplan in Resources */, - EDC2A0E728369E740039F3D6 /* CryptoTests.xctestplan in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -6796,7 +6828,13 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + EDA40A1629E9E2BF00C0CAB9 /* legacy_deprecated3_account.realm in Resources */, + EDA40A1829E9E2BF00C0CAB9 /* legacy_deprecated1_account.realm in Resources */, + EDA40A1429E9E2BF00C0CAB9 /* legacy_unverified_account.realm in Resources */, EDD7B74B29CB3F1B00548AB4 /* MXCrossSigningInfo_v0 in Resources */, + EDA40A1A29E9E2BF00C0CAB9 /* archived_encrypted_event in Resources */, + EDA40A1029E9E2BF00C0CAB9 /* legacy_version2_account.realm in Resources */, + EDA40A1229E9E2BF00C0CAB9 /* legacy_verified_account.realm in Resources */, EDD7B74929CB3F1B00548AB4 /* MXCrossSigningInfo_v1 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -7184,7 +7222,6 @@ EC2EACFF266625170038B61F /* MXRoomLastMessage.m in Sources */, EDF1B6902876CD2C00BBBCEE /* MXTaskQueue.swift in Sources */, EC8A539525B1BC77004E0802 /* MXUserModel.m in Sources */, - EDCAD251299BF7F40088B4DA /* MXCryptoV2Feature.swift in Sources */, ED5EF14F297AB29F00A5ADDA /* MXEventDecryptionResult+DecryptedEvent.swift in Sources */, 3252DCAF224BE5D40032264F /* MXKeyVerificationManager.m in Sources */, 323E0C5C1A306D7A00A31D73 /* MXEvent.m in Sources */, @@ -7315,7 +7352,7 @@ ED6DABFC28C7542800ECDCB6 /* MXRoomKeyInfoFactory.swift in Sources */, B11556EE230C45C600B2A2CF /* MXIdentityServerRestClient.swift in Sources */, ED5EF145297AB1F200A5ADDA /* MXRoomEventEncryption.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 */, @@ -7429,7 +7466,7 @@ ED7019F72886CA6C00FC31B9 /* VerificationRequestStub.swift in Sources */, ED55807629709943003443E3 /* MatrixSDKTestsE2EData.swift in Sources */, B14EECEE2578FE3F00448735 /* MXAuthenticationSessionUnitTests.swift in Sources */, - ED558070296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift in Sources */, + ED558070296F1BEE003443E3 /* MXCryptoMigrationV2UnitTests.swift in Sources */, ED2DD11D286C4F4400F06731 /* MXCryptoRequestsUnitTests.swift in Sources */, 32832B5D1BCC048300241108 /* MXStoreMemoryStoreTests.m in Sources */, EDB4209927DF842F0036AF39 /* MXEventFixtures.swift in Sources */, @@ -7499,7 +7536,6 @@ 32D5D16323E400A600E3E37C /* MXRoomSummaryTrustTests.m in Sources */, ED28068428F06C6C0070AE9F /* QrCodeStub.swift in Sources */, C61A4AF41E5DD88400442158 /* Dummy.swift in Sources */, - 32935F61216FA49D00A1BC24 /* MXCurve25519KeyBackupTests.m in Sources */, B1F04B162811EFF700103EBE /* MXBeaconAggregationsTests.swift in Sources */, ED8F1D2C2885A80B00F897E7 /* MXDeviceInfoSourceUnitTests.swift in Sources */, 328DDEC11A07E57E008C7DC8 /* MXJSONModelTests.m in Sources */, @@ -7522,6 +7558,7 @@ 329571931B0240CE00ABB3BA /* MXVoIPTests.m in Sources */, ED8F1D322885AC5700F897E7 /* Device+Stub.swift in Sources */, EDE1B13B28B7BEAB000DEEE8 /* MXCrossSigningV2UnitTests.swift in Sources */, + EDA40A1B29E9E2BF00C0CAB9 /* LegacyRealmStore.swift in Sources */, EC746C56274E5197002AD24C /* MXThreadingServiceUnitTests.swift in Sources */, ED8F1D252885A39800F897E7 /* MXCrossSigningInfoSourceUnitTests.swift in Sources */, ED6DAC1E28C79D2000ECDCB6 /* MXUnrequestedForwardedRoomKeyManagerUnitTests.swift in Sources */, @@ -7530,6 +7567,7 @@ 32FCAB4D19E578860049C555 /* MXRestClientTests.m in Sources */, 32C78BA7256D227D008130B1 /* MXCryptoMigrationTests.m in Sources */, ED7019F92886CA6C00FC31B9 /* SasStub.swift in Sources */, + EDA40A0529E9D6BE00C0CAB9 /* MXKeyProviderStub.swift in Sources */, ED21F68528104DA2002FF83D /* MXMegolmEncryptionTests.swift in Sources */, ED44F01A28180F4000452A5D /* MXSharedHistoryKeyManagerUnitTests.swift in Sources */, 322985CB26FAF898001890BC /* MXSession.swift in Sources */, @@ -7539,7 +7577,7 @@ 18C26C4F273C0EB300805154 /* MXPollAggregatorTests.swift in Sources */, ED35652F281153480002BF6A /* MXMegolmSessionDataUnitTests.swift in Sources */, 32EEA83F2603CA140041425B /* MXRestClientExtensionsTests.m in Sources */, - EDDB07CA297EE0A7005249A6 /* MXCryptoV2FactoryTests.swift in Sources */, + EDDB07CA297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift in Sources */, 18121F7A273E6E4200B68ADF /* PollBuilder.swift in Sources */, 18121F7F273E837300B68ADF /* PollModels.swift in Sources */, 32C03CB62123076F00D92712 /* DirectRoomTests.m in Sources */, @@ -7626,7 +7664,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 */, @@ -7768,7 +7806,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 /* MXSessionStartupProgress.swift in Sources */, B14EF2212397E90400758AF0 /* MX3PID.swift in Sources */, 18121F79273E6E4100B68ADF /* PollBuilder.swift in Sources */, @@ -7807,7 +7845,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 */, @@ -7856,7 +7894,6 @@ EC8A53D925B1BCC6004E0802 /* MXThirdPartyProtocolInstance.m in Sources */, EDF1B6912876CD2C00BBBCEE /* MXTaskQueue.swift in Sources */, B14EF2422397E90400758AF0 /* MXDeviceInfo.m in Sources */, - EDCAD252299BF7F40088B4DA /* MXCryptoV2Feature.swift in Sources */, ED5EF150297AB29F00A5ADDA /* MXEventDecryptionResult+DecryptedEvent.swift in Sources */, B14EF2432397E90400758AF0 /* MXIncomingSASTransaction.m in Sources */, B14EF2442397E90400758AF0 /* NSObject+sortedKeys.m in Sources */, @@ -7925,7 +7962,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 */, @@ -7987,7 +8024,7 @@ ED6DABFD28C7542800ECDCB6 /* MXRoomKeyInfoFactory.swift in Sources */, B14EF2782397E90400758AF0 /* MXTransactionCancelCode.m in Sources */, ED5EF146297AB1F200A5ADDA /* MXRoomEventEncryption.swift 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 */, @@ -8024,7 +8061,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 */, @@ -8081,7 +8118,6 @@ B1E09A392397FD7D0057C069 /* MXMyUserTests.m in Sources */, 322985D026FBAE7B001890BC /* TestObserver.swift in Sources */, 3A96CD4A2901512C00F9A5AB /* MXReceiptDataIntegrationTests.swift in Sources */, - B1E09A202397FCE90057C069 /* MXCurve25519KeyBackupTests.m in Sources */, ED7019DD2886C24100FC31B9 /* MXCrossSigningInfoSourceUnitTests.swift in Sources */, ED51943A28462D130006EEC6 /* MXRoomStateUnitTests.swift in Sources */, B1E09A3B2397FD820057C069 /* MXStoreNoStoreTests.m in Sources */, @@ -8101,7 +8137,7 @@ ED7019F82886CA6C00FC31B9 /* VerificationRequestStub.swift in Sources */, ED55807729709943003443E3 /* MatrixSDKTestsE2EData.swift in Sources */, 18121F76273E6D2400B68ADF /* MXPollBuilderTests.swift in Sources */, - ED558071296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift in Sources */, + ED558071296F1BEE003443E3 /* MXCryptoMigrationV2UnitTests.swift in Sources */, B1E09A1A2397FCE90057C069 /* MXAggregatedEditsTests.m in Sources */, B1E09A1F2397FCE90057C069 /* MXAutoDiscoveryTests.m in Sources */, EDB4209A27DF842F0036AF39 /* MXEventFixtures.swift in Sources */, @@ -8194,6 +8230,7 @@ 18937E7D273A5AE500902626 /* MXPollRelationTests.m in Sources */, B1E09A352397FD7D0057C069 /* MXEventTests.m in Sources */, EDE1B13C28B7BEAB000DEEE8 /* MXCrossSigningV2UnitTests.swift in Sources */, + EDA40A1C29E9E2BF00C0CAB9 /* LegacyRealmStore.swift in Sources */, A816248525F60D0300A46F05 /* MXDeviceListOperationsPoolUnitTests.swift in Sources */, EC746C57274E5197002AD24C /* MXThreadingServiceUnitTests.swift in Sources */, ED6DAC1F28C79D2000ECDCB6 /* MXUnrequestedForwardedRoomKeyManagerUnitTests.swift in Sources */, @@ -8202,6 +8239,7 @@ EC116598270FCA8B0089FA56 /* MXBackgroundTaskUnitTests.swift in Sources */, B1E09A322397FD750057C069 /* MXRoomTests.m in Sources */, ED7019FA2886CA6C00FC31B9 /* SasStub.swift in Sources */, + EDA40A0629E9D6BE00C0CAB9 /* MXKeyProviderStub.swift in Sources */, ED21F68628104DA2002FF83D /* MXMegolmEncryptionTests.swift in Sources */, ED44F01B28180F4000452A5D /* MXSharedHistoryKeyManagerUnitTests.swift in Sources */, 322985CC26FAF898001890BC /* MXSession.swift in Sources */, @@ -8211,7 +8249,7 @@ ED7019E12886C26D00FC31B9 /* MXCryptoRequestsUnitTests.swift in Sources */, 18C26C50273C0EB400805154 /* MXPollAggregatorTests.swift in Sources */, ED356530281153480002BF6A /* MXMegolmSessionDataUnitTests.swift in Sources */, - EDDB07CB297EE0A7005249A6 /* MXCryptoV2FactoryTests.swift in Sources */, + EDDB07CB297EE0A7005249A6 /* MXCryptoV2FactoryUnitTests.swift in Sources */, 32C78BA8256D227D008130B1 /* MXCryptoMigrationTests.m in Sources */, 18121F7B273E6E4200B68ADF /* PollBuilder.swift in Sources */, 18121F80273E837400B68ADF /* PollModels.swift in Sources */, diff --git a/MatrixSDK.xcodeproj/xcshareddata/xcschemes/MatrixSDK-macOS.xcscheme b/MatrixSDK.xcodeproj/xcshareddata/xcschemes/MatrixSDK-macOS.xcscheme index 6b26075d7f..4cafc18e35 100644 --- a/MatrixSDK.xcodeproj/xcshareddata/xcschemes/MatrixSDK-macOS.xcscheme +++ b/MatrixSDK.xcodeproj/xcshareddata/xcschemes/MatrixSDK-macOS.xcscheme @@ -64,9 +64,6 @@ - - diff --git a/MatrixSDK/Aggregations/MXAggregations.m b/MatrixSDK/Aggregations/MXAggregations.m index d94b7b9051..6a5c38b918 100644 --- a/MatrixSDK/Aggregations/MXAggregations.m +++ b/MatrixSDK/Aggregations/MXAggregations.m @@ -315,8 +315,6 @@ - (void)registerListener [self.beaconAggregations handleBeaconWithEvent:event]; } break; - case MXEventTypePollEnd: - [self.aggregatedPollsUpdater refreshPollAfter:event]; default: break; } diff --git a/MatrixSDK/Background/MXBackgroundSyncService.swift b/MatrixSDK/Background/MXBackgroundSyncService.swift index 5fe4e5abfb..efb2ad4d1f 100644 --- a/MatrixSDK/Background/MXBackgroundSyncService.swift +++ b/MatrixSDK/Background/MXBackgroundSyncService.swift @@ -67,7 +67,6 @@ public enum MXBackgroundSyncServiceError: Error { /// - Parameter credentials: account credentials public init( withCredentials credentials: MXCredentials, - isCryptoSDKEnabled: Bool = false, persistTokenDataHandler: MXRestClientPersistTokenDataHandler? = nil, unauthenticatedHandler: MXRestClientUnauthenticatedHandler? = nil ) { @@ -90,16 +89,9 @@ public enum MXBackgroundSyncServiceError: Error { self.restClient = restClient store = MXBackgroundStore(withCredentials: credentials) - // We can flush any crypto data if our sync response store is empty - let resetBackgroundCryptoStore = syncResponseStoreManager.syncToken() == nil - if isCryptoSDKEnabled { - MXLog.debug("[MXBackgroundSyncService] init: constructing crypto v2") - crypto = MXBackgroundCryptoV2(credentials: credentials, restClient: restClient) - } else { - MXLog.debug("[MXBackgroundSyncService] init: constructing legacy crypto") - crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore) - } + MXLog.debug("[MXBackgroundSyncService] init: constructing crypto") + crypto = MXBackgroundCryptoV2(credentials: credentials, restClient: restClient) pushRulesManager = MXBackgroundPushRulesManager(withCredentials: credentials) MXLog.debug("[MXBackgroundSyncService] init complete") diff --git a/MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift b/MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift index d46a648376..7abf8b4c9d 100644 --- a/MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift +++ b/MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift @@ -126,7 +126,7 @@ class MXCrossSigningV2: NSObject, MXCrossSigning { // If we are considered verified, there is no need for a verification upgrade // after migrating from legacy crypto if myUserCrossSigningKeys?.trustLevel.isVerified == true { - MXSDKOptions.sharedInstance().cryptoSDKFeature?.needsVerificationUpgrade = false + MXSDKOptions.sharedInstance().cryptoMigrationDelegate?.needsVerificationUpgrade = false } log.debug("Cross signing state refreshed, new state: \(state)") diff --git a/MatrixSDK/Crypto/MXCrypto.m b/MatrixSDK/Crypto/MXCrypto.m index 674347c44e..fc599496f7 100644 --- a/MatrixSDK/Crypto/MXCrypto.m +++ b/MatrixSDK/Crypto/MXCrypto.m @@ -156,12 +156,6 @@ @implementation MXLegacyCrypto __block id crypto; #ifdef MX_CRYPTO - if (MXSDKOptions.sharedInstance.enableCryptoSDK) - { - MXLogFailure(@"[MXCrypto] createCryptoWithMatrixSession: Crypto V2 should not be created directly, use initializeCryptoWithMatrixSession instead"); - return nil; - } - dispatch_queue_t cryptoQueue = [MXLegacyCrypto dispatchQueueForUser:mxSession.matrixRestClient.credentials.userId]; dispatch_sync(cryptoQueue, ^{ @@ -180,22 +174,6 @@ + (void)initializeCryptoWithMatrixSession:(MXSession *)mxSession complete:(void (^)(id crypto, NSError *error))complete { #ifdef MX_CRYPTO - - // Each time we construct the crypto module (app launch, login etc) we have a chance to try to enable - // the newer SDK crypto module, if it is available for this particular user. - [MXSDKOptions.sharedInstance.cryptoSDKFeature enableIfAvailableForUserId:mxSession.myUserId]; - if (MXSDKOptions.sharedInstance.enableCryptoSDK) - { - [MXCryptoV2Factory.shared buildCryptoWithSession:mxSession - migrationProgress:migrationProgress - success:^(id crypto) { - complete(crypto, nil); } - failure:^(NSError *error) { - complete(nil, error); - }]; - return; - } - [self initalizeLegacyCryptoWithMatrixSession:mxSession complete:complete]; #else complete(nil); diff --git a/MatrixSDK/Crypto/MXCryptoV2Factory.swift b/MatrixSDK/Crypto/MXCryptoV2Factory.swift index 4d32bd4495..d910a1dc7a 100644 --- a/MatrixSDK/Crypto/MXCryptoV2Factory.swift +++ b/MatrixSDK/Crypto/MXCryptoV2Factory.swift @@ -16,6 +16,16 @@ import Foundation +/// Delegate for migrating account data from legacy crypto to rust-based Crypto SDK +@objc public protocol MXCryptoV2MigrationDelegate { + + /// Flag indicating whether this account requires a re-verification after migrating to Crypto SDK + /// + /// This flag is set to true if the legacy account is considered verified but the rust account + /// does not consider the migrated data secure enough, as it applies stricter security conditions. + var needsVerificationUpgrade: Bool { get set } +} + @objc public class MXCryptoV2Factory: NSObject { enum Error: Swift.Error { case cryptoNotAvailable @@ -28,6 +38,21 @@ import Foundation .deprecated3 } + @objc public func hasCryptoData(for session: MXSession!) -> Bool { + guard let userId = session?.myUserId else { + log.error("Missing required dependencies") + return false + } + + do { + let url = try MXCryptoMachineStore.storeURL(for: userId) + return FileManager.default.fileExists(atPath: url.path) + } catch { + log.error("Failed creating url for user", context: error) + return false + } + } + @objc public func buildCrypto( session: MXSession!, migrationProgress: ((Double) -> Void)?, @@ -124,7 +149,7 @@ import Foundation // unless the rust-based crypto already considers the current session to be verified given // the migration data log.debug("Needs verification upgrade") - MXSDKOptions.sharedInstance().cryptoSDKFeature?.needsVerificationUpgrade = true + MXSDKOptions.sharedInstance().cryptoMigrationDelegate?.needsVerificationUpgrade = true } } } diff --git a/MatrixSDK/Crypto/MXCryptoV2Feature.swift b/MatrixSDK/Crypto/MXCryptoV2Feature.swift deleted file mode 100644 index 5fc1d4d6de..0000000000 --- a/MatrixSDK/Crypto/MXCryptoV2Feature.swift +++ /dev/null @@ -1,50 +0,0 @@ -// -// Copyright 2023 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 - -/// Feature representing the availability of the external rust-based Crypto SDK -/// whilst it is not fully available to everyone and / or is an optional feature. -@objc public protocol MXCryptoV2Feature { - /// Is Crypto SDK currently enabled - /// - /// By default this value is `false`. Once enabled, it can only be disabled by logging out, - /// as there is no way to migrate from from Crypto SDK back to legacy crypto. - var isEnabled: Bool { get } - - /// Flag indicating whether this account requires a re-verification after migrating to Crypto SDK - /// - /// This flag is set to true if the legacy account is considered verified but the rust account - /// does not consider the migrated data secure enough, as it applies stricter security conditions. - var needsVerificationUpgrade: Bool { get set } - - /// Manually enable the feature - /// - /// This is typically triggered by some user settings / Labs as an experimental feature. Once called - /// it should restart the session to re-initialize the crypto module. - func enable() - - /// Try to enable the feature for a given user - /// - /// This method should only be called when initializing a crypto module (e.g. during app launch or login), - /// as it is not possible to swap out crypto modules whilst a session is active. - /// - /// The availability conditions are implementation details, typically consisting of - /// various feature flags. - /// - /// If available, this method will set `isEnabled` permanently to `true`. - func enableIfAvailable(forUserId userId: String!) -} diff --git a/MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m b/MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m index cf9dabcaad..300ab9934a 100644 --- a/MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m +++ b/MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m @@ -142,8 +142,6 @@ - (void)initialiseState:(NSArray *)stateEvents - (void)destroy { - [room.mxSession resetReplayAttackCheckInTimeline:_timelineId]; - if (httpOperation) { // Cancel the current server request @@ -190,8 +188,6 @@ - (BOOL)canPaginate:(MXTimelineDirection)direction - (void)resetPagination { - [room.mxSession resetReplayAttackCheckInTimeline:_timelineId]; - // Reset the back state to the current room state backState = [[MXRoomState alloc] initBackStateWith:_state]; @@ -203,8 +199,6 @@ - (MXHTTPOperation *)resetPaginationAroundInitialEventWithLimit:(NSUInteger)limi { NSParameterAssert(success); NSAssert(_initialEventId, @"[MXRoomEventTimeline] resetPaginationAroundInitialEventWithLimit cannot be called on live timeline"); - - [room.mxSession resetReplayAttackCheckInTimeline:_timelineId]; // Reset the store if (!store.isPermanent) diff --git a/MatrixSDK/Data/EventTimeline/Thread/MXThreadEventTimeline.swift b/MatrixSDK/Data/EventTimeline/Thread/MXThreadEventTimeline.swift index b5fada9a90..f3b0c1e380 100644 --- a/MatrixSDK/Data/EventTimeline/Thread/MXThreadEventTimeline.swift +++ b/MatrixSDK/Data/EventTimeline/Thread/MXThreadEventTimeline.swift @@ -99,8 +99,6 @@ public class MXThreadEventTimeline: NSObject, MXEventTimeline { } public func destroy() { - thread.session?.resetReplayAttackCheck(inTimeline: timelineId) - removeAllListeners() currentHttpOperation?.cancel() @@ -132,8 +130,6 @@ public class MXThreadEventTimeline: NSObject, MXEventTimeline { } public func resetPagination() { - thread.session?.resetReplayAttackCheck(inTimeline: timelineId) - // Reset store pagination storeMessagesEnumerator = store.messagesEnumerator(forRoom: thread.roomId) @@ -150,8 +146,6 @@ public class MXThreadEventTimeline: NSObject, MXEventTimeline { fatalError("[MXThreadEventTimeline][\(timelineId)] resetPaginationAroundInitialEventWithLimit cannot be called on live timeline") } - thread.session?.resetReplayAttackCheck(inTimeline: timelineId) - // Reset the store if !store.isPermanent { store.deleteAllData() diff --git a/MatrixSDK/Data/MXRoom.m b/MatrixSDK/Data/MXRoom.m index 020af712d3..b626989f0b 100644 --- a/MatrixSDK/Data/MXRoom.m +++ b/MatrixSDK/Data/MXRoom.m @@ -82,11 +82,6 @@ The list of room operations (sending of text, images...) that must be sent FIFO queue of failure blocks waiting for [self members:]. */ NSMutableArray *pendingMembersFailureBlocks; - - /** - The manager for sharing keys of messages with invited users - */ - MXSharedHistoryKeyManager *sharedHistoryKeyManager; } @end @@ -123,14 +118,6 @@ - (id)initWithRoomId:(NSString *)roomId matrixSession:(MXSession *)mxSession2 an { _roomId = roomId; mxSession = mxSession2; - - if ([mxSession.crypto isKindOfClass:[MXLegacyCrypto class]]) - { - MXMegolmDecryption *decryption = [[MXMegolmDecryption alloc] initWithCrypto:mxSession.crypto]; - sharedHistoryKeyManager = [[MXSharedHistoryKeyManager alloc] initWithRoomId:roomId - crypto:mxSession.crypto - service:decryption]; - } if (store) { @@ -1977,24 +1964,9 @@ - (MXHTTPOperation*)inviteUser:(NSString*)userId success:(void (^)(void))success failure:(void (^)(NSError *error))failure { - if (MXSDKOptions.sharedInstance.enableRoomSharedHistoryOnInvite) - { - [self shareRoomKeysWith:userId]; - } return [mxSession.matrixRestClient inviteUser:userId toRoom:self.roomId success:success failure:failure]; } -- (void)shareRoomKeysWith:(NSString *)userId -{ - // The value of 20 is arbitrary and imprecise, we merely want to ensure that when a user is invited to a room - // they are able to read any immediately preciding messages that may be relevant to the invite. - NSInteger numberOfSharedMessage = 20; - id enumerator = [self enumeratorForStoredMessagesWithTypeIn:@[kMXEventTypeStringRoomMessage]]; - [sharedHistoryKeyManager shareMessageKeysWithUserId:userId - messageEnumerator:enumerator - limit:numberOfSharedMessage]; -} - - (MXHTTPOperation*)inviteUserByEmail:(NSString*)email success:(void (^)(void))success failure:(void (^)(NSError *error))failure diff --git a/MatrixSDK/MXSDKOptions.h b/MatrixSDK/MXSDKOptions.h index 929b183655..e4f82bdba1 100644 --- a/MatrixSDK/MXSDKOptions.h +++ b/MatrixSDK/MXSDKOptions.h @@ -48,7 +48,7 @@ typedef NS_ENUM(NSUInteger, MXCallTransferType) NS_ASSUME_NONNULL_BEGIN -@protocol MXBackgroundModeHandler, MXCryptoV2Feature; +@protocol MXBackgroundModeHandler, MXCryptoV2MigrationDelegate; /** SDK options that can be set at the launch time. @@ -204,23 +204,11 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) BOOL enableRoomSharedHistoryOnInvite; /** - An object which controls the availabilty of the rust-based `MatrixCryptoSDK`. + The delegate for migrating account data from legacy crypto to rust-based Crypto SDK - @remark nil by default. - */ -@property (nonatomic, nullable) id cryptoSDKFeature; - -/** - Use the rust-based `MatrixCryptoSDK` instead of `MatrixSDK`'s internal crypto module. - - @remark this property is a convenience getter for `cryptoSDKFeature.isEnabled` - */ -@property (nonatomic, readonly) BOOL enableCryptoSDK; - -/** - The text-based identifier for the crypto module being used (e.g. native vs rust) + By default, nil. */ -@property (nonatomic, readonly) NSString *cryptoModuleId; +@property (nonatomic, nullable, weak) id cryptoMigrationDelegate; /** Enable symmetric room key backups @@ -236,14 +224,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic) BOOL enableNewClientInformationFeature; -/** - Enable the calculating and display of progress during session startup, incl store migration, - syncing and response processing. - - @remark YES by default - */ -@property (nonatomic) BOOL enableStartupProgress; - @end NS_ASSUME_NONNULL_END diff --git a/MatrixSDK/MXSDKOptions.m b/MatrixSDK/MXSDKOptions.m index f9acfda590..d1f9f103ab 100644 --- a/MatrixSDK/MXSDKOptions.m +++ b/MatrixSDK/MXSDKOptions.m @@ -56,27 +56,12 @@ - (instancetype)init _enableRoomSharedHistoryOnInvite = NO; _enableSymmetricBackup = NO; _enableNewClientInformationFeature = NO; - _enableStartupProgress = YES; + _cryptoMigrationDelegate = nil; } return self; } -- (BOOL)enableCryptoSDK -{ - if (!self.cryptoSDKFeature) - { - MXLogError(@"[MXSDKOptions] enableCryptoSDK: Crypto SDK feature is not configured"); - return NO; - } - return self.cryptoSDKFeature.isEnabled; -} - -- (NSString *)cryptoModuleId -{ - return self.enableCryptoSDK ? @"rust" : @"native"; -} - - (void)setRoomListDataManagerClass:(Class)roomListDataManagerClass { // Sanity check diff --git a/MatrixSDK/MXSession.h b/MatrixSDK/MXSession.h index a9ce329a02..bfcb723119 100644 --- a/MatrixSDK/MXSession.h +++ b/MatrixSDK/MXSession.h @@ -1596,14 +1596,6 @@ typedef void (^MXOnBackgroundSyncFail)(NSError *error); inTimeline:(NSString*)timeline onComplete:(void (^)(NSArray *failedEvents))onComplete; -/** - Reset replay attack data for the given timeline. - - @param timeline the id of the timeline. - */ -- (void)resetReplayAttackCheckInTimeline:(NSString*)timeline; - - #pragma mark - Global events listeners /** Register a global listener to events related to the current session. diff --git a/MatrixSDK/MXSession.m b/MatrixSDK/MXSession.m index 051b41d122..7f4ae3d2e5 100644 --- a/MatrixSDK/MXSession.m +++ b/MatrixSDK/MXSession.m @@ -312,10 +312,7 @@ - (id)initWithMatrixRestClient:(MXRestClient*)mxRestClient _homeserverCapabilitiesService = [[MXHomeserverCapabilitiesService alloc] initWithSession: self]; [_homeserverCapabilitiesService updateWithCompletion:nil]; - if (MXSDKOptions.sharedInstance.enableStartupProgress) - { - _startupProgress = [[MXSessionStartupProgress alloc] init]; - } + _startupProgress = [[MXSessionStartupProgress alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDidDecryptEvent:) name:kMXEventDidDecryptNotification object:nil]; @@ -398,24 +395,12 @@ -(void)setStore:(id)store success:(void (^)(void))onStoreDataReady fail // Check if the user has enabled crypto MXWeakify(self); - [MXLegacyCrypto initializeCryptoWithMatrixSession:self migrationProgress:^(double progress) { - if (MXSDKOptions.sharedInstance.enableStartupProgress) - { - [self.startupProgress updateProgressForStage:MXSessionStartupStageStoreMigration progress:progress]; - } + [self initializeCryptoWithProgress:^(double progress) { + [self.startupProgress updateProgressForStage:MXSessionStartupStageStoreMigration progress:progress]; - } complete:^(id crypto, NSError *error) { + } success:^(id crypto) { MXStrongifyAndReturnIfNil(self); - if (!crypto && error) - { - if (failure) - { - failure(error); - } - return; - } - self->_crypto = crypto; // Sanity check: The session may be closed before the end of this operation. @@ -539,6 +524,11 @@ -(void)setStore:(id)store success:(void (^)(void))onStoreDataReady fail // The SDK client can use this data onStoreDataReady(); } + } failure:^(NSError *error) { + if (failure) + { + failure(error); + } }]; } failure:^(NSError *error) { @@ -551,6 +541,34 @@ -(void)setStore:(id)store success:(void (^)(void))onStoreDataReady fail }]; } +- (void)initializeCryptoWithProgress:(void (^)(double))progress + success:(void (^)(id crypto))success + failure:(void (^)(NSError *error))failure +{ + BOOL enableCrypto = [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession || [MXCryptoV2Factory.shared hasCryptoDataFor:self]; + if (!enableCrypto) + { + MXLogWarning(@"[MXSession] initializeCrypto: Not starting crypto automatically due to SDK settings"); + dispatch_async(dispatch_get_main_queue(), ^{ + success(nil); + }); + return; + } + + [MXCryptoV2Factory.shared buildCryptoWithSession:self + migrationProgress:progress + success:^(id crypto) { + + MXLogDebug(@"[MXSession] initializeCrypto: Successfully initialized crypto module"); + success(crypto); + + } failure:^(NSError *error) { + + MXLogErrorDetails(@"[MXSession] initializeCrypto: Error initialized crypto module", error); + failure(error); + }]; +} + - (void)setRoomListDataManager:(id)roomListDataManager { NSParameterAssert(_roomListDataManager == nil); @@ -574,7 +592,7 @@ - (void)handleSyncResponse:(MXSyncResponse *)syncResponse // Check whether this is the initial sync BOOL isInitialSync = !self.isEventStreamInitialised; - [self handleCryptoSyncResponse:syncResponse onComplete:^{ + [self handleCryptoEventsInSyncResponse:syncResponse onComplete:^{ dispatch_group_t dispatchGroup = dispatch_group_create(); @@ -591,7 +609,7 @@ - (void)handleSyncResponse:(MXSyncResponse *)syncResponse void(^dispatch_group_leave_with_progress)(dispatch_group_t) = ^(dispatch_group_t dispatchGroup) { dispatch_group_leave(dispatchGroup); - if (MXSDKOptions.sharedInstance.enableStartupProgress && progress) + if (progress) { progress([self.startupProgress overallProgressForStep:completedRooms totalCount:totalRooms progress:1]); completedRooms += 1; @@ -778,30 +796,6 @@ - (void)handleSyncResponse:(MXSyncResponse *)syncResponse // Sync point: wait that all rooms in the /sync response have been loaded // and their /sync response has been processed dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{ - - // Legacy crypto requires that we deal with device list changes, OTKs etc at the end of the sync loop. - // This will be removed altogether with `MXLegacyCrypto` - if ([self.crypto isKindOfClass:[MXLegacyCrypto class]]) - { - // Handle device list updates - if (syncResponse.deviceLists) - { - [(MXLegacyCrypto *)self.crypto handleDeviceListsChanges:syncResponse.deviceLists]; - } - - // Handle one_time_keys_count - if (syncResponse.deviceOneTimeKeysCount) - { - [(MXLegacyCrypto *)self.crypto handleDeviceOneTimeKeysCount:syncResponse.deviceOneTimeKeysCount]; - } - - [(MXLegacyCrypto *)self.crypto handleDeviceUnusedFallbackKeys:syncResponse.unusedFallbackKeys]; - - // Tell the crypto module to do its processing - [(MXLegacyCrypto *)self.crypto onSyncCompleted:self.store.eventStreamToken - nextSyncToken:syncResponse.nextBatch - catchingUp:self.catchingUp]; - } // Update live event stream token MXLogDebug(@"[MXSession] Next sync token: %@", syncResponse.nextBatch); @@ -1458,7 +1452,7 @@ - (void)serverSyncWithServerTimeout:(NSUInteger)serverTimeout setPresence:(NSString*)setPresence { // We only want to report sync progress when doing initial sync - BOOL shoulReportStartupProgress = MXSDKOptions.sharedInstance.enableStartupProgress && !self.isEventStreamInitialised; + BOOL shoulReportStartupProgress = !self.isEventStreamInitialised; if (shoulReportStartupProgress) { // There is no way to track percentage progress when syncing with the server, so we always use 0% @@ -1994,7 +1988,6 @@ - (void)handleAccountData:(NSDictionary*)accountDataUpdate } } - [self validateAccountData]; self.store.userAccountData = _accountData.accountData; // Trigger a global notification for the account data update @@ -2007,27 +2000,6 @@ - (void)handleAccountData:(NSDictionary*)accountDataUpdate } } -/** - Private method to validate local account data and report any potential state corruption - */ -- (void)validateAccountData -{ - if (![self.crypto isKindOfClass:[MXLegacyCrypto class]]) - { - return; - } - - // Detecting an issue in legacy crypto where more than one valid SSSS key is present on the client - // https://github.com/vector-im/element-ios/issues/4569 - NSInteger keysCount = ((MXLegacyCrypto *)self.crypto).secretStorage.numberOfValidKeys; - if (keysCount > 1) - { - MXLogErrorDetails(@"[MXSession] validateAccountData: Detected multiple valid SSSS keys, should only have one at most", @{ - @"count": @(keysCount) - }); - } -} - - (void)updateSummaryDirectUserIdForRooms:(NSSet *)roomIds { // If the initial sync response is not processed enough, rooms is not yet mounted. @@ -2052,95 +2024,15 @@ - (void)updateSummaryDirectUserIdForRooms:(NSSet *)roomIds } } -// Temporary junction to deal with sync response depending on the variant of crypto -// that cannot be easily hidden behind a protocol. Legacy implementation will eventually -// be fully removed. -- (void)handleCryptoSyncResponse:(MXSyncResponse *)syncResponse - onComplete:(void (^)(void))onComplete -{ - if (!self.crypto || [self.crypto isKindOfClass:[MXLegacyCrypto class]]) - { - // Legacy crypto requires pre-processed to-device events before everything else to make future decryptions work - [self handleToDeviceEvents:syncResponse.toDevice.events onComplete:onComplete]; - } - else - { - // New and all future crypto modules can handle the entire sync response in full - [self.crypto handleSyncResponse:syncResponse onComplete:onComplete]; - } -} - -- (void)handleToDeviceEvents:(NSArray *)events onComplete:(void (^)(void))onComplete +- (void)handleCryptoEventsInSyncResponse:(MXSyncResponse *)syncResponse onComplete:(void (^)(void))onComplete { - NSMutableArray *supportedEvents = [NSMutableArray arrayWithCapacity:events.count]; - for (MXEvent *event in events) - { - if ([MXTools isSupportedToDeviceEvent:event]) - { - MXLogDebug(@"[MXSession] handleToDeviceEvents: Processing new to-device event msgid: %@", event.content[kMXToDeviceMessageId]) - [supportedEvents addObject:event]; - } - } - - if (supportedEvents.count == 0) + if (!self.crypto) { onComplete(); return; } - [self decryptEvents:supportedEvents inTimeline:nil onComplete:^(NSArray *failedEvents) { - dispatch_group_t dispatchGroup = dispatch_group_create(); - - for (MXEvent *event in supportedEvents) - { - if (!event.decryptionError) - { - MXLogDebug(@"[MXSession] handleToDeviceEvents: Received new to-device event `%@` from `%@` msgid: %@", event.type, event.sender, event.wireContent[kMXToDeviceMessageId]) - dispatch_group_enter(dispatchGroup); - [self handleToDeviceEvent:event onComplete:^{ - dispatch_group_leave(dispatchGroup); - }]; - } - else - { - MXLogDebug(@"[MXSession] handleToDeviceEvents: Warning: Unable to decrypt to-device event: %@\nError: %@", event.wireContent[kMXMessageBodyKey], event.decryptionError); - } - } - - dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{ - onComplete(); - }); - }]; -} - -- (void)handleToDeviceEvent:(MXEvent *)event onComplete:(void (^)(void))onComplete -{ - void (^onHandleToDeviceEventDone)(void) = ^(void) { - [[NSNotificationCenter defaultCenter] postNotificationName:kMXSessionOnToDeviceEventNotification - object:self - userInfo:@{ - kMXSessionNotificationEventKey: event - }]; - - onComplete(); - }; - - switch (event.eventType) - { - case MXEventTypeRoomKey: - { - if ([_crypto isKindOfClass:[MXLegacyCrypto class]]) - { - [(MXLegacyCrypto *)_crypto handleRoomKeyEvent:event onComplete:onHandleToDeviceEventDone]; - } - break; - } - - default: - onHandleToDeviceEventDone(); - break; - } - [_eventStreamService dispatchOnLiveToDeviceWithEvent:event]; + [self.crypto handleSyncResponse:syncResponse onComplete:onComplete]; } /** @@ -2221,17 +2113,10 @@ - (void)handleBackgroundSyncCacheIfRequiredWithCompletion:(void (^)(void))comple [asyncTaskQueue asyncWithExecute:^(void (^ taskCompleted)(void)) { [syncResponseStoreManager mergedSyncResponseFromSyncResponseIds:outdatedSyncResponseIds completion:^(MXCachedSyncResponse * _Nullable outdatedCachedSyncResponse) { - if (outdatedCachedSyncResponse) - { - [self handleOutdatedSyncResponse:outdatedCachedSyncResponse.syncResponse - completion:^{ - taskCompleted(); - }]; - } - else - { + // There is no need to handle `outdatedCachedSyncResponse` manually anymore, ignoring the result + dispatch_async(dispatch_get_main_queue(), ^{ taskCompleted(); - } + }); }]; }]; @@ -2280,26 +2165,6 @@ - (void)handleBackgroundSyncCacheIfRequiredWithCompletion:(void (^)(void))comple }]; } -- (void)handleOutdatedSyncResponse:(MXSyncResponse *)syncResponse - completion:(void (^)(void))completion -{ - MXLogDebug(@"[MXSession] handleOutdatedSyncResponse: %tu joined rooms, %tu invited rooms, %tu left rooms, %tu toDevice events.", syncResponse.rooms.join.count, syncResponse.rooms.invite.count, syncResponse.rooms.leave.count, syncResponse.toDevice.events.count); - - if (!self.crypto || [self.crypto isKindOfClass:[MXLegacyCrypto class]]) - { - // Legacy crypto requires pre-processed to-device events before everything else to make future decryptions work - [self handleToDeviceEvents:syncResponse.toDevice.events onComplete:completion]; - } - else - { - // Only legacy crypto requires different DBs for foreground and background processes, other crypto modules - // write to a single DB in both processes, so there is no need to replay outdated sync response - dispatch_async(dispatch_get_main_queue(), ^{ - completion(); - }); - } -} - #pragma mark - Options - (void)enableVoIPWithCallStack:(id)callStack { @@ -2315,32 +2180,38 @@ - (void)enableCrypto:(BOOL)enableCrypto success:(void (^)(void))success failure: if (enableCrypto && !_crypto) { - NSError *error; - _crypto = [MXLegacyCrypto createCryptoWithMatrixSession:self error:&error]; - if (!_crypto && error) - { - if (failure) + MXWeakify(self); + [MXCryptoV2Factory.shared buildCryptoWithSession:self + migrationProgress:nil + success:^(id crypto) { + + MXLogDebug(@"[MXSession] enableCrypto: Successfully initialized crypto module"); + MXStrongifyAndReturnIfNil(self); + self->_crypto = crypto; + + if (self->_state == MXSessionStateRunning) { - failure(error); + [self startCrypto:success failure:failure]; } - return; - } - - if (_state == MXSessionStateRunning) - { - [self startCrypto:success failure:failure]; - } - else - { - MXLogDebug(@"[MXSesion] enableCrypto: crypto module will be start later (MXSession.state: %@)", [MXTools readableSessionState:_state]); + else + { + MXLogDebug(@"[MXSesion] enableCrypto: crypto module will be start later (MXSession.state: %@)", [MXTools readableSessionState:self->_state]); - if (success) + if (success) + { + dispatch_async(dispatch_get_main_queue(), ^{ + success(); + }); + } + } + + } failure:^(NSError *error) { + MXLogErrorDetails(@"[MXSession] enableCrypto: Error initialized crypto module", error); + if (failure) { - dispatch_async(dispatch_get_main_queue(), ^{ - success(); - }); + failure(error); } - } + }]; } else if (!enableCrypto && _crypto) { @@ -3199,6 +3070,8 @@ - (void)removeRoom:(NSString *)roomId // And remove the room and its summary from the list [rooms removeObjectForKey:roomId]; [roomSummaries removeObjectForKey:roomId]; + // Remove room from breadcrub list + [self removeBreadcrumbWithRoomWithId:roomId success:nil failure:nil]; // Broadcast the left room [[NSNotificationCenter defaultCenter] postNotificationName:kMXSessionDidLeaveRoomNotification @@ -3415,7 +3288,7 @@ - (void)fixRoomsSummariesLastMessageWithMaxServerPaginationCount:(NSUInteger)max __block NSInteger completedRooms = 0; void(^dispatch_group_leave_with_progress)(dispatch_group_t) = ^(dispatch_group_t dispatchGroup) { dispatch_group_leave(dispatchGroup); - if (MXSDKOptions.sharedInstance.enableStartupProgress && progress) + if (progress) { progress([self.startupProgress overallProgressForStep:completedRooms totalCount:self.rooms.count progress:1]); completedRooms += 1; @@ -4758,6 +4631,43 @@ - (void)updateBreadcrumbsWithRoomWithId:(NSString *)roomId }]; } +// Update breadcrub list when leaving a room +- (void)removeBreadcrumbWithRoomWithId:(NSString *)roomId + success:(void (^)(void))success + failure:(void (^)(NSError *error))failure +{ + NSDictionary *breadcrumbs = [self.accountData accountDataForEventType:kMXAccountDataTypeBreadcrumbs]; + + NSMutableArray *recentRoomIds = breadcrumbs[kMXAccountDataTypeRecentRoomsKey] ? [NSMutableArray arrayWithArray:breadcrumbs[kMXAccountDataTypeRecentRoomsKey]] : [NSMutableArray array]; + + NSInteger index = [recentRoomIds indexOfObject:roomId]; + if (index != NSNotFound) + { + [recentRoomIds removeObjectAtIndex:index]; + + [self setAccountData:@{kMXAccountDataTypeRecentRoomsKey : recentRoomIds} + forType:kMXAccountDataTypeBreadcrumbs + success:^{ + if (success) + { + success(); + } + } failure:^(NSError *error) { + if (failure) + { + failure(error); + } + }]; + } + else + { + if (success) + { + success(); + } + } +} + #pragma mark - Homeserver information - (MXWellKnown *)homeserverWellknown { @@ -5056,14 +4966,6 @@ - (void)decryptEvents:(NSArray *)events } } -- (void)resetReplayAttackCheckInTimeline:(NSString*)timeline -{ - if ([_crypto isKindOfClass:[MXLegacyCrypto class]]) - { - [(MXLegacyCrypto *)_crypto resetReplayAttackCheckInTimeline:timeline]; - } -} - // Called when an event finally got decrypted after a late room key reception - (void)onDidDecryptEvent:(NSNotification *)notification { diff --git a/MatrixSDK/MatrixSDKVersion.m b/MatrixSDK/MatrixSDKVersion.m index b65d29446d..89c6965f4d 100644 --- a/MatrixSDK/MatrixSDKVersion.m +++ b/MatrixSDK/MatrixSDKVersion.m @@ -16,4 +16,4 @@ #import -NSString *const MatrixSDKVersion = @"0.26.9"; +NSString *const MatrixSDKVersion = @"0.26.10"; diff --git a/MatrixSDK/Room/Polls/PollAggregator.swift b/MatrixSDK/Room/Polls/PollAggregator.swift index 85dadc1a74..63ded7ae1d 100644 --- a/MatrixSDK/Room/Polls/PollAggregator.swift +++ b/MatrixSDK/Room/Polls/PollAggregator.swift @@ -54,7 +54,7 @@ public class PollAggregator { private var events: [MXEvent] = [] private var hasBeenEdited = false - public private(set) var poll: PollProtocol! { + public private(set) var poll: PollProtocol? { didSet { delegate?.pollAggregatorDidUpdateData(self) } @@ -88,10 +88,10 @@ public class PollAggregator { throw PollAggregatorError.invalidPollStartEvent } - try self.init(session: session, room: room, pollStartEventId: pollStartEventId, delegate: delegate) + self.init(session: session, room: room, pollStartEventId: pollStartEventId, delegate: delegate) } - public init(session: MXSession, room: MXRoom, pollStartEventId: String, delegate: PollAggregatorDelegate? = nil) throws { + public init(session: MXSession, room: MXRoom, pollStartEventId: String, delegate: PollAggregatorDelegate? = nil) { self.session = session self.room = room self.pollStartEventId = pollStartEventId @@ -100,7 +100,9 @@ public class PollAggregator { NotificationCenter.default.addObserver(self, selector: #selector(handleRoomDataFlush), name: .mxRoomDidFlushData, object: self.room) setupEditListener() - try buildPollStartContent() + buildPollStartContent() + + reloadPollData() } private func setupEditListener() { @@ -111,34 +113,35 @@ public class PollAggregator { return } - do { - try self.buildPollStartContent() - } catch { - self.delegate?.pollAggregator(self, didFailWithError: PollAggregatorError.invalidPollStartEvent) - } + self.buildPollStartContent() } } - private func buildPollStartContent() throws { - guard let event = session.store.event(withEventId: pollStartEventId, inRoom: room.roomId), - let eventContent = MXEventContentPollStart(fromJSON: event.content), - eventContent.answerOptions.count >= Constants.minAnswerOptionCount + private func buildPollStartContent() { + let event = session.store.event(withEventId: pollStartEventId, inRoom: room.roomId) + tryUpdatePollStartedEvent(with: event) + if let pollStartedEvent = pollStartedEvent { + poll = pollBuilder.build(pollStartEventContent: pollStartEventContent, + pollStartEvent: pollStartedEvent, + events: events, + currentUserIdentifier: session.myUserId, + hasBeenEdited: hasBeenEdited) + } + } + + private func tryUpdatePollStartedEvent(with event: MXEvent?) { + guard + let event = event, + let eventContent = MXEventContentPollStart(fromJSON: event.content), + eventContent.answerOptions.count >= Constants.minAnswerOptionCount else { - throw PollAggregatorError.invalidPollStartEvent + delegate?.pollAggregator(self, didFailWithError: PollAggregatorError.invalidPollStartEvent) + return } pollStartedEvent = event pollStartEventContent = eventContent - hasBeenEdited = (event.unsignedData.relations?.replace != nil) - - poll = pollBuilder.build(pollStartEventContent: eventContent, - pollStartEvent: pollStartedEvent, - events: events, - currentUserIdentifier: session.myUserId, - hasBeenEdited: hasBeenEdited) - - reloadPollData() } @objc private func handleRoomDataFlush(sender: Notification) { @@ -157,8 +160,12 @@ public class PollAggregator { return } - self.events.removeAll() + self.tryUpdatePollStartedEvent(with: response.originalEvent) + if self.pollStartedEvent == nil { + return + } + self.events.removeAll() self.events.append(contentsOf: response.chunk) let eventTypes = [kMXEventTypeStringPollResponse, kMXEventTypeStringPollResponseMSC3381, kMXEventTypeStringPollEnd, kMXEventTypeStringPollEndMSC3381] @@ -179,7 +186,7 @@ public class PollAggregator { currentUserIdentifier: self.session.myUserId, hasBeenEdited: self.hasBeenEdited) } as Any - + self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent, pollStartEvent: self.pollStartedEvent, events: self.events, diff --git a/MatrixSDKTests/Crypto/CrossSigning/MXCrossSigningV2UnitTests.swift b/MatrixSDKTests/Crypto/CrossSigning/MXCrossSigningV2UnitTests.swift index 2de42cdb8c..fd5fcc2fee 100644 --- a/MatrixSDKTests/Crypto/CrossSigning/MXCrossSigningV2UnitTests.swift +++ b/MatrixSDKTests/Crypto/CrossSigning/MXCrossSigningV2UnitTests.swift @@ -217,3 +217,15 @@ private extension MXCrossSigningV2 { } } } + +private extension MXCrossSigning { + func refreshState() async throws { + return try await withCheckedThrowingContinuation { continuation in + refreshState { _ in + continuation.resume() + } failure: { error in + continuation.resume(throwing: error) + } + } + } +} diff --git a/MatrixSDKTests/Crypto/CryptoMachine/MXKeyProviderStub.swift b/MatrixSDKTests/Crypto/CryptoMachine/MXKeyProviderStub.swift new file mode 100644 index 0000000000..73b7781fdd --- /dev/null +++ b/MatrixSDKTests/Crypto/CryptoMachine/MXKeyProviderStub.swift @@ -0,0 +1,31 @@ +// +// Copyright 2023 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 + +class MXKeyProviderStub: NSObject, MXKeyProviderDelegate { + func isEncryptionAvailableForData(ofType dataType: String) -> Bool { + return true + } + + func hasKeyForData(ofType dataType: String) -> Bool { + return true + } + + func keyDataForData(ofType dataType: String) -> MXKeyData? { + MXRawDataKey(key: "1234".data(using: .ascii)!) + } +} diff --git a/MatrixSDKTests/Crypto/MXCryptoV2FactoryTests.swift b/MatrixSDKTests/Crypto/MXCryptoV2FactoryTests.swift deleted file mode 100644 index 2e1867afc7..0000000000 --- a/MatrixSDKTests/Crypto/MXCryptoV2FactoryTests.swift +++ /dev/null @@ -1,144 +0,0 @@ -// -// Copyright 2023 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 - -class MXCryptoV2FactoryTests: XCTestCase { - class KeyProvider: NSObject, MXKeyProviderDelegate { - func isEncryptionAvailableForData(ofType dataType: String) -> Bool { - return true - } - - func hasKeyForData(ofType dataType: String) -> Bool { - return true - } - - func keyDataForData(ofType dataType: String) -> MXKeyData? { - MXRawDataKey(key: "1234".data(using: .ascii)!) - } - } - - var data: MatrixSDKTestsData! - var e2eData: MatrixSDKTestsE2EData! - var factory: MXCryptoV2Factory! - - override func setUp() { - data = .init() - e2eData = .init(matrixSDKTestsData: data) - factory = MXCryptoV2Factory() - MXKeyProvider.sharedInstance().delegate = KeyProvider() - } - - override func tearDown() { - MXKeyProvider.sharedInstance().delegate = nil - } - - private func buildCrypto(session: MXSession) async throws -> (MXCrypto?, Bool) { - try await withCheckedThrowingContinuation { cont in - var hasMigrated = false - factory.buildCrypto( - session: session) { _ in - hasMigrated = true - } success: { - cont.resume(returning: ($0, hasMigrated)) - } failure: { - cont.resume(throwing: $0) - } - } - } - - func test_doesNotMigrateNewUser() async throws { - let env = try await e2eData.startE2ETest() - let session = env.session - - // Simulating new user as one without a crypto database - MXRealmCryptoStore.delete(with: session.credentials) - - // Build crypto and assert no migration has been performed - let (crypto, hasMigrated) = try await buildCrypto(session: session) - XCTAssertNotNil(crypto) - XCTAssertFalse(hasMigrated) - - // Assert that we have not created any legacy store for this user - let legacyStore = MXRealmCryptoStore.init(credentials: session.credentials) - XCTAssertNil(legacyStore) - - await env.close() - } - - func test_fullyMigratesLegacyUser() async throws { - let env = try await e2eData.startE2ETest() - let session = env.session - var legacyStore = session.legacyCrypto?.store - - // Assert that we have a legacy store that has not yet been deprecated - XCTAssertNotNil(legacyStore) - XCTAssertEqual(legacyStore?.cryptoVersion, .version2) - - // Build crypto and assert migration has been performed - let (crypto, hasMigrated) = try await buildCrypto(session: session) - XCTAssertNotNil(crypto) - XCTAssertTrue(hasMigrated) - - // Assert that we no longer have a legacy store for this user - legacyStore = MXRealmCryptoStore(credentials: session.credentials) - XCTAssertNil(legacyStore) - - await env.close() - } - - func test_migratesPartiallyMigratedUser() async throws { - let env = try await e2eData.startE2ETest() - let session = env.session - - // We set the legacy store as partially deprecated - var legacyStore = session.legacyCrypto?.store - XCTAssertNotNil(legacyStore) - legacyStore?.cryptoVersion = .deprecated1 - - // Build crypto and assert migration has been performed - let (crypto, hasMigrated) = try await buildCrypto(session: session) - XCTAssertNotNil(crypto) - XCTAssertTrue(hasMigrated) - - // Assert that we no longer have a legacy store for this user - legacyStore = MXRealmCryptoStore(credentials: session.credentials) - XCTAssertNil(legacyStore) - - await env.close() - } - - func test_doesNotMigrateDeprecatedStore() async throws { - let env = try await e2eData.startE2ETest() - let session = env.session - - // We set the legacy store as fully deprecated - var legacyStore = session.legacyCrypto?.store - XCTAssertNotNil(legacyStore) - legacyStore?.cryptoVersion = .deprecated3 - - // Build crypto and assert no migration has been performed - let (crypto, hasMigrated) = try await buildCrypto(session: session) - XCTAssertNotNil(crypto) - XCTAssertFalse(hasMigrated) - - // Assert that we no longer have a legacy store for this user - legacyStore = MXRealmCryptoStore(credentials: session.credentials) - XCTAssertNil(legacyStore) - - await env.close() - } -} diff --git a/MatrixSDKTests/Crypto/MXCryptoV2FactoryUnitTests.swift b/MatrixSDKTests/Crypto/MXCryptoV2FactoryUnitTests.swift new file mode 100644 index 0000000000..fae681fca3 --- /dev/null +++ b/MatrixSDKTests/Crypto/MXCryptoV2FactoryUnitTests.swift @@ -0,0 +1,151 @@ +// +// Copyright 2023 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 +@testable import MatrixSDK + +class MXCryptoV2FactoryUnitTests: XCTestCase { + class MXSessionStub: MXSession { + var stubbedCredentials: MXCredentials! + override var credentials: MXCredentials! { + return stubbedCredentials + } + + override var myUserId: String! { + return stubbedCredentials.userId + } + + override var aggregations: MXAggregations! { + return MXAggregations() + } + + override var matrixRestClient: MXRestClient! { + return MXRestClientStub(credentials: credentials) + } + } + + var factory: MXCryptoV2Factory! + + override func setUp() async throws { + factory = MXCryptoV2Factory() + MXKeyProvider.sharedInstance().delegate = MXKeyProviderStub() + } + + override func tearDown() async throws { + try LegacyRealmStore.deleteAllStores() + MXKeyProvider.sharedInstance().delegate = nil + } + + private func makeSession(userId: String) -> MXSession { + let credentials = MXCredentials() + credentials.userId = userId + + let session = MXSessionStub() + session.stubbedCredentials = credentials + return session + } + + private func buildCrypto(account: LegacyRealmStore.Account) async throws -> (MXCrypto?, Bool) { + let session = MXSessionStub() + session.stubbedCredentials = account.credentials + + return try await withCheckedThrowingContinuation { cont in + var hasMigrated = false + factory.buildCrypto( + session: session) { _ in + hasMigrated = true + } success: { + cont.resume(returning: ($0, hasMigrated)) + } failure: { + cont.resume(throwing: $0) + } + } + } + + func test_hasCryptoData() throws { + let alice = "Alice" + let bob = "Bob" + + // Only create crypto data for alice + let aliceUrl = try MXCryptoMachineStore.storeURL(for: alice) + let data = "something".data(using: .ascii)! + try data.write(to: aliceUrl) + + let aliceSession = makeSession(userId: alice) + XCTAssertTrue(MXCryptoV2Factory.shared.hasCryptoData(for: aliceSession)) + + let bobSession = makeSession(userId: bob) + XCTAssertFalse(MXCryptoV2Factory.shared.hasCryptoData(for: bobSession)) + } + + func test_doesNotMigrateNewUser() async throws { + // Build crypto and assert no migration has been performed + let (crypto, hasMigrated) = try await buildCrypto(account: .version2) + XCTAssertNotNil(crypto) + XCTAssertFalse(hasMigrated) + } + + func test_fullyMigratesLegacyUser() async throws { + // Load the unmigrated legacy store + let account = LegacyRealmStore.Account.version2 + XCTAssertFalse(LegacyRealmStore.hasData(for: account)) + let legacyStore = try LegacyRealmStore.load(account: account) + XCTAssertTrue(LegacyRealmStore.hasData(for: account)) + XCTAssertEqual(legacyStore.cryptoVersion, .version2) + + // Build crypto and assert migration has been performed + let (crypto, hasMigrated) = try await buildCrypto(account: account) + XCTAssertNotNil(crypto) + XCTAssertTrue(hasMigrated) + + // Assert that data for the legacy store has been removed + XCTAssertFalse(LegacyRealmStore.hasData(for: account)) + } + + func test_migratesPartiallyMigratedUser() async throws { + // Load partially deprecated legacy store + let account = LegacyRealmStore.Account.deprecated1 + XCTAssertFalse(LegacyRealmStore.hasData(for: account)) + let legacyStore = try LegacyRealmStore.load(account: account) + XCTAssertTrue(LegacyRealmStore.hasData(for: account)) + XCTAssertEqual(legacyStore.cryptoVersion, .deprecated1) + + // Build crypto and assert migration has been performed + let (crypto, hasMigrated) = try await buildCrypto(account: account) + XCTAssertNotNil(crypto) + XCTAssertTrue(hasMigrated) + + // Assert that data for the legacy store has been removed + XCTAssertFalse(LegacyRealmStore.hasData(for: account)) + } + + func test_doesNotMigrateDeprecatedStore() async throws { + // Load fully deprecated legacy store + let account = LegacyRealmStore.Account.deprecated3 + XCTAssertFalse(LegacyRealmStore.hasData(for: account)) + let legacyStore = try LegacyRealmStore.load(account: account) + XCTAssertTrue(LegacyRealmStore.hasData(for: account)) + XCTAssertEqual(legacyStore.cryptoVersion, .deprecated3) + + // Build crypto and assert no migration has been performed + let (crypto, hasMigrated) = try await buildCrypto(account: .deprecated3) + XCTAssertNotNil(crypto) + XCTAssertFalse(hasMigrated) + + // Assert that data for the legacy store has been removed + XCTAssertFalse(LegacyRealmStore.hasData(for: account)) + } +} diff --git a/MatrixSDKTests/Crypto/MXSession+LegacyCrypto.swift b/MatrixSDKTests/Crypto/MXSession+LegacyCrypto.swift index 815fdd9887..c98d489229 100644 --- a/MatrixSDKTests/Crypto/MXSession+LegacyCrypto.swift +++ b/MatrixSDKTests/Crypto/MXSession+LegacyCrypto.swift @@ -28,7 +28,6 @@ import Foundation } guard let legacy = crypto as? MXLegacyCrypto else { - assertionFailure("Legacy crypto is not available, adjust test to not depend on legacy APIs") return nil } return legacy diff --git a/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/LegacyRealmStore.swift b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/LegacyRealmStore.swift new file mode 100644 index 0000000000..4510c3a782 --- /dev/null +++ b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/LegacyRealmStore.swift @@ -0,0 +1,162 @@ +// +// Copyright 2023 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 Realm + +/// Class simulating legacy crypto store associated with the now-deprecated native crypto module +/// +/// It has access to several pre-made realm files with legacy accounts that can be loaded +/// and migrated to current crypto module +class LegacyRealmStore { + enum Error: Swift.Error { + case missingDependencies + } + + /// A few pre-created accounts with hardcoded details + enum Account { + + /// Realm store with crypto version `version2`, used for migration testing + case version2 + + /// Realm store with crypto version `deprecated1`, used for migration testing + case deprecated1 + + /// Realm store with crypto version `deprecated3`, used for migration testing + case deprecated3 + + /// Realm store with a verified accounts used to test cross-signing migration + case verified + + /// Realm store with an unverified accounts used to test cross-signing migration + case unverified + + /// File name for the associated account file + var fileName: String { + switch self { + case .version2: + return "legacy_version2_account" + case .deprecated1: + return "legacy_deprecated1_account" + case .deprecated3: + return "legacy_deprecated3_account" + case .verified: + return "legacy_verified_account" + case .unverified: + return "legacy_unverified_account" + } + } + + /// Hardcoded room id matching a given account + var roomId: String? { + switch self { + case .version2: + return nil + case .deprecated1: + return nil + case .deprecated3: + return nil + case .verified: + return "!QUWVMCIhJqIqTMLxof:x.y.z" + case .unverified: + return nil + } + } + + /// Hardcoded account credentials matching a given account + var credentials: MXCredentials { + let cred = MXCredentials() + switch self { + case .version2: + cred.userId = "@mxalice-54aeab93-b4b2-4edf-85e1-bc0dbbb710ee:x.y.z" + cred.deviceId = "NAHEYWCBBM" + case .deprecated1: + cred.userId = "@mxalice-d9eed33b-e269-4171-9352-8ee8b84b37a1:x.y.z" + cred.deviceId = "KLWNEPIHMX" + case .deprecated3: + cred.userId = "@mxalice-4c5a01ea-9fac-4568-bda6-09e2d14f0e5d:x.y.z" + cred.deviceId = "DCGBYVZFQI" + case .verified: + cred.userId = "@mxalice-107ca1c5-4d03-4ff4-affc-369f4ce6de6f:x.y.z" + cred.deviceId = "AXDAYKSETI" + case .unverified: + cred.userId = "@mxalice-f5314669-7d43-4662-8262-771728e1921f:x.y.z" + cred.deviceId = "ELSGFERWHH" + } + return cred + } + } + + static func load(account: Account) throws -> MXRealmCryptoStore { + guard + let sourceUrl = Bundle(for: Self.self).url(forResource: account.fileName, withExtension: "realm"), + let folder = realmFolder() + else { + throw Error.missingDependencies + } + + if !FileManager.default.fileExists(atPath: folder.path) { + try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) + } + + let credentials = account.credentials + let file = "\(credentials.userId!)-\(credentials.deviceId!).realm" + + let targetUrl = folder.appendingPathComponent(file) + if FileManager.default.fileExists(atPath: targetUrl.path) { + try FileManager.default.removeItem(at: targetUrl) + } + + try FileManager.default.copyItem(at: sourceUrl, to: targetUrl) + return MXRealmCryptoStore(credentials: credentials) + } + + static func hasData(for account: Account) -> Bool { + let credentials = account.credentials + let file = "\(credentials.userId!)-\(credentials.deviceId!).realm" + + return MXRealmCryptoStore.hasData(for: credentials) + } + + static func deleteAllStores() throws { + guard let folder = realmFolder() else { + throw Error.missingDependencies + } + + if FileManager.default.fileExists(atPath: folder.path) { + try FileManager.default.removeItem(at: folder) + } + } + + private static func realmFolder() -> URL? { + platformDirectoryURL()? + .appendingPathComponent("MXRealmCryptoStore") + } + + private static func platformDirectoryURL() -> URL? { + #if os(OSX) + guard + let applicationSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first, + let identifier = Bundle.main.bundleIdentifier + else { + return nil + } + return applicationSupport.appendingPathComponent(identifier) + #else + return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first + #endif + } +} diff --git a/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/archived_encrypted_event b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/archived_encrypted_event new file mode 100644 index 0000000000..ba709102e8 Binary files /dev/null and b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/archived_encrypted_event differ diff --git a/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_deprecated1_account.realm b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_deprecated1_account.realm new file mode 100644 index 0000000000..1bad5afe95 Binary files /dev/null and b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_deprecated1_account.realm differ diff --git a/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_deprecated3_account.realm b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_deprecated3_account.realm new file mode 100644 index 0000000000..e1f4f07f61 Binary files /dev/null and b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_deprecated3_account.realm differ diff --git a/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_unverified_account.realm b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_unverified_account.realm new file mode 100644 index 0000000000..07a5593447 Binary files /dev/null and b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_unverified_account.realm differ diff --git a/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_verified_account.realm b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_verified_account.realm new file mode 100644 index 0000000000..f45e7546e4 Binary files /dev/null and b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_verified_account.realm differ diff --git a/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_version2_account.realm b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_version2_account.realm new file mode 100644 index 0000000000..b02c1e73f7 Binary files /dev/null and b/MatrixSDKTests/Crypto/Migration/LegacyRealmStore/legacy_version2_account.realm differ diff --git a/MatrixSDKTests/Crypto/Migration/MXCryptoMigrationV2Tests.swift b/MatrixSDKTests/Crypto/Migration/MXCryptoMigrationV2Tests.swift deleted file mode 100644 index dff162d018..0000000000 --- a/MatrixSDKTests/Crypto/Migration/MXCryptoMigrationV2Tests.swift +++ /dev/null @@ -1,331 +0,0 @@ -// -// Copyright 2023 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 -@testable import MatrixSDK - -class MXCryptoMigrationV2Tests: XCTestCase { - enum Error: Swift.Error { - case missingDependencies - } - - class KeyProvider: NSObject, MXKeyProviderDelegate { - func isEncryptionAvailableForData(ofType dataType: String) -> Bool { - return true - } - - func hasKeyForData(ofType dataType: String) -> Bool { - return true - } - - func keyDataForData(ofType dataType: String) -> MXKeyData? { - MXRawDataKey(key: "1234".data(using: .ascii)!) - } - } - - var data: MatrixSDKTestsData! - var e2eData: MatrixSDKTestsE2EData! - - override func setUp() { - data = MatrixSDKTestsData() - e2eData = MatrixSDKTestsE2EData(matrixSDKTestsData: data) - } - - // MARK: - Helpers - - private func fullyMigratedOlmMachine(session: MXSession) throws -> MXCryptoMachine { - guard - let store = session.legacyCrypto?.store, - let restClient = session.matrixRestClient - else { - throw Error.missingDependencies - } - - MXKeyProvider.sharedInstance().delegate = KeyProvider() - let migration = MXCryptoMigrationV2(legacyStore: store) - try migration.migrateAllData { _ in } - let machine = try MXCryptoMachine( - userId: store.userId(), - deviceId: store.deviceId(), - restClient: restClient, - getRoomAction: { _ in - return nil - }) - MXKeyProvider.sharedInstance().delegate = nil - return machine - } - - private func partiallyMigratedOlmMachine(session: MXSession) throws -> MXCryptoMachine { - guard - let store = session.legacyCrypto?.store, - let restClient = session.matrixRestClient - else { - throw Error.missingDependencies - } - - MXKeyProvider.sharedInstance().delegate = KeyProvider() - let migration = MXCryptoMigrationV2(legacyStore: store) - try migration.migrateRoomAndGlobalSettingsOnly { _ in } - let machine = try MXCryptoMachine( - userId: store.userId(), - deviceId: store.deviceId(), - restClient: restClient, - getRoomAction: { _ in - return nil - }) - MXKeyProvider.sharedInstance().delegate = nil - return machine - } - - // MARK: - Tests - - func test_migratesAccountDetails() async throws { - let env = try await e2eData.startE2ETest() - let legacySession = env.session - - let machine = try self.fullyMigratedOlmMachine(session: env.session) - - XCTAssertEqual(machine.userId, legacySession.myUserId) - XCTAssertEqual(machine.deviceId, legacySession.myDeviceId) - XCTAssertEqual(machine.deviceCurve25519Key, legacySession.crypto.deviceCurve25519Key) - XCTAssertEqual(machine.deviceEd25519Key, legacySession.crypto.deviceEd25519Key) - - await env.close() - } - - func test_canDecryptMegolmMessageAfterMigration() async throws { - let env = try await e2eData.startE2ETest() - - guard let room = env.session.room(withRoomId: env.roomId) else { - throw Error.missingDependencies - } - - // Send a new message in encrypted room - let event = try await room.sendTextMessage("Hi bob") - - // Erase cleartext and make sure the event was indeed encrypted - event.setClearData(nil) - XCTAssertTrue(event.isEncrypted) - XCTAssertEqual(event.content["algorithm"] as? String, kMXCryptoMegolmAlgorithm) - XCTAssertNotNil(event.content["ciphertext"]) - - // Migrate the session to crypto v2 - let machine = try self.fullyMigratedOlmMachine(session: env.session) - - // Decrypt the event using crypto v2 - let decrypted = try machine.decryptRoomEvent(event) - let result = try MXEventDecryptionResult(event: decrypted) - let content = result.clearEvent["content"] as? [String: Any] - - // At this point we should be able to read back the original message after - // having decrypted the event with room keys migrated earlier - XCTAssertEqual(content?["body"] as? String, "Hi bob") - - await env.close() - } - - func test_notCrossSignedAfterMigration() async throws { - let env = try await e2eData.startE2ETest() - - // We start with user who cannot cross-sign (did not setup cross signing keys) - let legacyCrossSigning = env.session.crypto.crossSigning - XCTAssertFalse(legacyCrossSigning.canCrossSign) - XCTAssertFalse(legacyCrossSigning.hasAllPrivateKeys) - - // We then migrate the user into crypto v2 - let machine = try fullyMigratedOlmMachine(session: env.session) - let crossSigningV2 = MXCrossSigningV2(crossSigning: machine, restClient: env.session.matrixRestClient) - try await crossSigningV2.refreshState() - - // As expected we cannot cross sign in v2 either - XCTAssertFalse(crossSigningV2.canCrossSign) - XCTAssertFalse(crossSigningV2.hasAllPrivateKeys) - - await env.close() - } - - func test_migratesCrossSigningStatus() async throws { - let env = try await e2eData.startE2ETest() - - // We start with user who setup cross-signing with password - let legacyCrossSigning = env.session.crypto.crossSigning - try await legacyCrossSigning.setup(withPassword: MXTESTS_ALICE_PWD) - XCTAssertTrue(legacyCrossSigning.canCrossSign) - XCTAssertTrue(legacyCrossSigning.hasAllPrivateKeys) - - // We now migrate the data into crypto v2 - let machine = try fullyMigratedOlmMachine(session: env.session) - let crossSigningV2 = MXCrossSigningV2(crossSigning: machine, restClient: env.session.matrixRestClient) - try await crossSigningV2.refreshState() - - // And confirm that cross signing is ready - XCTAssertTrue(crossSigningV2.canCrossSign) - XCTAssertTrue(crossSigningV2.hasAllPrivateKeys) - - await env.close() - } - - func test_migratesRoomSettings() async throws { - let env = try await e2eData.startE2ETest() - - // We start with user and encrypted room with some settings - let legacyCrypto = env.session.crypto! - try await legacyCrypto.ensureEncryption(roomId: env.roomId) - legacyCrypto.setBlacklistUnverifiedDevicesInRoom(env.roomId, blacklist: true) - XCTAssertTrue(legacyCrypto.isRoomEncrypted(env.roomId)) - XCTAssertTrue(legacyCrypto.isBlacklistUnverifiedDevices(inRoom: env.roomId)) - - // We now migrate the data into crypto v2 - let machine = try fullyMigratedOlmMachine(session: env.session) - - // And confirm that room settings have been migrated - let settings = machine.roomSettings(roomId: env.roomId) - XCTAssertEqual(settings, .init(algorithm: .megolmV1AesSha2, onlyAllowTrustedDevices: true)) - - await env.close() - } - - func test_migratesRoomSettingsInPartialMigration() async throws { - let env = try await e2eData.startE2ETest() - - // We start with user and encrypted room with some settings - let legacyCrypto = env.session.crypto! - try await legacyCrypto.ensureEncryption(roomId: env.roomId) - legacyCrypto.setBlacklistUnverifiedDevicesInRoom(env.roomId, blacklist: true) - XCTAssertTrue(legacyCrypto.isRoomEncrypted(env.roomId)) - XCTAssertTrue(legacyCrypto.isBlacklistUnverifiedDevices(inRoom: env.roomId)) - - // We now migrate the data into crypto v2 - let machine = try partiallyMigratedOlmMachine(session: env.session) - - // And confirm that room settings have been migrated - let settings = machine.roomSettings(roomId: env.roomId) - XCTAssertEqual(settings, .init(algorithm: .megolmV1AesSha2, onlyAllowTrustedDevices: true)) - - await env.close() - } - - func test_migratesGlobalSettings() async throws { - let env1 = try await e2eData.startE2ETest() - env1.session.crypto.globalBlacklistUnverifiedDevices = true - let machine1 = try fullyMigratedOlmMachine(session: env1.session) - XCTAssertTrue(machine1.onlyAllowTrustedDevices) - await env1.close() - - let env2 = try await e2eData.startE2ETest() - env2.session.crypto.globalBlacklistUnverifiedDevices = false - let machine2 = try fullyMigratedOlmMachine(session: env2.session) - XCTAssertFalse(machine2.onlyAllowTrustedDevices) - await env2.close() - } - - func test_migratesGlobalSettingsInPartialMigration() async throws { - let env1 = try await e2eData.startE2ETest() - env1.session.crypto.globalBlacklistUnverifiedDevices = true - let machine1 = try partiallyMigratedOlmMachine(session: env1.session) - XCTAssertTrue(machine1.onlyAllowTrustedDevices) - await env1.close() - - let env2 = try await e2eData.startE2ETest() - env2.session.crypto.globalBlacklistUnverifiedDevices = false - let machine2 = try partiallyMigratedOlmMachine(session: env2.session) - XCTAssertFalse(machine2.onlyAllowTrustedDevices) - await env2.close() - } -} - -private extension MXCrypto { - func downloadKeys(userIds: [String]) async throws { - return try await withCheckedThrowingContinuation { continuation in - downloadKeys(userIds, forceDownload: false) { _, _ in - continuation.resume() - } - } - } - - func ensureEncryption(roomId: String) async throws { - return try await withCheckedThrowingContinuation { continuation in - ensureEncryption(inRoom: roomId) { - continuation.resume() - } - } - } -} - -extension MXCrossSigning { - func refreshState() async throws { - return try await withCheckedThrowingContinuation { continuation in - refreshState { _ in - continuation.resume() - } failure: { error in - continuation.resume(throwing: error) - } - } - } - - func signUser(userId: String) async throws { - return try await withCheckedThrowingContinuation { continuation in - signUser(withUserId: userId) { - continuation.resume() - } failure: { error in - continuation.resume(throwing: error) - } - } - } - - func setup(withPassword password: String) async throws { - return try await withCheckedThrowingContinuation { continuation in - setup(withPassword: password) { - continuation.resume() - } failure: { error in - continuation.resume(throwing: error) - } - } - } -} - -private extension MXRoom { - enum Error: Swift.Error { - case cannotSendMessage - } - - @MainActor - func sendTextMessage(_ text: String) async throws -> MXEvent { - var event: MXEvent? - _ = try await withCheckedThrowingContinuation{ (continuation: CheckedContinuation) in - sendTextMessage(text, localEcho: &event) { response in - switch response { - case .success(let value): - continuation.resume(returning: value) - case .failure(let error): - continuation.resume(throwing: error) - } - } - } - - guard let event = event else { - throw Error.cannotSendMessage - } - return event - } -} - -extension MXCryptoMigrationV2Tests: Logger { - func log(logLine: String) { - MXLog.debug("[MXCryptoMigrationV2Tests]: \(logLine)") - } -} diff --git a/MatrixSDKTests/Crypto/Migration/MXCryptoMigrationV2UnitTests.swift b/MatrixSDKTests/Crypto/Migration/MXCryptoMigrationV2UnitTests.swift new file mode 100644 index 0000000000..88b5cfc676 --- /dev/null +++ b/MatrixSDKTests/Crypto/Migration/MXCryptoMigrationV2UnitTests.swift @@ -0,0 +1,167 @@ +// +// Copyright 2023 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 +@testable import MatrixSDK + +class MXCryptoMigrationV2UnitTests: XCTestCase { + enum Error: Swift.Error { + case missingEvent + } + + override func tearDown() async throws { + try LegacyRealmStore.deleteAllStores() + } + + // MARK: - Helpers + + private func fullyMigratedOlmMachine(legacyStore: MXCryptoStore) throws -> MXCryptoMachine { + MXKeyProvider.sharedInstance().delegate = MXKeyProviderStub() + let migration = MXCryptoMigrationV2(legacyStore: legacyStore) + try migration.migrateAllData { _ in } + let machine = try MXCryptoMachine( + userId: legacyStore.userId(), + deviceId: legacyStore.deviceId(), + restClient: MXRestClientStub(), + getRoomAction: { _ in + return nil + }) + MXKeyProvider.sharedInstance().delegate = nil + return machine + } + + private func partiallyMigratedOlmMachine(legacyStore: MXCryptoStore) throws -> MXCryptoMachine { + MXKeyProvider.sharedInstance().delegate = MXKeyProviderStub() + let migration = MXCryptoMigrationV2(legacyStore: legacyStore) + try migration.migrateRoomAndGlobalSettingsOnly { _ in } + let machine = try MXCryptoMachine( + userId: legacyStore.userId(), + deviceId: legacyStore.deviceId(), + restClient: MXRestClientStub(), + getRoomAction: { _ in + return nil + }) + MXKeyProvider.sharedInstance().delegate = nil + return machine + } + + private func loadEncryptedEvent() throws -> MXEvent { + guard let url = Bundle(for: Self.self).url(forResource: "archived_encrypted_event", withExtension: nil) else { + throw Error.missingEvent + } + + let data = try Data(contentsOf: url) + guard let event = NSKeyedUnarchiver.unarchiveObject(with: data) as? MXEvent else { + throw Error.missingEvent + } + return event + } + + // MARK: - Tests + + func test_migratesAccountDetails() throws { + let store = try LegacyRealmStore.load(account: .verified) + let machine = try fullyMigratedOlmMachine(legacyStore: store) + + XCTAssertEqual(machine.userId, store.userId()) + XCTAssertEqual(machine.deviceId, store.deviceId()) + XCTAssertNotNil(machine.deviceCurve25519Key) + XCTAssertEqual(machine.deviceCurve25519Key, store.account().identityKeys()[kMXKeyCurve25519Type] as? String) + XCTAssertNotNil(machine.deviceEd25519Key) + XCTAssertEqual(machine.deviceEd25519Key, store.account().identityKeys()[kMXKeyEd25519Type] as? String) + } + + func test_canDecryptMegolmMessageAfterMigration() throws { + // Load a previously archived and encrypted event + let event = try loadEncryptedEvent() + XCTAssertTrue(event.isEncrypted) + XCTAssertEqual(event.content["algorithm"] as? String, kMXCryptoMegolmAlgorithm) + XCTAssertNotNil(event.content["ciphertext"]) + + // Migrate data to crypto v2 + let store = try LegacyRealmStore.load(account: .verified) + let machine = try fullyMigratedOlmMachine(legacyStore: store) + + // Decrypt the event using crypto v2 + let decrypted = try machine.decryptRoomEvent(event) + let result = try MXEventDecryptionResult(event: decrypted) + let content = result.clearEvent["content"] as? [String: Any] + + // At this point we should be able to read back the original message after + // having decrypted the event with room keys migrated earlier + XCTAssertEqual(content?["body"] as? String, "Hi bob") + } + + func test_notCrossSignedAfterMigration() throws { + let store = try LegacyRealmStore.load(account: .unverified) + let machine = try fullyMigratedOlmMachine(legacyStore: store) + + let crossSigningV2 = MXCrossSigningV2(crossSigning: machine, restClient: MXRestClientStub()) + XCTAssertFalse(crossSigningV2.canCrossSign) + XCTAssertFalse(crossSigningV2.hasAllPrivateKeys) + } + + func test_migratesCrossSigningStatus() throws { + let store = try LegacyRealmStore.load(account: .verified) + let machine = try fullyMigratedOlmMachine(legacyStore: store) + + let crossSigningV2 = MXCrossSigningV2(crossSigning: machine, restClient: MXRestClientStub()) + XCTAssertTrue(crossSigningV2.hasAllPrivateKeys) + } + + func test_migratesRoomSettings() throws { + let store = try LegacyRealmStore.load(account: .verified) + let machine = try fullyMigratedOlmMachine(legacyStore: store) + + let settings = machine.roomSettings(roomId: LegacyRealmStore.Account.verified.roomId!) + XCTAssertEqual(settings, .init(algorithm: .megolmV1AesSha2, onlyAllowTrustedDevices: true)) + } + + func test_migratesRoomSettingsInPartialMigration() throws { + let store = try LegacyRealmStore.load(account: .verified) + let machine = try partiallyMigratedOlmMachine(legacyStore: store) + + let settings = machine.roomSettings(roomId: LegacyRealmStore.Account.verified.roomId!) + XCTAssertEqual(settings, .init(algorithm: .megolmV1AesSha2, onlyAllowTrustedDevices: true)) + } + + func test_migratesGlobalSettings() throws { + let store1 = try LegacyRealmStore.load(account: .unverified) + let machine1 = try fullyMigratedOlmMachine(legacyStore: store1) + XCTAssertTrue(machine1.onlyAllowTrustedDevices) + + let store2 = try LegacyRealmStore.load(account: .verified) + let machine2 = try fullyMigratedOlmMachine(legacyStore: store2) + XCTAssertFalse(machine2.onlyAllowTrustedDevices) + } + + func test_migratesGlobalSettingsInPartialMigration() throws { + let store1 = try LegacyRealmStore.load(account: .unverified) + let machine1 = try partiallyMigratedOlmMachine(legacyStore: store1) + XCTAssertTrue(machine1.onlyAllowTrustedDevices) + + let store2 = try LegacyRealmStore.load(account: .verified) + let machine2 = try partiallyMigratedOlmMachine(legacyStore: store2) + XCTAssertFalse(machine2.onlyAllowTrustedDevices) + } +} + +extension MXCryptoMigrationV2UnitTests: Logger { + func log(logLine: String) { + MXLog.debug("[MXCryptoMigrationV2Tests]: \(logLine)") + } +} diff --git a/MatrixSDKTests/MXBaseKeyBackupTests.m b/MatrixSDKTests/MXBaseKeyBackupTests.m index 5cdca88f5b..94ec9b427a 100644 --- a/MatrixSDKTests/MXBaseKeyBackupTests.m +++ b/MatrixSDKTests/MXBaseKeyBackupTests.m @@ -757,8 +757,7 @@ - (void)testRestoreKeyBackup - Try to restore the e2e backup with a wrong recovery key - It must fail */ -// TODO: test is currently broken -- (void)xtestRestoreKeyBackupWithAWrongRecoveryKey +- (void)testRestoreKeyBackupWithAWrongRecoveryKey { // - Do an e2e backup to the homeserver with a recovery key // - Log Alice on a new device @@ -824,8 +823,7 @@ - (void)testRestoreKeyBackupWithPassword - Try to restore the e2e backup with a wrong password - It must fail */ -// TODO: test is currently broken -- (void)xtestRestoreKeyBackupWithAWrongPassword +- (void)testRestoreKeyBackupWithAWrongPassword { // - Do an e2e backup to the homeserver with a password // - Log Alice on a new device @@ -891,8 +889,7 @@ - (void)testUseRecoveryKeyToRestoreAPasswordKeyKeyBackup - Try to restore the e2e backup with a password - It must fail */ -// TODO: test is currently broken -- (void)xtestUsePasswordToRestoreARecoveryKeyKeyBackup +- (void)testUsePasswordToRestoreARecoveryKeyKeyBackup { // - Do an e2e backup to the homeserver with a recovery key // - And log Alice on a new device @@ -927,8 +924,7 @@ - (void)xtestUsePasswordToRestoreARecoveryKeyKeyBackup - Restart alice session -> The new alice session must back up to the same version */ -// TODO: test is currently broken -- (void)xtestCheckAndStartKeyBackupWhenRestartingAMatrixSession +- (void)testCheckAndStartKeyBackupWhenRestartingAMatrixSession { // - Create a backup version [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -1296,8 +1292,7 @@ - (void)testTrustKeyBackupVersionWithRecoveryKey - It must fail - The backup must still be untrusted and disabled */ -// TODO: test is currently broken -- (void)xtestTrustKeyBackupVersionWithWrongRecoveryKey +- (void)testTrustKeyBackupVersionWithWrongRecoveryKey { // - Do an e2e backup to the homeserver with a recovery key // - And log Alice on a new device @@ -1390,8 +1385,7 @@ - (void)testTrustKeyBackupVersionWithPassword - It must fail - The backup must still be untrusted and disabled */ -// TODO: test is currently broken -- (void)xtestTrustKeyBackupVersionWithWrongPassword +- (void)testTrustKeyBackupVersionWithWrongPassword { NSString *password = @"password"; diff --git a/MatrixSDKTests/MXCrossSigningTests.m b/MatrixSDKTests/MXCrossSigningTests.m index e311648759..fc52eb39a1 100644 --- a/MatrixSDKTests/MXCrossSigningTests.m +++ b/MatrixSDKTests/MXCrossSigningTests.m @@ -977,8 +977,7 @@ - (void)testTrustsBetweenBobAndAliceWithTwoDevices // -> Alice2 should see Alice1 as trusted thanks to cross-signing // -> Bob should see Alice3 as trusted thanks to cross-signing // -> Alice3 should see Bob as trusted thanks to cross-signing -// TODO: test is currently broken -- (void)xtestTrustChain +- (void)testTrustChain { // - Have Alice with 2 devices (Alice1 and Alice2) and Bob. All trusted via cross-signing [matrixSDKTestsE2EData doTestWithBobAndAliceWithTwoDevicesAllTrusted:self readyToTest:^(MXSession *aliceSession1, MXSession *aliceSession2, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -1230,8 +1229,7 @@ - (void)testMXCrossSigningResetDetection // - Reset XS on this new device // - Restart Alice first device // -> Alice first device must not trust the cross-signing anymore -// TODO: test is currently broken -- (void)xtestMXCrossSigningResetDetectionAfterRestart +- (void)testMXCrossSigningResetDetectionAfterRestart { // - Have Alice with cross-signing [self doTestWithBobAndBootstrappedAlice:self readyToTest:^(MXSession *bobSession, MXSession *aliceSession, NSString *roomId, XCTestExpectation *expectation) { diff --git a/MatrixSDKTests/MXCrossSigningVerificationTests.m b/MatrixSDKTests/MXCrossSigningVerificationTests.m index 2d38c3d957..c2aecc60ef 100644 --- a/MatrixSDKTests/MXCrossSigningVerificationTests.m +++ b/MatrixSDKTests/MXCrossSigningVerificationTests.m @@ -383,8 +383,7 @@ - (void)testSelfVerificationWithSAS -> Both ends must get a done message - Then, test MXKeyVerification */ -// TODO: test is currently broken -- (void)xtestVerificationByDMFullFlow +- (void)testVerificationByDMFullFlow { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -616,8 +615,7 @@ - (void)xtestVerificationByDMFullFlow -> Both ends must get a done message - Then, test MXKeyVerification */ -// TODO: test is currently broken -- (void)xtestVerifyingAnotherUserQRCodeVerificationFullFlow +- (void)testVerifyingAnotherUserQRCodeVerificationFullFlow { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { diff --git a/MatrixSDKTests/MXCryptoKeyVerificationTests.m b/MatrixSDKTests/MXCryptoKeyVerificationTests.m index 08b3a7c81e..c803b60442 100644 --- a/MatrixSDKTests/MXCryptoKeyVerificationTests.m +++ b/MatrixSDKTests/MXCryptoKeyVerificationTests.m @@ -369,8 +369,7 @@ - (void)checkVerificationByToDeviceFullFlowWithBobSession:(MXSession*)bobSession }]; } -// TODO: test is currently broken -- (void)xtestVerificationByToDeviceFullFlow +- (void)testVerificationByToDeviceFullFlow { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -412,8 +411,7 @@ - (void)testVerificationByToDeviceFullFlowWith2Devices /** Same tests as testVerificationByToDeviceFullFlow but with only alice verifying her 2 devices. */ -// TODO: test is currently broken -- (void)xtestVerificationByToDeviceSelfVerificationFullFlow +- (void)testVerificationByToDeviceSelfVerificationFullFlow { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -457,12 +455,6 @@ - (void)testVerificationByToDeviceRequestCancellation success:^(id requestFromAliceDevice1POV) { // -> The other device list should have been computed well - if (MXSDKOptions.sharedInstance.enableCryptoSDK) - { - XCTFail(@"This test uses `MXKeyVerificationByToDeviceRequest` which is only compatible with Crypto V1. Replace assertions to make it compatible with V2 as well"); - [expectation fulfill]; - return; - } MXKeyVerificationByToDeviceRequest *toDeviceRequestFromAliceDevice1POV = (MXKeyVerificationByToDeviceRequest*)requestFromAliceDevice1POV; XCTAssertNotNil(toDeviceRequestFromAliceDevice1POV.requestedOtherDeviceIds); NSSet *expectedRequestedDevices = [NSSet setWithArray:@[aliceSession2DeviceId, aliceSession3DeviceId]]; @@ -563,8 +555,7 @@ - (void)testVerificationByToDeviceRequestWithNoOtherDevice -> Alice gets the requests notification -> They both have it in their pending requests */ -// TODO: test is currently broken -- (void)xtestVerificationByDMRequests +- (void)testVerificationByDMRequests { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -611,8 +602,7 @@ - (void)xtestVerificationByDMRequests /** Nomical case: The full flow */ -// TODO: test is currently broken -- (void)xtestVerificationByDMFullFlow +- (void)testVerificationByDMFullFlow { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -1016,8 +1006,7 @@ - (void)testVerificationByDMWithRoomDetection -> Alice gets the requests notification -> They both have it in their pending requests */ -// TODO: test is currently broken -- (void)xtestVerificationByDMWithNoRoom +- (void)testVerificationByDMWithNoRoom { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithBobAndAlice:self readyToTest:^(MXSession *aliceSession, MXSession *bobSession, XCTestExpectation *expectation) { @@ -1075,8 +1064,7 @@ - (void)xtestVerificationByDMWithNoRoom /** Same tests as testVerificationByDMFullFlow but with alice with 2 sessions */ -// TODO: test is currently broken -- (void)xtestVerificationByDMWithAliceWith2Devices +- (void)testVerificationByDMWithAliceWith2Devices { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -1091,8 +1079,7 @@ - (void)xtestVerificationByDMWithAliceWith2Devices /** Same tests as testVerificationByDMFullFlow but with bob with 2 sessions */ -// TODO: test is currently broken -- (void)xtestVerificationByDMWithAUserWith2Devices +- (void)testVerificationByDMWithAUserWith2Devices { // - Alice and Bob are in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:YES aliceStore:[[MXMemoryStore alloc] init] bobStore:[[MXMemoryStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { diff --git a/MatrixSDKTests/MXCryptoSecretShareTests.m b/MatrixSDKTests/MXCryptoSecretShareTests.m index f5763032a9..63f07c624b 100644 --- a/MatrixSDKTests/MXCryptoSecretShareTests.m +++ b/MatrixSDKTests/MXCryptoSecretShareTests.m @@ -114,7 +114,7 @@ - (void)testSecretShare // -> She gets the secret XCTAssertEqualObjects(sharedSecret, secret); [expectation fulfill]; - + return YES; } failure:^(NSError * _Nonnull error) { XCTFail(@"The operation should not fail - NSError: %@", error); [expectation fulfill]; diff --git a/MatrixSDKTests/MXCryptoShareTests.m b/MatrixSDKTests/MXCryptoShareTests.m index 6c60b9588a..5f96246e84 100644 --- a/MatrixSDKTests/MXCryptoShareTests.m +++ b/MatrixSDKTests/MXCryptoShareTests.m @@ -142,8 +142,7 @@ - (void)createScenario:(void (^)(MXSession *aliceSession, NSString *roomId, MXMe -> Key share requests must be pending -> Then, they must have been sent */ -// TODO: Test currently broken -- (void)xtestKeyShareRequestFromNewDevice +- (void)testKeyShareRequestFromNewDevice { // - Have Alice and Bob in e2ee room with messages [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession1, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -194,8 +193,7 @@ - (void)xtestKeyShareRequestFromNewDevice -> After a bit, Alice2 should have received all keys -> Key share requests should have complete */ -// TODO: test is currently broken -- (void)xtestNominalCase +- (void)testNominalCase { // - Have Alice and Bob in e2ee room with messages [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession1, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -271,8 +269,7 @@ - (void)xtestNominalCase - Enable key share requests on Alice2 -> Key share requests should have complete */ -// TODO: test currently broken -- (void)xtestDisableKeyShareRequest +- (void)testDisableKeyShareRequest { // - Have Alice and Bob in e2ee room with messages [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession1, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -354,8 +351,7 @@ - (void)xtestDisableKeyShareRequest -> key share requests on Alice2 are enabled again -> No m.room_key_request have been made */ -// TODO: Test currently broken -- (void)xtestNoKeyShareRequestIfThereIsABackup +- (void)testNoKeyShareRequestIfThereIsABackup { // - Have Alice and Bob in e2ee room with messages [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession1, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -676,8 +672,7 @@ - (void)testShareHistoryKeysWithInvitedUser - Alice invites Bob into the room from her second device -> Bob has recieved only 2 session keys, namely those with `sharedHistory` set to true */ -// TODO: test is currently broken -- (void)xtestSharedHistoryPreservedWhenForwardingKeys +- (void)testSharedHistoryPreservedWhenForwardingKeys { [matrixSDKTestsE2EData doE2ETestWithAliceInARoom:self andStore:[[MXMemoryStore alloc] init] diff --git a/MatrixSDKTests/MXCryptoTests.m b/MatrixSDKTests/MXCryptoTests.m index 1cd1fb68ae..36b50f5138 100644 --- a/MatrixSDKTests/MXCryptoTests.m +++ b/MatrixSDKTests/MXCryptoTests.m @@ -111,18 +111,15 @@ - (void)testEnableCrypto XCTAssertNil(mxSession.crypto, @"Crypto is disabled by default"); - XCTAssertFalse([mxSession.legacyCrypto.store.class hasDataForCredentials:mxSession.matrixRestClient.credentials]); - + MXKeyProvider.sharedInstance.delegate = [[MXKeyProviderStub alloc] init]; [mxSession enableCrypto:YES success:^{ + MXKeyProvider.sharedInstance.delegate = nil; XCTAssert(mxSession.crypto); - XCTAssert([mxSession.legacyCrypto.store.class hasDataForCredentials:mxSession.matrixRestClient.credentials]); [mxSession enableCrypto:NO success:^{ XCTAssertNil(mxSession.crypto); - XCTAssertFalse([mxSession.legacyCrypto.store.class hasDataForCredentials:mxSession.matrixRestClient.credentials], @"Crypto data must have been trashed"); - [expectation fulfill]; } failure:^(NSError *error) { @@ -140,19 +137,18 @@ - (void)testEnableCrypto - (void)testMXSDKOptionsEnableCryptoWhenOpeningMXSession { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = YES; + MXKeyProvider.sharedInstance.delegate = [[MXKeyProviderStub alloc] init]; [matrixSDKTestsData doMXSessionTestWithBob:self readyToTest:^(MXSession *mxSession, XCTestExpectation *expectation) { // Reset the option to not disturb other tests [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = NO; + MXKeyProvider.sharedInstance.delegate = nil; XCTAssert(mxSession.crypto); - XCTAssert([mxSession.legacyCrypto.store.class hasDataForCredentials:mxSession.matrixRestClient.credentials]); [mxSession enableCrypto:NO success:^{ XCTAssertNil(mxSession.crypto); - XCTAssertFalse([mxSession.legacyCrypto.store.class hasDataForCredentials:mxSession.matrixRestClient.credentials], @"Crypto data must have been trashed"); - [expectation fulfill]; } failure:^(NSError *error) { @@ -237,8 +233,7 @@ - (void)testCryptoPersistenceInStore }]; } -// TODO: Test currently broken -- (void)xtestMultipleDownloadKeys +- (void)testMultipleDownloadKeys { [matrixSDKTestsE2EData doE2ETestWithBobAndAlice:self readyToTest:^(MXSession *bobSession, MXSession *aliceSession, XCTestExpectation *expectation) { @@ -882,8 +877,7 @@ - (void)testAliceAndBobInACryptedRoomBackPaginationFromMemoryStore }]; } -// TODO: Test currently broken -- (void)xtestAliceAndBobInACryptedRoomBackPaginationFromHomeServer +- (void)testAliceAndBobInACryptedRoomBackPaginationFromHomeServer { [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -1323,8 +1317,7 @@ - (void)testAliceAndBlockedBob // Alice sends a message #5 // Check that the message can be decrypted by the Bob's device and the Sam's device -// TODO: Test currently broken -- (void)xtestBlackListUnverifiedDevices +- (void)testBlackListUnverifiedDevices { NSArray *aliceMessages = @[ @"0", @@ -2056,8 +2049,7 @@ - (void)testRoomKeyReshare }]; } -// TODO: Test currently broken -- (void)xtestLateRoomKey +- (void)testLateRoomKey { [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:NO readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -2133,8 +2125,7 @@ - (void)xtestLateRoomKey // -> The third event must fail to decrypt at first because Bob the olm session is wedged // -> This is automatically fixed after SDKs restarted the olm session -// TODO: Test currently broken -- (void)xtestOlmSessionUnwedging +- (void)testOlmSessionUnwedging { // - Alice & Bob have messages in a room [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoom:self cryptedBob:YES warnOnUnknowDevices:NO aliceStore:[[MXFileStore alloc] init] bobStore:[[MXFileStore alloc] init] readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { @@ -2948,8 +2939,7 @@ - (void)testIncomingRoomKeyRequest - 3- Alice sends a second message -> 4- It must be sent (it was never sent before the fix) */ -// TODO: test is currently broken -- (void)xtestDeviceInvalidationWhileSending +- (void)testDeviceInvalidationWhileSending { [matrixSDKTestsE2EData doE2ETestWithAliceInARoom:self readyToTest:^(MXSession *aliceSession, NSString *roomId, XCTestExpectation *expectation) { @@ -3079,8 +3069,7 @@ - (void)testRestoreOlmOutboundKey - close current session and open a new session - Restore the outbound group session for the current room and check it exists and contains the new key */ -// TODO: test is currently broken -- (void)xtestDiscardAndRestoreOlmOutboundKey +- (void)testDiscardAndRestoreOlmOutboundKey { [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { MXOlmOutboundGroupSession *outboundSession = [aliceSession.legacyCrypto.store outboundGroupSessionWithRoomId:roomId]; diff --git a/MatrixSDKTests/MXCurve25519KeyBackupTests.m b/MatrixSDKTests/MXCurve25519KeyBackupTests.m deleted file mode 100644 index 346ff3a07f..0000000000 --- a/MatrixSDKTests/MXCurve25519KeyBackupTests.m +++ /dev/null @@ -1,125 +0,0 @@ -/* - 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 "MXBaseKeyBackupTests.h" - -#import "MXCrypto_Private.h" -#import "MXCryptoStore.h" -#import "MXRecoveryKey.h" -#import "MXKeybackupPassword.h" -#import "MXOutboundSessionInfo.h" -#import "MXCrossSigning_Private.h" -#import "MXCurve25519BackupAuthData.h" -#import "MXCurve25519KeyBackupAlgorithm.h" - -// Do not bother with retain cycles warnings in tests -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-retain-cycles" - -@interface MXCurve25519KeyBackupTests : MXBaseKeyBackupTests - -@end - -@implementation MXCurve25519KeyBackupTests - -- (NSString *)algorithm -{ - return kMXCryptoCurve25519KeyBackupAlgorithm; -} - -- (BOOL)isUntrusted -{ - return MXCurve25519KeyBackupAlgorithm.isUntrusted; -} - -- (MXKeyBackupVersion*)fakeKeyBackupVersion -{ - return [MXKeyBackupVersion modelFromJSON:@{ - @"algorithm": self.algorithm, - @"auth_data": @{ - @"public_key": @"abcdefg", - @"signatures": @{ - @"something": @{ - @"ed25519:something": @"hijklmnop" - } - } - } - }]; -} - -/** - Check that `[MXKeyBackup prepareKeyBackupVersion]` uses Curve25519 algorithm by default - */ -- (void)testPrepareKeyBackupVersionWithDefaultAlgorithm -{ - [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { - - XCTAssertNotNil(aliceSession.crypto.backup); - XCTAssertFalse(aliceSession.crypto.backup.enabled); - - // Check that `[MXKeyBackup prepareKeyBackupVersion` returns valid data - [aliceSession.crypto.backup prepareKeyBackupVersionWithPassword:nil algorithm:nil success:^(MXMegolmBackupCreationInfo * _Nonnull keyBackupCreationInfo) { - - XCTAssertNotNil(keyBackupCreationInfo); - XCTAssertEqualObjects(keyBackupCreationInfo.algorithm, kMXCryptoCurve25519KeyBackupAlgorithm); - XCTAssertTrue([keyBackupCreationInfo.authData isKindOfClass:MXCurve25519BackupAuthData.class]); - MXCurve25519BackupAuthData *authData = (MXCurve25519BackupAuthData*) keyBackupCreationInfo.authData; - XCTAssertNotNil(authData.publicKey); - XCTAssertNotNil(authData.signatures); - XCTAssertNotNil(keyBackupCreationInfo.recoveryKey); - - [expectation fulfill]; - - } failure:^(NSError * _Nonnull error) { - XCTFail(@"The request should not fail - NSError: %@", error); - [expectation fulfill]; - }]; - }]; -} - -/** - Check that `[MXKeyBackup prepareKeyBackupVersion` returns valid data - */ -- (void)testPrepareKeyBackupVersion -{ - [matrixSDKTestsE2EData doE2ETestWithAliceAndBobInARoomWithCryptedMessages:self cryptedBob:YES readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) { - - XCTAssertNotNil(aliceSession.crypto.backup); - XCTAssertFalse(aliceSession.crypto.backup.enabled); - - // Check that `[MXKeyBackup prepareKeyBackupVersion` returns valid data - [aliceSession.crypto.backup prepareKeyBackupVersionWithPassword:nil algorithm:self.algorithm success:^(MXMegolmBackupCreationInfo * _Nonnull keyBackupCreationInfo) { - - XCTAssertNotNil(keyBackupCreationInfo); - XCTAssertEqualObjects(keyBackupCreationInfo.algorithm, kMXCryptoCurve25519KeyBackupAlgorithm); - XCTAssertTrue([keyBackupCreationInfo.authData isKindOfClass:MXCurve25519BackupAuthData.class]); - MXCurve25519BackupAuthData *authData = (MXCurve25519BackupAuthData*) keyBackupCreationInfo.authData; - XCTAssertNotNil(authData.publicKey); - XCTAssertNotNil(authData.signatures); - XCTAssertNotNil(keyBackupCreationInfo.recoveryKey); - - [expectation fulfill]; - - } failure:^(NSError * _Nonnull error) { - XCTFail(@"The request should not fail - NSError: %@", error); - [expectation fulfill]; - }]; - }]; -} - -@end - -#pragma clang diagnostic pop diff --git a/MatrixSDKTests/MXPollAggregatorTests.swift b/MatrixSDKTests/MXPollAggregatorTests.swift index 9862243eda..0f7f0825f4 100644 --- a/MatrixSDKTests/MXPollAggregatorTests.swift +++ b/MatrixSDKTests/MXPollAggregatorTests.swift @@ -40,12 +40,12 @@ class MXPollAggregatorTest: XCTestCase { func testAggregations() { self.createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in self.delegate = PollAggregatorBlockWrapper(dataUpdateCallback: { pollAggregator in - XCTAssertEqual(self.pollAggregator.poll.answerOptions.first!.count, 2) - XCTAssertEqual(self.pollAggregator.poll.answerOptions.last!.count, 0) + XCTAssertEqual(self.pollAggregator.poll?.answerOptions.first!.count, 2) + XCTAssertEqual(self.pollAggregator.poll?.answerOptions.last!.count, 0) expectation.fulfill() }) - self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) + self.pollAggregator = PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) let dispatchGroup = DispatchGroup() @@ -74,14 +74,14 @@ class MXPollAggregatorTest: XCTestCase { func testSessionPausing() { self.createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in let delegate = PollAggregatorBlockWrapper(dataUpdateCallback: { aggregator in - XCTAssertEqual(aggregator.poll.answerOptions.first!.count, 2) - XCTAssertEqual(aggregator.poll.answerOptions.last!.count, 0) + XCTAssertEqual(aggregator.poll?.answerOptions.first!.count, 2) + XCTAssertEqual(aggregator.poll?.answerOptions.last!.count, 0) }) - self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) + self.pollAggregator = PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) - XCTAssertEqual(self.pollAggregator.poll.answerOptions.first!.count, 1) // One from Alice - XCTAssertEqual(self.pollAggregator.poll.answerOptions.last!.count, 0) + XCTAssertEqual(self.pollAggregator.poll?.answerOptions.first!.count, 1) // One from Alice + XCTAssertEqual(self.pollAggregator.poll?.answerOptions.last!.count, 0) bobSession.pause() @@ -99,16 +99,16 @@ class MXPollAggregatorTest: XCTestCase { func testGappySync() { self.createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in - self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) + self.pollAggregator = PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) self.delegate = PollAggregatorBlockWrapper(dataUpdateCallback: { aggregator in - XCTAssertEqual(aggregator.poll.answerOptions.first!.count, 2) // One from Bob and one from Alice - XCTAssertEqual(aggregator.poll.answerOptions.last!.count, 1) // One from Alice + XCTAssertEqual(aggregator.poll?.answerOptions.first!.count, 2) // One from Bob and one from Alice + XCTAssertEqual(aggregator.poll?.answerOptions.last!.count, 1) // One from Alice expectation.fulfill() }) - XCTAssertEqual(self.pollAggregator.poll.answerOptions.first!.count, 1) // One from Alice - XCTAssertEqual(self.pollAggregator.poll.answerOptions.last!.count, 0) + XCTAssertEqual(self.pollAggregator.poll?.answerOptions.first!.count, 1) // One from Alice + XCTAssertEqual(self.pollAggregator.poll?.answerOptions.last!.count, 0) bobSession.pause() @@ -135,7 +135,7 @@ class MXPollAggregatorTest: XCTestCase { func testEditing() { self.createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in - self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) + self.pollAggregator = PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) self.delegate = PollAggregatorBlockWrapper(dataUpdateCallback: { aggregator in defer { @@ -144,9 +144,9 @@ class MXPollAggregatorTest: XCTestCase { guard self.isFirstDelegateUpdate else { return } - XCTAssertEqual(aggregator.poll.text, "Some other question") - XCTAssertEqual(aggregator.poll.answerOptions.count, 2) - XCTAssertTrue(aggregator.poll.hasBeenEdited) + XCTAssertEqual(aggregator.poll?.text, "Some other question") + XCTAssertEqual(aggregator.poll?.answerOptions.count, 2) + XCTAssertEqual(aggregator.poll?.hasBeenEdited, true) expectation.fulfill() }) diff --git a/MatrixSDKTests/MatrixSDKTestsE2EData.m b/MatrixSDKTests/MatrixSDKTestsE2EData.m index a93e8479dd..c6e6cf3e33 100644 --- a/MatrixSDKTests/MatrixSDKTestsE2EData.m +++ b/MatrixSDKTests/MatrixSDKTestsE2EData.m @@ -63,12 +63,14 @@ - (void)doE2ETestWithBobAndAlice:(XCTestCase*)testCase readyToTest:(void (^)(MXSession *bobSession, MXSession *aliceSession, XCTestExpectation *expectation))readyToTest { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = YES; + MXKeyProvider.sharedInstance.delegate = [[MXKeyProviderStub alloc] init]; [matrixSDKTestsData doMXSessionTestWithBob:testCase readyToTest:^(MXSession *bobSession, XCTestExpectation *expectation) { [matrixSDKTestsData doMXSessionTestWithAlice:nil readyToTest:^(MXSession *aliceSession, XCTestExpectation *expectation2) { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = NO; + MXKeyProvider.sharedInstance.delegate = nil; readyToTest(bobSession, aliceSession, expectation); @@ -85,11 +87,13 @@ - (void)doE2ETestWithAliceInARoom:(XCTestCase*)testCase - (void)doE2ETestWithAliceInARoom:(XCTestCase *)testCase andStore:(id)store readyToTest:(void (^)(MXSession *, NSString *, XCTestExpectation *))readyToTest { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = YES; + MXKeyProvider.sharedInstance.delegate = [[MXKeyProviderStub alloc] init]; [matrixSDKTestsData doMXSessionTestWithAlice:testCase andStore:store readyToTest:^(MXSession *aliceSession, XCTestExpectation *expectation) { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = NO; + MXKeyProvider.sharedInstance.delegate = nil; [aliceSession createRoom:nil visibility:kMXRoomDirectoryVisibilityPrivate roomAlias:nil topic:nil success:^(MXRoom *room) { @@ -128,10 +132,15 @@ - (void)doE2ETestWithAliceAndBobInARoom:(XCTestCase*)testCase MXRoom *room = [aliceSession roomWithRoomId:roomId]; [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = cryptedBob; + if (cryptedBob) + { + MXKeyProvider.sharedInstance.delegate = [[MXKeyProviderStub alloc] init]; + } [matrixSDKTestsData doMXSessionTestWithBob:nil andStore:bobStore readyToTest:^(MXSession *bobSession, XCTestExpectation *expectation2) { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = NO; + MXKeyProvider.sharedInstance.delegate = nil; aliceSession.legacyCrypto.warnOnUnknowDevices = warnOnUnknowDevices; bobSession.legacyCrypto.warnOnUnknowDevices = warnOnUnknowDevices; @@ -180,10 +189,15 @@ - (void)doE2ETestWithAliceByInvitingBobInARoom:(XCTestCase*)testCase MXRoom *room = [aliceSession roomWithRoomId:roomId]; [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = cryptedBob; + if (cryptedBob) + { + MXKeyProvider.sharedInstance.delegate = [[MXKeyProviderStub alloc] init]; + } [matrixSDKTestsData doMXSessionTestWithBob:nil andStore:bobStore readyToTest:^(MXSession *bobSession, XCTestExpectation *expectation2) { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = NO; + MXKeyProvider.sharedInstance.delegate = nil; aliceSession.legacyCrypto.warnOnUnknowDevices = warnOnUnknowDevices; bobSession.legacyCrypto.warnOnUnknowDevices = warnOnUnknowDevices; @@ -256,12 +270,17 @@ - (void)doE2ETestWithAliceAndBobAndSamInARoom:(XCTestCase*)testCase MXRoom *room = [aliceSession roomWithRoomId:roomId]; [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = cryptedSam; + if (cryptedSam) + { + MXKeyProvider.sharedInstance.delegate = [[MXKeyProviderStub alloc] init]; + } // Ugly hack: Create a bob from another MatrixSDKTestsData instance and call him Sam... MatrixSDKTestsData *matrixSDKTestsData2 = [[MatrixSDKTestsData alloc] init]; [matrixSDKTestsData2 doMXSessionTestWithBob:nil readyToTest:^(MXSession *samSession, XCTestExpectation *expectation2) { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = NO; + MXKeyProvider.sharedInstance.delegate = nil; aliceSession.legacyCrypto.warnOnUnknowDevices = warnOnUnknowDevices; bobSession.legacyCrypto.warnOnUnknowDevices = warnOnUnknowDevices; @@ -309,6 +328,7 @@ - (void)loginUserOnANewDevice:(XCTestCase*)testCase onComplete:(void (^)(MXSession *newSession))onComplete { [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = YES; + MXKeyProvider.sharedInstance.delegate = [[MXKeyProviderStub alloc] init]; MXRestClient *mxRestClient = [[MXRestClient alloc] initWithHomeServer:credentials.homeServer andOnUnrecognizedCertificateBlock:nil]; @@ -327,6 +347,7 @@ - (void)loginUserOnANewDevice:(XCTestCase*)testCase MXStrongifyAndReturnIfNil(newSession); [newSession start:^{ [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = NO; + MXKeyProvider.sharedInstance.delegate = nil; onComplete(newSession); diff --git a/MatrixSDKTests/TestPlans/AllWorkingTests.xctestplan b/MatrixSDKTests/TestPlans/AllWorkingTests.xctestplan index fb12ca99dc..711f37fbce 100644 --- a/MatrixSDKTests/TestPlans/AllWorkingTests.xctestplan +++ b/MatrixSDKTests/TestPlans/AllWorkingTests.xctestplan @@ -17,6 +17,7 @@ "DirectRoomTests\/testDirectRoomsAfterInitialSync", "DirectRoomTests\/testDirectRoomsRaceConditions", "DirectRoomTests\/testSummaryAfterInitialSyncAndStorage", + "MXAes256KeyBackupTests", "MXAggregatedEditsTests\/testEditSendAndReceive", "MXAggregatedEditsTests\/testEditSendAndReceiveInE2ERoom", "MXAggregatedEditsTests\/testEditServerSide", @@ -26,7 +27,10 @@ "MXAggregatedEditsTests\/testFormattedEditSendAndReceive", "MXAggregatedEditsTests\/testFormattedEditServerSide", "MXAggregatedEditsUnitTests", + "MXAggregatedReactionTests", + "MXAggregatedReactionTests\/testAggregatedReactionServerSide", "MXAggregatedReactionTests\/testAggregationsFromInitialSync", + "MXAggregatedReactionTests\/testReactionsOnPermalinkFromAGappyInitialSync", "MXAggregatedReactionTests\/testReactionsWhenPaginatingFromAGappyInitialSync", "MXAggregatedReactionTests\/testReactionsWhenPaginatingFromAGappySync", "MXAggregatedReactionTests\/testUnreactAfterInitialSync", @@ -36,36 +40,84 @@ "MXAggregatedReferenceUnitTests", "MXAsyncTaskQueueUnitTests", "MXAuthenticationSessionUnitTests", + "MXAutoDiscoveryTests\/testAutoDiscoveryInvalidIdendityServer", "MXAutoDiscoveryTests\/testAutoDiscoveryNotJSON", "MXAutoDiscoveryTests\/testAutoDiscoverySuccessful", "MXAutoDiscoveryTests\/testAutoDiscoverySuccessfulWithNoContentType", + "MXBackgroundSyncServiceTests", "MXBackgroundSyncServiceTests\/testStoreWithGappyAndOutdatedSync()", "MXBackgroundTaskUnitTests", + "MXBaseKeyBackupTests", "MXBeaconInfoUnitTests", "MXCredentialsUnitTests", "MXCrossSigningTests", "MXCrossSigningVerificationTests", - "MXCrossSigningVerificationTests\/testVerificationByDMFullFlow", - "MXCrossSigningVerificationTests\/testVerifyingAnotherUserQRCodeVerificationFullFlow", "MXCryptoBackupTests", "MXCryptoKeyVerificationTests", - "MXCryptoKeyVerificationTests\/testVerificationByDMFullFlow", - "MXCryptoKeyVerificationTests\/testVerificationByDMWithAUserWith2Devices", - "MXCryptoKeyVerificationTests\/testVerificationByDMWithAliceWith2Devices", + "MXCryptoMigrationTests", "MXCryptoRecoveryServiceTests", "MXCryptoRequestsUnitTests", - "MXCryptoSecretShareTests\/testSecretRequestCancellation", - "MXCryptoSecretStorageTests\/testDeleteSecret", + "MXCryptoSecretShareTests", + "MXCryptoSecretStorageTests", "MXCryptoShareTests", - "MXCryptoTests", + "MXCryptoTests\/testAliceAndBlockedBob", + "MXCryptoTests\/testAliceAndBobInACryptedRoom", + "MXCryptoTests\/testAliceAndBobInACryptedRoom2", + "MXCryptoTests\/testAliceAndBobInACryptedRoomBackPaginationFromHomeServer", + "MXCryptoTests\/testAliceAndBobInACryptedRoomBackPaginationFromMemoryStore", + "MXCryptoTests\/testAliceAndBobInACryptedRoomFromInitialSync", + "MXCryptoTests\/testAliceAndBobWithNewDevice", + "MXCryptoTests\/testAliceAndNotCryptedBobInACryptedRoom", + "MXCryptoTests\/testAliceDecryptOldMessageWithANewDeviceInACryptedRoom", + "MXCryptoTests\/testAliceInACryptedRoom", + "MXCryptoTests\/testAliceInACryptedRoomAfterInitialSync", + "MXCryptoTests\/testAliceInACryptedRoomWithoutEncryption", + "MXCryptoTests\/testAliceWithNewDeviceAndBob", + "MXCryptoTests\/testAliceWithNewDeviceAndBobWithNewDevice", + "MXCryptoTests\/testBadSummaryIsEncryptedState", + "MXCryptoTests\/testBlackListUnverifiedDevices", + "MXCryptoTests\/testCryptoNoDeviceId", + "MXCryptoTests\/testCryptoPersistenceInStore", + "MXCryptoTests\/testDeviceInvalidationWhileSending", + "MXCryptoTests\/testDiscardAndRestoreOlmOutboundKey", + "MXCryptoTests\/testDownloadKeysForUserWithNoDevice", + "MXCryptoTests\/testDownloadKeysWithUnreachableHS", + "MXCryptoTests\/testEnableEncryptionAfterNonCryptedMessages", + "MXCryptoTests\/testEncryptionAlgorithmChange", + "MXCryptoTests\/testEnsureSingleOlmSession", + "MXCryptoTests\/testExportImportRoomKeysWithPassword", + "MXCryptoTests\/testFallbackKeySignatures", + "MXCryptoTests\/testFirstMessageSentWhileSessionWasPaused", + "MXCryptoTests\/testHasKeysToDecryptEvent", + "MXCryptoTests\/testImportRoomKeysWithWrongPassword", + "MXCryptoTests\/testIncomingRoomKeyRequest", + "MXCryptoTests\/testInvitedMemberInACryptedRoom", + "MXCryptoTests\/testInvitedMemberInACryptedRoom2", + "MXCryptoTests\/testIsRoomSharingHistory", + "MXCryptoTests\/testLateRoomKey", + "MXCryptoTests\/testLeftAndJoinedBob", + "MXCryptoTests\/testLeftBobAndAliceWithNewDevice", + "MXCryptoTests\/testMXDeviceListDidUpdateUsersDevicesNotification", + "MXCryptoTests\/testMXSessionEventWithEventId", + "MXCryptoTests\/testMultipleDownloadKeys", + "MXCryptoTests\/testOlmSessionUnwedging", + "MXCryptoTests\/testReplayAttack", + "MXCryptoTests\/testReplayAttackForEventEdits", + "MXCryptoTests\/testRestoreOlmOutboundKey", + "MXCryptoTests\/testRoomIsEncrypted", + "MXCryptoTests\/testRoomKeyReshare", + "MXCryptoTests\/testSendReplyToTextMessage", + "MXDehydrationTests", "MXErrorUnitTests", "MXEventAnnotationUnitTests", "MXEventReferenceUnitTests", "MXEventScanStoreUnitTests", "MXFilterTests\/testFilterAPI", "MXFilterTests\/testFilterCache", + "MXFilterTests\/testUnsupportedSyncFilter", "MXFilterUnitTests", "MXGeoURIComponentsUnitTests", + "MXHTTPClientTests", "MXHTTPClientTests\/testMainThread", "MXJSONModelTests\/testModelFromJSON", "MXJSONModelTests\/testModelsFromJSON", @@ -87,14 +139,30 @@ "MXPollRelationTests\/testBobAndAliceAnswer", "MXPushRuleUnitTests", "MXQRCodeDataUnitTests", + "MXReceiptDataIntegrationTests", + "MXReceiptDataIntegrationTests\/testAcknowledgeMessageInMainTimeline()", + "MXReceiptDataIntegrationTests\/testAcknowledgeMessageInThread()", + "MXReceiptDataIntegrationTests\/testReadReceiptsStorageInThread()", "MXReplyEventParserUnitTests", "MXResponseUnitTests", "MXRestClientExtensionsTests", "MXRestClientNoAuthAPITests", + "MXRestClientTests", + "MXRestClientTests\/testAddAndRemoveTag", + "MXRestClientTests\/testBanUserInRoom", + "MXRestClientTests\/testClaimOneTimeKeysForUsersDevices", + "MXRestClientTests\/testClose", + "MXRestClientTests\/testContextOfEvent", "MXRestClientTests\/testJoinRoomWithRoomAlias", + "MXRoomAliasAvailabilityCheckerResultTests", + "MXRoomAliasAvailabilityCheckerResultTests\/testAliasAvailable()", "MXRoomListDataManagerTests\/testNewRoomInvite()", "MXRoomListDataManagerTests\/testRoomLeave()", + "MXRoomListDataManagerTests\/testRoomUpdateWhenReceivingEncryptedEvent()", "MXRoomListDataManagerTests\/testRoomUpdateWhenReceivingEvent()", + "MXRoomListDataManagerTests\/testRoomUpdateWithLateRoomKeyFix()", + "MXRoomListDataManagerTests\/testRoomUpdateWithLateRoomKeyFixAfterBobRestart()", + "MXRoomListDataManagerTests\/testRoomUpdateWithUTD()", "MXRoomStateTests\/testDeallocation", "MXRoomStateTests\/testInviteByOtherInInitialSync", "MXRoomStateTests\/testInviteByOtherInLive", @@ -109,8 +177,10 @@ "MXSelfSignedHomeserverTests\/testTrustedCertificate", "MXSessionTests", "MXSharedHistoryKeyManagerUnitTests", + "MXSpaceChildContentTests\/testCreateSpaceCheckVisibilityOfPublicRoom()", "MXSpaceChildContentTests\/testUpdateChildSuggestion()", "MXSpaceChildContentTests\/testUpgradeSpaceChild()", + "MXSpaceServiceTest\/testCreateSpace()", "MXStoreFileStoreTests", "MXStoreMemoryStoreTests", "MXStoreNoStoreTests\/testMXNoStoreSeveralPaginateBacks", diff --git a/MatrixSDKTests/TestPlans/CryptoTests.xctestplan b/MatrixSDKTests/TestPlans/CryptoTests.xctestplan deleted file mode 100644 index 4c943befc0..0000000000 --- a/MatrixSDKTests/TestPlans/CryptoTests.xctestplan +++ /dev/null @@ -1,52 +0,0 @@ -{ - "configurations" : [ - { - "id" : "1FA4678B-FC03-4484-997A-D8629931F24B", - "name" : "Configuration 1", - "options" : { - - } - } - ], - "defaultOptions" : { - "codeCoverage" : { - "targets" : [ - { - "containerPath" : "container:MatrixSDK.xcodeproj", - "identifier" : "B14EF1C72397E90400758AF0", - "name" : "MatrixSDK-macOS" - } - ] - }, - "targetForVariableExpansion" : { - "containerPath" : "container:MatrixSDK.xcodeproj", - "identifier" : "B14EF1C72397E90400758AF0", - "name" : "MatrixSDK-macOS" - }, - "uiTestingScreenshotsLifetime" : "keepNever", - "userAttachmentLifetime" : "keepNever" - }, - "testTargets" : [ - { - "selectedTests" : [ - "MXAes256KeyBackupTests", - "MXCrossSigningTests", - "MXCrossSigningVerificationTests", - "MXCryptoKeyVerificationTests", - "MXCryptoMigrationV2Tests", - "MXCryptoSecretStorageTests", - "MXCryptoShareTests", - "MXCryptoTests", - "MXCryptoV2FactoryTests", - "MXCurve25519KeyBackupTests", - "MXMegolmEncryptionTests" - ], - "target" : { - "containerPath" : "container:MatrixSDK.xcodeproj", - "identifier" : "B1E09A0D2397FA950057C069", - "name" : "MatrixSDKTests-macOS" - } - } - ], - "version" : 1 -} diff --git a/MatrixSDKTests/TestPlans/UnitTests.xctestplan b/MatrixSDKTests/TestPlans/UnitTests.xctestplan index 1ebc14fb9b..730bc6d142 100644 --- a/MatrixSDKTests/TestPlans/UnitTests.xctestplan +++ b/MatrixSDKTests/TestPlans/UnitTests.xctestplan @@ -47,7 +47,9 @@ "MXCryptoKeyBackupEngineUnitTests", "MXCryptoMachineUnitTests", "MXCryptoMigrationStoreUnitTests", + "MXCryptoMigrationV2UnitTests", "MXCryptoRequestsUnitTests", + "MXCryptoV2FactoryUnitTests", "MXDeviceInfoSourceUnitTests", "MXDeviceInfoUnitTests", "MXDeviceListOperationsPoolUnitTests", diff --git a/MatrixSDKTests/TestPlans/UnitTestsWithSanitizers.xctestplan b/MatrixSDKTests/TestPlans/UnitTestsWithSanitizers.xctestplan index 392638cb35..4435fd6fbb 100644 --- a/MatrixSDKTests/TestPlans/UnitTestsWithSanitizers.xctestplan +++ b/MatrixSDKTests/TestPlans/UnitTestsWithSanitizers.xctestplan @@ -57,7 +57,9 @@ "MXCryptoKeyBackupEngineUnitTests", "MXCryptoMachineUnitTests", "MXCryptoMigrationStoreUnitTests", + "MXCryptoMigrationV2UnitTests", "MXCryptoRequestsUnitTests", + "MXCryptoV2FactoryUnitTests", "MXDeviceInfoSourceUnitTests", "MXDeviceInfoUnitTests", "MXDeviceListOperationsPoolUnitTests",