From d3a7a97c78186111af33dc6351766762a8215b06 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Sun, 31 Dec 2017 20:55:54 -0500 Subject: [PATCH] Wifi module test. Use wpa_passphrase to generate a safe password hash --- lib/wifi/index.js | 24 ++++++++++++++++++++++++ tests/wifi.js | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 tests/wifi.js diff --git a/lib/wifi/index.js b/lib/wifi/index.js index b07d74a..7040341 100644 --- a/lib/wifi/index.js +++ b/lib/wifi/index.js @@ -110,6 +110,30 @@ class Wifi { //this._callback(null, { ssid : ssid, pwd : pwd.length }) _cb = () => {} } + /** + * (internal function) Create sanitized wpa_supplicant.conf stanza for + * configuring wifi without storing plaintext passwords + * @example + * network={ + * ssid="YOUR_SSID" + * #psk="YOUR_PASSWORD" + * psk=6a24edf1592aec4465271b7dcd204601b6e78df3186ce1a62a31f40ae9630702 + * } + * + * @param {string} ssid SSID of wifi network + * @param {string} + */ + _createPSK (ssid, pwd, callback) { + const cmd = `wpa_passphrase "${ssid}" "${pwd}" | grep "psk="` + let output + exec(cmd, (err, stdout, stderr) => { + if (err) { + return callback(err) + } + output = stdout.replace('#psk=', '').split('psk=')[1] + callback(null, output.trim()) + }) + } /** * Function which initializes the processes for adding a wifi access point authentication * diff --git a/tests/wifi.js b/tests/wifi.js new file mode 100644 index 0000000..d92fb8e --- /dev/null +++ b/tests/wifi.js @@ -0,0 +1,4 @@ +'use strict' + +const log = require('../lib/log')('wifi-tests') +const wifi = require('../lib/wifi')