Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a feature to build with static sqlcipher and openssl #117

Merged
merged 5 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "seshat"
version = "2.3.3"
version = "2.3.4"
authors = ["Damir Jelić <poljar@termina.org.uk>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -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"]
bundled-sqlcipher = ["encryption", "rusqlite/bundled-sqlcipher-vendored-openssl"]

[dependencies]
tantivy = "0.12.0"
Expand Down
9 changes: 2 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/database/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)?;

Expand Down
8 changes: 4 additions & 4 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Database {
PathBuf: std::convert::From<P>,
{
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()?;
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/database/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl RecoveryDatabase {
PathBuf: std::convert::From<P>,
{
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()?;
Expand Down
2 changes: 1 addition & 1 deletion src/database/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 16 additions & 16 deletions src/database/static_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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(
Expand All @@ -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),
)?;

Expand Down Expand Up @@ -459,10 +459,10 @@ impl Database {
connection: &rusqlite::Connection,
room: &str,
) -> rusqlite::Result<i64> {
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)
})?;

Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand All @@ -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()),
Expand All @@ -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()),
Expand All @@ -597,7 +597,7 @@ impl Database {
connection: &rusqlite::Connection,
event_id: &str,
) -> rusqlite::Result<usize> {
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(
Expand All @@ -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),
)?;

Expand Down Expand Up @@ -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)?,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/index/encrypted_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion src/index/encrypted_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<D: NewCipher + StreamCipher, R: Read + Seek + Clone> AesReader<D, R> {
total_length: u64,
mac_length: u64,
) -> Result<usize> {
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 {
Expand Down