Skip to content

fix(pcapng): rebuild a ZigBee key off its fixed width as captured (#1986) - #2001

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1986-zigbee-short-key
Oct 21, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1986-zigbee-short-key

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

A Decryption Secrets Block holding a ZigBee NWK or APS key off its fixed width now rebuilds byte-exact. Before, a short key was zero-padded to full width, and secrets_length grew to match. Key octets beyond the fixed width that still fitted inside the block were dropped.

  • The data model keeps the key octets exactly as the block holds them in a new data attribute, which is set on parse only. This follows the TLS key-log precedent.
  • zigbee_key_held rebuilds the key schema from those octets. A short key packs back short.
  • A new trailing field keeps any octets past the fixed width.
  • A model built from its fields is still written at full width.

The other secret types (TLS, WireGuard and unknown) already span the whole secrets area, so they are unaffected.

test_pcapng_zigbee_key_width_1986_unit.py covers every short width, long keys, overruns, make→parse and building from fields. It fails on main with 60 failures and passes here.

Two assertions in the #1980 tests pinned the old full-width rebuild, so they now assert a byte-exact one.

Closes #1986

)

A Decryption Secrets Block's ZigBee NWK or APS key has a fixed width, but
Secrets Length may declare fewer octets or more.

- A short key parsed, but its data model rebuilt it zero-padded at full
  width, with Secrets Length rewritten and the block grown. The data
  model now keeps the Secrets Data octets as the block holds them, as a
  TLS key log keeps its text, and zigbee_key_held rebuilds the schema
  from them, recording a short read so packing cuts it back.
- Octets past the fixed width were dropped by the parse itself, so even
  the header packed short of its Block Total Length. Both key schemas
  now keep them in a trailing field.
- A Secrets Length past the block now rebuilds for a ZigBee key too, and
  the #1980 test that pinned the dropped octets now pins byte-exact.
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 20, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 20, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 24656f4ac. A Sonnet review fuzzed 2740 Decryption Secrets Blocks across the NWK, APS, TLS, WireGuard and unknown types:

  • every key width from empty to well past the fixed width;
  • seven declared secrets_length values, from 0 to a block overrun;
  • with and without trailing octets.

Every block rebuilt byte-exact. Pickle, deepcopy, equality and str on the ZigBee models raised nothing, and a model built from fields still writes full width. A parsed model ignores edited key fields on rebuild, as the TLS key log already does; both _make_secrets_* docstrings say so.

The new test fails on main (60 failed) and passes here. The #1980 change corrects an expectation that pinned the old full-width rebuild. All the pcapng, option-roundtrip and public-API test files pass.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 91.54% (unit tier, Python 3.15, 24656f4ac, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19597 881 2618 867 92.11%
pcapkit/corekit 2540 71 808 37 96.54%
pcapkit/dumpkit 276 3 100 3 98.40%
pcapkit/foundation 2918 23 1016 25 98.78%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17501 222 4612 187 98.13%
pcapkit/toolkit 872 36 298 10 95.21%
pcapkit/utilities 522 2 158 4 99.12%
pcapkit/vendor 4431 1995 1018 167 51.73%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit 7c3c6a9 into main Oct 21, 2026
60 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 21, 2026
@JarryShaw
JarryShaw deleted the fix/1986-zigbee-short-key branch October 21, 2026 00:51
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 21, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(pcapng): a short ZigBee key in a Decryption Secrets Block rebuilds at full width

1 participant