Files
pdtv26/box/wifi_psk.py
T
dckc 521998b666
check / check (push) Canceled after 0s
feat(box): the box's NixOS system as a module, and lib.mkBox from a few names
The box within reach of the couch: a Raspberry Pi 3B with the AIY Voice
HAT, from the first household's configuration, made generic.

- box/body: the button service, in Python: press and talk, turns by
  voice, a press interrupts; the look signal
- box/*.js: the ir and look capabilities, behind gates, for the brain;
  the ask client, the box's side of a conversation
- box/module.nix: the services, each confined to the devices and
  addresses it needs; the private network as an option (a tailnet by
  default); the Pico found by its USB IDs, as /dev/pdtv26-ir
- box/voicehat.nix: the Voice HAT's device tree overlay and ALSA setup
- lib.mkBox: a box's whole system from its name, the home server's,
  the Wi-Fi network's, and who looks after it
- checks: box-js, box-py (doctests and pyflakes), and box-system (an
  example box's system evaluates)

Generated-by: Claude Opus 5.5
2026-12-02 16:18:17 -06:00

37 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
r"""Print a Wi-Fi network's WPA PSK for wpa_supplicant, from the passphrase on stdin.
Usage: wifi_psk.py SSID NAME < passphrase
prints NAME=<64 hex digits>, a line for networking.wireless.secretsFile.
The passphrase never goes on argv, and the box gets only the PSK. wpa_passphrase
does the same, but won't read from a pipe (tcgetattr fails).
>>> psk('IEEE', 'password') # IEEE 802.11i, H.4.1 test vector
'f42c6fc52df0ebef9ebb4b90b38a5f902e83fe1b135a70e23aed762e9710a12e'
"""
import hashlib
def psk(ssid, passphrase):
"""WPA PSK: PBKDF2-HMAC-SHA1, salted by the SSID, 4096 rounds, 32 bytes."""
return hashlib.pbkdf2_hmac('sha1', passphrase.encode(), ssid.encode(), 4096, 32).hex()
def main(argv, stdin, stdout):
[_, ssid, name] = argv
passphrase = stdin.read().rstrip('\n')
if not 8 <= len(passphrase) <= 63:
raise SystemExit('a WPA passphrase is 8 to 63 characters')
stdout.write(f'{name}={psk(ssid, passphrase)}\n')
if __name__ == '__main__':
def _script_io():
from sys import argv, stdin, stdout
main(list(argv), stdin, stdout)
_script_io()