tooling: add a read-only Authenticode SHA-256 digest tool #1904
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1911"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-24T20:54:20Z.
A read-only tool that recomputes the Authenticode SHA-256 digest of a PE file, with self-built PE controls. This follows the maintainer's note in #52 that "a source-only version with a self-built PE control would be useful". It does not explain the mismatch reported there, and it does not use or name any packaged file.
Refs #52
Change
tools/pe_authentihash.py: PE32 and PE32+, SHA-256 only. No new dependency (struct,hashlib,mmap). It does not read or verify the signature, and it never writes, repairs or signs a file. Layouts it does not support are refused with an error and no digest:The docstring lists these refusals as limits of this tool.
tests/pe_authentihash_check.py(pure Python, added to thepython-linuxjob): builds PE32 and PE32+ files in a temporary directory. It compares the tool with digests pinned from the Windows API for the same bytes (Windows 11 build 26300). Cases: section ends not aligned to 8, gaps and filler between headers and sections, overlays of 1-13 bytes, certificate tables, and the refusals above. It also checks that a changed section byte changes the digest, and that CheckSum, the certificate data-directory entry and the certificate table do not. No PE file is committed.tests/pe_authentihash_oracle_check.py(Windows only; exits 77 elsewhere): compares the tool withCryptCATAdminAcquireContext2(NULL, "SHA256")+CryptCATAdminCalcHashFromFileHandle2on the synthetic files and on the builtxmem.dll. It does not touch a certificate store. The registered test uses only layouts that occur in real files;--exoticalso checks the synthetic edge cases.Registration:
AGENTS.md, thepython-linuxjob, two CTest entries (pe_authentihash,pe_authentihash_oraclewithSKIP_RETURN_CODE 77) and one line next to the Authenticode note inREADME.md.Two behaviours follow what the Windows API returned, not a reading of the specification: the handling of filler between sections and the zero padding at the end.
On this PR, the
python-linuxjob runs the pure check. Theprpreset does not include the two CTest entries.Verification
Head
cdd188ec; its tree is identical to4eb6a33b, where the runs below were made (only the commit message changed). Windows 11 Pro 26300.9974, Python 3.12.0.On
4eb6a33b:python -B tests/pe_authentihash_check.py: 12 tests OK, on Windows and in WSL Ubuntu with Python 3.12.3. In WSL the oracle check exits 77.ctest --test-dir <build> --no-tests=error -R pe_authentihash: 2/2 passed, no skip.python -B tests/pe_authentihash_oracle_check.py --exotic: 0 mismatches.docs_links_check.py,bidi_controls_check.pyandform_coverage_check.py: passed.On the same tool code before a final edit (an unused
algorithmparameter removed, CMake quoting, the README line):The corpus, fuzz and mutant runs were independent passes with separate scripts on the same machine. Two earlier versions failed them and were fixed before this head:
Not covered: the CI runner's Windows build (26100) was not compared with the oracle.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:10:50Z.
Review: COMMENTED
Review of
cdd188ec9ad1d32fe2cfe90c5ac72ab6a86b58ce(comment only, no approval).Verdict: no P1/P2 found.
Read: the full diff vs
origin/main(tools/pe_authentihash.py, the two tests, CMake/CI/AGENTS/README lines). The tool is read-only, bounds-checks the DOS/PE/optional header, data directories and section table before use, and refuses (error, no digest) the layouts its docstring lists. The README sentence does not claim more than the docstring.Commands run locally:
git diff --check origin/main...HEAD: cleanpython3 -B tests/pe_authentihash_check.py: 12 tests OKpython3 tests/docs_links_check.py: 377 links OK;python3 tests/bidi_controls_check.py: no bidirectional controlspython3 -B tests/pe_authentihash_oracle_check.py: SKIP (Windows catalog API absent on Linux)Mutations (each reverted with
git checkout -- ., tree clean afterwards):sizeinstead ofcert_offset(certificate table included): 11 failuresLimits: the comparison with the Windows hash (
pe_authentihash_oracle_check.py) is Windows-only and was not run here, so agreement with the Windows API rests on the constants in the test and on the Windows run recorded on the PR.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:25:08Z.
Review: COMMENTED
Re-review of exact head
11a7de790821bb1c61c86ff246560e145b0ad64f(my previous comment was oncdd188ec). Comment only, no approval.Verdict: no P1/P2 found. The new commit only rewords the docstring, so my earlier conclusions still hold.
What changed since
cdd188ecgit diff cdd188ec HEADtouches only the module docstring oftools/pe_authentihash.py(+2/-1). The old sentence said the hash "does not read" SectionAlignment, FileAlignment and the PointerToRawData of an empty section. The new one says "Their bytes are hashed; the tool does not validate their values." That is the accurate statement: those bytes sit in the headers and are hashed, only their values are not checked. The docstring is now consistent with the code. No code, test, CMake, CI or README change in this commit.Commands run locally (venv
x2w-rev-venv, worktree at the exact SHA,git rev-parse HEAD==headRefOid)git diff --check origin/main...HEAD-> exit 0, no outputpython -B tests/pe_authentihash_check.py->Ran 12 tests ... OKpython -B tests/pe_authentihash_oracle_check.py->SKIP: Windows catalog-admin hash API is not available(expected on Linux)python -B tests/bidi_controls_check.py->Checked 1340 tracked ... files: no bidirectional controls.python -B tests/docs_links_check.py->Checked 18 Markdown files and 377 links.x2w_pipe.py win2025 1911 --targets xmem_shim --regex '^pe_authentihash': Debug and Release both 2/2 passed, includingpe_authentihash_oracle(the comparison with the Windows catalog-admin hash), which cannot run on Linux.Mutations (each applied to
tools/pe_authentihash.py,tests/pe_authentihash_check.pyre-run, thengit checkout -- .; tree clean afterwards)digest.update(bytes(-tail_end % 8)))4/4 killed.
Limits
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:20:54Z.
Reran the 12 synthetic tests and the Windows catalog digest comparison in
--exoticmode oncdd188ec; all matched. Clarified that SectionAlignment, FileAlignment and the section header pointer are included in the digest bytes even when the tool does not validate their values. The synthetic tests still pass after this documentation-only edit.