From d7c5e36627c4c26529d6f5b6efb378ebdc0bef8f Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Thu, 27 Apr 2023 20:03:41 +0200 Subject: [PATCH] sftp: delete any existing keys since we are committed to regenerating at this point in code --- src/sftp.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sftp.js b/src/sftp.js index ca22eae87..5d7480025 100644 --- a/src/sftp.js +++ b/src/sftp.js @@ -33,6 +33,8 @@ async function ensureKeys() { if (!privateKey || !publicKey) { debug(`ensureSecrets: generating new sftp keys of type ${keyType}`); + safe.fs.unlinkSync(publicKeyFile); + safe.fs.unlinkSync(privateKeyFile); if (!safe.child_process.execSync(`ssh-keygen -m PEM -t ${keyType} -f "${paths.SFTP_KEYS_DIR}/ssh_host_${keyType}_key" -q -N ""`)) throw new BoxError(BoxError.OPENSSL_ERROR, `Could not generate sftp ${keyType} keys: ${safe.error.message}`); const newPublicKey = safe.fs.readFileSync(publicKeyFile); await blobs.set(`sftp_${keyType}_public_key`, newPublicKey);