From 3d751939ff0e63712417e2cb75097095b47112b8 Mon Sep 17 00:00:00 2001 From: Ulyssa Date: Sun, 20 Sep 2026 04:08:37 -0400 Subject: [PATCH] Remove sled to sqlite upgrade path --- Cargo.lock | 101 +++---------------------------------- Cargo.toml | 3 -- src/base.rs | 4 -- src/main.rs | 123 +-------------------------------------------- src/sled_export.rs | 58 --------------------- 5 files changed, 8 insertions(+), 281 deletions(-) delete mode 100644 src/sled_export.rs diff --git a/Cargo.lock b/Cargo.lock index e1bc38ac..6d4edab6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,7 +188,7 @@ dependencies = [ "objc2-core-foundation", "objc2-core-graphics", "objc2-foundation", - "parking_lot 0.12.5", + "parking_lot", "percent-encoding", "windows-sys 0.60.2", "wl-clipboard-rs", @@ -1188,7 +1188,7 @@ dependencies = [ "bitflags 2.13.2", "crossterm_winapi", "mio", - "parking_lot 0.12.5", + "parking_lot", "rustix 0.38.44", "serde", "signal-hook", @@ -1207,7 +1207,7 @@ dependencies = [ "derive_more 2.1.1", "document-features", "mio", - "parking_lot 0.12.5", + "parking_lot", "rustix 1.1.5", "serde", "signal-hook", @@ -2011,16 +2011,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "fs_extra" version = "1.3.0" @@ -2134,15 +2124,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -2558,7 +2539,6 @@ dependencies = [ "notify-rust", "open", "pretty_assertions", - "rand 0.10.2", "ratatui", "ratatui-image", "regex", @@ -2566,8 +2546,6 @@ dependencies = [ "serde", "serde_json", "shellexpand", - "sled", - "temp-dir", "thiserror 2.0.20", "tokio", "tokio-stream", @@ -2909,15 +2887,6 @@ dependencies = [ "syn 3.0.6", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - [[package]] name = "interpolate_name" version = "0.2.4" @@ -4295,17 +4264,6 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.5" @@ -4313,21 +4271,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" dependencies = [ "lock_api", - "parking_lot_core 0.9.12", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -4338,7 +4282,7 @@ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.18", + "redox_syscall", "smallvec", "windows-link 0.2.1", ] @@ -5233,15 +5177,6 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03251193000f4bd3b042892be858ee50e8b3719f2b08e5833ac4353724632430" -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.5.18" @@ -6023,22 +5958,6 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" -[[package]] -name = "sled" -version = "0.34.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" -dependencies = [ - "crc32fast", - "crossbeam-epoch", - "crossbeam-utils", - "fs2", - "fxhash", - "libc", - "log", - "parking_lot 0.11.2", -] - [[package]] name = "smallvec" version = "1.16.1" @@ -6108,7 +6027,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a18596f8c785a729f2819c0f6a7eae6ebeebdfffbfe4214ae6b087f690e31901" dependencies = [ "new_debug_unreachable", - "parking_lot 0.12.5", + "parking_lot", "phf_shared 0.13.1", "precomputed-hash", "serde", @@ -6235,12 +6154,6 @@ dependencies = [ "windows-version", ] -[[package]] -name = "temp-dir" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "016ef9739649996fcc983b9c588fe3d557cf216d4d98503ce1b057ab5a66d689" - [[package]] name = "tempfile" version = "3.27.0" @@ -6270,7 +6183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9048a889effe34a5cddee0af7f53285198b16dca3be510858d38dfdb3e62a04e" dependencies = [ "bitflags 2.13.2", - "parking_lot 0.12.5", + "parking_lot", "rustix 1.1.5", "signal-hook", "windows-sys 0.61.2", diff --git a/Cargo.toml b/Cargo.toml index 04f93cbd..07284512 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,15 +55,12 @@ mime = "0.3.16" mime_guess = "2.0.4" nom = "8.0" open = "5.0.0" -rand = "0.10" ratatui = { version = "0.30.2", features = ["serde"] } regex = "1.5" rpassword = "7.2" serde = "1.0" serde_json = "1.0" shellexpand = "3.1" -sled = "0.34.7" -temp-dir = "0.2" thiserror = "2.0" tokio-stream = "0.1.19" toml = "1.1" diff --git a/src/base.rs b/src/base.rs index 0c7d7608..00517dee 100644 --- a/src/base.rs +++ b/src/base.rs @@ -839,10 +839,6 @@ pub enum IambError { #[error("Failed to import room keys: {0}")] FailedKeyImport(#[from] matrix_sdk::encryption::RoomKeyImportError), - /// A failure related to the cryptographic store. - #[error("Cannot export keys from sled: {0}")] - UpgradeSled(#[from] crate::sled_export::SledMigrationError), - /// An HTTP error. #[error("HTTP client error: {0}")] Http(#[from] matrix_sdk::HttpError), diff --git a/src/main.rs b/src/main.rs index 6c25761e..952b5fce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,6 @@ use std::sync::atomic::AtomicUsize; use clap::{CommandFactory, Parser}; use matrix_sdk::ruma::api::error::ErrorKind; use matrix_sdk::{OwnedServerName, RoomState}; -use matrix_sdk_crypto::encrypt_room_key_export; use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer}; use modalkit::crossterm; use modalkit::crossterm::cursor::SetCursorStyle; @@ -40,11 +39,8 @@ use modalkit_ratatui::cmdbar::CommandBarState; use modalkit_ratatui::screen::{Screen, ScreenState, TabbedLayoutDescription}; use modalkit_ratatui::windows::{WindowLayoutDescription, WindowLayoutState}; use modalkit_ratatui::{TerminalExtOps, Window}; -use rand::RngExt as _; -use rand::distr::Alphanumeric; use ratatui::Terminal; use ratatui::backend::CrosstermBackend; -use temp_dir::TempDir; use tokio::sync::Mutex as AsyncMutex; use tracing::Level; use tracing_subscriber::{EnvFilter, FmtSubscriber}; @@ -66,7 +62,6 @@ mod message; mod notifications; mod prelude; mod preview; -mod sled_export; mod util; mod verifications; mod windows; @@ -899,10 +894,6 @@ impl Application { } } -fn gen_passphrase() -> String { - rand::rng().sample_iter(&Alphanumeric).take(20).map(char::from).collect() -} - fn read_response(question: &str) -> String { println!("{question}"); let mut input = String::new(); @@ -981,111 +972,6 @@ fn print_exit(v: T) -> N { process::exit(2); } -// We can't access the OlmMachine directly, so write the keys to a temporary -// file first, and then import them later. -async fn check_import_keys( - settings: &ApplicationSettings, -) -> IambResult> { - let do_import = settings.sled_dir.is_dir() && !settings.sqlite_dir.is_dir(); - - if !do_import { - return Ok(None); - } - - let question = format!( - "Found old sled store in {}. Would you like to export room keys from it? [y]es/[n]o", - settings.sled_dir.display() - ); - - loop { - match read_yesno(&question) { - Some('y') => { - break; - }, - Some('n') => { - return Ok(None); - }, - Some(_) | None => { - continue; - }, - } - } - - let keys = sled_export::export_room_keys(&settings.sled_dir).await?; - let passphrase = gen_passphrase(); - - println!("* Encrypting {} room keys with the passphrase {passphrase:?}...", keys.len()); - - let encrypted = match encrypt_room_key_export(&keys, &passphrase, 500000) { - Ok(encrypted) => encrypted, - Err(e) => { - eprintln!("* Failed to encrypt room keys during export: {e}"); - process::exit(2); - }, - }; - - let tmpdir = TempDir::new()?; - let exported = tmpdir.child("keys"); - - println!("* Writing encrypted room keys to {}...", exported.display()); - tokio::fs::write(&exported, &encrypted).await?; - - Ok(Some((tmpdir, passphrase))) -} - -async fn login_upgrade( - keydir: TempDir, - passphrase: String, - worker: &Requester, - settings: &ApplicationSettings, - store: &AsyncProgramStore, -) -> IambResult<()> { - println!( - "Please log in for {} to import the room keys into a new session", - settings.profile.user_id - ); - - login(worker, settings).await?; - - println!("* Importing room keys..."); - - let exported = keydir.child("keys"); - let imported = worker.client.encryption().import_room_keys(exported, &passphrase).await; - - match imported { - Ok(res) => { - println!( - "* Successfully imported {} out of {} keys", - res.imported_count, res.total_count - ); - let _ = keydir.cleanup(); - }, - Err(e) => { - println!( - "Failed to import room keys from {}/keys: {e}\n\n\ - They have been encrypted with the passphrase {passphrase:?}.\ - Please save them and try importing them manually instead\n", - keydir.path().display() - ); - - loop { - match read_yesno("Would you like to continue logging in? [y]es/[n]o") { - Some('y') => break, - Some('n') => print_exit("* Exiting..."), - Some(_) | None => continue, - } - } - }, - } - - println!("* Syncing..."); - worker::do_first_sync(&worker.client, store) - .await - .map_err(IambError::from)?; - - Ok(()) -} - async fn login_normal( worker: &Requester, settings: &ApplicationSettings, @@ -1109,9 +995,6 @@ async fn run( // setup_tty() and pop in restore_tty(). settings.probe_enhanced_keys(); - // Get old keys the first time we run w/ the upgraded SDK. - let import_keys = check_import_keys(&settings).await?; - // Set up client state. create_dir_all(settings.sqlite_dir.as_path())?; let client = worker::create_client(&settings).await; @@ -1130,11 +1013,7 @@ async fn run( let store = Arc::new(AsyncMutex::new(store)); worker.init(store.clone()); - let res = if let Some((keydir, pass)) = import_keys { - login_upgrade(keydir, pass, &worker, &settings, &store).await - } else { - login_normal(&worker, &settings, &store).await - }; + let res = login_normal(&worker, &settings, &store).await; match res { Err(UIError::Application(IambError::Matrix(e))) => { diff --git a/src/sled_export.rs b/src/sled_export.rs deleted file mode 100644 index f891494d..00000000 --- a/src/sled_export.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! # sled -> sqlite migration code -//! -//! Before the 0.0.9 release, iamb used matrix-sdk@0.6.2, which used [sled] -//! for storing information, including room keys. In matrix-sdk@0.7.0, -//! the SDK switched to using SQLite. This module takes care of opening -//! sled, exporting the inbound group sessions used for decryption, -//! and importing them into SQLite. -//! -//! This code will eventually be removed once people have been given enough -//! time to upgrade off of pre-0.0.9 versions. -//! -//! [sled]: https://docs.rs/sled/0.34.7/sled/index.html - -use matrix_sdk_crypto::olm::{ExportedRoomKey, InboundGroupSession, PickledInboundGroupSession}; -use sled::{Config, IVec}; - -use crate::prelude::*; - -#[derive(Debug, thiserror::Error)] -pub enum SledMigrationError { - #[error("sled failure: {0}")] - Sled(#[from] sled::Error), - - #[error("deserialization failure: {0}")] - Deserialize(#[from] serde_json::Error), -} - -fn group_session_from_slice( - (_, bytes): (IVec, IVec), -) -> Result { - serde_json::from_slice(&bytes).map_err(SledMigrationError::from) -} - -async fn export_room_keys_priv( - sled_dir: &Path, -) -> Result, SledMigrationError> { - let path = sled_dir.join("matrix-sdk-state"); - let store = Config::new().temporary(false).path(&path).open()?; - let inbound_groups = store.open_tree("inbound_group_sessions")?; - - let mut exported = vec![]; - let sessions = inbound_groups - .iter() - .map(|p| p.map_err(SledMigrationError::from).and_then(group_session_from_slice)) - .collect::, _>>()? - .into_iter() - .filter_map(|p| InboundGroupSession::from_pickle(p).ok()); - - for session in sessions { - exported.push(session.export().await); - } - - Ok(exported) -} - -pub async fn export_room_keys(sled_dir: &Path) -> Result, IambError> { - export_room_keys_priv(sled_dir).await.map_err(IambError::from) -}