fix(ssh): nur ed25519-Schlüssel speichern, die ssh2 lesen kann

ssh2.utils.generateKeyPairSync liefert in etwa 4 von 1000 Fällen einen privaten Schlüssel, an dem der eigene Parser scheitert. Ein so erzeugter Server-Schlüssel wäre dauerhaft unbrauchbar gewesen; in den Tests war es die Ursache des gelegentlich roten SSH-Tests.

Refs #014

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 16:39:54 +02:00
co-authored by Claude Opus 5.5
parent 543fc1c8b4
commit 8dca30e254
7 changed files with 52 additions and 15 deletions
+8 -1
View File
@@ -1,5 +1,6 @@
import type { AddressInfo } from "node:net";
import { Server, utils } from "ssh2";
import { ed25519Erzeugen } from "@/engine/ssh/schluessel";
import { hostSchluesselFingerabdruck } from "@/engine/ssh/verbindung";
/**
@@ -25,7 +26,7 @@ export class SshMock {
async starten(): Promise<this> {
// ssh2 liest ed25519 nur im OpenSSH-Format, nicht als PKCS8.
const hostPem = utils.generateKeyPairSync("ed25519").private;
const hostPem = ed25519Erzeugen().privat;
const host = utils.parseKey(hostPem);
if (host instanceof Error) throw host;
this.hostSchluessel = hostSchluesselFingerabdruck((Array.isArray(host) ? host[0]! : host).getPublicSSH());
@@ -64,3 +65,9 @@ export class SshMock {
await new Promise<void>((erfuellen) => this.server?.close(() => erfuellen()) ?? erfuellen());
}
}
/** Schlüsselpaar für Tests im Format von ssh2 (`public`/`private`) – immer lesbar. */
export function testPaar(): { public: string; private: string } {
const paar = ed25519Erzeugen();
return { public: paar.oeffentlich, private: paar.privat };
}