From 1676d1f2a97370b6872ca5e286057f2a4b909a41 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Sun, 28 Feb 2021 15:52:09 +0000 Subject: [PATCH] Use an askpass wrapper --- dist/index.js | 4 +++- index.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index beb213c..2570d83 100644 --- a/dist/index.js +++ b/dist/index.js @@ -179,6 +179,8 @@ try { console.log(`Write file ${keyFile}`); fs.writeFileSync(keyFile, key.replace("\r\n", "\n").trim() + "\n", { mode: '600' }); + fs.writeFileSync(`${homeSsh}/askpass`, `echo ${token}`, { mode: '700' }); + // Set private key passphrase let output = ''; try { @@ -193,7 +195,7 @@ try { // Load key into agent console.log('Load key'); //let sshAdd = child_process.execSync(`echo "${token}" | ssh-add "${keyFile}"`, { stdio: 'inherit' }); - let sshAdd = child_process.execFileSync('ssh-add', [keyFile], { stdio: 'inherit' }); + let sshAdd = child_process.execFileSync('ssh-add', [keyFile], { stdio: 'inherit', env: { 'SSH_ASKPASS': `${homeSsh}/askpass` } }); // input: token + "\n", stdio: ['pipe', 'inherit', 'inherit'] }); //sshAdd.stdin.write(token + "\n"); //sshAdd.stdin.end(); diff --git a/index.js b/index.js index be444f2..d7d5f84 100644 --- a/index.js +++ b/index.js @@ -62,6 +62,8 @@ try { console.log(`Write file ${keyFile}`); fs.writeFileSync(keyFile, key.replace("\r\n", "\n").trim() + "\n", { mode: '600' }); + fs.writeFileSync(`${homeSsh}/askpass`, `echo ${token}`, { mode: '700' }); + // Set private key passphrase let output = ''; try { @@ -76,7 +78,7 @@ try { // Load key into agent console.log('Load key'); //let sshAdd = child_process.execSync(`echo "${token}" | ssh-add "${keyFile}"`, { stdio: 'inherit' }); - let sshAdd = child_process.execFileSync('ssh-add', [keyFile], { stdio: 'inherit' }); + let sshAdd = child_process.execFileSync('ssh-add', [keyFile], { stdio: 'inherit', env: { 'SSH_ASKPASS': `${homeSsh}/askpass` } }); // input: token + "\n", stdio: ['pipe', 'inherit', 'inherit'] }); //sshAdd.stdin.write(token + "\n"); //sshAdd.stdin.end();