summaryrefslogtreecommitdiffstats
path: root/src/http/auth.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 17:33:17 +0000
committeraur-build <aur-build@localhost>2026-11-19 17:33:17 +0000
commit4304b0f336ddba7b4ec6780795059ff2066d105b (patch)
tree10edea744a1c2bf3fc363b4dc7f64abac8b1a0d3 /src/http/auth.rs
parente757979f1a2afdbe7146066345bb9acd19d3b151 (diff)
downloadaur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.tar.gz
aur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.zip
comments: keep only what the code cannot show
Stripped every comment that described what an item does, documented its arguments or fields, or cited the design docs (§n, I-n, m-n, decision n). 2247 comments down to 83. What survives: the section dividers that segment the large modules, the secret-handling warnings, the agent wire-frame directions, and the few notes without which the code they attach to reads as redundant, reorderable, or unsound.
Diffstat (limited to 'src/http/auth.rs')
-rw-r--r--src/http/auth.rs17
1 files changed, 0 insertions, 17 deletions
diff --git a/src/http/auth.rs b/src/http/auth.rs
index 9689fd8..6720607 100644
--- a/src/http/auth.rs
+++ b/src/http/auth.rs
@@ -4,23 +4,17 @@ use std::sync::OnceLock;
use crate::hash;
-/// Live sids and whether each has passed the password gate. One map, so
-/// dropping a session removes its authentication with it.
static SESSIONS: OnceLock<Mutex<HashMap<String, bool>>> = OnceLock::new();
fn sessions() -> &'static Mutex<HashMap<String, bool>> {
SESSIONS.get_or_init(|| Mutex::new(HashMap::new()))
}
-/// Random hex token from the system RNG, or `None` when there is no usable one.
-/// A session id is the whole credential (C-1), so "no RNG" is a refusal rather
-/// than a weaker, guessable token.
fn random_hex() -> Option<String> {
use std::io::Read;
let mut buf = [0u8; 32];
let mut f = std::fs::File::open("/dev/urandom").ok()?;
f.read_exact(&mut buf).ok()?;
- // Mixed in so two calls in the same instant still differ.
let nanos = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos())
@@ -34,8 +28,6 @@ fn counter() -> u64 {
C.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
}
-/// Mint an anonymous session: enough for a CSRF token, not enough to see a
-/// single page when a password is set.
pub fn new_session() -> Option<String> {
let sid = random_hex()?;
if let Ok(mut s) = sessions().lock() {
@@ -48,8 +40,6 @@ pub fn is_valid_session(sid: &str) -> bool {
sessions().lock().map(|s| s.contains_key(sid)).unwrap_or(false)
}
-/// Mark a session as having passed the password gate. An unknown sid stays
-/// unknown rather than being inserted as a side effect of a login attempt.
pub fn authenticate(sid: &str) {
if let Ok(mut s) = sessions().lock() {
if let Some(authenticated) = s.get_mut(sid) {
@@ -58,8 +48,6 @@ pub fn authenticate(sid: &str) {
}
}
-/// The gate's whole question: is this sid one we issued, and did someone type
-/// the password into a form on it?
pub fn is_authenticated(sid: &str) -> bool {
sessions().lock().map(|s| s.get(sid).copied().unwrap_or(false)).unwrap_or(false)
}
@@ -70,8 +58,6 @@ pub fn drop_session(sid: &str) {
}
}
-/// The CSRF token for a session. Derived rather than stored, so it cannot drift
-/// out of sync with the session.
pub fn csrf_token(sid: &str) -> String {
hash::hex(format!("csrf|{sid}").as_bytes())[..32].to_string()
}
@@ -92,7 +78,6 @@ fn constant_time_eq(a: &str, b: &str) -> bool {
diff == 0
}
-/// Parse a `Cookie:` header value.
pub fn parse_cookies(header: &str) -> Vec<(String, String)> {
header
.split(';')
@@ -104,8 +89,6 @@ pub fn parse_cookies(header: &str) -> Vec<(String, String)> {
.collect()
}
-/// An empty password means the UI is open, which is the default on loopback;
-/// the CSRF gate still applies.
pub fn password_ok(cfg: &crate::config::Config, given: &str) -> bool {
cfg.password.is_empty() || constant_time_eq(&cfg.password, given)
}