From 3152af43504bcfd6285d41f6b6ff67631d01fd0e Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 15 Nov 2026 16:31:37 +0000 Subject: signed values: one reading of an envelope, everywhere Three parts read an envelope three ways: the store's order took any string with the prefix whose meta held a `seq`, its reads any whose value decoded, the checks only one with four parts and a meta of exactly its fields. A string that the first two took and the checks refused was read first, read as the registry's or the policy's value, and treated as nothing by the check of the next write there. `document::signed` reads an envelope the one way: four parts, the value JSON, the meta exactly its six fields (one more, or one twice, and it isn't one), no newline in either, the signature decoding. The store's order, its plain reads, the checks, the API and the users API all go by it. What isn't one in every respect is a plain string, wherever it is read. --- src/api/store.rs | 2 +- src/api/users.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/api') diff --git a/src/api/store.rs b/src/api/store.rs index a7f4686..f0b3094 100644 --- a/src/api/store.rs +++ b/src/api/store.rs @@ -1342,7 +1342,7 @@ mod tests { json!({"swarm": "s", "path": ["x"], "user": "alice", "at": 1, "seq": 0, "prev": ""}); format!( "{}{}.{}.c2ln", - store::ENVELOPE, + crate::document::signed::START, URL_SAFE_NO_PAD.encode(value.to_string()), URL_SAFE_NO_PAD.encode(meta.to_string()) ) diff --git a/src/api/users.rs b/src/api/users.rs index 66b6a8b..f27eff1 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -48,7 +48,7 @@ use tracing::info; use super::ApiError; use super::access::{Access, Before, registry_kept}; use super::auth::AuthenticatedUser; -use crate::access::{Right, registry}; +use crate::access::{Right, envelope, registry}; use crate::document::store; use crate::state::AppState; @@ -153,7 +153,7 @@ pub(crate) async fn own_keys( .flatten() .ok_or_else(|| ApiError(StatusCode::NOT_FOUND, Some("no entry of yours".to_owned())))?; let signed = match store::read_path(&replica.doc, &path) { - Ok(Some(JsonValue::String(text))) if text.starts_with(store::ENVELOPE) => Some(text), + Ok(Some(JsonValue::String(text))) if envelope::read(&text).is_ok() => Some(text), _ => None, }; Ok(Json(json!({ -- cgit v1.3.1