diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..92d36f9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1712439257, + "narHash": "sha256-aSpiNepFOMk9932HOax0XwNxbA38GOUVOiXfUVPOrck=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ff0dbd94265ac470dda06a657d5fe49de93b4599", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..093224e --- /dev/null +++ b/flake.nix @@ -0,0 +1,15 @@ +{ + description = "Rudric, the keeper of secrets"; + + inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; }; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.${system}.default = pkgs.mkShell { + packages = with pkgs; [ cargo rustc rust-analyzer rustfmt sqlite ]; + }; + }; +} diff --git a/src/types/session.rs b/src/types/session.rs index 9ee95ea..a728c03 100644 --- a/src/types/session.rs +++ b/src/types/session.rs @@ -3,7 +3,7 @@ use std::{env, fmt::Display}; use anyhow::{bail, Context, Result}; use base64::{engine::general_purpose::STANDARD_NO_PAD as b64, Engine}; use orion::aead::SecretKey; -use sqlx::{sqlite::SqliteRow, FromRow, Row, SqlitePool}; +use sqlx::{sqlite::SqliteRow, Execute, FromRow, Row, SqlitePool}; use time::OffsetDateTime; use uuid::Uuid; @@ -91,13 +91,16 @@ impl SessionKey { } pub async fn delete_expired(db: &SqlitePool) -> Result<()> { - let now = OffsetDateTime::now_utc().unix_timestamp(); + let now = OffsetDateTime::now_utc(); sqlx::query!("delete from session_keys where expire_time < ?", now) .execute(db) .await .context("Failed to delete expired session key")?; + println!("{}",sqlx::query!("delete from session_keys where expire_time < ?", now).sql()); + + Ok(()) } } @@ -141,6 +144,10 @@ impl SessionToken { // The session key ID is prepended to the encrypted timed key. let session_token = [session_key.id.as_bytes(), encrypted_timed_key.as_slice()].concat(); + if let Err(e) = SessionKey::delete_expired(db).await { + eprintln!("Error deleting expired session tokens: {e}"); + } + Ok(Self(b64.encode(session_token))) }