Parse out hash and passphrase, mask passphrase when creating a record
This commit is contained in:
parent
d3a7a97c78
commit
488b614e16
|
@ -125,13 +125,17 @@ class Wifi {
|
||||||
*/
|
*/
|
||||||
_createPSK (ssid, pwd, callback) {
|
_createPSK (ssid, pwd, callback) {
|
||||||
const cmd = `wpa_passphrase "${ssid}" "${pwd}" | grep "psk="`
|
const cmd = `wpa_passphrase "${ssid}" "${pwd}" | grep "psk="`
|
||||||
let output
|
let lines
|
||||||
|
let hash
|
||||||
|
let plaintext
|
||||||
exec(cmd, (err, stdout, stderr) => {
|
exec(cmd, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
output = stdout.replace('#psk=', '').split('psk=')[1]
|
lines = stdout.replace('#psk=', '').split('psk=')
|
||||||
callback(null, output.trim())
|
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} ssid SSID of network to configure
|
||||||
* @param {string} pwd Password of access point, plaintext
|
* @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
|
* @param {function} callback Function invoked after process is complete, or fails
|
||||||
*/
|
*/
|
||||||
setNetwork (ssid, pwd, callback) {
|
setNetwork (ssid, pwd, hash, callback) {
|
||||||
_entry = `network={\n\tssid="${ssid}"\n\tpsk="${pwd}"\n}\n`
|
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
|
_cb = callback
|
||||||
_ssid = ssid
|
_ssid = ssid
|
||||||
fs.readFile(filePath, 'utf8', this._readConfigCb)
|
fs.readFile(filePath, 'utf8', this._readConfigCb)
|
||||||
|
|
Loading…
Reference in New Issue