Skip to content

fix(verify): require TDX quote version 4 and validate expected digest lengths in verify_tdx_quote and verify_sev_snp_report (#283) - #288

Open
drk-ram wants to merge 1 commit into
agentrust-io:mainfrom
drk-ram:drk-ram-fix-tdx-snp-verify-283
Open

drk-ram wants to merge 1 commit into
agentrust-io:mainfrom
drk-ram:drk-ram-fix-tdx-snp-verify-283

Conversation

@drk-ram

@drk-ram drk-ram commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What

Require quote.version == 4 in verify_tdx_quote, validate expected_mrtd / expected_measurement (48 bytes) and expected_report_data (64 bytes) in verify_tdx_quote and verify_sev_snp_report, and validate isinstance(reject_unrecognized_platform_bits, bool) in verify_sev_snp_report and sev_snp_verifier.

Why

Closes #283.

Security impact

Prevents non-v4 TDX quotes from being parsed with DCAP v4 offsets during verification and prevents caller misconfiguration with wrong-length expected measurements or report_data bindings.

Test plan

  • pytest passes (pytest tests/unit/test_tdx.py tests/unit/test_sev_snp.py -q: 54 passed, 2 skipped)
  • ruff check passes (ruff check src tests/unit/test_tdx.py tests/unit/test_sev_snp.py: All checks passed!)
  • mypy passes
  • Manual test performed

DCO sign-off

@drk-ram
drk-ram requested review from a team, carloshvp and zohebk8s as code owners October 25, 2026 06:00
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Contributor Check: MEDIUM

Check Result
Profile MEDIUM
Credential LOW
Overall MEDIUM

Automated check by AgenTrust Contributor Check.

@github-actions github-actions Bot added the needs-review:MEDIUM Contributor check flagged MEDIUM risk label Oct 25, 2026
carloshvp
carloshvp previously approved these changes Oct 25, 2026

@carloshvp carloshvp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head fa6f446cc727712e51845434825c240927d4f606 in an isolated checkout.

The TDX verifier requires the supported v4 layout and validates expected measurement/report-data byte lengths before appraisal. SNP expectations and the platform-bits option receive the corresponding type checks. All nine focused input/version cases pass here and fail against the baseline verifier modules at the expected guard boundary. Existing valid v4/SNP controls remain passing; no blocking source finding.

Independent validation in a fresh repository-hash-locked Python 3.12.10 environment: 785 tests passed, 16 skipped; pip check, configured Ruff, mypy, Bandit and diff whitespace checks passed. Commit sign-offs are present. Hosted CI and applicable independent maintainer/security gates remain separate prerequisites to merge.

Reviewed with OpenAI Codex.

@drk-ram drk-ram closed this Oct 29, 2026
@drk-ram
drk-ram force-pushed the drk-ram-fix-tdx-snp-verify-283 branch from fa6f446 to 1889ce4 Compare October 29, 2026 15:20
@drk-ram drk-ram reopened this Oct 29, 2026

@carloshvp carloshvp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed current head aabdad3eb9dabf4a73f19526c21971f104a90037 in an isolated checkout.

The scoped input-hardening behavior passes source review and the full local unit/conformance suite (841 passed, 16 skipped). Ruff lint, mypy, configured Bandit and dependency consistency pass; the commit is signed off.

The required ruff format --check src/ tests/ job still fails on this head, while the same command passes on current main. Please run the pinned formatter on src/ca2a_verify/tdx.py and rerun the format gate. The formatting diff is mechanical; no additional behavioral repair is requested by this review. Hosted CI and the independent security-review requirements still apply.

Reviewed with OpenAI Codex.

Copy link
Copy Markdown
Contributor

The requested formatting correction is ready for author adoption: dinakarjs#8, commit 0824465b14d7bdef7f92287b3d109b9eb5c8f988, based directly on this reviewed PR head. Pinned Ruff 0.17.1 formatting changes only; every changed Python AST is identical before/after. Final unit/conformance run: 855 passed, 2 skipped; Ruff format/lint, mypy, Bandit and whitespace checks pass. Environment and scope are recorded in the companion. Please cherry-pick into the existing PR and rerun hosted checks. This does not replace independent maintainer approval. DCO signed; prepared with Codex.

@drk-ram

drk-ram commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

@carloshvp Amended and force-pushed d9e1939 (d9e1939199795d4861442b55f44980fa0f8a43cd). ruff format --check src/ tests/ and ruff check src/ tests/ now pass with 0 errors.

@drk-ram
drk-ram force-pushed the drk-ram-fix-tdx-snp-verify-283 branch from aabdad3 to d9e1939 Compare October 31, 2026 15:08
carloshvp
carloshvp previously approved these changes Nov 3, 2026

@carloshvp carloshvp left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit d9e1939199795d4861442b55f44980fa0f8a43cd.

The requested formatting repair is complete. I compared the changed Python files with the revision from my prior review: their parsed ASTs are identical. The pinned repository formatter, Ruff, mypy and configured Bandit pass on this head. Focused tests: 25 passed, 1 hardware-dependent skip.

This resolves my formatting change request. The existing security impact and independent maintainer/CI requirements remain applicable.

@codecov-commenter

codecov-commenter commented Nov 18, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

zohebk8s
zohebk8s previously approved these changes Nov 19, 2026

@zohebk8s zohebk8s left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for hardening TDX and SNP verification. The TDX v4 requirement and validation of expected measurement and report-data lengths look correct, with regression coverage for invalid versions and inputs. Approved.

carloshvp
carloshvp previously approved these changes Nov 22, 2026

@carloshvp carloshvp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TDX and SNP verifier changes are preserved on this head. The additional assertions exercise expected-digest validation. The TDX unit module produced 25 passes and one skip for a physical quote fixture.

@rajnisht7 rajnisht7 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few gaps remain against #283 and the stated goal:

  • TDX version check is too late - verify_tdx_quote calls TdxQuote.parse() (which already uses hard-coded v4 offsets and parses the QE/PCK cert data) before checking quote.version == 4. Non-v4 quotes are still interpreted with the v4 layout; the version check only runs if parse succeeds, validate the version from the raw header (or inside TdxQuote.parse) before any v4-specific parsing. TdxProvider.attest() also calls parse directly and is uncovered.
  • memoryview length check is incorrect - the new guards accept memoryview but use len(). For non-byte formats len() counts elements, not bytes. A 192-byte memoryview(array.array("I", [0]*48)) passes the 48-byte check, while a valid 48-byte typed view is rejected. Same issue in both TDX and SNP. Use .nbytes (or normalize to bytes first) and add tests for typed memoryviews.
  • sev_snp_verifier still missing non-empty checks - issue #283 explicitly asked for validation that trusted_roots and vcek_chain are non-empty at construction time. The bool check was added, but empty lists are still accepted and only fail later during chain verification, kindly reject them with ValueError in the factory and add tests.
  • Wrapper silently accepts integers - expected_measurement = bytes(expected_measurement) turns bytes(48) into 48 zero bytes. An integer is accepted instead of being rejected. Add an explicit bytes-like type check before conversion.

Also resolve conflicts and rebase onto main

… lengths in verify_tdx_quote and verify_sev_snp_report (agentrust-io#283)

Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
@drk-ram
drk-ram dismissed stale reviews from carloshvp and zohebk8s via 6a679ac November 24, 2026 19:58
@drk-ram
drk-ram force-pushed the drk-ram-fix-tdx-snp-verify-283 branch from d045d5a to 6a679ac Compare November 24, 2026 19:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review:MEDIUM Contributor check flagged MEDIUM risk

Projects

None yet

7 participants