mirror of
https://github.com/element-hq/element-android
synced 2024-12-19 15:58:27 +03:00
rust: Bind the initial verification request type and methods
This commit is contained in:
parent
c0bac69733
commit
e46578a087
4 changed files with 158 additions and 8 deletions
|
@ -24,11 +24,11 @@ features = ["lax_deserialize"]
|
||||||
|
|
||||||
[dependencies.matrix-sdk-common]
|
[dependencies.matrix-sdk-common]
|
||||||
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
||||||
branch = "verification-qr"
|
rev = "0fb3dedd1cd3b0766fa7378754480d52d38e8ef2"
|
||||||
|
|
||||||
[dependencies.matrix-sdk-crypto]
|
[dependencies.matrix-sdk-crypto]
|
||||||
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
||||||
branch = "verification-qr"
|
rev = "0fb3dedd1cd3b0766fa7378754480d52d38e8ef2"
|
||||||
features = ["sled_cryptostore"]
|
features = ["sled_cryptostore"]
|
||||||
|
|
||||||
[dependencies.tokio]
|
[dependencies.tokio]
|
||||||
|
|
|
@ -7,7 +7,7 @@ mod responses;
|
||||||
pub use device::Device;
|
pub use device::Device;
|
||||||
pub use error::{CryptoStoreError, DecryptionError, KeyImportError, MachineCreationError};
|
pub use error::{CryptoStoreError, DecryptionError, KeyImportError, MachineCreationError};
|
||||||
pub use logger::{set_logger, Logger};
|
pub use logger::{set_logger, Logger};
|
||||||
pub use machine::{KeyRequestPair, OlmMachine, Sas};
|
pub use machine::{KeyRequestPair, OlmMachine, Sas, VerificationRequest};
|
||||||
pub use responses::{
|
pub use responses::{
|
||||||
DeviceLists, KeysImportResult, OutgoingVerificationRequest, Request, RequestType,
|
DeviceLists, KeysImportResult, OutgoingVerificationRequest, Request, RequestType,
|
||||||
};
|
};
|
||||||
|
@ -30,4 +30,35 @@ pub struct DecryptedEvent {
|
||||||
pub forwarding_curve25519_chain: Vec<String>,
|
pub forwarding_curve25519_chain: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum CancelCode {
|
||||||
|
User,
|
||||||
|
Timeout,
|
||||||
|
UnknownTransaction,
|
||||||
|
UnknownMethod,
|
||||||
|
UnexpectedMessage,
|
||||||
|
KeyMismatch,
|
||||||
|
UserMismatch,
|
||||||
|
InvalidMessage,
|
||||||
|
Accepted,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ruma::events::key::verification::cancel::CancelCode> for CancelCode {
|
||||||
|
fn from(c: ruma::events::key::verification::cancel::CancelCode) -> Self {
|
||||||
|
use ruma::events::key::verification::cancel::CancelCode as RumaCancelCode;
|
||||||
|
|
||||||
|
match c {
|
||||||
|
RumaCancelCode::User => Self::User,
|
||||||
|
RumaCancelCode::Timeout => Self::Timeout,
|
||||||
|
RumaCancelCode::UnknownTransaction => Self::UnknownTransaction,
|
||||||
|
RumaCancelCode::UnknownMethod => Self::UnknownMethod,
|
||||||
|
RumaCancelCode::UnexpectedMessage => Self::UnexpectedMessage,
|
||||||
|
RumaCancelCode::KeyMismatch => Self::KeyMismatch,
|
||||||
|
RumaCancelCode::UserMismatch => Self::UserMismatch,
|
||||||
|
RumaCancelCode::InvalidMessage => Self::InvalidMessage,
|
||||||
|
RumaCancelCode::Accepted => Self::Accepted,
|
||||||
|
RumaCancelCode::_Custom(_) => Self::User,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/olm.uniffi.rs"));
|
include!(concat!(env!("OUT_DIR"), "/olm.uniffi.rs"));
|
||||||
|
|
|
@ -18,8 +18,8 @@ use ruma::{
|
||||||
IncomingResponse,
|
IncomingResponse,
|
||||||
},
|
},
|
||||||
events::{
|
events::{
|
||||||
room::encrypted::EncryptedEventContent, AnyMessageEventContent, EventContent,
|
key::verification::VerificationMethod, room::encrypted::EncryptedEventContent,
|
||||||
SyncMessageEvent,
|
AnyMessageEventContent, EventContent, SyncMessageEvent,
|
||||||
},
|
},
|
||||||
DeviceKeyAlgorithm, RoomId, UserId,
|
DeviceKeyAlgorithm, RoomId, UserId,
|
||||||
};
|
};
|
||||||
|
@ -30,14 +30,14 @@ use tokio::runtime::Runtime;
|
||||||
use matrix_sdk_common::{deserialized_responses::AlgorithmInfo, uuid::Uuid};
|
use matrix_sdk_common::{deserialized_responses::AlgorithmInfo, uuid::Uuid};
|
||||||
use matrix_sdk_crypto::{
|
use matrix_sdk_crypto::{
|
||||||
decrypt_key_export, encrypt_key_export, EncryptionSettings, OlmMachine as InnerMachine,
|
decrypt_key_export, encrypt_key_export, EncryptionSettings, OlmMachine as InnerMachine,
|
||||||
Sas as InnerSas,
|
Sas as InnerSas, VerificationRequest as InnerVerificationRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{CryptoStoreError, DecryptionError, MachineCreationError},
|
error::{CryptoStoreError, DecryptionError, MachineCreationError},
|
||||||
responses::{response_from_string, OutgoingVerificationRequest, OwnedResponse},
|
responses::{response_from_string, OutgoingVerificationRequest, OwnedResponse},
|
||||||
DecryptedEvent, Device, DeviceLists, KeyImportError, KeysImportResult, ProgressListener,
|
CancelCode, DecryptedEvent, Device, DeviceLists, KeyImportError, KeysImportResult,
|
||||||
Request, RequestType,
|
ProgressListener, Request, RequestType,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A high level state machine that handles E2EE for Matrix.
|
/// A high level state machine that handles E2EE for Matrix.
|
||||||
|
@ -70,6 +70,44 @@ impl From<InnerSas> for Sas {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct VerificationRequest {
|
||||||
|
pub other_user_id: String,
|
||||||
|
pub other_device_id: Option<String>,
|
||||||
|
pub flow_id: String,
|
||||||
|
pub is_cancelled: bool,
|
||||||
|
pub is_done: bool,
|
||||||
|
pub is_ready: bool,
|
||||||
|
pub room_id: Option<String>,
|
||||||
|
pub cancel_code: Option<CancelCode>,
|
||||||
|
pub we_started: bool,
|
||||||
|
pub is_passive: bool,
|
||||||
|
pub their_methods: Option<Vec<String>>,
|
||||||
|
pub our_methods: Option<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<InnerVerificationRequest> for VerificationRequest {
|
||||||
|
fn from(v: InnerVerificationRequest) -> Self {
|
||||||
|
Self {
|
||||||
|
other_user_id: v.other_user().to_string(),
|
||||||
|
other_device_id: v.other_device_id().map(|d| d.to_string()),
|
||||||
|
flow_id: v.flow_id().as_str().to_owned(),
|
||||||
|
is_cancelled: v.is_cancelled(),
|
||||||
|
is_done: v.is_done(),
|
||||||
|
is_ready: v.is_ready(),
|
||||||
|
room_id: v.room_id().map(|r| r.to_string()),
|
||||||
|
cancel_code: v.cancel_code().map(|c| c.clone().into()),
|
||||||
|
we_started: v.we_started(),
|
||||||
|
is_passive: v.is_passive(),
|
||||||
|
their_methods: v
|
||||||
|
.their_supported_methods()
|
||||||
|
.map(|v| v.into_iter().map(|m| m.to_string()).collect()),
|
||||||
|
our_methods: v
|
||||||
|
.our_supported_methods()
|
||||||
|
.map(|v| v.into_iter().map(|m| m.to_string()).collect()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A pair of outgoing room key requests, both of those are sendToDevice
|
/// A pair of outgoing room key requests, both of those are sendToDevice
|
||||||
/// requests.
|
/// requests.
|
||||||
pub struct KeyRequestPair {
|
pub struct KeyRequestPair {
|
||||||
|
@ -556,6 +594,51 @@ impl OlmMachine {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_verification_requests(&self, user_id: &str) -> Vec<VerificationRequest> {
|
||||||
|
let user_id = if let Ok(user_id) = UserId::try_from(user_id) {
|
||||||
|
user_id
|
||||||
|
} else {
|
||||||
|
return vec![];
|
||||||
|
};
|
||||||
|
|
||||||
|
self.inner
|
||||||
|
.get_verification_requests(&user_id)
|
||||||
|
.into_iter()
|
||||||
|
.map(|v| v.into())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_verification_request(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
flow_id: &str,
|
||||||
|
) -> Option<VerificationRequest> {
|
||||||
|
let user_id = UserId::try_from(user_id).ok()?;
|
||||||
|
|
||||||
|
self.inner
|
||||||
|
.get_verification_request(&user_id, flow_id)
|
||||||
|
.map(|v| v.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn accept_verification_request(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
flow_id: &str,
|
||||||
|
methods: Vec<String>,
|
||||||
|
) -> Option<OutgoingVerificationRequest> {
|
||||||
|
let user_id = UserId::try_from(user_id).ok()?;
|
||||||
|
let methods = methods
|
||||||
|
.into_iter()
|
||||||
|
.map(|m| VerificationMethod::from(m))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if let Some(verification) = self.inner.get_verification_request(&user_id, flow_id) {
|
||||||
|
verification.accept_with_methods(methods).map(|r| r.into())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_verification(&self, flow_id: &str) -> Option<Sas> {
|
pub fn get_verification(&self, flow_id: &str) -> Option<Sas> {
|
||||||
todo!()
|
todo!()
|
||||||
// self.inner.get_verification(flow_id).map(|s| s.into())
|
// self.inner.get_verification(flow_id).map(|s| s.into())
|
||||||
|
|
|
@ -73,6 +73,34 @@ dictionary Sas {
|
||||||
boolean timed_out;
|
boolean timed_out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary VerificationRequest {
|
||||||
|
string other_user_id;
|
||||||
|
string? other_device_id;
|
||||||
|
string flow_id;
|
||||||
|
boolean is_cancelled;
|
||||||
|
boolean is_done;
|
||||||
|
boolean is_ready;
|
||||||
|
boolean we_started;
|
||||||
|
boolean is_passive;
|
||||||
|
string? room_id;
|
||||||
|
CancelCode? cancel_code;
|
||||||
|
sequence<string>? their_methods;
|
||||||
|
sequence<string>? our_methods;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
enum CancelCode {
|
||||||
|
"User",
|
||||||
|
"Timeout",
|
||||||
|
"UnknownTransaction",
|
||||||
|
"UnknownMethod",
|
||||||
|
"UnexpectedMessage",
|
||||||
|
"KeyMismatch",
|
||||||
|
"UserMismatch",
|
||||||
|
"InvalidMessage",
|
||||||
|
"Accepted",
|
||||||
|
};
|
||||||
|
|
||||||
dictionary KeyRequestPair {
|
dictionary KeyRequestPair {
|
||||||
Request? cancellation;
|
Request? cancellation;
|
||||||
Request key_request;
|
Request key_request;
|
||||||
|
@ -136,8 +164,16 @@ interface OlmMachine {
|
||||||
[Throws=CryptoStoreError]
|
[Throws=CryptoStoreError]
|
||||||
sequence<Request> share_room_key([ByRef] string room_id, sequence<string> users);
|
sequence<Request> share_room_key([ByRef] string room_id, sequence<string> users);
|
||||||
|
|
||||||
|
sequence<VerificationRequest> get_verification_requests([ByRef] string user_id);
|
||||||
|
VerificationRequest? get_verification_request([ByRef] string user_id, [ByRef] string flow_id);
|
||||||
Sas? get_verification([ByRef] string flow_id);
|
Sas? get_verification([ByRef] string flow_id);
|
||||||
|
|
||||||
|
OutgoingVerificationRequest? accept_verification_request(
|
||||||
|
[ByRef] string user_id,
|
||||||
|
[ByRef] string flow_id,
|
||||||
|
sequence<string> methods
|
||||||
|
);
|
||||||
|
|
||||||
[Throws=CryptoStoreError]
|
[Throws=CryptoStoreError]
|
||||||
Sas start_verification([ByRef] Device device);
|
Sas start_verification([ByRef] Device device);
|
||||||
[Throws=CryptoStoreError]
|
[Throws=CryptoStoreError]
|
||||||
|
|
Loading…
Reference in a new issue