Repository navigation
Conversation
extract_chain_certs walked CERT_CHAIN_CONTEXT / CERT_SIMPLE_CHAIN with hand-written offsets that do not match wincrypt.h on x64: cChain and cElement are at +12 and rgpChain / rgpElement at +16, not +16/+24 and +20/+24. The walk read cLowerQualityChainContext plus padding as the chain array, so it usually found no certificates and any thumbprint pin failed with CERT_E_UNTRUSTEDROOT (a non-zero read would have followed a junk pointer). Read the chain through windows-sys's CERT_CHAIN_CONTEXT, CERT_SIMPLE_CHAIN and CERT_CHAIN_ELEMENT (feature Win32_Security_Cryptography) instead. Tests: CertContext checked against the SDK's CERT_CONTEXT; a chain built from the SDK structs (fails with the old offsets); a real crypt32 chain for a root-store certificate yields that certificate as its leaf. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
extract_chain_certs(hle/xgameruntime/networking.rs) walks the chain with hand-written x64 offsets that don't matchwincrypt.h:CERT_CHAIN_CONTEXT.cChainCERT_CHAIN_CONTEXT.rgpChainCERT_SIMPLE_CHAIN.cElementCERT_SIMPLE_CHAIN.rgpElementAt +24 sits
cLowerQualityChainContextplus padding, so the walk usually finds no certificates andXNetworkingVerifyServerCertificatefails every thumbprint pin withCERT_E_UNTRUSTEDROOT. If those bytes are ever non-zero, it follows a junk pointer instead.docs/xnetworking-rust-review.mdalready flagged that these offsets "do not look consistent with the documented field order".Fix
The chain is now read through
windows-sys'sCERT_CHAIN_CONTEXT,CERT_SIMPLE_CHAINandCERT_CHAIN_ELEMENT, which needs one newwindows-sysfeature,Win32_Security_Cryptography. The function also gets a# Safetysection and// SAFETY:comments. Nothing else changes: TLS policy, pin matching and result handling stay as they were.Tests
cert_context_matches_sdk_layout: the module's ownCertContextchecked against the SDK'sCERT_CONTEXT(size and every field offset).chain_certs_follow_sdk_layout: a two-certificate chain built from the SDK structs must come back leaf first. Null and zero-count chains come back empty.chain_certs_from_crypt32: a real chain fromCertGetCertificateChainfor a certificate in the machine's root store must have that certificate as its leaf, compared by SHA-1. If the root store is empty, the test skips instead of failing.I checked that the tests catch the bug: with the old offsets put back temporarily,
chain_certs_follow_sdk_layoutandchain_certs_from_crypt32both fail, because both get an empty list. That includes the real crypt32 chain.What ran
Windows 11, Rust 1.100
x86_64-pc-windows-msvc, MSVC 14.44, Windows SDK 10.0.26100 (DXC from it), AMD Radeon RX 7900 XTX (RDNA3):cargo build --workspace+cargo test --workspace -- --test-threads=4: 344 passed, 0 failed, 34 ignored (the opt-in#[ignore]probes and surveys).System32\xgameruntime.dll). Both runs pass.gpu::tests: 157 passed). The README lists GPUs other than RDNA4 as untested, so this is also a first data point for RDNA3.XCL_SAMPLE_*game data was set, so those tests ran without doing anything.cargo clippy -p xcl --all-targets: no warnings on the changed lines. The rest of the file and the crate already had warnings, and I left those alone.🤖 Generated with Claude Code