Commit c53d68494a

c53d68494a7a3a2fdce8bbcbab26b080b67c1e4a

parent: fdddc5c639

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-09-20 08:24 UTC
committer: <noreply@github.com>

Remove sled to sqlite upgrade path (#722)

Layout: unified · split

Cargo.lock +7 −94
@@ -188,7 +188,7 @@ dependencies = [
188188 "objc2-core-foundation",
189189 "objc2-core-graphics",
190190 "objc2-foundation",
191 "parking_lot 0.12.5",
191 "parking_lot",
192192 "percent-encoding",
193193 "windows-sys 0.60.2",
194194 "wl-clipboard-rs",
@@ -1188,7 +1188,7 @@ dependencies = [
11881188 "bitflags 2.13.2",
11891189 "crossterm_winapi",
11901190 "mio",
1191 "parking_lot 0.12.5",
1191 "parking_lot",
11921192 "rustix 0.38.44",
11931193 "serde",
11941194 "signal-hook",
@@ -1207,7 +1207,7 @@ dependencies = [
12071207 "derive_more 2.1.1",
12081208 "document-features",
12091209 "mio",
1210 "parking_lot 0.12.5",
1210 "parking_lot",
12111211 "rustix 1.1.5",
12121212 "serde",
12131213 "signal-hook",
@@ -2011,16 +2011,6 @@ dependencies = [
20112011 "percent-encoding",
20122012]
20132013
2014[[package]]
2015name = "fs2"
2016version = "0.4.3"
2017source = "registry+https://github.com/rust-lang/crates.io-index"
2018checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
2019dependencies = [
2020 "libc",
2021 "winapi",
2022]
2023
20242014[[package]]
20252015name = "fs_extra"
20262016version = "1.3.0"
@@ -2134,15 +2124,6 @@ dependencies = [
21342124 "slab",
21352125]
21362126
2137[[package]]
2138name = "fxhash"
2139version = "0.2.1"
2140source = "registry+https://github.com/rust-lang/crates.io-index"
2141checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
2142dependencies = [
2143 "byteorder",
2144]
2145
21462127[[package]]
21472128name = "generic-array"
21482129version = "0.14.7"
@@ -2558,7 +2539,6 @@ dependencies = [
25582539 "notify-rust",
25592540 "open",
25602541 "pretty_assertions",
2561 "rand 0.10.2",
25622542 "ratatui",
25632543 "ratatui-image",
25642544 "regex",
@@ -2566,8 +2546,6 @@ dependencies = [
25662546 "serde",
25672547 "serde_json",
25682548 "shellexpand",
2569 "sled",
2570 "temp-dir",
25712549 "thiserror 2.0.20",
25722550 "tokio",
25732551 "tokio-stream",
@@ -2909,15 +2887,6 @@ dependencies = [
29092887 "syn 3.0.6",
29102888]
29112889
2912[[package]]
2913name = "instant"
2914version = "0.1.13"
2915source = "registry+https://github.com/rust-lang/crates.io-index"
2916checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
2917dependencies = [
2918 "cfg-if",
2919]
2920
29212890[[package]]
29222891name = "interpolate_name"
29232892version = "0.2.4"
@@ -4295,17 +4264,6 @@ version = "2.2.1"
42954264source = "registry+https://github.com/rust-lang/crates.io-index"
42964265checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
42974266
4298[[package]]
4299name = "parking_lot"
4300version = "0.11.2"
4301source = "registry+https://github.com/rust-lang/crates.io-index"
4302checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
4303dependencies = [
4304 "instant",
4305 "lock_api",
4306 "parking_lot_core 0.8.6",
4307]
4308
43094267[[package]]
43104268name = "parking_lot"
43114269version = "0.12.5"
@@ -4313,21 +4271,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
43134271checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
43144272dependencies = [
43154273 "lock_api",
4316 "parking_lot_core 0.9.12",
4317]
4318
4319[[package]]
4320name = "parking_lot_core"
4321version = "0.8.6"
4322source = "registry+https://github.com/rust-lang/crates.io-index"
4323checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
4324dependencies = [
4325 "cfg-if",
4326 "instant",
4327 "libc",
4328 "redox_syscall 0.2.16",
4329 "smallvec",
4330 "winapi",
4274 "parking_lot_core",
43314275]
43324276
43334277[[package]]
@@ -4338,7 +4282,7 @@ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
43384282dependencies = [
43394283 "cfg-if",
43404284 "libc",
4341 "redox_syscall 0.5.18",
4285 "redox_syscall",
43424286 "smallvec",
43434287 "windows-link 0.2.1",
43444288]
@@ -5233,15 +5177,6 @@ version = "0.5.5"
52335177source = "registry+https://github.com/rust-lang/crates.io-index"
52345178checksum = "03251193000f4bd3b042892be858ee50e8b3719f2b08e5833ac4353724632430"
52355179
5236[[package]]
5237name = "redox_syscall"
5238version = "0.2.16"
5239source = "registry+https://github.com/rust-lang/crates.io-index"
5240checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
5241dependencies = [
5242 "bitflags 1.3.2",
5243]
5244
52455180[[package]]
52465181name = "redox_syscall"
52475182version = "0.5.18"
@@ -6023,22 +5958,6 @@ version = "0.4.12"
60235958source = "registry+https://github.com/rust-lang/crates.io-index"
60245959checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
60255960
6026[[package]]
6027name = "sled"
6028version = "0.34.7"
6029source = "registry+https://github.com/rust-lang/crates.io-index"
6030checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935"
6031dependencies = [
6032 "crc32fast",
6033 "crossbeam-epoch",
6034 "crossbeam-utils",
6035 "fs2",
6036 "fxhash",
6037 "libc",
6038 "log",
6039 "parking_lot 0.11.2",
6040]
6041
60425961[[package]]
60435962name = "smallvec"
60445963version = "1.16.1"
@@ -6108,7 +6027,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
61086027checksum = "a18596f8c785a729f2819c0f6a7eae6ebeebdfffbfe4214ae6b087f690e31901"
61096028dependencies = [
61106029 "new_debug_unreachable",
6111 "parking_lot 0.12.5",
6030 "parking_lot",
61126031 "phf_shared 0.13.1",
61136032 "precomputed-hash",
61146033 "serde",
@@ -6235,12 +6154,6 @@ dependencies = [
62356154 "windows-version",
62366155]
62376156
6238[[package]]
6239name = "temp-dir"
6240version = "0.2.0"
6241source = "registry+https://github.com/rust-lang/crates.io-index"
6242checksum = "016ef9739649996fcc983b9c588fe3d557cf216d4d98503ce1b057ab5a66d689"
6243
62446157[[package]]
62456158name = "tempfile"
62466159version = "3.27.0"
@@ -6270,7 +6183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
62706183checksum = "9048a889effe34a5cddee0af7f53285198b16dca3be510858d38dfdb3e62a04e"
62716184dependencies = [
62726185 "bitflags 2.13.2",
6273 "parking_lot 0.12.5",
6186 "parking_lot",
62746187 "rustix 1.1.5",
62756188 "signal-hook",
62766189 "windows-sys 0.61.2",
Cargo.toml −3
@@ -55,15 +55,12 @@ mime = "0.3.16"
5555mime_guess = "2.0.4"
5656nom = "8.0"
5757open = "5.0.0"
58rand = "0.10"
5958ratatui = { version = "0.30.2", features = ["serde"] }
6059regex = "1.5"
6160rpassword = "7.2"
6261serde = "1.0"
6362serde_json = "1.0"
6463shellexpand = "3.1"
65sled = "0.34.7"
66temp-dir = "0.2"
6764thiserror = "2.0"
6865tokio-stream = "0.1.19"
6966toml = "1.1"
src/base.rs −4
@@ -839,10 +839,6 @@ pub enum IambError {
839839 #[error("Failed to import room keys: {0}")]
840840 FailedKeyImport(#[from] matrix_sdk::encryption::RoomKeyImportError),
841841
842 /// A failure related to the cryptographic store.
843 #[error("Cannot export keys from sled: {0}")]
844 UpgradeSled(#[from] crate::sled_export::SledMigrationError),
845
846842 /// An HTTP error.
847843 #[error("HTTP client error: {0}")]
848844 Http(#[from] matrix_sdk::HttpError),
src/main.rs +1 −122
@@ -26,7 +26,6 @@ use std::sync::atomic::AtomicUsize;
2626use clap::{CommandFactory, Parser};
2727use matrix_sdk::ruma::api::error::ErrorKind;
2828use matrix_sdk::{OwnedServerName, RoomState};
29use matrix_sdk_crypto::encrypt_room_key_export;
3029use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer};
3130use modalkit::crossterm;
3231use modalkit::crossterm::cursor::SetCursorStyle;
@@ -40,11 +39,8 @@ use modalkit_ratatui::cmdbar::CommandBarState;
4039use modalkit_ratatui::screen::{Screen, ScreenState, TabbedLayoutDescription};
4140use modalkit_ratatui::windows::{WindowLayoutDescription, WindowLayoutState};
4241use modalkit_ratatui::{TerminalExtOps, Window};
43use rand::RngExt as _;
44use rand::distr::Alphanumeric;
4542use ratatui::Terminal;
4643use ratatui::backend::CrosstermBackend;
47use temp_dir::TempDir;
4844use tokio::sync::Mutex as AsyncMutex;
4945use tracing::Level;
5046use tracing_subscriber::{EnvFilter, FmtSubscriber};
@@ -66,7 +62,6 @@ mod message;
6662mod notifications;
6763mod prelude;
6864mod preview;
69mod sled_export;
7065mod util;
7166mod verifications;
7267mod windows;
@@ -899,10 +894,6 @@ impl Application {
899894 }
900895}
901896
902fn gen_passphrase() -> String {
903 rand::rng().sample_iter(&Alphanumeric).take(20).map(char::from).collect()
904}
905
906897fn read_response(question: &str) -> String {
907898 println!("{question}");
908899 let mut input = String::new();
@@ -981,111 +972,6 @@ fn print_exit<T: Display, N>(v: T) -> N {
981972 process::exit(2);
982973}
983974
984// We can't access the OlmMachine directly, so write the keys to a temporary
985// file first, and then import them later.
986async fn check_import_keys(
987 settings: &ApplicationSettings,
988) -> IambResult<Option<(temp_dir::TempDir, String)>> {
989 let do_import = settings.sled_dir.is_dir() && !settings.sqlite_dir.is_dir();
990
991 if !do_import {
992 return Ok(None);
993 }
994
995 let question = format!(
996 "Found old sled store in {}. Would you like to export room keys from it? [y]es/[n]o",
997 settings.sled_dir.display()
998 );
999
1000 loop {
1001 match read_yesno(&question) {
1002 Some('y') => {
1003 break;
1004 },
1005 Some('n') => {
1006 return Ok(None);
1007 },
1008 Some(_) | None => {
1009 continue;
1010 },
1011 }
1012 }
1013
1014 let keys = sled_export::export_room_keys(&settings.sled_dir).await?;
1015 let passphrase = gen_passphrase();
1016
1017 println!("* Encrypting {} room keys with the passphrase {passphrase:?}...", keys.len());
1018
1019 let encrypted = match encrypt_room_key_export(&keys, &passphrase, 500000) {
1020 Ok(encrypted) => encrypted,
1021 Err(e) => {
1022 eprintln!("* Failed to encrypt room keys during export: {e}");
1023 process::exit(2);
1024 },
1025 };
1026
1027 let tmpdir = TempDir::new()?;
1028 let exported = tmpdir.child("keys");
1029
1030 println!("* Writing encrypted room keys to {}...", exported.display());
1031 tokio::fs::write(&exported, &encrypted).await?;
1032
1033 Ok(Some((tmpdir, passphrase)))
1034}
1035
1036async fn login_upgrade(
1037 keydir: TempDir,
1038 passphrase: String,
1039 worker: &Requester,
1040 settings: &ApplicationSettings,
1041 store: &AsyncProgramStore,
1042) -> IambResult<()> {
1043 println!(
1044 "Please log in for {} to import the room keys into a new session",
1045 settings.profile.user_id
1046 );
1047
1048 login(worker, settings).await?;
1049
1050 println!("* Importing room keys...");
1051
1052 let exported = keydir.child("keys");
1053 let imported = worker.client.encryption().import_room_keys(exported, &passphrase).await;
1054
1055 match imported {
1056 Ok(res) => {
1057 println!(
1058 "* Successfully imported {} out of {} keys",
1059 res.imported_count, res.total_count
1060 );
1061 let _ = keydir.cleanup();
1062 },
1063 Err(e) => {
1064 println!(
1065 "Failed to import room keys from {}/keys: {e}\n\n\
1066 They have been encrypted with the passphrase {passphrase:?}.\
1067 Please save them and try importing them manually instead\n",
1068 keydir.path().display()
1069 );
1070
1071 loop {
1072 match read_yesno("Would you like to continue logging in? [y]es/[n]o") {
1073 Some('y') => break,
1074 Some('n') => print_exit("* Exiting..."),
1075 Some(_) | None => continue,
1076 }
1077 }
1078 },
1079 }
1080
1081 println!("* Syncing...");
1082 worker::do_first_sync(&worker.client, store)
1083 .await
1084 .map_err(IambError::from)?;
1085
1086 Ok(())
1087}
1088
1089975async fn login_normal(
1090976 worker: &Requester,
1091977 settings: &ApplicationSettings,
@@ -1109,9 +995,6 @@ async fn run(
1109995 // setup_tty() and pop in restore_tty().
1110996 settings.probe_enhanced_keys();
1111997
1112 // Get old keys the first time we run w/ the upgraded SDK.
1113 let import_keys = check_import_keys(&settings).await?;
1114
1115998 // Set up client state.
1116999 create_dir_all(settings.sqlite_dir.as_path())?;
11171000 let client = worker::create_client(&settings).await;
@@ -1130,11 +1013,7 @@ async fn run(
11301013 let store = Arc::new(AsyncMutex::new(store));
11311014 worker.init(store.clone());
11321015
1133 let res = if let Some((keydir, pass)) = import_keys {
1134 login_upgrade(keydir, pass, &worker, &settings, &store).await
1135 } else {
1136 login_normal(&worker, &settings, &store).await
1137 };
1016 let res = login_normal(&worker, &settings, &store).await;
11381017
11391018 match res {
11401019 Err(UIError::Application(IambError::Matrix(e))) => {
src/sled_export.rs deleted −58
@@ -1,58 +0,0 @@
1//! # sled -> sqlite migration code
2//!
3//! Before the 0.0.9 release, iamb used matrix-sdk@0.6.2, which used [sled]
4//! for storing information, including room keys. In matrix-sdk@0.7.0,
5//! the SDK switched to using SQLite. This module takes care of opening
6//! sled, exporting the inbound group sessions used for decryption,
7//! and importing them into SQLite.
8//!
9//! This code will eventually be removed once people have been given enough
10//! time to upgrade off of pre-0.0.9 versions.
11//!
12//! [sled]: https://docs.rs/sled/0.34.7/sled/index.html
13
14use matrix_sdk_crypto::olm::{ExportedRoomKey, InboundGroupSession, PickledInboundGroupSession};
15use sled::{Config, IVec};
16
17use crate::prelude::*;
18
19#[derive(Debug, thiserror::Error)]
20pub enum SledMigrationError {
21 #[error("sled failure: {0}")]
22 Sled(#[from] sled::Error),
23
24 #[error("deserialization failure: {0}")]
25 Deserialize(#[from] serde_json::Error),
26}
27
28fn group_session_from_slice(
29 (_, bytes): (IVec, IVec),
30) -> Result<PickledInboundGroupSession, SledMigrationError> {
31 serde_json::from_slice(&bytes).map_err(SledMigrationError::from)
32}
33
34async fn export_room_keys_priv(
35 sled_dir: &Path,
36) -> Result<Vec<ExportedRoomKey>, SledMigrationError> {
37 let path = sled_dir.join("matrix-sdk-state");
38 let store = Config::new().temporary(false).path(&path).open()?;
39 let inbound_groups = store.open_tree("inbound_group_sessions")?;
40
41 let mut exported = vec![];
42 let sessions = inbound_groups
43 .iter()
44 .map(|p| p.map_err(SledMigrationError::from).and_then(group_session_from_slice))
45 .collect::<Result<Vec<_>, _>>()?
46 .into_iter()
47 .filter_map(|p| InboundGroupSession::from_pickle(p).ok());
48
49 for session in sessions {
50 exported.push(session.export().await);
51 }
52
53 Ok(exported)
54}
55
56pub async fn export_room_keys(sled_dir: &Path) -> Result<Vec<ExportedRoomKey>, IambError> {
57 export_room_keys_priv(sled_dir).await.map_err(IambError::from)
58}