From 7e86dee8b7019b8287fca2dd9dcf0714d67df057 Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Mon, 3 Apr 2023 11:56:59 +0200 Subject: [PATCH 1/5] Add a feature to build with static sqlcipher and openssl --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 2f51dce..d121cb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ repository="/~https://github.com/matrix-org/seshat/" default = ["encryption"] encryption = ["rusqlite/sqlcipher", "aes", "crypto-mac", "hmac", "sha2", "hkdf", "pbkdf2", "rand", "zeroize", "byteorder"] +encryption-bundled = ["encryption", "rusqlite/bundled-sqlcipher-vendored-openssl"] [dependencies] tantivy = "0.12.0" From 4e7c058e252ba1f45143525b5c762b5fd7163a29 Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Mon, 3 Apr 2023 12:06:28 +0200 Subject: [PATCH 2/5] Rename + increment version --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d121cb6..eaa8f01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "seshat" -version = "2.3.3" +version = "2.3.4" authors = ["Damir Jelić "] edition = "2018" license = "Apache-2.0" @@ -12,7 +12,7 @@ repository="/~https://github.com/matrix-org/seshat/" default = ["encryption"] encryption = ["rusqlite/sqlcipher", "aes", "crypto-mac", "hmac", "sha2", "hkdf", "pbkdf2", "rand", "zeroize", "byteorder"] -encryption-bundled = ["encryption", "rusqlite/bundled-sqlcipher-vendored-openssl"] +bundled-sqlcipher = ["encryption", "rusqlite/bundled-sqlcipher-vendored-openssl"] [dependencies] tantivy = "0.12.0" From 83c2b0374904606c29a7c5dba499d8452ecac3fb Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Mon, 3 Apr 2023 12:25:30 +0200 Subject: [PATCH 3/5] Add changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e54ea7..64c9a2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.3.4 - 2023-04-03 + +- [[#117]] Add a feature to build with static sqlcipher and openssl + +[#117]: /~https://github.com/matrix-org/seshat/pull/117 + ## 2.3.3 - 2022-01-24 - [[#106]] Bracket search terms so multiple words in a search term don't cause a syntax error From baf98d4e5f5420c1957787be160b34b0595495ee Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Mon, 3 Apr 2023 12:51:55 +0200 Subject: [PATCH 4/5] Fix clippy --- src/config.rs | 9 ++------- src/database/connection.rs | 2 +- src/database/mod.rs | 6 +++--- src/database/recovery.rs | 2 +- src/database/searcher.rs | 2 +- src/database/static_methods.rs | 32 ++++++++++++++++---------------- src/index/encrypted_dir.rs | 4 ++-- src/index/encrypted_stream.rs | 2 +- 8 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/config.rs b/src/config.rs index eb74d91..9942619 100644 --- a/src/config.rs +++ b/src/config.rs @@ -263,21 +263,16 @@ impl Default for Config { } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] #[allow(missing_docs)] pub enum LoadDirection { + #[default] #[serde(rename = "b", alias = "backwards", alias = "backward")] Backwards, #[serde(rename = "f", alias = "forwards", alias = "forward")] Forwards, } -impl Default for LoadDirection { - fn default() -> LoadDirection { - LoadDirection::Backwards - } -} - /// Configuration for the event loading methods. /// /// A load configuration allows users to limit the number of events that will be diff --git a/src/database/connection.rs b/src/database/connection.rs index 142395d..09e3351 100644 --- a/src/database/connection.rs +++ b/src/database/connection.rs @@ -94,7 +94,7 @@ impl Connection { let event_count: i64 = Database::get_event_count_for_room(&self.inner, room_id)?; let checkpoint_count: i64 = self.query_row( "SELECT COUNT(*) FROM crawlercheckpoints WHERE room_id=?1", - &[room_id], + [room_id], |row| row.get(0), )?; diff --git a/src/database/mod.rs b/src/database/mod.rs index 9bc5099..5066bc2 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -107,7 +107,7 @@ impl Database { PathBuf: std::convert::From

, { let db_path = path.as_ref().join(EVENTS_DB_NAME); - let manager = SqliteConnectionManager::file(&db_path); + let manager = SqliteConnectionManager::file(db_path); let pool = r2d2::Pool::new(manager)?; let mut connection = pool.get()?; @@ -156,8 +156,8 @@ impl Database { fn set_pragmas(connection: &rusqlite::Connection) -> Result<()> { connection.pragma_update(None, "foreign_keys", &1 as &dyn ToSql)?; - connection.pragma_update(None, "journal_mode", &"WAL")?; - connection.pragma_update(None, "synchronous", &"NORMAL")?; + connection.pragma_update(None, "journal_mode", "WAL")?; + connection.pragma_update(None, "synchronous", "NORMAL")?; connection.execute_batch("PRAGMA wal_checkpoint(TRUNCATE);")?; Ok(()) } diff --git a/src/database/recovery.rs b/src/database/recovery.rs index 29e5742..26d89a7 100644 --- a/src/database/recovery.rs +++ b/src/database/recovery.rs @@ -95,7 +95,7 @@ impl RecoveryDatabase { PathBuf: std::convert::From

, { let db_path = path.as_ref().join(EVENTS_DB_NAME); - let manager = SqliteConnectionManager::file(&db_path); + let manager = SqliteConnectionManager::file(db_path); let pool = r2d2::Pool::new(manager)?; let mut connection = pool.get()?; diff --git a/src/database/searcher.rs b/src/database/searcher.rs index cf2e0b2..3ad01a9 100644 --- a/src/database/searcher.rs +++ b/src/database/searcher.rs @@ -94,7 +94,7 @@ impl Searcher { let events = loop { match Database::load_events( - &*self.database.lock().unwrap(), + &self.database.lock().unwrap(), &search_result.results, config.before_limit, config.after_limit, diff --git a/src/database/static_methods.rs b/src/database/static_methods.rs index 0a5b6be..db6bab4 100644 --- a/src/database/static_methods.rs +++ b/src/database/static_methods.rs @@ -74,7 +74,7 @@ impl Database { Database::delete_event_by_id(&transaction, &event_id)?; transaction.execute( "INSERT OR IGNORE INTO pending_deletion_events (event_id) VALUES (?1)", - &[&event_id], + [&event_id], )?; transaction.commit().unwrap(); @@ -420,7 +420,7 @@ impl Database { INSERT OR IGNORE INTO profile ( user_id, displayname, avatar_url ) VALUES(?1, ?2, ?3)", - &[user_id, displayname, avatar_url], + [user_id, displayname, avatar_url], )?; let profile_id: i64 = connection.query_row( @@ -429,7 +429,7 @@ impl Database { user_id=?1 and displayname=?2 and avatar_url=?3)", - &[user_id, displayname, avatar_url], + [user_id, displayname, avatar_url], |row| row.get(0), )?; @@ -459,10 +459,10 @@ impl Database { connection: &rusqlite::Connection, room: &str, ) -> rusqlite::Result { - connection.execute("INSERT OR IGNORE INTO rooms (room_id) VALUES(?1)", &[room])?; + connection.execute("INSERT OR IGNORE INTO rooms (room_id) VALUES(?1)", [room])?; let room_id: i64 = - connection.query_row("SELECT id FROM rooms WHERE (room_id=?1)", &[room], |row| { + connection.query_row("SELECT id FROM rooms WHERE (room_id=?1)", [room], |row| { row.get(0) })?; @@ -523,7 +523,7 @@ impl Database { ) VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)", )?; - let event_id = statement.insert(&[ + let event_id = statement.insert([ &event.event_id, &event.sender, &event.server_ts as &dyn ToSql, @@ -541,7 +541,7 @@ impl Database { ) VALUES (?1, ?2)", )?; - let id = stmt.insert(&[&event_id as &dyn ToSql, &event.content_value])?; + let id = stmt.insert([&event_id as &dyn ToSql, &event.content_value])?; Ok(id) } @@ -564,8 +564,8 @@ impl Database { // bytes and converting it to a C string isn't possible this // way. This is likely some string containing malicious nul // bytes so we filter them out. - profile.displayname = profile.displayname.as_mut().map(|d| d.replace("\0", "")); - profile.avatar_url = profile.avatar_url.as_mut().map(|u| u.replace("\0", "")); + profile.displayname = profile.displayname.as_mut().map(|d| d.replace('\0', "")); + profile.avatar_url = profile.avatar_url.as_mut().map(|u| u.replace('\0', "")); Database::save_profile(connection, &event.sender, profile)? } _ => return Err(e.into()), @@ -582,8 +582,8 @@ impl Database { // complain about the unique constraint that we have for // the event id. Database::delete_event_by_id(connection, &event.event_id)?; - event.content_value = event.content_value.replace("\0", ""); - event.msgtype = event.msgtype.as_mut().map(|m| m.replace("\0", "")); + event.content_value = event.content_value.replace('\0', ""); + event.msgtype = event.msgtype.as_mut().map(|m| m.replace('\0', "")); Database::save_event_helper(connection, event, profile_id)? } _ => return Err(e.into()), @@ -597,7 +597,7 @@ impl Database { connection: &rusqlite::Connection, event_id: &str, ) -> rusqlite::Result { - connection.execute("DELETE from events WHERE event_id == ?1", &[event_id]) + connection.execute("DELETE from events WHERE event_id == ?1", [event_id]) } pub(crate) fn event_in_store( @@ -610,7 +610,7 @@ impl Database { SELECT COUNT(*) FROM events WHERE ( event_id=?1 and room_id=?2)", - &[&event.event_id, &room_id as &dyn ToSql], + [&event.event_id, &room_id as &dyn ToSql], |row| row.get(0), )?; @@ -848,7 +848,7 @@ impl Database { FROM events INNER JOIN rooms on rooms.id = events.room_id WHERE (events.room_id == ?1) & (event_id == ?2)", - &[&room_id as &dyn ToSql, &event_id], + [&room_id as &dyn ToSql, &event_id], |row| { Ok(Event { event_type: row.get(0)?, @@ -970,7 +970,7 @@ impl Database { connection.execute( "INSERT OR IGNORE INTO crawlercheckpoints (room_id, token, full_crawl, direction) VALUES(?1, ?2, ?3, ?4)", - &[ + [ &checkpoint.room_id, &checkpoint.token, &checkpoint.full_crawl as &dyn ToSql, @@ -983,7 +983,7 @@ impl Database { connection.execute( "DELETE FROM crawlercheckpoints WHERE (room_id=?1 AND token=?2 AND full_crawl=?3 AND direction=?4)", - &[ + [ &checkpoint.room_id, &checkpoint.token, &checkpoint.full_crawl as &dyn ToSql, diff --git a/src/index/encrypted_dir.rs b/src/index/encrypted_dir.rs index abb0465..80fc7d6 100644 --- a/src/index/encrypted_dir.rs +++ b/src/index/encrypted_dir.rs @@ -163,7 +163,7 @@ impl EncryptedMmapDirectory { let (encryption_key, mac_key) = EncryptedMmapDirectory::expand_store_key(&store_key)?; // Open our underlying bare Tantivy mmap based directory. - let mmap_dir = tantivy::directory::MmapDirectory::open(&path)?; + let mmap_dir = tantivy::directory::MmapDirectory::open(path)?; Ok(EncryptedMmapDirectory { mmap_dir, @@ -248,7 +248,7 @@ impl EncryptedMmapDirectory { } let key_path = path.as_ref().join(KEYFILE); - let key_file = File::open(&key_path)?; + let key_file = File::open(key_path)?; // Expand the store key into a encryption and MAC key. let (_, store_key) = EncryptedMmapDirectory::load_store_key(key_file, passphrase)?; diff --git a/src/index/encrypted_stream.rs b/src/index/encrypted_stream.rs index d214f19..4d8789b 100644 --- a/src/index/encrypted_stream.rs +++ b/src/index/encrypted_stream.rs @@ -281,7 +281,7 @@ impl AesReader { total_length: u64, mac_length: u64, ) -> Result { - let current_pos = reader.seek(SeekFrom::Current(0))?; + let current_pos = reader.stream_position()?; let mac_start = total_length - mac_length; if current_pos >= mac_start { From 2c132e6df8a9112b080192562648de9e69f9b10b Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Mon, 3 Apr 2023 12:59:12 +0200 Subject: [PATCH 5/5] More clippy --- src/database/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index 5066bc2..51743e2 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -734,7 +734,7 @@ fn duplicate_empty_profiles() { .prepare("SELECT id FROM profile WHERE user_id=?1") .unwrap(); - let profile_ids = stmt.query_map(&[user_id], |row| row.get(0)).unwrap(); + let profile_ids = stmt.query_map([user_id], |row| row.get(0)).unwrap(); let mut id_count = 0;