~ev/wiredove

2e65eed6badbb6a527046e905cb4a60d7dfe37fc — Ev Bogue 1 year, 6 months ago 7a5f277 master
see if I can use Node.js to access the wg genkey command
1 files changed, 24 insertions(+), 0 deletions(-)

A bin.js
A bin.js => bin.js +24 -0
@@ 0,0 1,24 @@
const util = require('util');
const pfs = require('fs').promises
const exec = util.promisify(require('child_process').exec);

async function genkey () {
  await exec('sudo wg genkey > private')
  await exec('sudo wg genkey < private > public')
}


if (process.argv[2] === 'genkey') {
  genkey().then(function () {
    var keypair = {}
    pfs.readFile(__dirname + '/private', 'UTF-8').then(privatekey => {
      console.log(privatekey.substring(0, 44))
      keypair.privateKey = privatekey.substring(0, 44)
      pfs.readFile(__dirname + '/public', 'UTF-8').then(publickey => {
        keypair.publicKey = publickey.substring(0, 44)
	console.log(keypair)
      })
    })
  })
}