XNetworking: read the certificate chain through the SDK's layouts #36
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/37"
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 ivall/xcl. Originally posted by grooving6 on 2026-11-22T17:30:16Z.
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
precise, and thes_round_modeNOOPs are not free #72Pull request closed