check_apt_key: reject extra pub without fpr, secret keys, option injection, and unnormalized expected (CHECK-APT-KEY-PARSING-AND-GUARDS) #1610

Open
github-bot wants to merge 1 commit from github-bot/gh-1610 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 05:51 UTC · original
IlyassRS3:fix/check-apt-key-parsing-and-guards → main · +77 −11 · 2 files · 1 commits · open

Item ID: CHECK-APT-KEY-PARSING-AND-GUARDS (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches scripts/check_apt_key.py).

What changed

  • Count primary pub keys even when they lack an fpr record (scripts/check_apt_key.py, primary_fingerprints): previously a pub record followed by another pub, sub/ssb/sec, or EOF without an fpr line was silently dropped, so appending an extra pub record without fpr after the pinned key passed check(). Now every pub record without a matching fpr appends "" (rendered as <missing> in diagnostics), causing check() to fail.
  • Reject secret key records (sec / ssb) in check(): previously a sec record appended after the pinned pub key was ignored and passed check(). Key files handed to apt must contain public key material only.
  • Pass -- end-of-options before path in show_keys(): prevents a key file path starting with - from being interpreted as a gpg option.
  • Normalize and validate expected inside check() and guard non-strings in normalize(): direct callers passing lowercase/spaced fingerprints now match, invalid/empty expected values are refused before invoking gpg, and normalize(None) returns None instead of raising TypeError.
  • Support -h / --help and default argv=None in main().
  • Synthetic regression tests (tests/test_check_apt_key.py): 6 new tests plus expanded test_normalize covering all of the above (no game files, no GPU, no real gpg required).

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU-only Python script on macOS)
  • python3 -W error -I tests/test_check_apt_key.py -v: 19 passed
  • python3 -W error -I tests/test_text_write_line_endings.py: passed
  • python3 -I scripts/check_no_game_data.py scripts/check_apt_key.py tests/test_check_apt_key.py: clean
  • python3 -m compileall -q scripts/check_apt_key.py tests/test_check_apt_key.py: clean
  • Mutation test (tests/test_check_apt_key.py against unpatched main:scripts/check_apt_key.py): 7 failures, 1 error across the 19 tests (all new tests fail on unpatched main).
**@⁠IlyassRS3** on GitHub · 2026-11-25 05:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1610) `IlyassRS3:fix/check-apt-key-parsing-and-guards` → `main` · +77 −11 · 2 files · 1 commits · open Item ID: `CHECK-APT-KEY-PARSING-AND-GUARDS` (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches `scripts/check_apt_key.py`). ## What changed - **Count primary `pub` keys even when they lack an `fpr` record (`scripts/check_apt_key.py`, `primary_fingerprints`)**: previously a `pub` record followed by another `pub`, `sub`/`ssb`/`sec`, or EOF without an `fpr` line was silently dropped, so appending an extra `pub` record without `fpr` after the pinned key passed `check()`. Now every `pub` record without a matching `fpr` appends `""` (rendered as `<missing>` in diagnostics), causing `check()` to fail. - **Reject secret key records (`sec` / `ssb`) in `check()`**: previously a `sec` record appended after the pinned `pub` key was ignored and passed `check()`. Key files handed to `apt` must contain public key material only. - **Pass `--` end-of-options before `path` in `show_keys()`**: prevents a key file path starting with `-` from being interpreted as a `gpg` option. - **Normalize and validate `expected` inside `check()` and guard non-strings in `normalize()`**: direct callers passing lowercase/spaced fingerprints now match, invalid/empty `expected` values are refused before invoking `gpg`, and `normalize(None)` returns `None` instead of raising `TypeError`. - **Support `-h` / `--help` and default `argv=None` in `main()`**. - **Synthetic regression tests (`tests/test_check_apt_key.py`)**: 6 new tests plus expanded `test_normalize` covering all of the above (no game files, no GPU, no real `gpg` required). ## Verification - AI-assisted: yes - GPUs tested: none (CPU-only Python script on macOS) - `python3 -W error -I tests/test_check_apt_key.py -v`: **19 passed** - `python3 -W error -I tests/test_text_write_line_endings.py`: passed - `python3 -I scripts/check_no_game_data.py scripts/check_apt_key.py tests/test_check_apt_key.py`: clean - `python3 -m compileall -q scripts/check_apt_key.py tests/test_check_apt_key.py`: clean - Mutation test (`tests/test_check_apt_key.py` against unpatched `main:scripts/check_apt_key.py`): **7 failures, 1 error** across the 19 tests (all new tests fail on unpatched `main`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:57 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 05:51 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 05:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1610#pullrequestreview-6052504857) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1610/head:github-bot/gh-1610'
git switch 'github-bot/gh-1610'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1610'
git switch 'github-bot/gh-1610'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1610'
git switch 'github-bot/gh-1610'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1610'
git switch 'main'
git merge --squash 'github-bot/gh-1610'
git switch 'main'
git merge --ff-only 'github-bot/gh-1610'
git switch 'main'
git merge 'github-bot/gh-1610'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.