sftp: delete any existing keys since we are committed to regenerating at this point in code

This commit is contained in:
Girish Ramakrishnan
2023-04-27 20:03:41 +02:00
parent aaf31efd0f
commit d7c5e36627

View File

@@ -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);