Wifi module test. Use wpa_passphrase to generate a safe password hash

This commit is contained in:
mmcwilliams 2017-12-31 20:55:54 -05:00
parent a1ced19b42
commit d3a7a97c78
2 changed files with 28 additions and 0 deletions

View File

@ -110,6 +110,30 @@ class Wifi {
//this._callback(null, { ssid : ssid, pwd : pwd.length }) //this._callback(null, { ssid : ssid, pwd : pwd.length })
_cb = () => {} _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 * Function which initializes the processes for adding a wifi access point authentication
* *

4
tests/wifi.js Normal file
View File

@ -0,0 +1,4 @@
'use strict'
const log = require('../lib/log')('wifi-tests')
const wifi = require('../lib/wifi')