Schlüssel: Kontopasswort einmal beim Öffnen abfragen
Die Schlüsselseite fragt das Kontopasswort vorab ab, prüft es über den neuen Endpunkt /user/password/check und schickt es dann mit jeder Änderung mit. So steht nie ein Passwortfeld neben einem für die Passphrase, und beides wird nicht verwechselt. Es liegt nur im Speicher der Seite; passt es nicht mehr, geht es zurück zur Abfrage. Der Server verlangt das Passwort jetzt auch beim ersten Einrichten und nach Widerruf oder Verlust: Sonst könnte eine gestohlene Session einen eigenen Schlüssel unterschieben und künftige Direktnachrichten mitlesen. Widerrufen und „als verloren markieren“ fragen ohne Passwortfeld per Rückfrage nach, wie das Löschen von Beiträgen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TiXsPUqw7oeomZ8wZrQW5q
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3a8de894ca
commit
49a3284e12
@@ -31,4 +31,5 @@
|
||||
<li>Auf einem neuen Gerät lädst du deinen Schlüssel unter <em>Einstellungen → Schlüssel</em> aus der gesicherten Datei</li>
|
||||
<li>Schlüssel lassen sich mit dem Widerrufszertifikat widerrufen, auch ohne Schlüsseldatei und Passphrase.</li>
|
||||
<li>Ohne Widerrufszertifikat lässt sich ein Schlüssel als verloren markieren; er wird dann hier nicht mehr angeboten.</li>
|
||||
<li>Die Schlüsselseite fragt das Kontopasswort einmal beim Öffnen ab statt bei jeder Änderung.</li>
|
||||
</ul>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { createContext, useContext, useEffect, useState, type FormEvent } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { ApiError, api, errMsg } from "../api";
|
||||
@@ -27,9 +27,15 @@ import {
|
||||
// (notes/schluessel.md). Bisher: Browser-Prüfung, Anzeige, Einrichten, Laden
|
||||
// der Schlüsseldatei, Widerruf per Zertifikat und als verloren markieren;
|
||||
// Ersetzen folgt.
|
||||
//
|
||||
// Das Kontopasswort wird einmal beim Öffnen abgefragt und geprüft, bevor die
|
||||
// Seite erscheint, und dann mit jeder Änderung mitgeschickt. So steht nie ein
|
||||
// Feld fürs Kontopasswort neben einem für die Passphrase. Es liegt nur im
|
||||
// Speicher dieser Seite und ist beim Verlassen oder Neuladen weg.
|
||||
export function KeysPage() {
|
||||
const me = useMe();
|
||||
const support = useSupport();
|
||||
const [pass, setPass] = useState<string | null>(null);
|
||||
return (
|
||||
<>
|
||||
<section id="settings">
|
||||
@@ -37,19 +43,74 @@ export function KeysPage() {
|
||||
<p>
|
||||
<Link to="/settings">← Einstellungen</Link>
|
||||
</p>
|
||||
<p className="muted">
|
||||
Mit deinem Schlüssel schreibst du verschlüsselte Direktnachrichten und kannst Beiträge auf Wunsch signieren.
|
||||
Der Schlüssel bleibt auf deinem Gerät und in einer Datei, die du selbst sicherst – der Server bekommt ihn
|
||||
nie.
|
||||
</p>
|
||||
<BrowserCheck support={support} />
|
||||
{me.data && support && supported(support) && <MyKey username={me.data.username} />}
|
||||
{me.data && pass === null && <Unlock onUnlock={setPass} />}
|
||||
{me.data && pass !== null && (
|
||||
<PassContext.Provider value={{ pass, forget: () => setPass(null) }}>
|
||||
<KeysContent username={me.data.username} support={support} />
|
||||
</PassContext.Provider>
|
||||
)}
|
||||
</section>
|
||||
{me.isSuccess && !me.data && <AuthBox />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// Unlock fragt das Kontopasswort ab und prüft es beim Server.
|
||||
function Unlock({ onUnlock }: { onUnlock: (pass: string) => void }) {
|
||||
const check = useMutation({
|
||||
mutationFn: async (pass: string) => {
|
||||
const fd = new FormData();
|
||||
fd.set("pass", pass);
|
||||
await api.post("/user/password/check", fd);
|
||||
return pass;
|
||||
},
|
||||
onSuccess: onUnlock,
|
||||
});
|
||||
const onSubmit = (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
check.mutate(String(new FormData(e.currentTarget).get("pass") ?? ""));
|
||||
};
|
||||
return (
|
||||
<form id="key-unlock" onSubmit={onSubmit}>
|
||||
<input name="pass" type="password" placeholder="Kontopasswort" autoComplete="current-password" autoFocus />
|
||||
<button type="submit" disabled={check.isPending}>
|
||||
Weiter
|
||||
</button>
|
||||
<p className="msg">{check.isError ? errMsg(check.error, "Prüfen fehlgeschlagen.") : ""}</p>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
const PassContext = createContext<{ pass: string; forget: () => void }>({ pass: "", forget: () => {} });
|
||||
|
||||
// usePassPost liefert ein api.post, das das Kontopasswort mitschickt. Passt es
|
||||
// nicht mehr (etwa inzwischen geändert), geht es zurück zur Abfrage.
|
||||
function usePassPost() {
|
||||
const { pass, forget } = useContext(PassContext);
|
||||
return async <T,>(path: string, fd: FormData) => {
|
||||
fd.set("pass", pass);
|
||||
try {
|
||||
return await api.post<T>(path, fd);
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.code === "auth.bad_password") forget();
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function KeysContent({ username, support }: { username: string; support: Support | null }) {
|
||||
return (
|
||||
<>
|
||||
<p className="muted">
|
||||
Mit deinem Schlüssel schreibst du verschlüsselte Direktnachrichten und kannst Beiträge auf Wunsch signieren. Der
|
||||
Schlüssel bleibt auf deinem Gerät und in einer Datei, die du selbst sicherst – der Server bekommt ihn nie.
|
||||
</p>
|
||||
<BrowserCheck support={support} />
|
||||
{support && supported(support) && <MyKey username={username} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function useSupport() {
|
||||
const [support, setSupport] = useState<Support | null>(null);
|
||||
useEffect(() => {
|
||||
@@ -160,16 +221,16 @@ function KeyDetails({ username, info }: { username: string; info: KeyInfo }) {
|
||||
|
||||
// RevokeKey widerruft den Schlüssel mit dem Widerrufszertifikat -- für den
|
||||
// Fall, dass Schlüsseldatei oder Passphrase weg oder in fremden Händen sind.
|
||||
// Der Widerruf ist endgültig; das Kontopasswort bestätigt ihn.
|
||||
// Der Widerruf ist endgültig, daher die Rückfrage.
|
||||
function RevokeKey({ username, info }: { username: string; info: KeyInfo }) {
|
||||
const qc = useQueryClient();
|
||||
const post = usePassPost();
|
||||
const revoke = useMutation({
|
||||
mutationFn: async ({ file, pass }: { file: File; pass: string }) => {
|
||||
mutationFn: async (file: File) => {
|
||||
const revoked = await applyRevocation(info.key, await file.text());
|
||||
const fd = new FormData();
|
||||
fd.set("key", toBase64(revoked));
|
||||
fd.set("pass", pass);
|
||||
await api.post<KeyInfo>("/user/key/update", fd);
|
||||
await post<KeyInfo>("/user/key/update", fd);
|
||||
},
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ["key", username] }),
|
||||
});
|
||||
@@ -178,14 +239,13 @@ function RevokeKey({ username, info }: { username: string; info: KeyInfo }) {
|
||||
const fd = new FormData(e.currentTarget);
|
||||
const file = fd.get("revfile");
|
||||
if (!(file instanceof File) || file.size === 0) return;
|
||||
revoke.mutate({ file, pass: String(fd.get("pass") ?? "") });
|
||||
if (confirm("Schlüssel wirklich widerrufen? Das lässt sich nicht zurücknehmen.")) revoke.mutate(file);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<h3>Widerrufen</h3>
|
||||
<form id="key-revoke" onSubmit={onSubmit}>
|
||||
<input name="revfile" type="file" accept=".asc,.txt,application/pgp-keys" />
|
||||
<input name="pass" type="password" placeholder="Kontopasswort" autoComplete="current-password" />
|
||||
<button type="submit" disabled={revoke.isPending}>
|
||||
{revoke.isPending ? "Widerrufe …" : "Schlüssel widerrufen"}
|
||||
</button>
|
||||
@@ -238,23 +298,19 @@ function LoadKey({ username, fingerprint }: { username: string; fingerprint: str
|
||||
// nicht mehr aus, wer ihn schon hat, merkt davon nichts.
|
||||
function MarkLost({ username }: { username: string }) {
|
||||
const qc = useQueryClient();
|
||||
const post = usePassPost();
|
||||
const lost = useMutation({
|
||||
mutationFn: (pass: string) => {
|
||||
const fd = new FormData();
|
||||
fd.set("pass", pass);
|
||||
return api.post("/user/key/lost", fd);
|
||||
},
|
||||
mutationFn: () => post("/user/key/lost", new FormData()),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ["key", username] }),
|
||||
});
|
||||
const onSubmit = (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
lost.mutate(String(new FormData(e.currentTarget).get("pass") ?? ""));
|
||||
if (confirm("Schlüssel wirklich als verloren markieren?")) lost.mutate();
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<h3>Als verloren markieren</h3>
|
||||
<form id="key-lost" onSubmit={onSubmit}>
|
||||
<input name="pass" type="password" placeholder="Kontopasswort" autoComplete="current-password" />
|
||||
<button type="submit" disabled={lost.isPending}>
|
||||
Als verloren markieren
|
||||
</button>
|
||||
@@ -305,6 +361,7 @@ function CreateKey({ username, onCreated }: { username: string; onCreated: (c: C
|
||||
|
||||
function SaveKey({ username, created, onCancel }: { username: string; created: Created; onCancel: () => void }) {
|
||||
const qc = useQueryClient();
|
||||
const post = usePassPost();
|
||||
const { key, passphrase } = created;
|
||||
const [saved, setSaved] = useState(false);
|
||||
const [msg, setMsg] = useState("");
|
||||
@@ -313,7 +370,7 @@ function SaveKey({ username, created, onCancel }: { username: string; created: C
|
||||
mutationFn: async () => {
|
||||
const fd = new FormData();
|
||||
fd.set("key", toBase64(key.publicBinary));
|
||||
await api.post<KeyInfo>("/user/key", fd);
|
||||
await post<KeyInfo>("/user/key", fd);
|
||||
// Erst wenn der Server den Schlüssel kennt, gilt er als eingerichtet.
|
||||
await saveLocalKey({
|
||||
fingerprint: key.fingerprint,
|
||||
@@ -348,8 +405,8 @@ function SaveKey({ username, created, onCancel }: { username: string; created: C
|
||||
</div>
|
||||
<input name="passphrase" type="text" placeholder="Passphrase eingeben" autoComplete="off" spellCheck={false} />
|
||||
<label>
|
||||
<input type="checkbox" checked={saved} onChange={(e) => setSaved(e.target.checked)} /> Ich habe beide
|
||||
Dateien gesichert.
|
||||
<input type="checkbox" checked={saved} onChange={(e) => setSaved(e.target.checked)} /> Ich habe beide Dateien
|
||||
gesichert.
|
||||
</label>
|
||||
<div className="row">
|
||||
<button type="submit" disabled={!saved || upload.isPending}>
|
||||
|
||||
Reference in New Issue
Block a user