From 8218fd584e4053848738a310258893e14c4ee10e Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 24 Aug 2026 15:27:06 +0200 Subject: TOFU host trust: SPKI fingerprint pinning, tests, forget-host --- src/bin/server/database.rs | 5 +---- src/bin/server/handler.rs | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/bin/server') diff --git a/src/bin/server/database.rs b/src/bin/server/database.rs index 1653071..c73aec5 100644 --- a/src/bin/server/database.rs +++ b/src/bin/server/database.rs @@ -1,8 +1,6 @@ use rusqlite::Connection; -pub fn init_db() -> Connection { - let db_path = std::env::var("SERVER_DB").unwrap_or_else(|_| "server.db".to_string()); - let conn = Connection::open(&db_path).unwrap(); +pub fn init_db(conn: &Connection) { conn.execute( "CREATE TABLE IF NOT EXISTS users ( username TEXT PRIMARY KEY, @@ -19,7 +17,6 @@ pub fn init_db() -> Connection { "ALTER TABLE users ADD COLUMN balance INTEGER DEFAULT 1000", [], ); - conn } pub fn add_user( diff --git a/src/bin/server/handler.rs b/src/bin/server/handler.rs index 867910e..48e9d3a 100644 --- a/src/bin/server/handler.rs +++ b/src/bin/server/handler.rs @@ -8,7 +8,11 @@ use std::io::{BufRead, BufReader, Write}; use std::net::TcpStream; use std::sync::Mutex; -static DB_CONN: Lazy> = Lazy::new(|| Mutex::new(database::init_db())); +static DB_CONN: Lazy> = Lazy::new(|| { + let conn = Connection::open(std::env::var("SERVER_DB").unwrap_or_else(|_| "server.db".to_string())).unwrap(); + database::init_db(&conn); + Mutex::new(conn) +}); #[allow(dead_code)] pub fn handle_client(stream: TcpStream) { -- cgit v1.2.3