ffi: configure encryption settings only when it's needed

It's wrong that the first client, used only to determine how to log in and find the user id, try to run the encryption initialization tasks.
In particular, it should not even try to bootstrap the account, as this may send OTKs to the server, which the client will forget about as soon
as it's respawned as a database-backed client.
This commit is contained in:
Benjamin Bouvier
2024-02-09 17:47:27 +01:00
parent 53d723d149
commit c20e6aeca7
2 changed files with 32 additions and 30 deletions

View File

@@ -591,6 +591,12 @@ impl AuthenticationService {
.passphrase(self.passphrase.clone())
.homeserver_url(homeserver_url)
.sliding_sync_proxy(sliding_sync_proxy)
.with_encryption_settings(matrix_sdk::encryption::EncryptionSettings {
auto_enable_cross_signing: true,
backup_download_strategy:
matrix_sdk::encryption::BackupDownloadStrategy::AfterDecryptionFailure,
auto_enable_backups: true,
})
.username(user_id.to_string());
if let Some(id) = &self.cross_process_refresh_lock_id {

View File

@@ -1,7 +1,7 @@
use std::{fs, path::PathBuf, sync::Arc};
use matrix_sdk::{
encryption::{BackupDownloadStrategy, EncryptionSettings},
encryption::EncryptionSettings,
ruma::{
api::{error::UnknownVersionError, MatrixVersion},
ServerName, UserId,
@@ -43,7 +43,22 @@ pub struct ClientBuilder {
impl ClientBuilder {
#[uniffi::constructor]
pub fn new() -> Arc<Self> {
Arc::new(Self::default())
Arc::new(Self {
base_path: None,
username: None,
server_name: None,
homeserver_url: None,
server_versions: None,
passphrase: Zeroizing::new(None),
user_agent: None,
sliding_sync_proxy: None,
proxy: None,
disable_ssl_verification: false,
disable_automatic_token_refresh: false,
inner: MatrixClient::builder(),
cross_process_refresh_lock_id: None,
session_delegate: None,
})
}
pub fn enable_cross_process_refresh_lock(
@@ -136,6 +151,15 @@ impl ClientBuilder {
}
impl ClientBuilder {
pub(crate) fn with_encryption_settings(
self: Arc<Self>,
settings: EncryptionSettings,
) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.inner = builder.inner.with_encryption_settings(settings);
Arc::new(builder)
}
pub(crate) fn enable_cross_process_refresh_lock_inner(
self: Arc<Self>,
process_id: String,
@@ -247,31 +271,3 @@ impl ClientBuilder {
)?)
}
}
impl Default for ClientBuilder {
fn default() -> Self {
let encryption_settings = EncryptionSettings {
auto_enable_cross_signing: true,
auto_enable_backups: true,
backup_download_strategy: BackupDownloadStrategy::AfterDecryptionFailure,
};
let inner = MatrixClient::builder().with_encryption_settings(encryption_settings);
Self {
base_path: None,
username: None,
server_name: None,
homeserver_url: None,
server_versions: None,
passphrase: Zeroizing::new(None),
user_agent: None,
sliding_sync_proxy: None,
proxy: None,
disable_ssl_verification: false,
disable_automatic_token_refresh: false,
inner,
cross_process_refresh_lock_id: None,
session_delegate: None,
}
}
}