summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorRanieri Althoff2020-05-29 23:06:46 -0300
committerRanieri Althoff2020-05-29 23:07:25 -0300
commit5c75617725b61b2679ec85ec95733b1f00f65fca (patch)
tree0c6a22cc19161a474d024f6ae39d8801f259bf41
parent9d95efb5e6cd78aa9d9fa2b96ab8f1d57a4e10cb (diff)
downloadaur-5c75617725b61b2679ec85ec95733b1f00f65fca.tar.gz
v0.2.0
- Add support for iwd (thanks, henhell)
-rw-r--r--.SRCINFO4
-rw-r--r--PKGBUILD4
-rw-r--r--wpa-psk.py31
3 files changed, 24 insertions, 15 deletions
diff --git a/.SRCINFO b/.SRCINFO
index e5fbcab2e65e..e39c31ee058b 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,13 +1,13 @@
pkgbase = wpa-psk
pkgdesc = Generate a WPA PSK from an ASCII passphrase for a SSID
- pkgver = 0.1.0
+ pkgver = 0.2.0
pkgrel = 1
url = https://aur.archlinux.org/packages/wpa-psk
arch = any
license = MIT
depends = python
source = wpa-psk.py
- sha256sums = 8dddd39534c9c48574222bef1d81efbb34992a6143a786f07c051d58904b1fff
+ sha256sums = 61e387b8af78d4aad16c2b8727008982e987a694e31c4f3814ef422e045f4b09
pkgname = wpa-psk
diff --git a/PKGBUILD b/PKGBUILD
index 14581c774622..fd53171c5e44 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,6 +1,6 @@
# Maintainer: Ranieri Althoff <@domain.com>
pkgname=wpa-psk
-pkgver=0.1.0
+pkgver=0.2.0
pkgrel=1
pkgdesc='Generate a WPA PSK from an ASCII passphrase for a SSID'
arch=('any')
@@ -8,7 +8,7 @@ url="https://aur.archlinux.org/packages/$pkgname"
license=('MIT')
depends=('python')
source=("$pkgname.py")
-sha256sums=('8dddd39534c9c48574222bef1d81efbb34992a6143a786f07c051d58904b1fff')
+sha256sums=('61e387b8af78d4aad16c2b8727008982e987a694e31c4f3814ef422e045f4b09')
package() {
install -Dm755 "$srcdir/$pkgname.py" "$pkgdir/usr/bin/$pkgname"
diff --git a/wpa-psk.py b/wpa-psk.py
index f0012f64317e..0881ae30a416 100644
--- a/wpa-psk.py
+++ b/wpa-psk.py
@@ -5,8 +5,17 @@ from argparse import ArgumentParser
from getpass import getpass
from hashlib import pbkdf2_hmac
+iwd = """[Security]
+PreSharedKey={psk}"""
+
+supplicant = """network={{
+ ssid={ssid}
+ #psk={passphrase}
+ psk={psk}
+}}"""
+
parser = ArgumentParser(
- description="%(prog)s pre-computes PSK entries for network configuration blocks of a wpa_supplicant.conf file. An ASCII passphrase and SSID are used to generate a 256-bit PSK."
+ description="%(prog)s pre-computes PSK entries for network configuration blocks of wpa_supplicant or iwd config. An ASCII passphrase and SSID are used to generate a 256-bit PSK."
)
parser.add_argument("ssid", help="The SSID whose passphrase should be derived.")
parser.add_argument(
@@ -14,16 +23,23 @@ parser.add_argument(
help="The passphrase to use. If not included on the command line, passphrase will be read from standard input.",
nargs="?",
)
+parser.add_argument(
+ "--iwd",
+ "-i",
+ dest="template",
+ action="store_const",
+ const=iwd,
+ default=supplicant,
+ help="Generate for iwd (default: generate for wpa_supplicant).",
+)
args = parser.parse_args()
if not args.passphrase:
print("# reading passphrase from stdin")
args.passphrase = getpass(prompt="")
-
if not 8 <= len(args.passphrase) <= 63:
print("Passphrase must be 8..63 characters")
sys.exit(1)
-args.ssid.encode()
passphrase = args.passphrase.encode()
if any(b < 32 or b == 127 for b in passphrase):
print("Invalid passphrase character")
@@ -31,11 +47,4 @@ if any(b < 32 or b == 127 for b in passphrase):
ssid = args.ssid.encode()
psk = pbkdf2_hmac("sha1", passphrase, ssid, iterations=4096, dklen=32)
-print(
- "network={",
- f'\tssid="{args.ssid}"',
- f'\t#psk="{args.passphrase}"',
- f"\tpsk={psk.hex()}",
- "}",
- sep="\n",
-)
+print(args.template.format(ssid=args.ssid, passphrase=args.passphrase, psk=psk.hex()))