From 488b614e16053936782be741b72d15dfcddefae2 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Sun, 31 Dec 2017 21:06:42 -0500 Subject: [PATCH] Parse out hash and passphrase, mask passphrase when creating a record --- lib/wifi/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/wifi/index.js b/lib/wifi/index.js index 7040341..698fcf3 100644 --- a/lib/wifi/index.js +++ b/lib/wifi/index.js @@ -125,13 +125,17 @@ class Wifi { */ _createPSK (ssid, pwd, callback) { const cmd = `wpa_passphrase "${ssid}" "${pwd}" | grep "psk="` - let output + let lines + let hash + let plaintext exec(cmd, (err, stdout, stderr) => { if (err) { return callback(err) } - output = stdout.replace('#psk=', '').split('psk=')[1] - callback(null, output.trim()) + lines = stdout.replace('#psk=', '').split('psk=') + hash = lines[1] + plaintext = lines[0] + callback(null, hash.trim(), plaintext.trim()) }) } /** @@ -139,10 +143,13 @@ class Wifi { * * @param {string} ssid SSID of network to configure * @param {string} pwd Password of access point, plaintext + * @param {string} hash Password/SSID of access point, securely hashed * @param {function} callback Function invoked after process is complete, or fails */ - setNetwork (ssid, pwd, callback) { - _entry = `network={\n\tssid="${ssid}"\n\tpsk="${pwd}"\n}\n` + setNetwork (ssid, pwd, hash, callback) { + let masked = pwd.split('').map(char => { return '*' }).join('') + console.log(pwd + ' vs. ' + masked) + _entry = `network={\n\tssid="${ssid}"\n\t#psk=${masked}\n\tpsk=${hash}\n}\n` _cb = callback _ssid = ssid fs.readFile(filePath, 'utf8', this._readConfigCb)