Update write characteristic to use hash function, making createPSK public function

This commit is contained in:
mmcwilliams 2017-12-31 21:32:09 -05:00
parent 43f62e4885
commit 5b3d1ff2b3
2 changed files with 18 additions and 10 deletions

View File

@ -65,16 +65,23 @@ function onWifiWrite (data, offset, withoutResponse, callback) {
ssid = obj.ssid ssid = obj.ssid
pwd = obj.pwd pwd = obj.pwd
log.info(`connecting to AP`, { ssid : ssid }) log.info(`connecting to AP`, { ssid : ssid })
return wifi.setNetwork(ssid, pwd, (err, data) => { return wifi.createPSK(ssid, pwd, (err, hash, plaintext) => {
if (err) { if (err) {
log.error('Error configuring wifi', err) log.error('Error hashing wifi password', err)
result = bleno.Characteristic.RESULT_UNLIKELY_ERROR result = bleno.Characteristic.RESULT_UNLIKELY_ERROR
return callback(result) return callback(result)
} }
currentWifi = ssid return wifi.setNetwork(ssid, plaintext, hash, (err, data) => {
log.info(`Connected to AP`, { ssid : ssid }) if (err) {
result = bleno.Characteristic.RESULT_SUCCESS log.error('Error configuring wifi', err)
return callback(result) result = bleno.Characteristic.RESULT_UNLIKELY_ERROR
return callback(result)
}
currentWifi = ssid
log.info(`Connected to AP`, { ssid : ssid })
result = bleno.Characteristic.RESULT_SUCCESS
return callback(result)
})
}) })
} }

View File

@ -111,7 +111,7 @@ class Wifi {
_cb = () => {} _cb = () => {}
} }
/** /**
* (internal function) Create sanitized wpa_supplicant.conf stanza for * Create sanitized wpa_supplicant.conf stanza for
* configuring wifi without storing plaintext passwords * configuring wifi without storing plaintext passwords
* @example * @example
* network={ * network={
@ -121,9 +121,10 @@ class Wifi {
* } * }
* *
* @param {string} ssid SSID of wifi network * @param {string} ssid SSID of wifi network
* @param {string} * @param {string} pwd Plaintext passphrase of wifi network
* @param {function} callback Function called after psk hash is generated
*/ */
_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 lines let lines
let hash let hash