sync: update from private repo (bd7e2ac0)
All checks were successful
CI / build-and-test (push) Successful in 6m50s
All checks were successful
CI / build-and-test (push) Successful in 6m50s
This commit is contained in:
parent
fb1477c9d5
commit
96bffa9a15
@ -81,11 +81,23 @@ export interface RunningTestServer {
|
||||
forceClose(): Promise<void>;
|
||||
}
|
||||
|
||||
/** 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 } {
|
||||
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). */
|
||||
export function generateRsaPair(): { privatePem: Buffer; publicSsh: string } {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user