From 96f0d499febb447e2b646d298922d950ed61b347 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 17:08:39 -0500 Subject: [PATCH 01/10] bump: argon2 --- Cargo.lock | 75 ++++++++++++++++++++++-------------------------------- Cargo.toml | 2 +- 2 files changed, 31 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7920dfe..390b881 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,13 +31,13 @@ checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" [[package]] name = "argon2" -version = "0.5.3" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" +checksum = "134c52ddac6d63c576bef8168db10c83c49c26444ecbc68060fef078925a901c" dependencies = [ "base64ct", "blake2", - "cpufeatures 0.2.17", + "cpufeatures 0.3.1", "password-hash", ] @@ -143,11 +143,11 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.6" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f" dependencies = [ - "digest 0.10.7", + "digest 0.11.3", ] [[package]] @@ -216,7 +216,7 @@ checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" dependencies = [ "cfg-if", "cpufeatures 0.3.1", - "rand_core 0.10.1", + "rand_core", ] [[package]] @@ -364,7 +364,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common 0.1.7", - "subtle", ] [[package]] @@ -585,17 +584,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "getrandom" version = "0.4.3" @@ -606,7 +594,7 @@ dependencies = [ "js-sys", "libc", "r-efi", - "rand_core 0.10.1", + "rand_core", "wasm-bindgen", ] @@ -1180,13 +1168,13 @@ dependencies = [ [[package]] name = "password-hash" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" +checksum = "aab41826031698d6ffcd9cff78ef56ef998e39dc7e5067cdfebe373842d4723b" dependencies = [ - "base64ct", - "rand_core 0.6.4", - "subtle", + "getrandom", + "phc", + "rand_core", ] [[package]] @@ -1195,6 +1183,18 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" +[[package]] +name = "phc" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44dc769b75f93afdddd8c7fa12d685292ddeff1e66f7f0f3a234cf1818afe892" +dependencies = [ + "base64ct", + "ctutils", + "getrandom", + "rand_core", +] + [[package]] name = "pin-project-lite" version = "0.2.17" @@ -1253,17 +1253,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" dependencies = [ "chacha20", - "getrandom 0.4.3", - "rand_core 0.10.1", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.17", + "getrandom", + "rand_core", ] [[package]] @@ -1774,12 +1765,6 @@ dependencies = [ "unicode-properties", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "2.0.119" @@ -1826,7 +1811,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom", "once_cell", "rustix", "windows-sys", @@ -2188,7 +2173,7 @@ version = "1.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514" dependencies = [ - "getrandom 0.4.3", + "getrandom", "js-sys", "serde_core", "wasm-bindgen", @@ -2374,7 +2359,7 @@ checksum = "1156b39d142a34b999c2310a50455e0cb3760bf7efad0122f796d813bee26ccb" dependencies = [ "crc32fast", "flate2", - "getrandom 0.4.3", + "getrandom", "indexmap", "memchr", "nix", diff --git a/Cargo.toml b/Cargo.toml index 1e2f8e5..4fb740c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ tower = { version = "0.5.3", features = ["full"] } tower-http = { version = "0.7.1", features = ["cors"] } sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] } uuid = { version = "1.29.0", features = ["v4", "serde"] } -argon2 = { version = "0.5.3", features = ["std"] } +argon2 = { version = "0.6.0", features = ["alloc", "getrandom", "rand_core"] } time = { version = "0.3.55", features = ["macros", "serde"] } josekit = { version = "0.10.3" } utoipa = { version = "6.0.0", features = ["axum_extras", "uuid", "time"] } -- 2.47.3 From 7a6cca4dac0546a2c0874b3eca66e2f856a7a8f0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 17:17:17 -0500 Subject: [PATCH 02/10] Making some changes. Will fail tests --- src/hashing/mod.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/hashing/mod.rs b/src/hashing/mod.rs index 2c53f0b..46b1881 100644 --- a/src/hashing/mod.rs +++ b/src/hashing/mod.rs @@ -3,15 +3,34 @@ use argon2::{ PasswordVerifier, password_hash::{ PasswordHasher, - SaltString, - rand_core::OsRng, // Secure random number generator + // SaltString, + // rand_core::OsRng, // Secure random number generator }, }; +pub struct SaltString { + pub raw: String, + pub in_bytes: Vec +} + +impl SaltString { + pub fn generate() -> Result { + Err(argon2::Error::SaltTooLong) + } + + pub fn from_b64(s: &str) -> Result { + Err(argon2::password_hash::Error::SaltInvalid) + } + + pub fn to_string(&self) -> String { + self.raw.clone() + } +} + pub fn generate_salt() -> Result { // Generate a random salt // SaltString::generate uses OsRng internally for cryptographic security - Ok(SaltString::generate(&mut OsRng)) + SaltString::generate() } pub fn get_salt(s: &str) -> Result { @@ -31,7 +50,9 @@ pub fn hash_password( // Hash the password with the salt // The output is a PasswordHash string format that includes algorithm, version, // parameters, salt, and the hash itself. - Ok(argon2.hash_password(password_bytes, salt)?.to_string()) + // Ok(argon2.hash_password(password_bytes, salt)?.to_string()) + // Ok(argon2.hash_password(password_bytes)?.to_string()) + Ok(argon2.hash_password_with_salt(password_bytes, &salt.in_bytes)?.to_string()) } pub fn verify_password( @@ -49,7 +70,7 @@ pub fn verify_password( // This automatically uses the correct salt and parameters embedded in `parsed_hash` match Argon2::default().verify_password(password_bytes, &parsed_hash) { Ok(()) => Ok(true), // Passwords match - Err(argon2::password_hash::Error::Password) => Ok(false), // Passwords don't match + Err(argon2::password_hash::Error::PasswordInvalid) => Ok(false), // Passwords don't match Err(e) => Err(e), // Some other error occurred (e.g., invalid hash format) } } -- 2.47.3 From a729d2f5dd8db09f81495e8129283fa49089872c Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 18:19:25 -0500 Subject: [PATCH 03/10] bump: Adding rand dependency --- Cargo.lock | 1 + Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 390b881..827e5db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1533,6 +1533,7 @@ dependencies = [ "http-body-util", "josekit", "openssl", + "rand", "serde", "serde_json", "sienvy", diff --git a/Cargo.toml b/Cargo.toml index 4fb740c..7dc826c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ utoipa = { version = "6.0.0", features = ["axum_extras", "uuid", "time"] } utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] } simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.7" } sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.2" } +rand = { version = "0.10.3" } [dev-dependencies] http-body-util = { version = "0.1.5" } -- 2.47.3 From 0127a45216c164efbdd705b52285771d7719ab4a Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 18:44:12 -0500 Subject: [PATCH 04/10] Making some changes --- src/hashing/mod.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/hashing/mod.rs b/src/hashing/mod.rs index 46b1881..ef657ed 100644 --- a/src/hashing/mod.rs +++ b/src/hashing/mod.rs @@ -8,6 +8,8 @@ use argon2::{ }, }; +use rand::distr::SampleString; + pub struct SaltString { pub raw: String, pub in_bytes: Vec @@ -15,11 +17,27 @@ pub struct SaltString { impl SaltString { pub fn generate() -> Result { - Err(argon2::Error::SaltTooLong) + let mut rng = rand::rng(); + let s = rand::distr::Alphanumeric.sample_string(&mut rng, 20); + let salt_string = SaltString { + raw: (&s).to_string(), + in_bytes: s.into_bytes() + }; + + Ok(salt_string) + + // Err(argon2::Error::SaltTooLong) } pub fn from_b64(s: &str) -> Result { - Err(argon2::password_hash::Error::SaltInvalid) + let salt_string = SaltString { + raw: (&s).to_string(), + in_bytes: s.to_string().into_bytes(), + }; + + Ok(salt_string) + + // Err(argon2::password_hash::Error::SaltInvalid) } pub fn to_string(&self) -> String { -- 2.47.3 From bc6b36defd099c0cf32db8034d6759b50453bad6 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 18:44:38 -0500 Subject: [PATCH 05/10] cargo fmt --- src/hashing/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hashing/mod.rs b/src/hashing/mod.rs index ef657ed..ad6a256 100644 --- a/src/hashing/mod.rs +++ b/src/hashing/mod.rs @@ -12,7 +12,7 @@ use rand::distr::SampleString; pub struct SaltString { pub raw: String, - pub in_bytes: Vec + pub in_bytes: Vec, } impl SaltString { @@ -21,7 +21,7 @@ impl SaltString { let s = rand::distr::Alphanumeric.sample_string(&mut rng, 20); let salt_string = SaltString { raw: (&s).to_string(), - in_bytes: s.into_bytes() + in_bytes: s.into_bytes(), }; Ok(salt_string) @@ -70,7 +70,9 @@ pub fn hash_password( // parameters, salt, and the hash itself. // Ok(argon2.hash_password(password_bytes, salt)?.to_string()) // Ok(argon2.hash_password(password_bytes)?.to_string()) - Ok(argon2.hash_password_with_salt(password_bytes, &salt.in_bytes)?.to_string()) + Ok(argon2 + .hash_password_with_salt(password_bytes, &salt.in_bytes)? + .to_string()) } pub fn verify_password( @@ -87,9 +89,9 @@ pub fn verify_password( // Verify the password against the parsed hash // This automatically uses the correct salt and parameters embedded in `parsed_hash` match Argon2::default().verify_password(password_bytes, &parsed_hash) { - Ok(()) => Ok(true), // Passwords match + Ok(()) => Ok(true), // Passwords match Err(argon2::password_hash::Error::PasswordInvalid) => Ok(false), // Passwords don't match - Err(e) => Err(e), // Some other error occurred (e.g., invalid hash format) + Err(e) => Err(e), // Some other error occurred (e.g., invalid hash format) } } -- 2.47.3 From 7bd55bd26bf1629c1875be9feb76160296ca50ed Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 18:47:51 -0500 Subject: [PATCH 06/10] Cleanup --- src/hashing/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hashing/mod.rs b/src/hashing/mod.rs index ad6a256..add74df 100644 --- a/src/hashing/mod.rs +++ b/src/hashing/mod.rs @@ -20,7 +20,7 @@ impl SaltString { let mut rng = rand::rng(); let s = rand::distr::Alphanumeric.sample_string(&mut rng, 20); let salt_string = SaltString { - raw: (&s).to_string(), + raw: s.to_string(), in_bytes: s.into_bytes(), }; -- 2.47.3 From eb135b73a1416497b4e6b3e53905cd1b20a4a837 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 18:54:04 -0500 Subject: [PATCH 07/10] Warning fix --- src/callers/login.rs | 2 +- src/callers/register.rs | 2 +- src/hashing/mod.rs | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 5248ca5..2d4dc98 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -344,7 +344,7 @@ pub mod endpoint { Ok(salt) => { let updated_salt_string = hashing::generate_salt().unwrap(); let updated_salt = simodels::user::salt::Salt { - salt: updated_salt_string.to_string(), + salt: updated_salt_string.to_string().clone(), id: salt.id, }; let updated_hashed_password = hashing::hash_password( diff --git a/src/callers/register.rs b/src/callers/register.rs index 15d3924..6adba69 100644 --- a/src/callers/register.rs +++ b/src/callers/register.rs @@ -93,7 +93,7 @@ pub async fn register_user( let salt_string = hashing::generate_salt().unwrap(); let mut salt = simodels::user::salt::Salt::default(); let generated_salt = salt_string; - salt.salt = generated_salt.to_string(); + salt.salt = generated_salt.to_string().clone(); salt.id = repo::salt::insert(&pool, &salt).await.unwrap(); user.salt_id = salt.id; let hashed_password = diff --git a/src/hashing/mod.rs b/src/hashing/mod.rs index add74df..f8a240b 100644 --- a/src/hashing/mod.rs +++ b/src/hashing/mod.rs @@ -40,9 +40,11 @@ impl SaltString { // Err(argon2::password_hash::Error::SaltInvalid) } - pub fn to_string(&self) -> String { - self.raw.clone() + pub fn to_string(&self) -> &String { + &self.raw } + + // pub fn final_string } pub fn generate_salt() -> Result { -- 2.47.3 From ff63c190982b6d6cc527bbab5f0389894e87c49c Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 19:09:03 -0500 Subject: [PATCH 08/10] Cleanup --- src/hashing/mod.rs | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/src/hashing/mod.rs b/src/hashing/mod.rs index f8a240b..3e53cb9 100644 --- a/src/hashing/mod.rs +++ b/src/hashing/mod.rs @@ -1,13 +1,4 @@ -use argon2::{ - Argon2, // The Argon2 algorithm struct - PasswordVerifier, - password_hash::{ - PasswordHasher, - // SaltString, - // rand_core::OsRng, // Secure random number generator - }, -}; - +use argon2::{Argon2, PasswordVerifier, password_hash::PasswordHasher}; use rand::distr::SampleString; pub struct SaltString { @@ -25,8 +16,6 @@ impl SaltString { }; Ok(salt_string) - - // Err(argon2::Error::SaltTooLong) } pub fn from_b64(s: &str) -> Result { @@ -36,20 +25,14 @@ impl SaltString { }; Ok(salt_string) - - // Err(argon2::password_hash::Error::SaltInvalid) } pub fn to_string(&self) -> &String { &self.raw } - - // pub fn final_string } pub fn generate_salt() -> Result { - // Generate a random salt - // SaltString::generate uses OsRng internally for cryptographic security SaltString::generate() } @@ -63,15 +46,8 @@ pub fn hash_password( ) -> Result { let password_bytes = password.as_bytes(); - // Create an Argon2 instance with default parameters (recommended) - // You could customize parameters here if needed, but defaults are strong let argon2 = Argon2::default(); - // Hash the password with the salt - // The output is a PasswordHash string format that includes algorithm, version, - // parameters, salt, and the hash itself. - // Ok(argon2.hash_password(password_bytes, salt)?.to_string()) - // Ok(argon2.hash_password(password_bytes)?.to_string()) Ok(argon2 .hash_password_with_salt(password_bytes, &salt.in_bytes)? .to_string()) @@ -101,10 +77,15 @@ pub fn verify_password( mod tests { use super::*; + pub const TEST_PASSWORD: &str = "somethingrandom"; + pub const TEST_WRONG_PASSWORD: &str = "Differentanotherlevel"; + #[test] fn test_hash_password() { - let some_password = String::from("somethingrandom"); - match hash_password(&some_password, &generate_salt().unwrap()) { + let some_password = String::from(TEST_PASSWORD); + let salt = generate_salt().unwrap(); + + match hash_password(&some_password, &salt) { Ok(p) => match verify_password(&some_password, p.clone()) { Ok(res) => { assert_eq!(res, true); @@ -121,8 +102,10 @@ mod tests { #[test] fn test_wrong_password() { - let some_password = String::from("somethingrandom"); - match hash_password(&some_password, &generate_salt().unwrap()) { + let some_password = String::from(TEST_PASSWORD); + let salt = generate_salt().unwrap(); + + match hash_password(&some_password, &salt) { Ok(p) => { match verify_password(&some_password, p.clone()) { Ok(res) => { @@ -132,7 +115,7 @@ mod tests { assert!(false, "Error: {:?}", err.to_string()); } } - let wrong_password = String::from("Differentanotherlevel"); + let wrong_password = String::from(TEST_WRONG_PASSWORD); let result = verify_password(&wrong_password, p.clone()).unwrap(); assert_eq!(false, result, "Passwords should not match"); } -- 2.47.3 From edb4897253a25f05f3537d4e6dc628b85ffb5d4c Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 19:10:10 -0500 Subject: [PATCH 09/10] Reorganized cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7dc826c..eae0124 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ time = { version = "0.3.55", features = ["macros", "serde"] } josekit = { version = "0.10.3" } utoipa = { version = "6.0.0", features = ["axum_extras", "uuid", "time"] } utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] } +rand = { version = "0.10.3" } simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.7" } sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.2" } -rand = { version = "0.10.3" } [dev-dependencies] http-body-util = { version = "0.1.5" } -- 2.47.3 From aa0f7d5cba6e155d7a85d3493108ffaaab135bde Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 19:10:43 -0500 Subject: [PATCH 10/10] bump: soaricarus_auth --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 827e5db..a11c45d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1526,7 +1526,7 @@ dependencies = [ [[package]] name = "soaricarus_auth" -version = "0.8.6" +version = "0.8.7" dependencies = [ "argon2", "axum", diff --git a/Cargo.toml b/Cargo.toml index eae0124..b23726b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "soaricarus_auth" -version = "0.8.6" +version = "0.8.7" edition = "2024" rust-version = "1.95" license = "MIT" -- 2.47.3