Skip to content

Commit

Permalink
Update oputil_ssh_key.js per feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
crhultay authored Nov 23, 2024
1 parent c0044dc commit 2c85a9b
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions core/oputil/oputil_ssh_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getHelpFor = require('./oputil_help.js').getHelpFor;

// deps
const async = require('async');
const fs = require('graceful-fs');
const fs = require('fs-extra');
const exec = require('child_process').exec;
const inq = require('inquirer');
const _ = require('lodash');
Expand Down Expand Up @@ -47,8 +47,6 @@ const QUESTIONS = {
};

function execute(ui, command) {
ui.log.write("Ping!");
ui.log.write(command);
exec(
command,
function (error, stdout, stderr) {
Expand All @@ -75,8 +73,6 @@ function execute(ui, command) {
function createNew(cb) {
const ui = new inq.ui.BottomBar();

let sslPassword;

async.waterfall(
[
function init(callback) {
Expand All @@ -89,8 +85,8 @@ function createNew(cb) {
}

// Get Answer Value
sslPassword = answers.password;
if (!sslPassword || sslPassword.replaceAll(" ", "") == "") {
const sslPassword = answers.password.trim();
if (!sslPassword || sslPassword == "") {
ui.log.write('Password must be set.');

return callback('exit');
Expand All @@ -106,31 +102,16 @@ function createNew(cb) {
const sshKeyFilename = "ssh_private_key.pem";
const targetKeyFile = sshKeyPath + sshKeyFilename;

// Check if Keyfile Exists
if (fs.existsSync(targetKeyFile)) {
ui.log.write(`${targetKeyFile} already exists.`)

return callback('exit');
}

ui.log.write(`Creating SSH Key: ${targetKeyFile}`);

// Create Dir
if (!fs.existsSync(sshKeyPath)) {
if (!fs.pathExists(sshKeyPath)) {
ui.log.write(`Creating Directory: ${sshKeyPath}`);
exec(`mkdir -p ${sshKeyPath}`);
}

// Check if OpenSSL binary is installed
const binaryPath = "/usr/bin/openssl";
if (!fs.existsSync(binaryPath)) {
ui.log.write(`${binaryPath} was not found in your path`);

return callback('exit');
}

// Create SSH Keys
const command = `${binaryPath} genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 | openssl rsa -out ./${targetKeyFile} -aes128 -traditional -passout pass:`;
const command = `openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 | openssl rsa -out ./${targetKeyFile} -aes128 -traditional -passout pass:`;
execute(ui, `${command}${sslPassword}`);
});
},
Expand Down

0 comments on commit 2c85a9b

Please sign in to comment.