Renew the device certificate from the browser, with the recovery phrase

Within the last 30 days the owner page offers it. The node signs a new certificate for the same device key (peer ID and listings stay), saves it, and signs again own listings that would outlive the old certificate. The phrase is used for one request and not kept; another identity's phrase and no-phrase identities are refused. Device.Current gives the certificate to sign with while a renewal happens.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 23:19:30 +01:00
co-authored by Claude Sonnet 5.5
parent 210ba1b3e9
commit dfe35b422d
23 changed files with 1011 additions and 29 deletions
+20
View File
@@ -141,6 +141,26 @@ sleep 1 # a newer report must be dated a second later
curl -s -X POST -H "Authorization: Bearer $TOKEN" -d "${REPORT/scam/withdrawn}" http://127.0.0.1:18101/api/v1/reports >/dev/null
[ "$(count 18101 '')" = 1 ] && ok "withdrawing the report shows the listing again" || bad "a withdrawn report still hides it"
echo "== renewing the device certificate from the browser, with the phrase"
status_field() { curl -s http://127.0.0.1:18101/api/v1/status | python3 -c "import json,sys; print(json.load(sys.stdin)[\"$1\"])"; }
CERT_BEFORE=$(status_field cert_expires_at)
[ "$(status_field can_renew)" = True ] && ok "status says the certificate can be renewed, and until when ($CERT_BEFORE)" || bad "status does not offer renewal"
renew_code() { curl -s -o /dev/null -w "%{http_code}" -X PUT ${2:+-H "Authorization: Bearer $2"} -d "{\"phrase\":\"$1\"}" http://127.0.0.1:18101/api/v1/certificate; }
[ "$(renew_code "$PHRASE")" = 401 ] && ok "renewal without the admin token is refused" || bad "renewal worked without a token"
PHRASE_B=$(grep -E '^ +[0-9]+\.' $W/init-b.txt | sed -E 's/[0-9]+\.//g' | tr -s ' \n' ' ' | sed 's/^ //; s/ $//')
[ "$(renew_code "$PHRASE_B" "$TOKEN")" = 409 ] && ok "another identity's phrase is refused" || bad "renewed with the wrong identity's phrase"
[ "$(renew_code "wrong words here" "$TOKEN")" = 400 ] && ok "a malformed phrase is refused" || bad "a malformed phrase was accepted"
[ "$(status_field cert_expires_at)" = "$CERT_BEFORE" ] && ok "refused renewals changed nothing" || bad "a refused renewal moved the expiry"
sleep 1.2 # the new certificate must be dated a second later to expire later
[ "$(renew_code "$PHRASE" "$TOKEN")" = 200 ] && ok "the owner's phrase renews it" || bad "renewal with the right phrase failed"
CERT_AFTER=$(status_field cert_expires_at)
[ "$CERT_AFTER" -gt "$CERT_BEFORE" ] && ok "the certificate now runs until $CERT_AFTER" || bad "expiry did not move: $CERT_BEFORE -> $CERT_AFTER"
[ "$(status_field peer_id)" = "$PEER" ] && ok "same device key, same peer ID" || bad "renewing changed the peer ID"
grep -q "\"expires_at\":$CERT_AFTER" $A/device.cert && ok "the new certificate is saved, so a restart keeps it" || bad "device.cert does not hold the renewal"
grep -rqi "$(echo $PHRASE | cut -d' ' -f1-3)" $A && bad "the phrase was written to the data directory"
ok "the phrase was not stored"
[ "$(count 18101 '')" = 1 ] && ok "the owner's listing is untouched" || bad "renewal disturbed the listing"
echo "== recover on A (simulate a stolen machine)"
OLD_DEVICE=$(curl -s http://127.0.0.1:18101/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["device"])')
kill ${PIDS[0]}; wait ${PIDS[0]} 2>/dev/null