add script to obfuscate wpa keys in netctl files

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-11-30 12:06:36 +01:00
parent 5eca0b1c1d
commit 67b29e1505
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

44
bin/obfuscate_netctl Executable file
View file

@ -0,0 +1,44 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pbkdf2 import PBKDF2
import sys
def get_ssid(netctl_file):
for line in netctl_file:
if line.startswith('ESSID='):
return line.split('=')[1].strip("\"'")
raise Exception("No ESSID assignment found")
def replace_key(netctl_file, ssid):
netctl_out = []
for line in netctl_file:
if line.startswith('Key='):
passphrase = line.split('=')[1].strip("\"'")
key = PBKDF2(passphrase, ssid, iterations=4096).hexread(32)
netctl_out.append('Key=\\"{}'.format(key))
else:
netctl_out.append(line)
return netctl_out
def main(args):
netctl_file = []
with open(args[1], 'r') as f:
netctl_file = f.read().split('\n')
ssid = get_ssid(netctl_file)
netctl_file = replace_key(netctl_file, ssid)
with open(args[1], 'w+') as f:
f.write('\n'.join(netctl_file))
if __name__ == '__main__':
main(sys.argv)