aboutsummaryrefslogtreecommitdiff
path: root/.local/share/bin/androidwifistore2pass
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-02-28 20:52:41 +0100
committerlonkaars <loek@pipeframe.xyz>2024-02-28 20:52:41 +0100
commitabbbe1f416bb7db9544ddf7ed554ec8daeda0827 (patch)
tree1208e224ac3725c655f3ac196e88bb2135930ef7 /.local/share/bin/androidwifistore2pass
parentcd3a460d9a9f8d062719bd04a63692d5d52e0a66 (diff)
add script for importing android WiFi networks into pass
Diffstat (limited to '.local/share/bin/androidwifistore2pass')
-rwxr-xr-x.local/share/bin/androidwifistore2pass43
1 files changed, 43 insertions, 0 deletions
diff --git a/.local/share/bin/androidwifistore2pass b/.local/share/bin/androidwifistore2pass
new file mode 100755
index 0000000..a0d7a06
--- /dev/null
+++ b/.local/share/bin/androidwifistore2pass
@@ -0,0 +1,43 @@
+#!/bin/sh
+# Use xmlstarlet and ADB to pull WifiConfigStore.xml from a (rooted) Android
+# phone and import wifi network passwords into pass. Tested with a rooted pixel
+# 4a (sunfish) running LineageOS 21 (Android 14)
+
+TAB="$(printf '\t')"
+
+get_wifi_cfg() {
+ adb shell cat /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
+ if [ $? -ne 0 ] ; then
+ echo "note: try running \`adb root\` first"
+ exit 1
+ fi
+}
+
+parse_filter() {
+ xmlstarlet select --template \
+ --match '/WifiConfigStoreData/NetworkList/Network' \
+ --if './WifiConfiguration/string[@name="PreSharedKey"]' \
+ --value-of './WifiConfiguration/string[@name="SSID"]' \
+ --output "$TAB" \
+ --value-of './WifiConfiguration/string[@name="PreSharedKey"]' \
+ --nl
+}
+
+cut_quotes() {
+ cut -c2- | rev | cut -c2- | rev
+}
+
+import_pass() {
+ while read line; do
+ SSID="$(echo "$line" | cut -d"$TAB" -f1 | cut_quotes | tr '/' '-')"
+ PASSWD="$(echo "$line" | cut -d"$TAB" -f2 | cut_quotes)"
+ PASS_NAME="net/$SSID/passwd"
+
+ printf 'insert SSID "%s" as %s ...' "$SSID" "$PASS_NAME"
+ echo "$PASSWD" | pass insert --multiline "$PASS_NAME" 1>/dev/null 2>/dev/null
+ printf ' %s\n' "$([ $? -eq 0 ] && echo "OK" || echo "ERROR")"
+ done
+}
+
+get_wifi_cfg | parse_filter | import_pass
+