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
+97 -5
View File
@@ -233,6 +233,16 @@ var de = {
"rep.done": "Gemeldet.",
"rep.withdrawn": "Zur\xFCckgezogen.",
"rep.mine": "Deine Meldung: {what}.",
"cert.title": "Ger\xE4te-Zertifikat",
"cert.soon": "Das Zertifikat dieses Knotens l\xE4uft am {date} ab (in {n} Tagen). Danach geht der Knoten nicht mehr an und deine Anzeigen verschwinden.",
"cert.expired": "Das Zertifikat dieses Knotens ist am {date} abgelaufen. Erneuere es jetzt.",
"cert.noPhrase": "Diese Identit\xE4t hat keine Wiederherstellungsphrase und l\xE4sst sich nicht erneuern. Lege mit \u201Eallmende init --no-phrase\u201C in einem leeren Datenverzeichnis eine neue an.",
"cert.intro": "Gib die zw\xF6lf W\xF6rter deiner Wiederherstellungsphrase ein. Der Knoten stellt damit ein neues Zertifikat aus und vergisst sie sofort wieder. Der Schl\xFCssel des Ger\xE4ts bleibt gleich, nichts wird widerrufen.",
"cert.phrase": "Die zw\xF6lf W\xF6rter",
"cert.renew": "Zertifikat erneuern",
"cert.working": "Wird erneuert \u2026",
"cert.done": "Erneuert. Das Zertifikat gilt jetzt bis zum {date}.",
"cert.fail": "Das hat nicht geklappt: {detail}",
"rep.title": "Meldungen",
"rep.tipsIntro": "Hinweise von Besuchern dieses Knotens. Sie blenden nichts aus: du entscheidest, ob du selbst meldest.",
"rep.none": "Keine Hinweise von Besuchern.",
@@ -521,6 +531,16 @@ var en = {
"rep.done": "Reported.",
"rep.withdrawn": "Withdrawn.",
"rep.mine": "Your report: {what}.",
"cert.title": "Device certificate",
"cert.soon": "This node's certificate expires on {date} (in {n} days). After that the node will not start and your listings disappear.",
"cert.expired": "This node's certificate expired on {date}. Renew it now.",
"cert.noPhrase": "This identity has no recovery phrase, so it cannot be renewed. Make a new one with \u201Callmende init --no-phrase\u201D in an empty data directory.",
"cert.intro": "Enter the twelve words of your recovery phrase. The node signs a new certificate with them and forgets them at once. The device key stays the same and nothing is revoked.",
"cert.phrase": "The twelve words",
"cert.renew": "Renew certificate",
"cert.working": "Renewing\u2026",
"cert.done": "Renewed. The certificate is now valid until {date}.",
"cert.fail": "That did not work: {detail}",
"rep.title": "Reports",
"rep.tipsIntro": "Tips from visitors of this node. They hide nothing: you decide whether to report yourself.",
"rep.none": "No tips from visitors.",
@@ -5021,6 +5041,9 @@ async function deleteAddress(listing) {
async function setRegions(regions) {
return (await call("PUT", "/api/v1/regions", { regions })).regions;
}
async function renewCertificate(phrase) {
return (await call("PUT", "/api/v1/certificate", { phrase })).cert_expires_at;
}
async function createListing(d) {
return await call("POST", "/api/v1/listings", d);
}
@@ -5039,6 +5062,74 @@ async function renewListing(author, id, days = MAX_LIFETIME_DAYS) {
return updateListing(id, draftFromListing(l, days));
}
// src/certificate.ts
var RENEW_WINDOW_DAYS = 30;
function describe2(e2) {
if (e2 instanceof Unauthorized) return t("reg.signedOut");
if (e2 instanceof HttpError) return e2.detail;
return t("send.network");
}
function certificatePanel() {
const expires = state.node?.cert_expires_at;
if (expires === void 0) return null;
const days = Math.floor((expires - nowSeconds()) / 86400);
if (days > RENEW_WINDOW_DAYS) return null;
const root = h("section", { class: "panel certificate" });
const lead = days >= 0 ? t("cert.soon", { date: date(expires), n: days }) : t("cert.expired", { date: date(expires) });
append(root, [h("h2", { class: "pane-title" }, t("cert.title")), h("p", { class: "note warn", role: "status" }, lead)]);
if (!state.node?.can_renew) {
append(root, [h("p", { class: "muted" }, t("cert.noPhrase"))]);
return root;
}
const phrase = h("input", {
type: "password",
name: "phrase",
autocomplete: "off",
autocapitalize: "none",
spellcheck: "false",
// a bare false would drop the attribute
"aria-label": t("cert.phrase"),
placeholder: t("cert.phrase")
});
const status = h("p", { class: "muted", role: "status" });
const problem = h("p", { class: "error", role: "alert" });
const button = h("button", { type: "submit", class: "btn primary" }, t("cert.renew"));
const form = h(
"form",
{
class: "compose",
onsubmit: (ev) => {
ev.preventDefault();
const words = phrase.value.trim();
problem.textContent = "";
if (!words) {
problem.textContent = t("cert.fail", { detail: t("cert.phrase") });
return;
}
button.disabled = true;
status.textContent = t("cert.working");
void renewCertificate(words).then((until) => {
phrase.value = "";
if (state.node) state.node.cert_expires_at = until;
clear(root);
append(root, [h("h2", { class: "pane-title" }, t("cert.title")), h("p", { role: "status" }, t("cert.done", { date: date(until) }))]);
}).catch((e2) => {
button.disabled = false;
status.textContent = "";
problem.textContent = t("cert.fail", { detail: describe2(e2) });
});
}
},
h("p", { class: "muted" }, t("cert.intro")),
phrase,
h("div", { class: "actions" }, button),
status,
problem
);
root.append(form);
return root;
}
// src/owner.ts
var VALID_DAYS = [1, 3, 7, 14, 30];
var DEFAULT_DAYS = 7;
@@ -5097,6 +5188,7 @@ async function showOwner(listingId, thread) {
const listingsPane = h(
"section",
{ class: "pane pane-listings" },
certificatePanel(),
h("h2", { class: "pane-title" }, t("own.listings")),
h("p", null, h("a", { class: "btn primary", href: "#/mine/new" }, t("own.new"))),
listingsBox,
@@ -5634,7 +5726,7 @@ async function sendTip(author, id, category, note) {
await mine(body, bits);
await postSignal(canonicalize(body));
}
function describe2(e2) {
function describe3(e2) {
if (e2 instanceof Unauthorized) return t("reg.signedOut");
if (e2 instanceof HttpError) return e2.detail;
return t("send.network");
@@ -5695,7 +5787,7 @@ function visitorForm(l) {
}).catch((e2) => {
button.disabled = false;
status.textContent = "";
problem.textContent = t("rep.fail", { detail: describe2(e2) });
problem.textContent = t("rep.fail", { detail: describe3(e2) });
});
}
},
@@ -5717,7 +5809,7 @@ function operatorForm(l, changed) {
status.textContent = t(done);
changed();
}).catch((e2) => {
problem.textContent = t("rep.fail", { detail: describe2(e2) });
problem.textContent = t("rep.fail", { detail: describe3(e2) });
});
};
return h(
@@ -5769,7 +5861,7 @@ async function showReports() {
tips = await getTips();
} catch (e2) {
if (e2 instanceof Unauthorized) return renderLogin(true);
problem.textContent = describe2(e2);
problem.textContent = describe3(e2);
return;
}
clear(list);
@@ -5786,7 +5878,7 @@ async function showReports() {
function card(group, reload, problem) {
const first = group[0];
const fail2 = (e2) => {
problem.textContent = describe2(e2);
problem.textContent = describe3(e2);
};
const categories = [...new Set(group.map((g) => g.category))];
return h(