From e52d2690eefe0e367e0c5312c8aa173df38c6c76 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 31 Jul 2026 20:32:47 +0200 Subject: [PATCH] Accept printable Wi-Fi hotspot passwords --- install.sh | 2 +- scripts/pi-car-companion-network-setup | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 2cd8590..2386f90 100755 --- a/install.sh +++ b/install.sh @@ -38,7 +38,7 @@ fi echo "[1/7] Installing operating-system packages" export DEBIAN_FRONTEND=noninteractive apt-get update -apt-get install -y ca-certificates curl gnupg git rsync sudo util-linux avahi-daemon sqlite3 android-tools-adb build-essential network-manager +apt-get install -y ca-certificates curl gnupg git rsync sudo util-linux avahi-daemon sqlite3 android-tools-adb build-essential network-manager wpasupplicant node_major="" if command -v node >/dev/null 2>&1; then diff --git a/scripts/pi-car-companion-network-setup b/scripts/pi-car-companion-network-setup index 739c196..fe093b9 100644 --- a/scripts/pi-car-companion-network-setup +++ b/scripts/pi-car-companion-network-setup @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -Eeuo pipefail +export LC_ALL=C CONFIG_FILE="/etc/pi-car-companion/companion.env" HOTSPOT_CONNECTION="pi-car-hotspot" @@ -25,10 +26,15 @@ if [[ "$(nmcli --get-values GENERAL.STATE device show "${UPSTREAM_INTERFACE}" 2> exit 1 fi -read -r -s -p "Password for ${HOTSPOT_SSID} (8-63 characters): " hotspot_password +IFS= read -r -s -p "Password for ${HOTSPOT_SSID} (8-63 characters): " hotspot_password echo -if (( ${#hotspot_password} < 8 || ${#hotspot_password} > 63 )) || [[ ! "${hotspot_password}" =~ ^[[:alnum:]_.-]+$ ]]; then - echo "The hotspot password must contain 8-63 letters, numbers, dots, hyphens, or underscores." >&2 +if (( ${#hotspot_password} < 8 || ${#hotspot_password} > 63 )) || [[ ! "${hotspot_password}" =~ ^[[:print:]]+$ ]]; then + echo "The hotspot password must contain 8-63 printable ASCII characters." >&2 + exit 1 +fi +psk_hex="$(printf '%s\n' "${hotspot_password}" | wpa_passphrase "${HOTSPOT_SSID}" | sed -n 's/^[[:space:]]*psk=//p')" +if [[ ! "${psk_hex}" =~ ^[[:xdigit:]]{64}$ ]]; then + echo "The hotspot password could not be converted into a WPA key." >&2 exit 1 fi @@ -51,7 +57,7 @@ ssid=${HOTSPOT_SSID} [wifi-security] key-mgmt=wpa-psk -psk=${hotspot_password} +psk=${psk_hex} [ipv4] address1=${HOTSPOT_ADDRESS} @@ -66,6 +72,7 @@ fi install -m 0600 -o root -g root "${temporary_file}" "${hotspot_file}" nmcli connection load "${hotspot_file}" hotspot_password="" +psk_hex="" set_env() { local key="$1"