diff --git a/CHANGES.md b/CHANGES.md index b29f7cbc4..8412d1990 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +## Changes in 0.26.9 (2023-04-18) + +🐛 Bugfixes + +- Cross-signing: Setup cross-signing with empty auth session ([#1774](https://github.com/matrix-org/matrix-ios-sdk/pull/1774)) + + ## Changes in 0.26.8 (2023-04-18) 🙌 Improvements diff --git a/MatrixSDK.podspec b/MatrixSDK.podspec index bd29e618e..ecd9a2d63 100644 --- a/MatrixSDK.podspec +++ b/MatrixSDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "MatrixSDK" - s.version = "0.26.8" + s.version = "0.26.9" s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)" s.description = <<-DESC diff --git a/MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift b/MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift index 2c165967c..d46a64837 100644 --- a/MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift +++ b/MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift @@ -217,8 +217,9 @@ class MXCrossSigningV2: NSObject, MXCrossSigning { let session = authSession.session, let userId = restClient.credentials?.userId else { - log.error("Missing parameters") - throw Error.missingAuthSession + // Try to setup cross-signing without authentication parameters in case if a grace period is enabled + log.warning("Setting up cross-signing without authentication parameters") + return [:] } return [ diff --git a/MatrixSDK/MatrixSDKVersion.m b/MatrixSDK/MatrixSDKVersion.m index b8ab06bb4..b65d29446 100644 --- a/MatrixSDK/MatrixSDKVersion.m +++ b/MatrixSDK/MatrixSDKVersion.m @@ -16,4 +16,4 @@ #import -NSString *const MatrixSDKVersion = @"0.26.8"; +NSString *const MatrixSDKVersion = @"0.26.9"; diff --git a/MatrixSDKTests/Crypto/CrossSigning/MXCrossSigningV2UnitTests.swift b/MatrixSDKTests/Crypto/CrossSigning/MXCrossSigningV2UnitTests.swift index 617eb4486..2de42cdb8 100644 --- a/MatrixSDKTests/Crypto/CrossSigning/MXCrossSigningV2UnitTests.swift +++ b/MatrixSDKTests/Crypto/CrossSigning/MXCrossSigningV2UnitTests.swift @@ -21,19 +21,74 @@ import MatrixSDKCrypto class MXCrossSigningV2UnitTests: XCTestCase { + class RestClientStub: MXRestClientStub { + var stubbedAuthSession: MXAuthenticationSession? + + override var credentials: MXCredentials! { + let cred = MXCredentials() + cred.userId = "Alice" + cred.deviceId = "XYZ" + return cred + } + + override func authSession( + toUploadDeviceSigningKeys success: ((MXAuthenticationSession?) -> Void)!, + failure: ((Error?) -> Void)! + ) -> MXHTTPOperation! { + success(stubbedAuthSession) + return MXHTTPOperation() + } + } + var crypto: CryptoCrossSigningStub! var crossSigning: MXCrossSigningV2! - var restClient: MXRestClientStub! + var restClient: RestClientStub! override func setUp() { crypto = CryptoCrossSigningStub() - restClient = MXRestClientStub() + restClient = RestClientStub() crossSigning = MXCrossSigningV2( crossSigning: crypto, restClient: restClient ) } + // MARK: - Setup + + func test_setup_canSetupWithoutAuthSession() { + let exp = expectation(description: "exp") + crossSigning.setup(withPassword: "pass") { + XCTAssertEqual(self.crypto.spyAuthParams as? [String: String], [:]) + exp.fulfill() + } failure: { + XCTFail("Failed setting up cross signing with error - \($0)") + exp.fulfill() + } + waitForExpectations(timeout: 1) + } + + func test_setup_canSetupWitAuthSession() { + let exp = expectation(description: "exp") + restClient.stubbedAuthSession = MXAuthenticationSession() + restClient.stubbedAuthSession?.session = "123" + + crossSigning.setup(withPassword: "pass") { + XCTAssertEqual(self.crypto.spyAuthParams as? [String: String], [ + "session": "123", + "user": "Alice", + "password": "pass", + "type": kMXLoginFlowTypePassword + ]) + exp.fulfill() + } failure: { + XCTFail("Failed setting up cross signing with error - \($0)") + exp.fulfill() + } + waitForExpectations(timeout: 1) + } + + // MARK: - State + func test_state_notBootstrapped() { XCTAssertEqual(crossSigning.state, .notBootstrapped) } @@ -104,6 +159,8 @@ class MXCrossSigningV2UnitTests: XCTestCase { } } + // MARK: - Devices + func test_crossSignDevice_verifiesUntrustedDevice() async throws { let userId = "Alice" let deviceId = "ABCD" diff --git a/MatrixSDKTests/Crypto/CryptoMachine/MXCryptoProtocolStubs.swift b/MatrixSDKTests/Crypto/CryptoMachine/MXCryptoProtocolStubs.swift index 79069835a..570e35d39 100644 --- a/MatrixSDKTests/Crypto/CryptoMachine/MXCryptoProtocolStubs.swift +++ b/MatrixSDKTests/Crypto/CryptoMachine/MXCryptoProtocolStubs.swift @@ -89,7 +89,9 @@ class CryptoCrossSigningStub: CryptoIdentityStub, MXCryptoCrossSigning { return stubbedStatus } + var spyAuthParams: [AnyHashable: Any]? func bootstrapCrossSigning(authParams: [AnyHashable : Any]) async throws { + self.spyAuthParams = authParams } func exportCrossSigningKeys() -> CrossSigningKeyExport? {