feat: incoming rate limit, identity backup, v0.2.0
All checks were successful
ci / test (push) Successful in 4m11s
All checks were successful
ci / test (push) Successful in 4m11s
App-level token bucket on rend accepts (30/60s, burst 10), panic-safe TUI restore, sqlite WAL + integrity_check fail-closed. Encrypted owbak1 identity backup/restore. README and threat model cover profile, XMR sidecar, backup, mixed-version frames.
This commit is contained in:
parent
1a9b54d138
commit
e63203ff56
14 changed files with 809 additions and 26 deletions
35
src/store.rs
35
src/store.rs
|
|
@ -104,6 +104,10 @@ impl Store {
|
|||
mkdir_700(&home.join("arti"))?;
|
||||
let db_path = home.join("onionwire.db");
|
||||
let conn = Connection::open(&db_path)?;
|
||||
let journal: String = conn.query_row("PRAGMA journal_mode = WAL", [], |row| row.get(0))?;
|
||||
if !journal.eq_ignore_ascii_case("wal") {
|
||||
return Err(Error(format!("journal_mode WAL failed: {journal}")));
|
||||
}
|
||||
conn.execute_batch(
|
||||
"
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
|
@ -164,12 +168,43 @@ impl Store {
|
|||
INSERT OR IGNORE INTO self_profile (id) VALUES (1);
|
||||
",
|
||||
)?;
|
||||
let check: String = conn.query_row("PRAGMA integrity_check", [], |row| row.get(0))?;
|
||||
if check != "ok" {
|
||||
return Err(Error(format!("integrity_check: {check}")));
|
||||
}
|
||||
let store = Self { conn };
|
||||
store.migrate()?;
|
||||
store.ensure_self()?;
|
||||
Ok(store)
|
||||
}
|
||||
|
||||
pub fn journal_mode(&self) -> Result<String> {
|
||||
self.conn
|
||||
.query_row("PRAGMA journal_mode", [], |row| row.get(0))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn replace_identity_keys(
|
||||
&self,
|
||||
identity_sk: &[u8],
|
||||
identity_pk: &[u8],
|
||||
prekey_sk: &[u8],
|
||||
prekey_pk: &[u8],
|
||||
) -> Result<()> {
|
||||
if identity_sk.len() != 32
|
||||
|| identity_pk.len() != 32
|
||||
|| prekey_sk.len() != 32
|
||||
|| prekey_pk.len() != 32
|
||||
{
|
||||
return Err(Error("identity key length".into()));
|
||||
}
|
||||
self.conn.execute(
|
||||
"UPDATE self SET identity_sk = ?1, identity_pk = ?2, prekey_sk = ?3, prekey_pk = ?4 WHERE id = 1",
|
||||
params![identity_sk, identity_pk, prekey_sk, prekey_pk],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn migrate(&self) -> Result<()> {
|
||||
self.add_column_if_missing(
|
||||
"friends",
|
||||
|
|
|
|||
Loading…
Reference in a new issue