Schlüssel: nur noch für Direktnachrichten, ohne Namen und Widerruf
Der Schlüssel dient vorerst nur dazu, Direktnachrichten Ende-zu-Ende zu verschlüsseln. Die laufen allein über unseren Server, der ihn dem Konto zuordnet; niemand holt ihn von außen. Damit fallen User-ID, Widerruf und Ablaufdatum weg: Ist der Schlüssel weg, sind auch die Nachrichten weg, man markiert ihn als verloren und richtet einen neuen ein. - Zurückgebaut: Schlüsselnamen (<name@kver.xyz>, Tabelle key_name, /user/key/name), Widerruf per Passphrase und Widerrufszertifikat (/user/key/update, pgpkey.Revoked, revoked_at), Ablaufdatum, die öffentliche Historie /u/{username}/keys, updated_at. - Schlüssel ohne User-ID (RFC 9580 erlaubt das, OpenPGP.js kann es). - Die Seite zeigt „Schlüssel hinterlegt“ mit Fingerprint zum Vergleichen. - DEV: account_key und key_name gelöscht und account_key frisch aus schema.sql angelegt; Fixtures neu erzeugt, ohne User-ID. 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
93159aa12b
commit
e5ec60d72c
@@ -21,8 +21,7 @@ func fixture(t *testing.T, name string) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
// keyForm baut das Formular für /user/key (mit secret) und /user/key/update
|
||||
// (secret nil).
|
||||
// keyForm baut das Formular für /user/key.
|
||||
func keyForm(cert, secret []byte, pass string) url.Values {
|
||||
f := url.Values{"key": {base64.StdEncoding.EncodeToString(cert)}, "pass": {pass}}
|
||||
if secret != nil {
|
||||
@@ -61,7 +60,7 @@ func TestKeys(t *testing.T) {
|
||||
alice := registerAndLogin(t, srv, "alice")
|
||||
bob := registerAndLogin(t, srv, "bob")
|
||||
const pass = "supersecret1"
|
||||
v6, v6b, revoked := fixture(t, "v6.pgp"), fixture(t, "v6-2.pgp"), fixture(t, "v6-revoked.pgp")
|
||||
v6, v6b := fixture(t, "v6.pgp"), fixture(t, "v6-2.pgp")
|
||||
locked, lockedB := fixture(t, "v6-locked.pgp"), fixture(t, "v6-2-locked.pgp")
|
||||
fpr := strings.TrimSpace(string(fixture(t, "v6.fpr")))
|
||||
fpr2 := strings.TrimSpace(string(fixture(t, "v6-2.fpr")))
|
||||
@@ -86,7 +85,6 @@ func TestKeys(t *testing.T) {
|
||||
{"ohne login", newClient(t), keyForm(v6, locked, pass), 401, "auth.required"},
|
||||
{"privater schlüssel", alice, keyForm(fixture(t, "v6-secret.pgp"), locked, pass), 400, "key.secret"},
|
||||
{"v4", alice, keyForm(fixture(t, "v4.pgp"), locked, pass), 400, "key.unsupported"},
|
||||
{"fremde user-id", alice, keyForm(fixture(t, "v6-foreign.pgp"), locked, pass), 400, "key.user_id"},
|
||||
{"kein base64", alice, url.Values{"key": {"%%%"}, "pass": {pass}}, 400, "key.invalid"},
|
||||
{"leer", alice, url.Values{"pass": {pass}}, 400, "key.invalid"},
|
||||
} {
|
||||
@@ -111,14 +109,14 @@ func TestKeys(t *testing.T) {
|
||||
t.Fatalf("schlüssel setzen: %d %s", st, code)
|
||||
}
|
||||
var k keyJSON
|
||||
if got := getAny(t, keyURL, &k); got != http.StatusOK || k.Fingerprint != fpr || k.Address != "alice@kver.xyz" || !bytes.Equal(k.Key, v6) || k.Status != "current" {
|
||||
if got := getAny(t, keyURL, &k); got != http.StatusOK || k.Fingerprint != fpr || !bytes.Equal(k.Key, v6) || k.Status != "current" {
|
||||
t.Fatalf("aktueller schlüssel: %d %+v", got, k)
|
||||
}
|
||||
if st, code := postCode(t, alice, srv.URL+"/api/user/key", keyForm(v6, locked, pass)); st != http.StatusConflict || code != "key.exists" {
|
||||
t.Fatalf("doppelt: %d %s", st, code)
|
||||
}
|
||||
// Derselbe Schlüssel und sein Name gehören nicht zusätzlich bob.
|
||||
if st, code := postCode(t, bob, srv.URL+"/api/user/key", keyForm(v6, locked, pass)); st != http.StatusConflict || code != "key.name_taken" {
|
||||
// Derselbe Schlüssel gehört nicht zusätzlich bob.
|
||||
if st, code := postCode(t, bob, srv.URL+"/api/user/key", keyForm(v6, locked, pass)); st != http.StatusConflict || code != "key.exists" {
|
||||
t.Fatalf("fremder schlüssel: %d %s", st, code)
|
||||
}
|
||||
|
||||
@@ -126,7 +124,6 @@ func TestKeys(t *testing.T) {
|
||||
if st, code := postCode(t, alice, srv.URL+"/api/user/key", keyForm(v6b, lockedB, "falsch")); st != http.StatusForbidden || code != "auth.bad_password" {
|
||||
t.Fatalf("ersetzen mit falschem passwort: %d %s", st, code)
|
||||
}
|
||||
// Ersetzen: der alte bleibt in der Historie.
|
||||
if st, code := postCode(t, alice, srv.URL+"/api/user/key", keyForm(v6b, lockedB, pass)); st != http.StatusCreated {
|
||||
t.Fatalf("ersetzen: %d %s", st, code)
|
||||
}
|
||||
@@ -134,25 +131,6 @@ func TestKeys(t *testing.T) {
|
||||
t.Fatalf("nach ersetzen: %+v", k)
|
||||
}
|
||||
|
||||
// Widerruf des alten Schlüssels nachreichen; bob darf das nicht.
|
||||
if st, _ := postCode(t, bob, srv.URL+"/api/user/key/update", keyForm(revoked, nil, pass)); st != http.StatusNotFound {
|
||||
t.Fatalf("update fremder schlüssel: %d", st)
|
||||
}
|
||||
if st, code := postCode(t, alice, srv.URL+"/api/user/key/update", keyForm(revoked, nil, pass)); st != http.StatusOK {
|
||||
t.Fatalf("update: %d %s", st, code)
|
||||
}
|
||||
var hist struct{ Keys []keyJSON }
|
||||
getAny(t, srv.URL+"/api/u/alice/keys", &hist)
|
||||
if len(hist.Keys) != 2 ||
|
||||
hist.Keys[0].Fingerprint != fpr || hist.Keys[0].Status != "revoked" || !bytes.Equal(hist.Keys[0].Key, revoked) ||
|
||||
hist.Keys[1].Fingerprint != fpr2 || hist.Keys[1].Status != "current" {
|
||||
t.Fatalf("historie: %+v", hist.Keys)
|
||||
}
|
||||
// Zurücknehmen mit der alten Fassung geht nicht.
|
||||
if st, code := postCode(t, alice, srv.URL+"/api/user/key/update", keyForm(v6, nil, pass)); st != http.StatusConflict || code != "key.revoked" {
|
||||
t.Fatalf("widerruf zurücknehmen: %d %s", st, code)
|
||||
}
|
||||
|
||||
// Als verloren markieren.
|
||||
if st, _ := postCode(t, alice, srv.URL+"/api/user/key/lost", url.Values{"pass": {"falsch"}}); st != http.StatusForbidden {
|
||||
t.Fatalf("verloren mit falschem passwort: %d", st)
|
||||
@@ -181,76 +159,6 @@ func TestKeys(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestKeyRevokeCurrent: Ein widerrufener aktueller Schlüssel wird nicht mehr
|
||||
// ausgeliefert, ein neuer lässt sich einrichten. Eigener Server, damit die
|
||||
// Drosselung der Schlüssel-Endpunkte nicht greift.
|
||||
func TestKeyRevokeCurrent(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := newTestServer(t)
|
||||
const pass = "supersecret1"
|
||||
v6, v6b, revoked := fixture(t, "v6.pgp"), fixture(t, "v6-2.pgp"), fixture(t, "v6-revoked.pgp")
|
||||
locked, lockedB := fixture(t, "v6-locked.pgp"), fixture(t, "v6-2-locked.pgp")
|
||||
fpr2 := strings.TrimSpace(string(fixture(t, "v6-2.fpr")))
|
||||
var e errorResponse
|
||||
var k keyJSON
|
||||
|
||||
carol := registerAndLogin(t, srv, "carol")
|
||||
if st, code := postCode(t, carol, srv.URL+"/api/user/key", keyForm(v6, locked, pass)); st != http.StatusCreated {
|
||||
t.Fatalf("carol schlüssel: %d %s", st, code)
|
||||
}
|
||||
if st, code := postCode(t, carol, srv.URL+"/api/user/key/update", keyForm(revoked, nil, pass)); st != http.StatusOK {
|
||||
t.Fatalf("carol widerruf: %d %s", st, code)
|
||||
}
|
||||
if got := getAny(t, srv.URL+"/api/u/carol/key", &e); got != http.StatusNotFound || e.Error.Code != "key.revoked" {
|
||||
t.Fatalf("widerrufen: %d %s", got, e.Error.Code)
|
||||
}
|
||||
if st, code := postCode(t, carol, srv.URL+"/api/user/key", keyForm(v6b, lockedB, pass)); st != http.StatusCreated {
|
||||
t.Fatalf("neuer nach widerruf: %d %s", st, code)
|
||||
}
|
||||
if getAny(t, srv.URL+"/api/u/carol/key", &k); k.Fingerprint != fpr2 || k.Status != "current" {
|
||||
t.Fatalf("carol neu: %+v", k)
|
||||
}
|
||||
}
|
||||
|
||||
// TestKeyNames: Prüfung der Schlüsselnamen vor dem Erzeugen.
|
||||
func TestKeyNames(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := newTestServer(t)
|
||||
alice := registerAndLogin(t, srv, "alice")
|
||||
bob := registerAndLogin(t, srv, "bob")
|
||||
for _, tc := range []struct {
|
||||
c *http.Client
|
||||
name string
|
||||
status int
|
||||
code string
|
||||
}{
|
||||
{alice, "alice", 200, ""}, // eigener Forumsname
|
||||
{bob, "alice", 409, "key.name_taken"},
|
||||
{alice, "a.b-c_9", 200, ""},
|
||||
{alice, "Alice", 400, "key.name_invalid"},
|
||||
{alice, "jürgen", 400, "key.name_invalid"},
|
||||
{alice, ".alice", 400, "key.name_invalid"},
|
||||
{alice, "a..b", 400, "key.name_invalid"},
|
||||
{alice, "a", 400, "key.name_invalid"},
|
||||
{alice, "admin", 409, "key.name_taken"},
|
||||
} {
|
||||
if st, code := postCode(t, tc.c, srv.URL+"/api/user/key/name", url.Values{"name": {tc.name}}); st != tc.status || code != tc.code {
|
||||
t.Errorf("name %q: %d %s, erwartet %d %s", tc.name, st, code, tc.status, tc.code)
|
||||
}
|
||||
}
|
||||
|
||||
// Ein benutzter Name bleibt vergeben, auch wenn das Konto gelöscht ist.
|
||||
if st, code := postCode(t, alice, srv.URL+"/api/user/key", keyForm(fixture(t, "v6.pgp"), fixture(t, "v6-locked.pgp"), "supersecret1")); st != http.StatusCreated {
|
||||
t.Fatalf("schlüssel: %d %s", st, code)
|
||||
}
|
||||
if st := postStatus(t, alice, srv.URL+"/api/user/delete", url.Values{"pass1": {"supersecret1"}}); st != http.StatusOK {
|
||||
t.Fatalf("konto löschen: %d", st)
|
||||
}
|
||||
if st, code := postCode(t, bob, srv.URL+"/api/user/key/name", url.Values{"name": {"alice"}}); st != http.StatusConflict || code != "key.name_taken" {
|
||||
t.Fatalf("name nach konto-löschung: %d %s", st, code)
|
||||
}
|
||||
}
|
||||
|
||||
// TestKeySecret: Der private Schlüssel kommt nur verschlüsselt und passend
|
||||
// zum Zertifikat an, geht nur mit Passwort an das eigene Konto zurück und
|
||||
// lässt sich mit neuer Passphrase ersetzen.
|
||||
|
||||
Reference in New Issue
Block a user