diff options
| author | tv <tv@krebsco.de> | 2026-11-29 03:15:05 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-29 03:15:05 +0000 |
| commit | 9188fa6e13ea7facfab5fb6f55bf26444ec2c01e (patch) | |
| tree | 28b33908d0519bd21b03ee18bb34126c484ec0bb /src/access/token.rs | |
| parent | c396d33a34ee6685e9a561baa4d3ae4956b697be (diff) | |
document: values read and written through a view any kind of document gives
document::view: Read (the value at a path, plain, typed, a map's keys)
and Write (a value written, one deleted), which Automerge's documents,
writes in progress and documents as they were all are. The member
registry, the users, access control's reads and rules, the topology,
forgetting and bootstrap read and write through them, and name neither
Automerge's ReadDoc and Transactable nor document::store, which is what
an Automerge document can do beyond.
How a swarm holding a store judges what a change writes is handed to
the rules (rules::judge_seen), being its kind of document's to say.
Diffstat (limited to 'src/access/token.rs')
| -rw-r--r-- | src/access/token.rs | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/src/access/token.rs b/src/access/token.rs index 650a5c4..073d1e4 100644 --- a/src/access/token.rs +++ b/src/access/token.rs @@ -17,7 +17,8 @@ use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD as BASE64URL}; use serde::{Deserialize, Serialize}; use super::{Capability, registry}; -use crate::document::{ReadDoc, meta, store}; +use crate::document::meta; +use crate::document::view::{self, Read}; use crate::identity::{self, NodeKey}; const PREFIX: &str = "ct1."; @@ -117,7 +118,7 @@ pub(crate) enum Refused { /// (`registry::User::tokens_not_before`), of a session not ended /// (`registry::session_ended`). pub(crate) fn verify( - doc: &impl ReadDoc, + doc: &impl Read, token: &str, swarm: &str, now: u64, @@ -161,11 +162,7 @@ pub(crate) fn verify( /// store, only one it issued itself (`docs/store.md`, Members), as a node there is /// whoever its operator lets in, and lets in nobody's but its own. #[cfg(feature = "federation")] -pub(crate) fn issued_here( - doc: &impl ReadDoc, - local: &str, - claims: Claims, -) -> Result<Claims, Refused> { +pub(crate) fn issued_here(doc: &impl Read, local: &str, claims: Claims) -> Result<Claims, Refused> { match super::policy::of(doc) { super::policy::Policy::Store(_) if claims.issuer != local => Err(Refused::ElsewhereIssued), _ => Ok(claims), @@ -176,14 +173,14 @@ pub(crate) fn issued_here( /// its issuer a member and not banned, its user registered, enabled, its tokens not /// revoked since and its session not ended. What a stream opened with it is judged by /// as the document changes (`api::login::streams_end`). -pub(crate) fn still_taken(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> { +pub(crate) fn still_taken(doc: &impl Read, claims: &Claims) -> Result<(), Refused> { issuer_counts(doc, claims)?; user_counts(doc, claims) } /// Its issuer a member of the swarm, not banned. -fn issuer_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> { - let member = store::read_path(doc, &meta::path(&[meta::MEMBERS, &claims.issuer])) +fn issuer_counts(doc: &impl Read, claims: &Claims) -> Result<(), Refused> { + let member = view::read_path(doc, &meta::path(&[meta::MEMBERS, &claims.issuer])) .ok() .flatten() .is_some(); @@ -198,7 +195,7 @@ fn issuer_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> { /// In a swarm with a registry: its user registered, enabled, its tokens not revoked /// since it was issued, its session not ended. -fn user_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> { +fn user_counts(doc: &impl Read, claims: &Claims) -> Result<(), Refused> { user_taken(doc, &claims.user)?; if let Some(user) = registry::user(doc, &claims.user) { if claims.iat < user.tokens_not_before { @@ -214,7 +211,7 @@ fn user_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> { /// In a swarm with a registry: user `name` registered and enabled. What a stream opened /// by password or a proxy's header is judged by as the document changes /// (`api::login::streams_end`), as one opened with a token is by `still_taken`. -pub(crate) fn user_taken(doc: &impl ReadDoc, name: &str) -> Result<(), Refused> { +pub(crate) fn user_taken(doc: &impl Read, name: &str) -> Result<(), Refused> { if registry::exists(doc) { let user = registry::user(doc, name).ok_or(Refused::UnknownUser)?; if user.disabled { @@ -256,7 +253,7 @@ mod tests { fn member(doc: &mut Document, key: &NodeKey) { let path = meta::path(&[meta::MEMBERS, &key.id()]); - change(doc, |tx| store::write_path(tx, &path, &json!({})).unwrap()); + change(doc, |tx| view::write_path(tx, &path, &json!({})).unwrap()); } /// A party's session names the key it logged in with, which a token of a user's @@ -374,7 +371,7 @@ mod tests { let ban = crate::access::bans::path(&key.id()); let mut banned = doc.fork(); change(&mut banned, |tx| { - store::write_path(tx, &ban, &json!({"reason": "lost"})).unwrap() + view::write_path(tx, &ban, &json!({"reason": "lost"})).unwrap() }); assert_eq!( verify(&banned, &token, "s", 1_500), @@ -405,24 +402,24 @@ mod tests { assert!(verify(&doc, &token, "s", 1_500).is_ok()); let bob = registry::entry("x", 0, ®istry::all_caps()); change(&mut doc, |tx| { - store::write_path(tx, ®istry::user_path("bob"), &bob).unwrap() + view::write_path(tx, ®istry::user_path("bob"), &bob).unwrap() }); assert_eq!(verify(&doc, &token, "s", 1_500), Err(Refused::UnknownUser)); let mut alice = registry::entry("x", 0, &[(Vec::new(), &[Right::Read][..])]); change(&mut doc, |tx| { - store::write_path(tx, ®istry::user_path("alice"), &alice).unwrap(); - store::write_path(tx, ®istry::logouts_path("alice"), &json!(1_000)).unwrap() + view::write_path(tx, ®istry::user_path("alice"), &alice).unwrap(); + view::write_path(tx, ®istry::logouts_path("alice"), &json!(1_000)).unwrap() }); assert!(verify(&doc, &token, "s", 1_500).is_ok()); change(&mut doc, |tx| { - store::write_path(tx, ®istry::logouts_path("alice"), &json!(1_001)).unwrap() + view::write_path(tx, ®istry::logouts_path("alice"), &json!(1_001)).unwrap() }); assert_eq!(verify(&doc, &token, "s", 1_500), Err(Refused::Revoked)); // One session ended: its tokens refused, another's taken. let session = claims_of(&token).session; change(&mut doc, |tx| { - store::write_path(tx, ®istry::logouts_path("alice"), &json!(0)).unwrap(); - store::write_path( + view::write_path(tx, ®istry::logouts_path("alice"), &json!(0)).unwrap(); + view::write_path( tx, ®istry::session_path("alice", &session), &json!(10_000), @@ -433,8 +430,8 @@ mod tests { assert!(verify(&doc, &issue(&key, &claims(&key)), "s", 1_500).is_ok()); alice["disabled"] = json!(true); change(&mut doc, |tx| { - store::write_path(tx, ®istry::logouts_path("alice"), &json!(0)).unwrap(); - store::write_path(tx, ®istry::user_path("alice"), &alice).unwrap() + view::write_path(tx, ®istry::logouts_path("alice"), &json!(0)).unwrap(); + view::write_path(tx, ®istry::user_path("alice"), &alice).unwrap() }); assert_eq!(verify(&doc, &token, "s", 1_500), Err(Refused::Disabled)); } |
