wpa_supplicant

This commit is contained in:
mwiegand 2021-10-28 23:02:40 +02:00
parent 3652a521de
commit 9e4163d291
2 changed files with 24 additions and 11 deletions

View file

@ -1,24 +1,15 @@
import hashlib, binascii import hashlib, binascii
def wpa_psk(ssid, password):
return binascii.hexlify(
hashlib.pbkdf2_hmac('sha1', str.encode(password), str.encode(ssid), 4096, 32)
).decode()
interface = node.metadata.get('wpa-supplicant/interface') interface = node.metadata.get('wpa-supplicant/interface')
ssid = node.metadata.get('wpa-supplicant/ssid')
passowrd = repo.vault.decrypt(node.metadata.get('wpa-supplicant/password')).value
psk = wpa_psk(ssid, passowrd)
files = { files = {
f'/etc/wpa_supplicant/wpa_supplicant-{interface}.conf': { f'/etc/wpa_supplicant/wpa_supplicant-{interface}.conf': {
'source': 'wpa_supplicant.conf', 'source': 'wpa_supplicant.conf',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
'ssid': ssid, 'ssid': node.metadata.get('wpa-supplicant/ssid'),
'psk': psk, 'psk': node.metadata.get('wpa-supplicant/psk'),
}, },
'needs': [ 'needs': [
'pkg_apt:wpasupplicant', 'pkg_apt:wpasupplicant',

View file

@ -1,3 +1,6 @@
import hashlib, binascii
defaults = { defaults = {
'apt': { 'apt': {
'packages': { 'packages': {
@ -5,3 +8,22 @@ defaults = {
}, },
}, },
} }
@metadata_reactor.provides(
'wpa-supplicant/psk',
)
def psk(metadata):
return {
'wpa-supplicant': {
'psk': binascii.hexlify(
hashlib.pbkdf2_hmac(
'sha1',
repo.vault.decrypt(metadata.get('wpa-supplicant/password')).value.encode(),
metadata.get('wpa-supplicant/ssid').encode(),
4096,
32
)
).decode()
}
}