From d7c41a7cb00345a5b2fc34e8ad4da8f44aceebd3 Mon Sep 17 00:00:00 2001 From: Jeongkyu Shin Date: Fri, 6 Nov 2026 14:41:09 +0900 Subject: [PATCH 1/4] fix(server): warn on unsupported password hashes and fix hash docs The UserDefinition::password_hash rustdoc told operators to run `openssl passwd -6`, which yields a SHA-crypt hash the verifier rejects, so a user created that way could never log in. The rustdoc now recommends Argon2id via `bssh-server hash-password`, notes bcrypt is accepted, and states that SHA-crypt and /etc/shadow values are unsupported. reload_users now warns once per final user whose hash is neither Argon2 (parseable) nor bcrypt, without logging the hash. Loading still succeeds and verify_internal dispatch is unchanged, so auth stays fail-closed. Adds tests for the format helper, verifier construction with unsupported hashes, and a regression matrix for `*`, `!`, empty, and `$6$` hashes across password lengths 0 to 1024. The config test fixture now uses an Argon2id-style placeholder. Refs #354 --- src/server/auth/password.rs | 88 +++++++++++++++++++++++++++++++++++++ src/server/config/types.rs | 6 +-- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/server/auth/password.rs b/src/server/auth/password.rs index fc0992f4a..808b1ff6b 100644 --- a/src/server/auth/password.rs +++ b/src/server/auth/password.rs @@ -182,6 +182,17 @@ impl PasswordVerifier { users.insert(user.name.clone(), user.clone()); } + // Flag users that can never log in. The auth path already fails closed, + // this only surfaces the misconfiguration at load time. Never log the hash. + for (name, user) in &users { + if !is_supported_hash_format(&user.password_hash) { + tracing::warn!( + user = %name, + "Unsupported password hash format; supported formats are Argon2id (bssh-server hash-password) and bcrypt ($2a$/$2b$/$2y$). This user cannot log in with a password." + ); + } + } + let user_count = users.len(); *self.users.write().await = users; @@ -485,6 +496,17 @@ pub fn verify_password_hash(password: &str, hash: &str) -> Result { } } +/// Check whether a stored hash is in a format the verifier can handle. +/// +/// Mirrors the formats accepted by `verify_internal` (Argon2 and bcrypt) without +/// changing its dispatch. Used only to warn at load time. +fn is_supported_hash_format(hash: &str) -> bool { + if hash.starts_with("$argon2") { + return PasswordHash::new(hash).is_ok(); + } + hash.starts_with("$2a$") || hash.starts_with("$2b$") || hash.starts_with("$2y$") +} + #[cfg(test)] mod tests { use super::*; @@ -788,4 +810,70 @@ mod tests { assert!(verify_password_hash(&password, &hash).unwrap()); assert!(!verify_password_hash(&"a".repeat(999), &hash).unwrap()); } + + #[test] + fn test_is_supported_hash_format() { + assert!(is_supported_hash_format(&hash_password("pw").unwrap())); + assert!(is_supported_hash_format(&bcrypt::hash("pw", 4).unwrap())); + for bad in [ + "$6$rounds=5000$salt$hash", + "$5$salt$hash", + "*", + "!", + "", + "$argon2id$v=19$", + ] { + assert!(!is_supported_hash_format(bad), "should reject {bad:?}"); + } + } + + fn user_with_hash(name: &str, hash: String) -> UserDefinition { + UserDefinition { + name: name.to_string(), + password_hash: hash, + shell: None, + home: None, + env: HashMap::new(), + } + } + + #[tokio::test] + async fn test_verifier_builds_with_unsupported_hashes() { + let users = vec![ + user_with_hash("locked", "*".to_string()), + user_with_hash("shacrypt", "$6$rounds=5000$saltsalt$abc".to_string()), + ]; + let verifier = PasswordVerifier::new(PasswordAuthConfig::with_users(users)).await; + assert!(verifier.is_ok()); + } + + #[tokio::test] + async fn test_unsupported_hashes_reject_all_password_lengths() { + let users = vec![ + user_with_hash("star", "*".to_string()), + user_with_hash("bang", "!".to_string()), + user_with_hash("empty", String::new()), + user_with_hash("shacrypt", "$6$rounds=5000$saltsalt$abc".to_string()), + user_with_hash("argonuser", hash_password("argon_pw").unwrap()), + user_with_hash("bcryptuser", bcrypt::hash("bcrypt_pw", 4).unwrap()), + ]; + let verifier = PasswordVerifier::new(PasswordAuthConfig::with_users(users)) + .await + .unwrap(); + + for user in ["star", "bang", "empty", "shacrypt"] { + for len in [0usize, 1, 72, 256, 257, 1024] { + let pw = "a".repeat(len); + assert!( + !verifier.verify(user, &pw).await.unwrap(), + "user {user} must not authenticate with a password of length {len}" + ); + } + } + + assert!(verifier.verify("argonuser", "argon_pw").await.unwrap()); + assert!(!verifier.verify("argonuser", "wrong").await.unwrap()); + assert!(verifier.verify("bcryptuser", "bcrypt_pw").await.unwrap()); + assert!(!verifier.verify("bcryptuser", "wrong").await.unwrap()); + } } diff --git a/src/server/config/types.rs b/src/server/config/types.rs index 1faa22ac3..61a8897b3 100644 --- a/src/server/config/types.rs +++ b/src/server/config/types.rs @@ -236,9 +236,9 @@ pub struct UserDefinition { /// Username. pub name: String, - /// Password hash (bcrypt or similar). + /// Password hash. /// - /// Generate with: `openssl passwd -6` + /// Argon2id is recommended; generate it with `bssh-server hash-password`. bcrypt (`$2a$`, `$2b$`, `$2y$`) is accepted for compatibility. SHA-crypt hashes (`openssl passwd -5` / `-6`, `$5$` / `$6$`) and values copied from `/etc/shadow` are not supported and are rejected, so such a user cannot log in with a password. pub password_hash: String, /// Override shell for this user. @@ -847,7 +847,7 @@ auth: password: users: - name: testuser - password_hash: "$6$rounds=656000$..." + password_hash: "$argon2id$v=19$m=19456,t=2,p=1$c2FsdHNhbHQ$aGFzaA" shell: /bin/bash shell: From efbd37478d4cf12ebe45bbc615e4f94d58912d6f Mon Sep 17 00:00:00 2001 From: Jeongkyu Shin Date: Fri, 6 Nov 2026 14:45:38 +0900 Subject: [PATCH 2/4] docs(server): wrap password_hash rustdoc to match file style The rewritten rustdoc on UserDefinition::password_hash was a single long line, while every other doc comment in src/server/config/types.rs wraps near 80 columns. Rewrap it without changing the wording. Narrow password and config tests pass. Refs #354 --- src/server/config/types.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server/config/types.rs b/src/server/config/types.rs index 61a8897b3..0b76c140d 100644 --- a/src/server/config/types.rs +++ b/src/server/config/types.rs @@ -238,7 +238,11 @@ pub struct UserDefinition { /// Password hash. /// - /// Argon2id is recommended; generate it with `bssh-server hash-password`. bcrypt (`$2a$`, `$2b$`, `$2y$`) is accepted for compatibility. SHA-crypt hashes (`openssl passwd -5` / `-6`, `$5$` / `$6$`) and values copied from `/etc/shadow` are not supported and are rejected, so such a user cannot log in with a password. + /// Argon2id is recommended; generate it with `bssh-server hash-password`. + /// bcrypt (`$2a$`, `$2b$`, `$2y$`) is accepted for compatibility. + /// SHA-crypt hashes (`openssl passwd -5` / `-6`, `$5$` / `$6$`) and values + /// copied from `/etc/shadow` are not supported and are rejected, so such a + /// user cannot log in with a password. pub password_hash: String, /// Override shell for this user. From 8bc086264379dca26b0ccbe0db5785c5030b0fbd Mon Sep 17 00:00:00 2001 From: Jeongkyu Shin Date: Fri, 6 Nov 2026 14:47:33 +0900 Subject: [PATCH 3/4] docs: note unsupported password hash warning and add changelog entry Document in the server configuration guide that SHA-crypt and /etc/shadow hashes are unsupported and now produce a load-time warning per affected user. Add an Unreleased changelog section covering the warning and the corrected password_hash rustdoc. Validation: - cargo fmt --all -- --check: ok - cargo test --lib server::auth::password: 18 passed Refs #354 --- CHANGELOG.md | 10 ++++++++++ docs/architecture/server-configuration.md | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 311bcf431..fa4deab79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to bssh 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). +## [Unreleased] + +### Improvements + +- Logged a warning at load time for each server user whose `password_hash` is not Argon2id or bcrypt, instead of only at login attempts (#354). + +### Bug Fixes + +- Fixed the `UserDefinition::password_hash` documentation recommending `openssl passwd -6`, which produces a hash the server rejects (#354). + ## [3.1.1] - 2026-11-05 ### New Features diff --git a/docs/architecture/server-configuration.md b/docs/architecture/server-configuration.md index d9b45a04f..2dd32f55e 100644 --- a/docs/architecture/server-configuration.md +++ b/docs/architecture/server-configuration.md @@ -488,7 +488,7 @@ The generated hash includes: - Time cost: 2 iterations - Parallelism: 1 -Note: bcrypt hashes are also supported for backward compatibility with existing configurations. +Note: bcrypt hashes are also supported for backward compatibility with existing configurations. SHA-crypt hashes (`$5$`, `$6$`, such as the output of `openssl passwd -6`) and values copied from `/etc/shadow` are not supported. The server logs a warning for each such user when it loads the configuration, and that user cannot log in with a password. ### Validate Configuration From 6196f22d343ed592a274d7a71b88a3eaad48cc7e Mon Sep 17 00:00:00 2001 From: Jeongkyu Shin Date: Fri, 6 Nov 2026 14:48:00 +0900 Subject: [PATCH 4/4] docs: drop Unreleased changelog section CHANGELOG.md in this repo is written only by release preparation commits, so the entry for #354 belongs to the next release preparation, not this PR. Refs #354 --- CHANGELOG.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa4deab79..311bcf431 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,16 +5,6 @@ All notable changes to bssh 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). -## [Unreleased] - -### Improvements - -- Logged a warning at load time for each server user whose `password_hash` is not Argon2id or bcrypt, instead of only at login attempts (#354). - -### Bug Fixes - -- Fixed the `UserDefinition::password_hash` documentation recommending `openssl passwd -6`, which produces a hash the server rejects (#354). - ## [3.1.1] - 2026-11-05 ### New Features