fix: use psk for network authentication

also migrate to latest ljwpaclient with breaking api change
pull/2591/head
Qingping Hou 7 years ago committed by Frans de Jonge
parent d478eaeabe
commit 098ceeb95b

@ -1 +1 @@
Subproject commit 47de692e5743e7c98dfe3f620f8f78db034d0d4f
Subproject commit aab8c73aa5cc3814680ebd8a9ae46ce61af615f6

@ -196,9 +196,11 @@ end
function NetworkMgr:saveNetwork(setting)
if not self.nw_settings then self:readNWSettings() end
self.nw_settings:saveSetting(setting.ssid, {
ssid = setting.ssid,
password = setting.password,
psk = setting.psk,
flags = setting.flags,
})
self.nw_settings:flush()

@ -28,6 +28,7 @@ function WpaSupplicant:getNetworkList()
-- TODO: verify saved_nw.flags == network.flags? This will break if user changed the
-- network setting from [WPA-PSK-TKIP+CCMP][WPS][ESS] to [WPA-PSK-TKIP+CCMP][ESS]
network.password = saved_nw.password
network.psk = saved_nw.psk
end
-- TODO: also verify bssid if it is not set to any
if curr_network and curr_network.ssid == network.ssid then
@ -38,6 +39,18 @@ function WpaSupplicant:getNetworkList()
return list
end
local function calculatePsk(ssid, pwd)
-- TODO: calculate PSK with native function instead of shelling out
-- hostap's reference implementation is available at:
-- * /wpa_supplicant/wpa_passphrase.c
-- * /src/crypto/sha1-pbkdf2.c
-- see: http://docs.ros.org/diamondback/api/wpa_supplicant/html/sha1-pbkdf2_8c_source.html
local fp = io.popen(string.format("wpa_passphrase %s %s", ssid, pwd))
local out = fp:read("*a")
fp:close()
return string.match(out, 'psk=([a-f0-9]+)')
end
function WpaSupplicant:authenticateNetwork(network)
-- TODO: support passwordless network
local err, wcli, nw_id
@ -49,12 +62,16 @@ function WpaSupplicant:authenticateNetwork(network)
nw_id, err = wcli:addNetwork()
if err then return false, err end
local re = wcli:setNetwork(nw_id, "ssid", network.ssid)
local re = wcli:setNetwork(nw_id, "ssid", string.format("\"%s\"", network.ssid))
if re == 'FAIL' then
wcli:removeNetwork(nw_id)
return false, _("Failed to set network SSID.")
end
re = wcli:setNetwork(nw_id, "psk", network.password)
if not network.psk then
network.psk = calculatePsk(network.ssid, network.password)
self:saveNetwork(network)
end
re = wcli:setNetwork(nw_id, "psk", network.psk)
if re == 'FAIL' then
wcli:removeNetwork(nw_id)
return false, _("Failed to set network password.")

Loading…
Cancel
Save