Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new Error(`Options 'dataDir' is required to enable SSH`)
}
// Get host keys
let files = fs.readdirSync(dataDir),
keyRe = /\.key$/,
hostKeys = []
for (let file of files) {
if (keyRe.test(file)) {
hostKeys.push(`${dataDir}/${file}`)
}
}
if (!hostKeys.length) {
console.log('No SSH host key found. Generating new host key...')
let keys = keypair()
fs.writeFileSync(`${dataDir}/rsa.key`, keys.private)
fs.writeFileSync(`${dataDir}/rsa.key.pub`, keys.public)
hostKeys = [ `${dataDir}/rsa.key` ]
}
this.SSHMan = new SSHMan({
monkey: this,
cmdManager: this._cmdMan,
userManager: this.userManager,
silent: this.options.server.silent,
host: sshOpts.host,
port: sshOpts.port,
title: _.result(sshOpts, 'title'),
prompt: _.result(sshOpts, 'prompt'),
hostKeys
})
export function generateKeyPair({ email }) {
if (!email) {
Log.error('An email is required to generate a keypair');
process.exit(1);
}
const pair = keypair();
const pub = pki.publicKeyFromPem(pair.public);
const priv = pki.privateKeyFromPem(pair.private);
const publicKey = ssh.publicKeyToOpenSSH(pub, email);
const privateKey = ssh.privateKeyToOpenSSH(priv);
const userHome = os.homedir();
const title = uuid.v1();
const publicKeyFile = path.resolve(`${userHome}/.reaction/keys/${title}.pub`);
const privateKeyFile = path.resolve(`${userHome}/.reaction/keys/${title}`);
fs.ensureFileSync(publicKeyFile);
fs.ensureFileSync(privateKeyFile);
fs.writeFileSync(publicKeyFile, publicKey);
private async generateKeyPair(connection: Connection, userIdentity: UserIdentity) {
const pair = Keypair({ bits: 1024 });
const privateKey = pair.private;
const publicKey = pair.public;
await connection.insertOne({
provider: userIdentity.provider,
userId: userIdentity.id,
privateKey: privateKey,
publicKey: publicKey
});
return publicKey;
}
}
generatePrivateRSAKey() {
let pair = new Keypair({bits: 1024})
let privateKey = pair.private.substring(32)
privateKey = privateKey.substring(0, privateKey.length - 31)
return privateKey
}
computeCompressedEthereumPublicKey(privKey) {
export const makeKeys = async () => {
if (existsSync(privateKeyFile)) {
return;
}
const keys = rsaGen();
const options = { flag: 'w', encoding: 'utf8' };
writeFileSync(privateKeyFile, keys.private, options);
writeFileSync(publicKeyFile, keys.public, options);
};