aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/continuum-signed
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-15 12:28:33 +0000
committertv <tv@krebsco.de>2026-11-15 12:28:33 +0000
commit6be5646df342b21fe82c63f59cfec5a369ab54f8 (patch)
tree48ede9923ab4fa762623a6e32b9b18a088276b98 /scripts/continuum-signed
parentd1d081cf8e0e8bb5809c1c82bbdfec6bd7ad0285 (diff)
signed values: value and meta apart, numbered; the highest seq is read
A member could put a user's older signed value back beside a newer one: a change made with dependencies from before both is judged where the place was empty, so the older envelope (`prev` empty) is taken; and of values written at once, the one read was the one with the highest operation, which whoever writes the change steers. A revoked capability, a lifted ban or an earlier policy came back that way, signed by whoever signed it then. An envelope is now `cv2.<value>.<meta>.<signature>`: the value as its user wrote it, and apart from it what continuum adds (swarm, path, user, at, seq, prev), the signature over the value's line and the meta's. `seq` is one more than that of the envelope it replaces, 0 where it replaces none; every node checks it with `prev`. Of the values a place holds, written at once, signed ones are read before any other, the highest `seq` first, of equal ones the lower digest (`store::candidates`): reads, snapshots and writes all go by it. An older envelope beside a newer one changes nothing. `application/continuum-signed` is the value's line, the meta's, then the signature; `scripts/continuum-signed` writes and checks it so. The wire version goes up: nodes must agree on what a place's value is.
Diffstat (limited to 'scripts/continuum-signed')
-rwxr-xr-xscripts/continuum-signed39
1 files changed, 23 insertions, 16 deletions
diff --git a/scripts/continuum-signed b/scripts/continuum-signed
index 21eb376..b66949f 100755
--- a/scripts/continuum-signed
+++ b/scripts/continuum-signed
@@ -94,22 +94,27 @@ raw() {
"$url/store/$1?raw=true" || true
}
-# Writes JSON $2 at $1, signed: replacing the envelope there, if any (`prev`; $3, if
-# given, instead of reading it).
+# Writes JSON $2 at $1, signed: replacing the envelope there, if any (`prev`), and
+# numbered after it (`seq`; $3, if given, instead of reading it).
write() {
[ -n "$user" ] || die "who signs? set CONTINUUM_USER"
if [ $# -ge 3 ]; then current=$3; else current=$(raw "$1"); fi
case $current in
- cv1.*) prev=$(printf %s "$current" | sha256sum | cut -d' ' -f1) ;;
- *) prev= ;;
+ cv2.*)
+ prev=$(printf %s "$current" | sha256sum | cut -d' ' -f1)
+ seq=$(( $(printf %s "$current" | cut -d. -f3 | unb64url | jq -r .seq) + 1 ))
+ ;;
+ *) prev= seq=0 ;;
esac
swarm=$(curl -sf -H "Authorization: Bearer $CONTINUUM_TOKEN" "$url/auth/whoami" |
jq -r .swarm) || die "no swarm from $url"
- # The exact bytes signed and sent: one line of JSON, no newline.
- jq -cnj --arg swarm "$swarm" --arg path "$1" --argjson value "$2" --arg user "$user" \
- --argjson at "$(date +%s)000" --arg prev "$prev" \
- '{swarm: $swarm, path: ($path | split("/")), value: $value, user: $user, at: $at, prev: $prev}' \
- >"$work/payload" || die "not JSON: $2"
+ # The exact bytes signed and sent: the value's line of JSON, then the meta's, no
+ # newline after it.
+ { jq -cn --argjson value "$2" '$value' || die "not JSON: $2"
+ jq -cnj --arg swarm "$swarm" --arg path "$1" --arg user "$user" \
+ --argjson at "$(date +%s)000" --argjson seq "$seq" --arg prev "$prev" \
+ '{swarm: $swarm, path: ($path | split("/")), user: $user, at: $at, seq: $seq, prev: $prev}'
+ } >"$work/payload"
sign "$work/payload" continuum-value
{ cat "$work/payload"; echo; cat "$work/payload.sig"; } |
curl -sS --fail-with-body -X PUT "$url/store/$1" \
@@ -157,7 +162,7 @@ open_sealed() {
command -v age >/dev/null || die "needs age"
stored=$(raw "$1")
case $stored in
- cv1.*) sealed=$(printf %s "$stored" | cut -d. -f2 | unb64url | jq -r '.value // empty') ;;
+ cv2.*) sealed=$(printf %s "$stored" | cut -d. -f2 | unb64url | jq -r '. // empty') ;;
*) sealed=$stored ;;
esac
case $sealed in
@@ -172,16 +177,18 @@ open_sealed() {
verify() {
envelope=$(raw "$1")
case $envelope in
- cv1.*) ;;
+ cv2.*) ;;
*) die "no signed value at $1" ;;
esac
- printf %s "$envelope" | cut -d. -f2 | unb64url >"$work/payload"
- printf %s "$envelope" | cut -d. -f3 | unb64url | base64 | tr -d '\n' | fold -w 70 >"$work/blob"
+ # What was signed: the value, a newline, the meta.
+ printf %s "$envelope" | cut -d. -f3 | unb64url >"$work/meta"
+ { printf %s "$envelope" | cut -d. -f2 | unb64url; echo; cat "$work/meta"; } >"$work/payload"
+ printf %s "$envelope" | cut -d. -f4 | unb64url | base64 | tr -d '\n' | fold -w 70 >"$work/blob"
echo >>"$work/blob"
{ echo '-----BEGIN SSH SIGNATURE-----'; cat "$work/blob"
echo '-----END SSH SIGNATURE-----'; } >"$work/payload.sig"
- signer=$(jq -r .user "$work/payload")
- signed_for=$(jq -r '.path | join("/")' "$work/payload")
+ signer=$(jq -r .user "$work/meta")
+ signed_for=$(jq -r '.path | join("/")' "$work/meta")
[ "$signed_for" = "$1" ] || die "signed for $signed_for, not $1"
curl -sf -H "Authorization: Bearer $CONTINUUM_TOKEN" "$url/store/_continuum/users/$signer" |
jq -r --arg user "$signer" \
@@ -190,7 +197,7 @@ verify() {
ssh-keygen -q -Y verify -f "$work/allowed" -I "$signer" -n continuum-value \
-s "$work/payload.sig" <"$work/payload" >/dev/null 2>&1 ||
die "the signature of $1 doesn't check against $signer's keys"
- echo "$1: signed by $signer at $(jq -r .at "$work/payload")"
+ echo "$1: signed by $signer at $(jq -r .at "$work/meta")"
}
# The user's own entry with key $1 set to the line in file $2, or removed (no $2),