PIN hashing is a three-way mismatch: CLI, FSM, and web arm/disarm all incompatible #2
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: bug (and a mild security regression in one of the paths)
Files:
vigilar/cli/cmd_config.py,vigilar/events/state.py,vigilar/web/blueprints/system.py,vigilar/alerts/pin.py,vigilar/config.pyThree different modules hash the arm/disarm PIN three different ways, using two different config keys. None of them interoperate.
web/blueprints/system.py:63-64, 74-75, 88viaalerts/pin.pypbkdf2_sha256$salt$dk[security] pin_hashArmStateFSM)events/state.py:50[system] arm_pin_hashvigilar config set-pincli/cmd_config.py:86-95secret_hex:mac[system] arm_pin_hashConsequences:
vigilar config set-pinproduces an unusable value. It writes an HMAC-format string to[system] arm_pin_hash. The FSM reads that same key but expects a raw SHA-256 hex digest, so verification always fails.system.py:57-66checks the PBKDF2 hash at[security] pin_hashbut then just returns{"ok": true, "state": mode}without calling the FSM. State never transitions from the web UI even when the PIN is correct.alerts/pin.pypath already uses PBKDF2-SHA256 with 600k iterations, which is the right choice.events/state.py:46says "Verify a PIN against the stored hash using HMAC comparison" — buthmac.compare_digestis a timing-safe equality check, not an HMAC. No HMAC is computed on the FSM path.Fix (proposed design, wants sign-off before implementation):
alerts/pin.hash_pin/verify_pin(PBKDF2-SHA256, 600k iterations).[security] pin_hash(already in use by the web path, lives in a security-scoped section) and removing[system] arm_pin_hashfromSystemConfig.ArmStateFSM.verify_pinto callalerts.pin.verify_pin.set-pinto callalerts.pin.hash_pinand emit a[security] pin_hashline.web/blueprints/system.py:arm_system/disarm_systemto actually publish a transition request on MQTT that the FSM subscribes to (or call the FSM directly if they share a process — they don't, so MQTT).[system] arm_pin_hashis set but[security] pin_hashis empty, log a warning that the old key is ignored andvigilar config set-pinmust be re-run.