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 = [
188 "objc2-core-foundation", 188 "objc2-core-foundation",
189 "objc2-core-graphics", 189 "objc2-core-graphics",
190 "objc2-foundation", 190 "objc2-foundation",
191 "parking_lot 0.12.5", 191 "parking_lot",
192 "percent-encoding", 192 "percent-encoding",
193 "windows-sys 0.60.2", 193 "windows-sys 0.60.2",
194 "wl-clipboard-rs", 194 "wl-clipboard-rs",
@@ -1188,7 +1188,7 @@ dependencies = [
1188 "bitflags 2.13.2", 1188 "bitflags 2.13.2",
1189 "crossterm_winapi", 1189 "crossterm_winapi",
1190 "mio", 1190 "mio",
1191 "parking_lot 0.12.5", 1191 "parking_lot",
1192 "rustix 0.38.44", 1192 "rustix 0.38.44",
1193 "serde", 1193 "serde",
1194 "signal-hook", 1194 "signal-hook",
@@ -1207,7 +1207,7 @@ dependencies = [
1207 "derive_more 2.1.1", 1207 "derive_more 2.1.1",
1208 "document-features", 1208 "document-features",
1209 "mio", 1209 "mio",
1210 "parking_lot 0.12.5", 1210 "parking_lot",
1211 "rustix 1.1.5", 1211 "rustix 1.1.5",
1212 "serde", 1212 "serde",
1213 "signal-hook", 1213 "signal-hook",
@@ -2011,16 +2011,6 @@ dependencies = [
2011 "percent-encoding", 2011 "percent-encoding",
2012] 2012]
2013 2013
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
2024[[package]] 2014[[package]]
2025name = "fs_extra" 2015name = "fs_extra"
2026version = "1.3.0" 2016version = "1.3.0"
@@ -2134,15 +2124,6 @@ dependencies = [
2134 "slab", 2124 "slab",
2135] 2125]
2136 2126
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
2146[[package]] 2127[[package]]
2147name = "generic-array" 2128name = "generic-array"
2148version = "0.14.7" 2129version = "0.14.7"
@@ -2558,7 +2539,6 @@ dependencies = [
2558 "notify-rust", 2539 "notify-rust",
2559 "open", 2540 "open",
2560 "pretty_assertions", 2541 "pretty_assertions",
2561 "rand 0.10.2",
2562 "ratatui", 2542 "ratatui",
2563 "ratatui-image", 2543 "ratatui-image",
2564 "regex", 2544 "regex",
@@ -2566,8 +2546,6 @@ dependencies = [
2566 "serde", 2546 "serde",
2567 "serde_json", 2547 "serde_json",
2568 "shellexpand", 2548 "shellexpand",
2569 "sled",
2570 "temp-dir",
2571 "thiserror 2.0.20", 2549 "thiserror 2.0.20",
2572 "tokio", 2550 "tokio",
2573 "tokio-stream", 2551 "tokio-stream",
@@ -2909,15 +2887,6 @@ dependencies = [
2909 "syn 3.0.6", 2887 "syn 3.0.6",
2910] 2888]
2911 2889
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
2921[[package]] 2890[[package]]
2922name = "interpolate_name" 2891name = "interpolate_name"
2923version = "0.2.4" 2892version = "0.2.4"
@@ -4295,17 +4264,6 @@ version = "2.2.1"
4295source = "registry+https://github.com/rust-lang/crates.io-index" 4264source = "registry+https://github.com/rust-lang/crates.io-index"
4296checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" 4265checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
4297 4266
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
4309[[package]] 4267[[package]]
4310name = "parking_lot" 4268name = "parking_lot"
4311version = "0.12.5" 4269version = "0.12.5"
@@ -4313,21 +4271,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
4313checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" 4271checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
4314dependencies = [ 4272dependencies = [
4315 "lock_api", 4273 "lock_api",
4316 "parking_lot_core 0.9.12", 4274 "parking_lot_core",
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",
4331] 4275]
4332 4276
4333[[package]] 4277[[package]]
@@ -4338,7 +4282,7 @@ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
4338dependencies = [ 4282dependencies = [
4339 "cfg-if", 4283 "cfg-if",
4340 "libc", 4284 "libc",
4341 "redox_syscall 0.5.18", 4285 "redox_syscall",
4342 "smallvec", 4286 "smallvec",
4343 "windows-link 0.2.1", 4287 "windows-link 0.2.1",
4344] 4288]
@@ -5233,15 +5177,6 @@ version = "0.5.5"
5233source = "registry+https://github.com/rust-lang/crates.io-index" 5177source = "registry+https://github.com/rust-lang/crates.io-index"
5234checksum = "03251193000f4bd3b042892be858ee50e8b3719f2b08e5833ac4353724632430" 5178checksum = "03251193000f4bd3b042892be858ee50e8b3719f2b08e5833ac4353724632430"
5235 5179
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
5245[[package]] 5180[[package]]
5246name = "redox_syscall" 5181name = "redox_syscall"
5247version = "0.5.18" 5182version = "0.5.18"
@@ -6023,22 +5958,6 @@ version = "0.4.12"
6023source = "registry+https://github.com/rust-lang/crates.io-index" 5958source = "registry+https://github.com/rust-lang/crates.io-index"
6024checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" 5959checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
6025 5960
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
6042[[package]] 5961[[package]]
6043name = "smallvec" 5962name = "smallvec"
6044version = "1.16.1" 5963version = "1.16.1"
@@ -6108,7 +6027,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
6108checksum = "a18596f8c785a729f2819c0f6a7eae6ebeebdfffbfe4214ae6b087f690e31901" 6027checksum = "a18596f8c785a729f2819c0f6a7eae6ebeebdfffbfe4214ae6b087f690e31901"
6109dependencies = [ 6028dependencies = [
6110 "new_debug_unreachable", 6029 "new_debug_unreachable",
6111 "parking_lot 0.12.5", 6030 "parking_lot",
6112 "phf_shared 0.13.1", 6031 "phf_shared 0.13.1",
6113 "precomputed-hash", 6032 "precomputed-hash",
6114 "serde", 6033 "serde",
@@ -6235,12 +6154,6 @@ dependencies = [
6235 "windows-version", 6154 "windows-version",
6236] 6155]
6237 6156
6238[[package]]
6239name = "temp-dir"
6240version = "0.2.0"
6241source = "registry+https://github.com/rust-lang/crates.io-index"
6242checksum = "016ef9739649996fcc983b9c588fe3d557cf216d4d98503ce1b057ab5a66d689"
6243
6244[[package]] 6157[[package]]
6245name = "tempfile" 6158name = "tempfile"
6246version = "3.27.0" 6159version = "3.27.0"
@@ -6270,7 +6183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
6270checksum = "9048a889effe34a5cddee0af7f53285198b16dca3be510858d38dfdb3e62a04e" 6183checksum = "9048a889effe34a5cddee0af7f53285198b16dca3be510858d38dfdb3e62a04e"
6271dependencies = [ 6184dependencies = [
6272 "bitflags 2.13.2", 6185 "bitflags 2.13.2",
6273 "parking_lot 0.12.5", 6186 "parking_lot",
6274 "rustix 1.1.5", 6187 "rustix 1.1.5",
6275 "signal-hook", 6188 "signal-hook",
6276 "windows-sys 0.61.2", 6189 "windows-sys 0.61.2",
Cargo.toml −3
@@ -55,15 +55,12 @@ mime = "0.3.16"
55mime_guess = "2.0.4" 55mime_guess = "2.0.4"
56nom = "8.0" 56nom = "8.0"
57open = "5.0.0" 57open = "5.0.0"
58rand = "0.10"
59ratatui = { version = "0.30.2", features = ["serde"] } 58ratatui = { version = "0.30.2", features = ["serde"] }
60regex = "1.5" 59regex = "1.5"
61rpassword = "7.2" 60rpassword = "7.2"
62serde = "1.0" 61serde = "1.0"
63serde_json = "1.0" 62serde_json = "1.0"
64shellexpand = "3.1" 63shellexpand = "3.1"
65sled = "0.34.7"
66temp-dir = "0.2"
67thiserror = "2.0" 64thiserror = "2.0"
68tokio-stream = "0.1.19" 65tokio-stream = "0.1.19"
69toml = "1.1" 66toml = "1.1"
src/base.rs −4
@@ -839,10 +839,6 @@ pub enum IambError {
839 #[error("Failed to import room keys: {0}")] 839 #[error("Failed to import room keys: {0}")]
840 FailedKeyImport(#[from] matrix_sdk::encryption::RoomKeyImportError), 840 FailedKeyImport(#[from] matrix_sdk::encryption::RoomKeyImportError),
841 841
842 /// A failure related to the cryptographic store.
843 #[error("Cannot export keys from sled: {0}")]
844 UpgradeSled(#[from] crate::sled_export::SledMigrationError),
845
846 /// An HTTP error. 842 /// An HTTP error.
847 #[error("HTTP client error: {0}")] 843 #[error("HTTP client error: {0}")]
848 Http(#[from] matrix_sdk::HttpError), 844 Http(#[from] matrix_sdk::HttpError),
src/main.rs +1 −122
@@ -26,7 +26,6 @@ use std::sync::atomic::AtomicUsize;
26use clap::{CommandFactory, Parser}; 26use clap::{CommandFactory, Parser};
27use matrix_sdk::ruma::api::error::ErrorKind; 27use matrix_sdk::ruma::api::error::ErrorKind;
28use matrix_sdk::{OwnedServerName, RoomState}; 28use matrix_sdk::{OwnedServerName, RoomState};
29use matrix_sdk_crypto::encrypt_room_key_export;
30use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer}; 29use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer};
31use modalkit::crossterm; 30use modalkit::crossterm;
32use modalkit::crossterm::cursor::SetCursorStyle; 31use modalkit::crossterm::cursor::SetCursorStyle;
@@ -40,11 +39,8 @@ use modalkit_ratatui::cmdbar::CommandBarState;
40use modalkit_ratatui::screen::{Screen, ScreenState, TabbedLayoutDescription}; 39use modalkit_ratatui::screen::{Screen, ScreenState, TabbedLayoutDescription};
41use modalkit_ratatui::windows::{WindowLayoutDescription, WindowLayoutState}; 40use modalkit_ratatui::windows::{WindowLayoutDescription, WindowLayoutState};
42use modalkit_ratatui::{TerminalExtOps, Window}; 41use modalkit_ratatui::{TerminalExtOps, Window};
43use rand::RngExt as _;
44use rand::distr::Alphanumeric;
45use ratatui::Terminal; 42use ratatui::Terminal;
46use ratatui::backend::CrosstermBackend; 43use ratatui::backend::CrosstermBackend;
47use temp_dir::TempDir;
48use tokio::sync::Mutex as AsyncMutex; 44use tokio::sync::Mutex as AsyncMutex;
49use tracing::Level; 45use tracing::Level;
50use tracing_subscriber::{EnvFilter, FmtSubscriber}; 46use tracing_subscriber::{EnvFilter, FmtSubscriber};
@@ -66,7 +62,6 @@ mod message;
66mod notifications; 62mod notifications;
67mod prelude; 63mod prelude;
68mod preview; 64mod preview;
69mod sled_export;
70mod util; 65mod util;
71mod verifications; 66mod verifications;
72mod windows; 67mod windows;
@@ -899,10 +894,6 @@ impl Application {
899 } 894 }
900} 895}
901 896
902fn gen_passphrase() -> String {
903 rand::rng().sample_iter(&Alphanumeric).take(20).map(char::from).collect()
904}
905
906fn read_response(question: &str) -> String { 897fn read_response(question: &str) -> String {
907 println!("{question}"); 898 println!("{question}");
908 let mut input = String::new(); 899 let mut input = String::new();
@@ -981,111 +972,6 @@ fn print_exit<T: Display, N>(v: T) -> N {
981 process::exit(2); 972 process::exit(2);
982} 973}
983 974
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
1089async fn login_normal( 975async fn login_normal(
1090 worker: &Requester, 976 worker: &Requester,
1091 settings: &ApplicationSettings, 977 settings: &ApplicationSettings,
@@ -1109,9 +995,6 @@ async fn run(
1109 // setup_tty() and pop in restore_tty(). 995 // setup_tty() and pop in restore_tty().
1110 settings.probe_enhanced_keys(); 996 settings.probe_enhanced_keys();
1111 997
1112 // Get old keys the first time we run w/ the upgraded SDK.
1113 let import_keys = check_import_keys(&settings).await?;
1114
1115 // Set up client state. 998 // Set up client state.
1116 create_dir_all(settings.sqlite_dir.as_path())?; 999 create_dir_all(settings.sqlite_dir.as_path())?;
1117 let client = worker::create_client(&settings).await; 1000 let client = worker::create_client(&settings).await;
@@ -1130,11 +1013,7 @@ async fn run(
1130 let store = Arc::new(AsyncMutex::new(store)); 1013 let store = Arc::new(AsyncMutex::new(store));
1131 worker.init(store.clone()); 1014 worker.init(store.clone());
1132 1015
1133 let res = if let Some((keydir, pass)) = import_keys { 1016 let res = login_normal(&worker, &settings, &store).await;
1134 login_upgrade(keydir, pass, &worker, &settings, &store).await
1135 } else {
1136 login_normal(&worker, &settings, &store).await
1137 };
1138 1017
1139 match res { 1018 match res {
1140 Err(UIError::Application(IambError::Matrix(e))) => { 1019 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}