From 96bffa9a15b85604c11599af3fefc8c96ec847e8 Mon Sep 17 00:00:00 2001 From: oss-sync Date: Thu, 9 Jul 2026 02:02:26 +0000 Subject: [PATCH] sync: update from private repo (bd7e2ac0) --- src/ssh/session-test-server.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ssh/session-test-server.ts b/src/ssh/session-test-server.ts index 366ad4c..95c6c90 100644 --- a/src/ssh/session-test-server.ts +++ b/src/ssh/session-test-server.ts @@ -81,10 +81,22 @@ export interface RunningTestServer { forceClose(): Promise; } -/** Generate a fresh ed25519 keypair in OpenSSH format (parseable by ssh2 both sides). */ +/** + * Generate a fresh ed25519 keypair in OpenSSH format (parseable by ssh2 both sides). + * ssh2's ed25519 generation has a ~0.4% chance of producing a key that it cannot parse; + * this function validates and retries up to 10 times to avoid the flake. + */ export function generateEd25519Pair(): { privatePem: string; publicSsh: string } { - const kp = sshUtils.generateKeyPairSync('ed25519'); - return { privatePem: kp.private, publicSsh: kp.public }; + let lastError: Error | null = null; + for (let attempt = 0; attempt < 10; attempt++) { + const kp = sshUtils.generateKeyPairSync('ed25519'); + const parsed = sshUtils.parseKey(kp.private); + if (!(parsed instanceof Error)) { + return { privatePem: kp.private, publicSsh: kp.public }; + } + lastError = parsed; + } + throw lastError || new Error('Failed to generate valid ed25519 keypair after 10 attempts'); } /** Generate an RSA-2048 PKCS#1 PEM keypair (parseable by ssh2.utils.parseKey). */