fp-verify.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # Fingerprint verification via the Wine sandbox + hacked winusb + vendor driver.
  3. # Usage: fp-verify.sh (touch the sensor when the log says it waits)
  4. # Exit codes: 0 = MATCH (enrolled "Unicorn" record returned), 1 = no match, 2 = error/timeout
  5. set -u
  6. export PATH=/usr/local/bin:/usr/bin:/bin
  7. ROOT=/home/nebulon/projects/fingerprint
  8. SANDBOX=$ROOT/work/synaWudfBioUsb-sandbox
  9. mkdir -p /tmp/opencode 2>/dev/null
  10. # Serialize sensor access: sudo/polkit (pam_fp.so), the fprintd shim (GNOME
  11. # lock screen) and manual runs must not drive the Wine sandbox at the same
  12. # time - the fake winusb cannot handle two Wine runs on one USB device.
  13. if [ "${FP_VERIFY_LOCK:-1}" = "1" ]; then
  14. LOCK=/tmp/opencode/fp-verify.lock
  15. exec 9>"$LOCK" || exit 2
  16. if ! flock -w "${FP_VERIFY_LOCK_WAIT:-30}" 9; then
  17. echo "Fingerprint: another verification is already in progress."
  18. exit 2
  19. fi
  20. fi
  21. export HOME="${HOME:-/home/nebulon}"
  22. export WINEPREFIX=$ROOT/work/wineprefix-48
  23. export WINEDEBUG=-all
  24. export USB_SCRIPT=$ROOT/work/debug/usb-verify-$(date +%s).txt
  25. export USB_PLAYBACK=""
  26. touch "$USB_SCRIPT"
  27. mkdir -p /tmp/opencode 2>/dev/null
  28. LOG=/tmp/opencode/fp-verify-last.log
  29. cd "$SANDBOX" || exit 2
  30. # self-heal: the device spec the driver reads (sandbox copy + Wine C: drive)
  31. [ -f usb.txt ] || echo "06cb:0081" > usb.txt
  32. USB_TXT="$WINEPREFIX/drive_c/usb.txt"
  33. if [ ! -f "$USB_TXT" ]; then
  34. mkdir -p "$(dirname "$USB_TXT")" 2>/dev/null
  35. echo "06cb:0081" > "$USB_TXT" 2>/dev/null || true
  36. fi
  37. [ "${FP_VERIFY_QUIET:-0}" = "1" ] || echo "Fingerprint: touch the reader (or wait for the password prompt)..."
  38. timeout -k 5 "${FP_VERIFY_TIMEOUT:-90}" \
  39. "$ROOT/work/wine-build/install/bin/wine64" verify.exe > "$LOG" 2>&1
  40. rc=$?
  41. if grep -q "556e69636f726e" "$LOG"; then # hex of "Unicorn"
  42. echo "Fingerprint matched."
  43. exit 0
  44. elif [ "$rc" -eq 124 ] || [ "$rc" -eq 137 ]; then
  45. echo "No fingerprint detected - falling back to password."
  46. exit 2
  47. else
  48. echo "Fingerprint did not match - falling back to password."
  49. exit 1
  50. fi