From 00d12335120f856fec605e5114d23b00a4bb3957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 11 Aug 2021 15:49:37 +0200 Subject: [PATCH] crypto: Upload signatures when we confirm a verification as well --- .../sdk/internal/crypto/QrCodeVerification.kt | 12 ++++++--- .../sdk/internal/crypto/SasVerification.kt | 13 +++++++--- rust-sdk/src/lib.rs | 2 +- rust-sdk/src/machine.rs | 26 ++++++++++++------- rust-sdk/src/olm.udl | 7 ++++- rust-sdk/src/verification.rs | 12 ++++++++- 6 files changed, 54 insertions(+), 18 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/QrCodeVerification.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/QrCodeVerification.kt index de06691f93..bb6af2a48c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/QrCodeVerification.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/QrCodeVerification.kt @@ -174,14 +174,20 @@ internal class QrCodeVerification( */ @Throws(CryptoStoreErrorException::class) private suspend fun confirm() { - val request = withContext(Dispatchers.IO) + val result = withContext(Dispatchers.IO) { machine.confirmVerification(request.otherUser(), request.flowId()) } - if (request != null) { - this.sender.sendVerificationRequest(request) + if (result != null) { + this.sender.sendVerificationRequest(result.request) dispatchTxUpdated() + + val signatureRequest = result.signatureRequest + + if (signatureRequest != null) { + this.sender.sendSignatureUpload(signatureRequest) + } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SasVerification.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SasVerification.kt index 4756ac5b1c..61e366ea94 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SasVerification.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SasVerification.kt @@ -204,12 +204,19 @@ internal class SasVerification( @Throws(CryptoStoreErrorException::class) private suspend fun confirm() { - val request = withContext(Dispatchers.IO) { + val result = withContext(Dispatchers.IO) { machine.confirmVerification(inner.otherUserId, inner.flowId) } - if (request != null) { - this.sender.sendVerificationRequest(request) + + if (result != null) { + this.sender.sendVerificationRequest(result.request) dispatchTxUpdated() + + val signatureRequest = result.signatureRequest + + if (signatureRequest != null) { + this.sender.sendSignatureUpload(signatureRequest) + } } } diff --git a/rust-sdk/src/lib.rs b/rust-sdk/src/lib.rs index 41842f7b6d..7d93ac22b4 100644 --- a/rust-sdk/src/lib.rs +++ b/rust-sdk/src/lib.rs @@ -29,7 +29,7 @@ pub use responses::{ pub use users::UserIdentity; pub use verification::{ CancelInfo, QrCode, RequestVerificationResult, Sas, ScanResult, StartSasResult, Verification, - VerificationRequest, + VerificationRequest, ConfirmVerificationResult, }; /// Callback that will be passed over the FFI to report progress diff --git a/rust-sdk/src/machine.rs b/rust-sdk/src/machine.rs index 0be6f0fde1..701baa0602 100644 --- a/rust-sdk/src/machine.rs +++ b/rust-sdk/src/machine.rs @@ -38,10 +38,10 @@ use matrix_sdk_crypto::{ use crate::{ error::{CryptoStoreError, DecryptionError, SecretImportError, SignatureError}, responses::{response_from_string, OutgoingVerificationRequest, OwnedResponse}, - BootstrapCrossSigningResult, CrossSigningKeyExport, CrossSigningStatus, DecryptedEvent, Device, - DeviceLists, KeyImportError, KeysImportResult, ProgressListener, QrCode, Request, RequestType, - RequestVerificationResult, ScanResult, SignatureUploadRequest, StartSasResult, UserIdentity, - Verification, VerificationRequest, + BootstrapCrossSigningResult, ConfirmVerificationResult, CrossSigningKeyExport, + CrossSigningStatus, DecryptedEvent, Device, DeviceLists, KeyImportError, KeysImportResult, + ProgressListener, QrCode, Request, RequestType, RequestVerificationResult, ScanResult, + SignatureUploadRequest, StartSasResult, UserIdentity, Verification, VerificationRequest, }; /// A high level state machine that handles E2EE for Matrix. @@ -945,18 +945,26 @@ impl OlmMachine { &self, user_id: &str, flow_id: &str, - ) -> Result, CryptoStoreError> { + ) -> Result, CryptoStoreError> { let user_id = UserId::try_from(user_id)?; Ok( if let Some(verification) = self.inner.get_verification(&user_id, flow_id) { match verification { RustVerification::SasV1(v) => { - // TODO there's a signature upload request here, we'll - // want to return that one as well. - self.runtime.block_on(v.confirm())?.0.map(|r| r.into()) + let (request, signature_request) = self.runtime.block_on(v.confirm())?; + + request.map(|r| ConfirmVerificationResult { + request: r.into(), + signature_request: signature_request.map(|s| s.into()), + }) + } + RustVerification::QrV1(v) => { + v.confirm_scanning().map(|r| ConfirmVerificationResult { + request: r.into(), + signature_request: None, + }) } - RustVerification::QrV1(v) => v.confirm_scanning().map(|r| r.into()), } } else { None diff --git a/rust-sdk/src/olm.udl b/rust-sdk/src/olm.udl index f54c00cba2..41c5747bf6 100644 --- a/rust-sdk/src/olm.udl +++ b/rust-sdk/src/olm.udl @@ -180,6 +180,11 @@ dictionary RequestVerificationResult { OutgoingVerificationRequest request; }; +dictionary ConfirmVerificationResult { + OutgoingVerificationRequest request; + SignatureUploadRequest? signature_request; +}; + [Enum] interface Verification { SasV1(Sas sas); @@ -296,7 +301,7 @@ interface OlmMachine { ); [Throws=CryptoStoreError] - OutgoingVerificationRequest? confirm_verification([ByRef] string user_id, [ByRef] string flow_id); + ConfirmVerificationResult? confirm_verification([ByRef] string user_id, [ByRef] string flow_id); OutgoingVerificationRequest? cancel_verification( [ByRef] string user_id, [ByRef] string flow_id, diff --git a/rust-sdk/src/verification.rs b/rust-sdk/src/verification.rs index d75bc01d3c..39f3012622 100644 --- a/rust-sdk/src/verification.rs +++ b/rust-sdk/src/verification.rs @@ -3,7 +3,7 @@ use matrix_sdk_crypto::{ VerificationRequest as InnerVerificationRequest, }; -use crate::OutgoingVerificationRequest; +use crate::{OutgoingVerificationRequest, SignatureUploadRequest}; /// Enum representing the different verification flows we support. pub enum Verification { @@ -165,6 +165,16 @@ pub struct RequestVerificationResult { pub request: OutgoingVerificationRequest, } +/// A result type for confirming verifications. +pub struct ConfirmVerificationResult { + /// The request that needs to be sent out to notify the other side that we + /// confirmed the verification. + pub request: OutgoingVerificationRequest, + /// A request that will upload signatures of the verified device or user, if + /// the verification is completed and we're able to sign devices or users + pub signature_request: Option, +} + /// The verificatoin request object which then can transition into some concrete /// verification method pub struct VerificationRequest {