chadtmiller.com/monolith
An atproto PDS
0
0
OAuth permission sets, resolved, expanded and shown on consent
compat/README.md+1−0
| @@ -48,6 +48,7 @@ in its gates. | ||
| `checkOAuthMetadata` | oauth | core (but see below) | oauth | | ||
| `oauthLogin`, `oauthParRefused`, `oauthDpopRefused`, `oauthTokenRefused`, `oauthRevokeRefused`, `oauthRefresh`, `oauthRevoke`, `oauthGetSession`, `oauthClientLibrary` | oauth | core | oauth | | ||
| `oauthScopedCall`, `oauthScopedRefused`, `oauthScopedEdges` | oauth-scopes | core | oauth scopes | | ||
| `oauthSetPar`, `oauthSetLogin`, `oauthSetCall` (the sets published on a third PDS, the lexicon authority each server is given) | permission-sets | core, where an implementation can be given a lexicon authority | oauth permission sets | | ||
| `oauthClientDocument`, `oauthClientCache`, `oauthClientLogin`, `oauthAssertionRefused`, `oauthConfidentialSession` | oauth-clients | core | oauth clients | | ||
| `oauthAuthorizeRefused` (the page, its API and its redirect endpoint, each with one thing wrong) | oauth | spec-pds's own: the reference's page API | | | ||
| `oauthDeviceCookies` (device cookies, renewed at sign-in, 30 s of grace) | oauth | spec-pds's own: the reference's page API | | | ||
crates/pds-repo/src/lib.rs+146−0
| @@ -751,6 +751,65 @@ pub fn read_car(bytes: &[u8]) -> Result<(Vec<Vec<u8>>, Vec<Block>), String> { | ||
Ok((roots, blocks)) | ||
} | ||
| ||
/// Whether `cid`, a CID of version 1 with a one-byte codec and a SHA-256 | ||
/// multihash, is the hash of `bytes`. | ||
fn hashes_to(cid: &[u8], bytes: &[u8]) -> bool { | ||
cid.len() == 36 && cid[0] == 1 && cid[1] < 0x80 && cid_of(cid[1], bytes) == cid | ||
} | ||
| ||
/// The record at `path` that a CAR file proves to be `did`'s, as | ||
/// `atproto/sync.md` has a consumer check one: the CAR's one root is a | ||
/// commit of `did`, version 3, whose signature `signed` accepts (given the | ||
/// commit's bytes without its `sig`, and the `sig`), and whose tree holds | ||
/// `path` at a CID whose block, in the CAR, hashes to it. Every block read | ||
/// must hash to its CID. Err says why not. | ||
pub fn proven_record( | ||
car: &[u8], | ||
did: &str, | ||
path: &str, | ||
signed: impl Fn(&[u8], &[u8]) -> bool, | ||
) -> Result<V, String> { | ||
let (roots, blocks) = read_car(car)?; | ||
let [root] = roots.as_slice() else { | ||
return Err("a CAR without exactly one root".into()); | ||
}; | ||
let block = |cid: &[u8]| { | ||
blocks | ||
.iter() | ||
.find(|(c, b)| c == cid && hashes_to(c, b)) | ||
.map(|(_, b)| b.as_slice()) | ||
}; | ||
let commit = block(root).ok_or("the commit is not in the CAR under its CID")?; | ||
let V::Map(mut fields) = decode(commit)? else { | ||
return Err("a commit that is no map".into()); | ||
}; | ||
let sig = match fields.iter().position(|(k, _)| k == "sig") { | ||
Some(i) => match fields.remove(i).1 { | ||
V::Bytes(s) => s, | ||
_ => return Err("a commit whose sig is not bytes".into()), | ||
}, | ||
None => return Err("a commit with no sig".into()), | ||
}; | ||
let field = |k: &str| fields.iter().find(|(n, _)| n == k).map(|(_, v)| v); | ||
if field("did") != Some(&V::Str(did.to_string())) { | ||
return Err(format!("a commit not of {did}")); | ||
} | ||
if field("version") != Some(&V::Int(3)) { | ||
return Err("a commit not of version 3".into()); | ||
} | ||
let Some(V::Link(data)) = field("data") else { | ||
return Err("a commit with no tree".into()); | ||
}; | ||
let data = data.clone(); | ||
if !signed(&encode(&V::Map(fields)), &sig) { | ||
return Err("a commit its key did not sign".into()); | ||
} | ||
let fetch = |c: &[u8]| block(c).map(Arc::from); | ||
let cid = edit::get(&fetch, &data, path.as_bytes())? | ||
.ok_or_else(|| format!("a tree that does not hold {path}"))?; | ||
decode(block(&cid).ok_or("the record is not in the CAR under its CID")?) | ||
} | ||
| ||
/// A varint-prefixed section of a CAR file, at `pos`, moving past it. | ||
fn section<'a>(bytes: &'a [u8], pos: &mut usize) -> Result<&'a [u8], String> { | ||
let n = read_varint(bytes, pos).ok_or("a length cut short")?; | ||
| @@ -1106,4 +1165,91 @@ mod tests { | ||
before | ||
); | ||
} | ||
| ||
/// A record proven by the CAR `proof_car` makes passes the check a | ||
/// consumer makes, against the repository's key; with its record, its | ||
/// commit or the commit's signature changed, or another DID or path | ||
/// asked for, it does not. | ||
#[test] | ||
fn proofs() { | ||
use k256::ecdsa::signature::Verifier; | ||
let key = SigningKey::from_slice(&[9u8; 32]).unwrap(); | ||
let did = "did:plc:aaaaaaaaaaaaaaaaaaaaaaaa"; | ||
let mut r = Repo::new(did.into(), key.clone()); | ||
let mut mem = Memory::default(); | ||
let c = r.init(); | ||
mem.commit(&c); | ||
let ops = (0..40) | ||
.map(|n| Op::Create { | ||
collection: "com.example.thing".into(), | ||
rkey: Some(format!("k{n}")), | ||
value: value(n), | ||
}) | ||
.collect(); | ||
r.apply(&mem, ops, None).unwrap(); | ||
mem.commit(&r.change.take().unwrap()); | ||
let path = "com.example.thing/k7"; | ||
let car = r.proof_car(&mem, path); | ||
let vk = *key.verifying_key(); | ||
let signed = |msg: &[u8], sig: &[u8]| { | ||
k256::ecdsa::Signature::from_slice(sig).is_ok_and(|s| vk.verify(msg, &s).is_ok()) | ||
}; | ||
let seven = encode(&value(7)); | ||
assert_eq!( | ||
proven_record(&car, did, path, signed).map(|v| encode(&v)), | ||
Ok(seven.clone()) | ||
); | ||
assert!(proven_record(&car, "did:plc:bbbbbbbbbbbbbbbbbbbbbbbb", path, signed).is_err()); | ||
assert!(proven_record(&car, did, "com.example.thing/k8", signed).is_err()); | ||
let other = SigningKey::from_slice(&[8u8; 32]).unwrap(); | ||
let ovk = *other.verifying_key(); | ||
let other_signed = |msg: &[u8], sig: &[u8]| { | ||
k256::ecdsa::Signature::from_slice(sig).is_ok_and(|s| ovk.verify(msg, &s).is_ok()) | ||
}; | ||
assert!(proven_record(&car, did, path, other_signed).is_err()); | ||
// Each block rewritten in place, its CID kept: the record, a tree | ||
// node or the commit no longer hashes to it, and the proof fails. | ||
let (roots, blocks) = read_car(&car).unwrap(); | ||
for i in 0..blocks.len() { | ||
let mut tampered = blocks.clone(); | ||
let last = tampered[i].1.len() - 1; | ||
tampered[i].1[last] ^= 1; | ||
let bad = car_with_roots( | ||
&[roots[0].as_slice()], | ||
tampered.iter().map(|(c, b)| (c.as_slice(), b.as_slice())), | ||
); | ||
assert!(proven_record(&bad, did, path, signed).is_err(), "block {i}"); | ||
} | ||
// A record changed with its CID made to match: the tree does not hold that CID. | ||
let rec = blocks.iter().position(|(_, b)| *b == seven).unwrap(); | ||
let mut swapped = blocks.clone(); | ||
let other_value = encode(&value(8)); | ||
swapped[rec] = (cid_of(0x71, &other_value), other_value); | ||
let bad = car_with_roots( | ||
&[roots[0].as_slice()], | ||
swapped.iter().map(|(c, b)| (c.as_slice(), b.as_slice())), | ||
); | ||
assert!(proven_record(&bad, did, path, signed).is_err()); | ||
// A commit re-signed by another key, its CID made to match. | ||
let V::Map(mut m) = decode(&blocks[0].1).unwrap() else { | ||
panic!() | ||
}; | ||
m.retain(|(k, _)| k != "sig"); | ||
let hash = Sha256::digest(encode(&V::Map(m.clone()))); | ||
let sig: k256::ecdsa::Signature = other.sign_prehash(&hash).unwrap(); | ||
m.push(( | ||
"sig".into(), | ||
V::Bytes(sig.normalize_s().to_bytes().to_vec()), | ||
)); | ||
let commit = encode(&V::Map(m)); | ||
let cid = cid_of(0x71, &commit); | ||
let mut resigned = blocks.clone(); | ||
resigned[0] = (cid.clone(), commit); | ||
let bad = car_with_roots( | ||
&[cid.as_slice()], | ||
resigned.iter().map(|(c, b)| (c.as_slice(), b.as_slice())), | ||
); | ||
assert!(proven_record(&bad, did, path, signed).is_err()); | ||
assert!(proven_record(&bad, did, path, other_signed).is_ok()); | ||
} | ||
} | ||
crates/pds-server/src/oauth/page.rs+7−2
| @@ -409,7 +409,11 @@ pub(super) async fn authorize( | ||
Err(None) => return bad_page("Unknown or ended request"), | ||
Err(Some((r, back))) => return redirect_to(&r.response_mode, &r.redirect_uri, &back), | ||
}; | ||
let mut r = authorization_page(&svc, request_uri, &client, &loaded); | ||
// Each set the request includes, resolved again (`spec/OAUTH-PERMISSION-SETS.md`). | ||
let mut r = match svc.oauth.sets.resolve_all(&svc, &loaded.request.scope).await { | ||
Ok(sets) => authorization_page(&svc, request_uri, &client, &loaded, &sets), | ||
Err((nsid, _)) => error_page(400, "invalid_scope", &format!("Permission set {nsid} could not be resolved")), | ||
}; | ||
device_cookie(&svc, &mut r, &device); | ||
let csrf = format!("{CSRF_COOKIE}={}; Path=/; SameSite=Lax{}", hex::encode(rand::random::<[u8; 16]>()), secure(&svc)); | ||
if let Ok(v) = csrf.parse() { | ||
| @@ -425,13 +429,14 @@ fn authorization_page( | ||
request_uri: &str, | ||
client: &client::Client, | ||
loaded: &Loaded, | ||
sets: &std::collections::HashMap<String, std::sync::Arc<Json>>, | ||
) -> Response { | ||
let r = &loaded.request; | ||
let now = svc.sessions.now(); | ||
let mut data = json!({ | ||
"requestUri": request_uri, "clientId": client.id, "clientMetadata": client.metadata(), | ||
"clientTrusted": false, "clientFirstParty": false, "scope": r.scope.join(" "), | ||
"permissionSets": {}, | ||
"permissionSets": sets.iter().map(|(nsid, main)| (nsid.clone(), (**main).clone())).collect::<Map<String, Json>>(), | ||
}); | ||
// A public client's request always has its kept prompt; a confidential one's may have none. | ||
if let Some(p) = &r.prompt { | ||
crates/pds-server/src/oauth/scope.rs+6−3
| @@ -1,6 +1,7 @@ | ||
//! Scope strings (RFC 6749 §3.3) and the scopes the server keeps of them: | ||
//! atproto's own, and the permissions of `atproto/permission.md` that parse, | ||
//! as `spec/OAUTH.md` says. | ||
//! atproto's own, the permissions of `atproto/permission.md` that parse, | ||
//! and the `include:` scopes that parse (`super::sets`), as `spec/OAUTH.md` | ||
//! says. | ||
| ||
use pds_repo::data::{valid_did, valid_nsid}; | ||
use std::collections::HashMap; | ||
| @@ -34,7 +35,9 @@ pub(crate) fn tokens(s: &str) -> Vec<&str> { | ||
pub(crate) fn kept(tokens: &[&str]) -> Vec<String> { | ||
let mut out: Vec<String> = Vec::new(); | ||
for t in tokens { | ||
if (KNOWN.contains(t) || permission(t)) && !out.iter().any(|o| o == t) { | ||
if (KNOWN.contains(t) || permission(t) || super::sets::include(t).is_some()) | ||
&& !out.iter().any(|o| o == t) | ||
{ | ||
out.push(t.to_string()); | ||
} | ||
} | ||
crates/pds-server/src/oauth/sets.rsnew+767−0
767 lines changed: not loaded until asked for.
crates/pds-server/src/ops/trace.rs+3−0
| @@ -388,6 +388,7 @@ pub(crate) enum Target { | ||
DidWeb, | ||
Client, | ||
Space, | ||
Lexicon, | ||
} | ||
| ||
impl Target { | ||
| @@ -399,6 +400,7 @@ impl Target { | ||
Target::DidWeb => "did-web", | ||
Target::Client => "client", | ||
Target::Space => "space", | ||
Target::Lexicon => "lexicon", | ||
} | ||
} | ||
| ||
| @@ -411,6 +413,7 @@ impl Target { | ||
Target::DidWeb => ("did:web failure", Level::Debug), | ||
Target::Client => ("client failure", Level::Debug), | ||
Target::Space => ("space notification failure", Level::Debug), | ||
Target::Lexicon => ("lexicon failure", Level::Debug), | ||
} | ||
} | ||
} | ||
crates/pds-server/src/lib.rs+17−0
| @@ -100,6 +100,12 @@ pub(crate) struct Config { | ||
pub crawlers: Vec<String>, | ||
/// `PDS_OAUTH_CLIENT_FETCH`, for development only (`spec/OAUTH-CLIENTS.md`). | ||
pub oauth_client_fetch: Option<oauth::ClientFetch>, | ||
/// `PDS_LEXICON_AUTHORITY_DID`: every NSID's authority, in place of DNS | ||
/// (`spec/OAUTH-PERMISSION-SETS.md`). | ||
pub lexicon_authority: Option<String>, | ||
/// The DNS server `_lexicon` records are looked up from, in place of the | ||
/// system's: the tests' stub; none from the environment. | ||
pub lexicon_dns: Option<std::net::SocketAddr>, | ||
/// Whether `createAccount` needs an invite code. | ||
pub invite_required: bool, | ||
/// The password of the admin's `Basic` auth; with none (unset or empty), no request is the admin. | ||
| @@ -168,6 +174,14 @@ impl Config { | ||
.map(str::to_string) | ||
.collect(), | ||
oauth_client_fetch: oauth::ClientFetch::from_env()?, | ||
lexicon_authority: match std::env::var("PDS_LEXICON_AUTHORITY_DID") { | ||
Ok(did) if pds_repo::data::valid_did(&did) => Some(did), | ||
Ok(did) => { | ||
return Err(format!("PDS_LEXICON_AUTHORITY_DID is not a DID: {did:?}")); | ||
} | ||
Err(_) => None, | ||
}, | ||
lexicon_dns: None, | ||
invite_required: limits::env_bool("PDS_INVITE_REQUIRED", false)?, | ||
admin_password: std::env::var("PDS_ADMIN_PASSWORD") | ||
.ok() | ||
| @@ -1293,6 +1307,9 @@ mod testing { | ||
), | ||
crawlers: vec![], | ||
oauth_client_fetch: None, | ||
// A DID the directory does not have: no set resolves, and nothing asks DNS. | ||
lexicon_authority: Some("did:plc:aaaaaaaaaaaaaaaaaaaaaaaa".into()), | ||
lexicon_dns: None, | ||
invite_required: false, | ||
admin_password: Some(ADMIN_PASSWORD.into()), | ||
trusted_proxies: Default::default(), | ||
crates/pds-server/src/oauth.rs+86−10
| @@ -29,6 +29,7 @@ mod clients; | ||
mod dpop; | ||
mod page; | ||
mod scope; | ||
mod sets; | ||
#[cfg(test)] | ||
pub(crate) mod tests; | ||
| ||
| @@ -52,7 +53,7 @@ use std::collections::HashMap; | ||
use std::io::Write; | ||
use std::path::Path; | ||
use std::sync::atomic::{AtomicU64, Ordering}; | ||
use std::sync::{Mutex, MutexGuard, PoisonError}; | ||
use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; | ||
| ||
/// The kinds of `accounts.log` entry this module keeps. | ||
pub(crate) const ENTRIES: &[&str] = &[ | ||
| @@ -314,7 +315,11 @@ struct Session { | ||
did: String, | ||
client_id: String, | ||
jkt: String, | ||
/// Its scope as consented, `include:` tokens and all. | ||
scope: Vec<String>, | ||
/// Its scope expanded (`sets::expand`): what its tokens allow, and what | ||
/// its token answers say. | ||
granted: Vec<String>, | ||
started: u64, | ||
/// The code it was made from. | ||
code: String, | ||
| @@ -483,11 +488,14 @@ impl State { | ||
if self.sessions.contains_key(&sid) { | ||
return Err(format!("a second session {sid}")); | ||
} | ||
let scope = list("scope")?; | ||
let s = Session { | ||
did: account("did")?, | ||
client_id: text("client")?, | ||
jkt: text("jkt")?, | ||
scope: list("scope")?, | ||
// A session kept before sets were served kept no expansion: it had nothing to expand. | ||
granted: strings(&e["granted"]).unwrap_or_else(|| scope.clone()), | ||
scope, | ||
started: number("started")?, | ||
code: code.clone(), | ||
access: text("access")?, | ||
| @@ -509,6 +517,9 @@ impl State { | ||
s.access = text("access")?; | ||
s.access_exp = number("accessExp")?; | ||
s.refresh = text("refresh")?; | ||
if let Some(granted) = strings(&e["granted"]) { | ||
s.granted = granted; | ||
} | ||
if let Some(at) = e["at"].as_u64() { | ||
s.refreshed = at; | ||
} | ||
| @@ -644,6 +655,8 @@ pub(crate) struct OAuth { | ||
clients: clients::Clients, | ||
/// DPoP proofs spent, held in memory (`dpop::Spent`). | ||
proofs: Mutex<dpop::Spent>, | ||
/// Permission sets resolved, held in memory (`sets`). | ||
sets: sets::Sets, | ||
} | ||
| ||
fn new_id(bytes: usize) -> String { | ||
| @@ -685,6 +698,7 @@ impl OAuth { | ||
next_forget: AtomicU64::new(0), | ||
clients, | ||
proofs, | ||
sets: sets::Sets::default(), | ||
}) | ||
} | ||
| ||
| @@ -807,6 +821,29 @@ impl OAuth { | ||
self.state.lock().unwrap_or_else(PoisonError::into_inner) | ||
} | ||
| ||
/// The scope a code was approved with, if it is a code to exchange: what | ||
/// the code grant resolves the sets of before it takes the lock. | ||
fn approved_scope(&self, code: &str) -> Vec<String> { | ||
let st = self.lock(); | ||
st.codes | ||
.get(code) | ||
.and_then(|id| st.requests.get(id)?.approval.as_ref()) | ||
.map(|a| a.scope.clone()) | ||
.unwrap_or_default() | ||
} | ||
| ||
/// The scope, as consented, of the session a refresh token is of. | ||
fn session_scope(&self, token: &str) -> Vec<String> { | ||
let Some((sid, _)) = self.token_of("refresh", token) else { | ||
return vec![]; | ||
}; | ||
self.lock() | ||
.sessions | ||
.get(&sid) | ||
.map(|s| s.scope.clone()) | ||
.unwrap_or_default() | ||
} | ||
| ||
fn mac(&self, label: &str, data: &[u8]) -> [u8; 32] { | ||
let mut m = HmacSha256::new_from_slice(&self.key).expect("HMAC takes a key of any length"); | ||
m.update(label.as_bytes()); | ||
| @@ -1597,8 +1634,13 @@ async fn par( | ||
{ | ||
return bad("login_hint is neither a handle nor a DID"); | ||
} | ||
if tokens.iter().any(|t| t.starts_with("include:")) { | ||
return refuse(400, "invalid_scope", "Permission sets are not supported"); | ||
// 15. Each set the scope includes resolves, and is a set. | ||
if let Err((nsid, why)) = svc.oauth.sets.resolve_all(svc, &scope::kept(&tokens)).await { | ||
let description = match why { | ||
sets::Unresolved::Fails(_) => format!("Permission set {nsid} could not be resolved"), | ||
sets::Unresolved::NotASet => format!("{nsid} is not a permission set"), | ||
}; | ||
return refuse(400, "invalid_scope", description); | ||
} | ||
let Some(state) = text("state").filter(|s| !s.is_empty()) else { | ||
return bad("state is required"); | ||
| @@ -1644,7 +1686,7 @@ fn verifier_form(v: &str) -> bool { | ||
fn token_answer(svc: &Service, sid: &str, s: &Session, now: u64) -> Json { | ||
json!({ | ||
"access_token": svc.oauth.token("access", sid, &s.access), "token_type": "DPoP", | ||
"refresh_token": svc.oauth.token("refresh", sid, &s.refresh), "scope": s.scope.join(" "), | ||
"refresh_token": svc.oauth.token("refresh", sid, &s.refresh), "scope": s.granted.join(" "), | ||
"expires_in": s.access_exp.saturating_sub(now), "sub": s.did, | ||
}) | ||
} | ||
| @@ -1702,6 +1744,9 @@ async fn token(svc: &Service, tx: &mut Tx<'_>, headers: &HeaderMap, body: &[u8]) | ||
p.filled("redirect_uri").unwrap_or_default(), | ||
p.filled("code_verifier"), | ||
); | ||
// The sets the code's scope includes, resolved again, with no lock held. | ||
let approved = svc.oauth.approved_scope(code); | ||
let sets = svc.oauth.sets.resolve_all(svc, &approved).await.ok(); | ||
let mut out = tx.change(|st, now| { | ||
settle( | ||
svc, | ||
| @@ -1719,6 +1764,7 @@ async fn token(svc: &Service, tx: &mut Tx<'_>, headers: &HeaderMap, body: &[u8]) | ||
code, | ||
redirect_uri, | ||
verifier, | ||
sets.as_ref(), | ||
), | ||
) | ||
}); | ||
| @@ -1732,13 +1778,25 @@ async fn token(svc: &Service, tx: &mut Tx<'_>, headers: &HeaderMap, body: &[u8]) | ||
} | ||
Some("refresh_token") if client.refresh => { | ||
let token = p.filled("refresh_token").unwrap_or_default(); | ||
// The session's sets, resolved again, with no lock held. | ||
let consented = svc.oauth.session_scope(token); | ||
let sets = svc.oauth.sets.resolve_all(svc, &consented).await.ok(); | ||
tx.change(|st, now| { | ||
settle( | ||
svc, | ||
&proof, | ||
now, | ||
low, | ||
refresh(svc, st, now, client_id, &proof.jkt, key.as_deref(), token), | ||
refresh( | ||
svc, | ||
st, | ||
now, | ||
client_id, | ||
&proof.jkt, | ||
key.as_deref(), | ||
token, | ||
sets.as_ref(), | ||
), | ||
) | ||
}) | ||
} | ||
| @@ -1762,6 +1820,7 @@ fn exchange( | ||
code: &str, | ||
redirect_uri: &str, | ||
verifier: Option<&str>, | ||
sets: Option<&HashMap<String, Arc<Json>>>, | ||
) -> (Vec<Json>, Out) { | ||
let refused = || refuse(400, "invalid_grant", "Invalid code"); | ||
let Some((r, a)) = st | ||
| @@ -1799,6 +1858,17 @@ fn exchange( | ||
if !up { | ||
return (spend(), refused()); | ||
} | ||
// The sets its scope includes, each resolved again (`spec/OAUTH-PERMISSION-SETS.md`). | ||
let Some(sets) = sets else { | ||
return ( | ||
vec![], | ||
refuse( | ||
400, | ||
"invalid_request", | ||
"A permission set could not be resolved", | ||
), | ||
); | ||
}; | ||
if low { | ||
return (vec![], unavailable()); | ||
} | ||
| @@ -1814,6 +1884,7 @@ fn exchange( | ||
client_id: client_id.to_string(), | ||
jkt: jkt.to_string(), | ||
scope: a.scope.clone(), | ||
granted: sets::expand(&a.scope, sets), | ||
started: now, | ||
code: code.to_string(), | ||
access: new_id(12), | ||
| @@ -1824,7 +1895,7 @@ fn exchange( | ||
}; | ||
s.access_exp = (now + ACCESS_LIFE).min(s.end()); | ||
let entry = json!({ | ||
"t": "oauthSession", "sid": sid, "did": s.did, "client": s.client_id, "jkt": s.jkt, "scope": s.scope, | ||
"t": "oauthSession", "sid": sid, "did": s.did, "client": s.client_id, "jkt": s.jkt, "scope": s.scope, "granted": s.granted, | ||
"started": s.started, "code": s.code, "access": s.access, "accessExp": s.access_exp, "refresh": s.refresh, | ||
"clientKey": s.client_key, | ||
}); | ||
| @@ -1841,6 +1912,7 @@ fn refresh( | ||
jkt: &str, | ||
key: Option<&str>, | ||
token: &str, | ||
sets: Option<&HashMap<String, Arc<Json>>>, | ||
) -> (Vec<Json>, Out) { | ||
let refused = || refuse(400, "invalid_grant", "Invalid refresh token"); | ||
let Some((sid, jti)) = svc.oauth.token_of("refresh", token) else { | ||
| @@ -1865,7 +1937,11 @@ fn refresh( | ||
next.refreshed = now; | ||
next.access_exp = (now + ACCESS_LIFE).min(next.end()); | ||
next.refresh = new_id(12); | ||
let entry = json!({ "t": "oauthRefresh", "sid": sid, "access": next.access, "accessExp": next.access_exp, "refresh": next.refresh, "at": now }); | ||
// Expanded again from its sets as they are now; as it was if one no longer resolves. | ||
if let Some(sets) = sets { | ||
next.granted = sets::expand(&next.scope, sets); | ||
} | ||
let entry = json!({ "t": "oauthRefresh", "sid": sid, "access": next.access, "accessExp": next.access_exp, "refresh": next.refresh, "at": now, "granted": next.granted }); | ||
(vec![entry], ok(200, token_answer(svc, &sid, &next, now))) | ||
} | ||
| ||
| @@ -1945,7 +2021,7 @@ async fn revoke(svc: &Service, tx: &mut Tx<'_>, headers: &HeaderMap, body: &[u8] | ||
/// The session an XRPC call's OAuth access token is of, once the token and its proof pass. | ||
pub(crate) struct Access { | ||
pub did: String, | ||
/// Its scope tokens, as kept and narrowed. | ||
/// Its scope tokens, as kept and narrowed, its `include:` scopes expanded. | ||
pub scope: Vec<String>, | ||
} | ||
| ||
| @@ -2016,7 +2092,7 @@ fn check_access( | ||
} | ||
Ok(Access { | ||
did: s.did, | ||
scope: s.scope, | ||
scope: s.granted, | ||
}) | ||
} | ||
| ||
crates/pds-server/src/proxy.rs+6−1
| @@ -510,7 +510,12 @@ fn is_document(doc: &Json, did: &str) -> bool { | ||
/// The endpoint of the first service of `doc` whose `id` is `#<id>` or | ||
/// `<did>#<id>`, of type `kind` if given: a string that starts with | ||
/// `http://` or `https://` and parses as a URL. | ||
fn service_endpoint(doc: &Json, did: &str, id: &str, kind: Option<&str>) -> Option<String> { | ||
pub(crate) fn service_endpoint( | ||
doc: &Json, | ||
did: &str, | ||
id: &str, | ||
kind: Option<&str>, | ||
) -> Option<String> { | ||
let (short, long) = (format!("#{id}"), format!("{did}#{id}")); | ||
let s = doc["service"] | ||
.as_array()? | ||
crates/pds-server/src/space_credentials.rs+1−1
| @@ -14,7 +14,7 @@ | ||
//! asks them through `space_authz`'s `Lifecycle` and `Perimeter`. | ||
| ||
mod attestation; | ||
mod jwt; | ||
pub(crate) mod jwt; | ||
#[cfg(test)] | ||
pub(crate) mod tests; | ||
| ||
crates/pds-server/Cargo.toml+1−0
| @@ -14,6 +14,7 @@ base64.workspace = true | ||
bs58.workspace = true | ||
flate2.workspace = true | ||
hex.workspace = true | ||
hickory-resolver.workspace = true | ||
hmac.workspace = true | ||
http-body.workspace = true | ||
hyper.workspace = true | ||
harness/checks/oauth-scopes.mjs+3−0
harness/checks/oauth.mjs+2−2
harness/checks/operations.mjs+2−2
harness/checks/pages.mjs+147−54
harness/checks/permission-sets.mjsnew+151−0
harness/lib/adapters/index.mjs+2−1
harness/lib/adapters/pds.js.mjs+1−0
harness/lib/adapters/spec-pds.mjs+1−1
harness/lib/adapters/vlpds.mjs+1−0
harness/lib/adapters/zds.mjs+1−0
harness/lib/areas.mjs+5−0
harness/lib/env.mjs+5−2
harness/lib/processes.mjs+14−4
harness/lib/sets.mjsnew+224−0
harness/compare.mjs+3−0
harness/compat.mjs+1−1
spec/COMPAT.md+4−2
spec/OAUTH-PAGES.md+49−15
spec/OAUTH-PERMISSION-SETS.mdnew+246−0
spec/OAUTH-SCOPES.md+7−5
spec/OAUTH.md+16−11
spec/OPERATIONS.md+4−3
spec/PDS.md+4−2
web/src/lib/molecules/Permission.svelte+13−3
web/src/lib/molecules/TechnicalDetails.svelte+31−4
web/src/lib/organisms/PermissionList.svelte+1−1
web/src/lib/data.ts+3−0
web/src/lib/scopes.ts+238−28
web/src/views/Consent.svelte+3−3
Cargo.lock+446−0
446 lines changed: not loaded until asked for.