Skip to content

Commit

Permalink
Merge pull request #1725 from matrix-org/andy/update_crypto
Browse files Browse the repository at this point in the history
Update MatrixSDKCrypto
  • Loading branch information
Anderas authored Feb 28, 2023
2 parents 29e3713 + 2906861 commit 69e4dc3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion MatrixSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Pod::Spec.new do |s|
ss.dependency 'OLMKit', '~> 3.2.5'
ss.dependency 'Realm', '10.27.0'
ss.dependency 'libbase58', '~> 0.1.4'
ss.dependency 'MatrixSDKCrypto', '0.2.0', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
ss.dependency 'MatrixSDKCrypto', '0.2.1', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
end

s.subspec 'JingleCallStack' do |ss|
Expand Down
6 changes: 6 additions & 0 deletions MatrixSDKTests/Crypto/MXCryptoV2FactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class MXCryptoV2FactoryTests: XCTestCase {
let legacyStore = MXRealmCryptoStore.init(credentials: session.credentials)
XCTAssertNotNil(legacyStore)
XCTAssertEqual(legacyStore?.cryptoVersion, .versionLegacyDeprecated)

await env.close()
}

func test_migratesExistingUser() async throws {
Expand All @@ -95,6 +97,8 @@ class MXCryptoV2FactoryTests: XCTestCase {
// Assert we still have legacy store but it is now marked as deprecated
XCTAssertNotNil(legacyStore)
XCTAssertEqual(legacyStore?.cryptoVersion, .versionLegacyDeprecated)

await env.close()
}

func test_doesNotMigrateDeprecatedStore() async throws {
Expand All @@ -114,5 +118,7 @@ class MXCryptoV2FactoryTests: XCTestCase {
// Assert we still have legacy store which is still marked as deprecated
XCTAssertNotNil(legacyStore)
XCTAssertEqual(legacyStore?.cryptoVersion, .versionLegacyDeprecated)

await env.close()
}
}
23 changes: 15 additions & 8 deletions MatrixSDKTests/Crypto/Migration/MXCryptoMigrationV2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,36 @@ class MXCryptoMigrationV2Tests: XCTestCase {
func test_migratesAccountDetails() async throws {
let env = try await e2eData.startE2ETest()
let legacySession = env.session

let machine = try self.migratedOlmMachine(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()
}

// Temporary disable test that fails to run on CI
func xtest_canDecryptMegolmMessageAfterMigration() async throws {
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.migratedOlmMachine(session: env.session)

// Decrypt the event using crypto v2
let decrypted = try machine.decryptRoomEvent(event)
let result = try MXEventDecryptionResult(event: decrypted)
Expand All @@ -111,6 +112,8 @@ class MXCryptoMigrationV2Tests: XCTestCase {
// 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 {
Expand All @@ -129,6 +132,8 @@ class MXCryptoMigrationV2Tests: XCTestCase {
// As expected we cannot cross sign in v2 either
XCTAssertFalse(crossSigningV2.canCrossSign)
XCTAssertFalse(crossSigningV2.hasAllPrivateKeys)

await env.close()
}

func test_migratesCrossSigningStatus() async throws {
Expand All @@ -148,6 +153,8 @@ class MXCryptoMigrationV2Tests: XCTestCase {
// And confirm that cross signing is ready
XCTAssertTrue(crossSigningV2.canCrossSign)
XCTAssertTrue(crossSigningV2.hasAllPrivateKeys)

await env.close()
}
}

Expand Down
10 changes: 5 additions & 5 deletions MatrixSDKTests/MatrixSDKTestsE2EData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ extension MatrixSDKTestsE2EData {
self.roomId = roomId
}

deinit {
let session = session
DispatchQueue.main.async {
session.close()
}
@MainActor
func close() {
session.close()
}
}

@MainActor
func startE2ETest() async throws -> Environment {

return try await withCheckedThrowingContinuation { continuation in
doE2ETestWithAlice(inARoom: nil) { session, roomId, _ in
guard let session = session, let roomId = roomId else {
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract_target 'MatrixSDK' do

pod 'Realm', '10.27.0'
pod 'libbase58', '~> 0.1.4'
pod 'MatrixSDKCrypto', "0.2.0", :inhibit_warnings => true
pod 'MatrixSDKCrypto', "0.2.1", :inhibit_warnings => true

target 'MatrixSDK-iOS' do
platform :ios, '11.0'
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PODS:
- AFNetworking/NSURLSession
- GZIP (1.3.0)
- libbase58 (0.1.4)
- MatrixSDKCrypto (0.2.0)
- MatrixSDKCrypto (0.2.1)
- OHHTTPStubs (9.1.0):
- OHHTTPStubs/Default (= 9.1.0)
- OHHTTPStubs/Core (9.1.0)
Expand Down Expand Up @@ -44,7 +44,7 @@ DEPENDENCIES:
- AFNetworking (~> 4.0.0)
- GZIP (~> 1.3.0)
- libbase58 (~> 0.1.4)
- MatrixSDKCrypto (= 0.2.0)
- MatrixSDKCrypto (= 0.2.1)
- OHHTTPStubs (~> 9.1.0)
- OLMKit (~> 3.2.5)
- Realm (= 10.27.0)
Expand All @@ -65,12 +65,12 @@ SPEC CHECKSUMS:
AFNetworking: 3bd23d814e976cd148d7d44c3ab78017b744cd58
GZIP: 416858efbe66b41b206895ac6dfd5493200d95b3
libbase58: 7c040313537b8c44b6e2d15586af8e21f7354efd
MatrixSDKCrypto: e1ef22aae76b5a6f030ace21a47be83864f4ff44
MatrixSDKCrypto: 477d818bf2cc37b6cf702a290eb647bc8cf3cb1b
OHHTTPStubs: 90eac6d8f2c18317baeca36698523dc67c513831
OLMKit: da115f16582e47626616874e20f7bb92222c7a51
Realm: 9ca328bd7e700cc19703799785e37f77d1a130f2
SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82

PODFILE CHECKSUM: 22dbe406b768ebe51e6de5fe02348d35a4d3d9f6
PODFILE CHECKSUM: e6ea6492ce460203d61def97cf6ceb27f8827d70

COCOAPODS: 1.11.3
1 change: 1 addition & 0 deletions changelog.d/pr-1725.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update MatrixSDKCrypto

0 comments on commit 69e4dc3

Please sign in to comment.