Skip to content

Handle Hikvision AX HOME quirks: truncated ciphertext → NAK, accept O block, opt-in minute-precision timestamps - #94

Open
4gnus wants to merge 1 commit into
eavanvalkenburg:masterfrom
4gnus:hikvision-ax-home-quirks
Open

4gnus wants to merge 1 commit into
eavanvalkenburg:masterfrom
4gnus:hikvision-ax-home-quirks

Conversation

@4gnus

@4gnus 4gnus commented Oct 30, 2026

Copy link
Copy Markdown

Fixes #93.

A Hikvision AX HOME hub (encrypted SIA DC-09) loses about 1 event in 5 with 3.2.2. The details and a reproduction are in the issue. This PR:

  • Truncated ciphertext → NAK instead of a dropped connection. decrypt_content() raises EventFormatError when the ciphertext is not hex or not a multiple of the AES block size. parse_and_check_event() already answers EventFormatError with NAK, so the panel resends. Before, AES.decrypt() raised ValueError, which escaped handle_line() and closed the connection without a reply.
  • Accept the DC-03 old event block O. The panel resends with |Ori… instead of |Nri…. The regex took Or as the code and the receiver answered DUH. O now counts as the block only when two letters follow, so OP and other O… codes still parse when a sender leaves the block letter out (regression test added).
  • Opt-in SIAAccount.timestamp_minute_precision (default False) for panels whose seconds field is unreliable (this one sends HH:MM:MM). When set, an event passes if any second of its minute falls inside the allowed band, so replay protection stays on. That is safer than allowed_timeband=None.

Tests: new cases for all three (truncated at 8/10/38/43 bytes, non-hex, O block encrypted and unencrypted, timestamp window with a frozen clock), and a guard for O… codes without a block. 211 passed and 13 skipped on Python 3.13 (190/13 on master), run with pytest<9, as #92 notes. Merges cleanly with #87, #89, #90 and #92.

Validated on a live Home Assistant 2026.5.4 install with an equivalent local patch (same NAK and O handling; the timestamp check there is always on rather than a flag): arm, disarm, bypass and periodic tests arrive. Cut frames get NAK, and the panel's resend is ACKed within about 1 s.

🤖 Generated with Claude Code

- decrypt_content: a ciphertext that is not hex or not a multiple of the AES
  block size raises EventFormatError instead of ValueError, so the server
  answers NAK (and the panel resends) instead of dropping the connection.
- SIA content regex: accept the DC-03 old event block "O" next to "N"; O is
  only taken as the block when two letters follow, so codes such as OP still
  parse when a sender omits the block letter.
- SIAAccount.timestamp_minute_precision (default False): check the timestamp
  window with minute precision for panels that send HH:MM:MM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hikvision AX HOME (SIA DC-09, encrypted): cut ciphertext drops the connection, resends with O block get DUH, timestamps are HH:MM:MM

1 participant