Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to log in using a QR code #3466

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ratatui = "ratatui"
# base64 false positives
Nd = "Nd"
Abl = "Abl"
Som = "Som"
Ba = "Ba"

[files]
extend-exclude = [
Expand Down
109 changes: 106 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ tracing-core = "0.1.32"
uniffi = { version = "0.27.1" }
uniffi_bindgen = { version = "0.27.1" }
url = "2.5.0"
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "826d0aa22a9b5405535927c7691492db4b92a43b" }
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "4ef989c6a8eba0bc809e285a081c56320a9bbf1e" }
wiremock = "0.6.0"
zeroize = "1.6.0"

Expand Down
11 changes: 7 additions & 4 deletions benchmarks/benches/room_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ pub fn receive_all_members_benchmark(c: &mut Criterion) {

let base_client = BaseClient::with_store_config(StoreConfig::new().state_store(sqlite_store));
runtime
.block_on(base_client.set_session_meta(SessionMeta {
user_id: user_id!("@somebody:example.com").to_owned(),
device_id: device_id!("DEVICE_ID").to_owned(),
}))
.block_on(base_client.set_session_meta(
SessionMeta {
user_id: user_id!("@somebody:example.com").to_owned(),
device_id: device_id!("DEVICE_ID").to_owned(),
},
None,
))
.expect("Could not set session meta");
base_client.get_or_create_room(&room_id, RoomState::Joined);

Expand Down
55 changes: 39 additions & 16 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use ruma::events::{
room::{history_visibility::HistoryVisibility, message::MessageType},
SyncMessageLikeEvent,
};
#[cfg(doc)]
use ruma::DeviceId;
use ruma::{
api::client as api,
events::{
Expand Down Expand Up @@ -200,13 +202,28 @@ impl BaseClient {
/// * `session_meta` - The meta of a session that the user already has from
/// a previous login call.
///
/// * `custom_account` - A custom
/// [`matrix_sdk_crypto::vodozemac::olm::Account`] to be used for the
/// identity and one-time keys of this [`BaseClient`]. If no account is
/// provided, a new default one or one from the store will be used. If an
/// account is provided and one already exists in the store for this
/// [`UserId`]/[`DeviceId`] combination, an error will be raised. This is
/// useful if one wishes to create identity keys before knowing the
/// user/device IDs, e.g., to use the identity key as the device ID.
///
/// This method panics if it is called twice.
pub async fn set_session_meta(&self, session_meta: SessionMeta) -> Result<()> {
pub async fn set_session_meta(
&self,
session_meta: SessionMeta,
#[cfg(feature = "e2e-encryption")] custom_account: Option<
crate::crypto::vodozemac::olm::Account,
>,
) -> Result<()> {
debug!(user_id = ?session_meta.user_id, device_id = ?session_meta.device_id, "Restoring login");
self.store.set_session_meta(session_meta.clone(), &self.roominfo_update_sender).await?;

#[cfg(feature = "e2e-encryption")]
self.regenerate_olm().await?;
self.regenerate_olm(custom_account).await?;

Ok(())
}
Expand All @@ -215,7 +232,10 @@ impl BaseClient {
///
/// In particular, this will clear all its caches.
#[cfg(feature = "e2e-encryption")]
pub async fn regenerate_olm(&self) -> Result<()> {
pub async fn regenerate_olm(
&self,
custom_account: Option<crate::crypto::vodozemac::olm::Account>,
) -> Result<()> {
tracing::debug!("regenerating OlmMachine");
let session_meta = self.session_meta().ok_or(Error::OlmError(OlmError::MissingSession))?;

Expand All @@ -226,7 +246,7 @@ impl BaseClient {
&session_meta.user_id,
&session_meta.device_id,
self.crypto_store.clone(),
None,
custom_account,
)
.await
.map_err(OlmError::from)?;
Expand Down Expand Up @@ -1704,10 +1724,11 @@ mod tests {

let client = BaseClient::new();
client
.set_session_meta(SessionMeta {
user_id: user_id.to_owned(),
device_id: "FOOBAR".into(),
})
.set_session_meta(
SessionMeta { user_id: user_id.to_owned(), device_id: "FOOBAR".into() },
#[cfg(feature = "e2e-encryption")]
None,
)
.await
.unwrap();

Expand Down Expand Up @@ -1764,10 +1785,11 @@ mod tests {

let client = BaseClient::new();
client
.set_session_meta(SessionMeta {
user_id: user_id.to_owned(),
device_id: "FOOBAR".into(),
})
.set_session_meta(
SessionMeta { user_id: user_id.to_owned(), device_id: "FOOBAR".into() },
#[cfg(feature = "e2e-encryption")]
None,
)
.await
.unwrap();

Expand Down Expand Up @@ -1823,10 +1845,11 @@ mod tests {

let client = BaseClient::new();
client
.set_session_meta(SessionMeta {
user_id: user_id.to_owned(),
device_id: "FOOBAR".into(),
})
.set_session_meta(
SessionMeta { user_id: user_id.to_owned(), device_id: "FOOBAR".into() },
#[cfg(feature = "e2e-encryption")]
None,
)
.await
.unwrap();

Expand Down
Loading
Loading