xnetworking: fail closed on cert verification errors and malformed pin metadata #77

Manually merged
github merged 1 commit from gh-pr/77/head into gh-pr/77/base 2026-11-26 04:08:21 +00:00
Owner

@⁠certified-retart on GitHub · 2026-11-23 01:22 UTC · original
certified-retart:fix/xnetworking-cert-verify → main · +198 −32 · 1 files · 1 commits · merged 2026-11-23 10:29 UTC

Summary

Hardens XNetworkingVerifyServerCertificate and verify_thumbprints in crates/xcl/src/hle/xgameruntime/networking.rs to fail closed on missing URLs/hostnames, zero GetLastError() codes, plain-HTTP loopback with pins, and malformed pin metadata (addressing the certificate verification items in docs/xnetworking-rust-review.md).

What changed

  • Fail closed on WinHTTP / CryptoAPI failures:
    • WINHTTP_OPTION_URL failure, odd/empty/oversized byte counts, or empty extracted host now fail closed instead of proceeding with a null server_name (which disabled SSL hostname verification).
    • Failed CertGetCertificateChain (or null chain) and failed CertVerifyCertificateChainPolicy now map GetLastError() == 0 to E_FAIL via win32_failure_hr rather than turning hresult_from_win32(0) into S_OK.
    • Positive non-zero status.error values from CertVerifyCertificateChainPolicy are converted via policy_status_hr so they never become positive HRESULTs.
  • Strict SHA-1 thumbprint pin validation (validate_thumbprint_metadata / check_thumbprints):
    • Rejects thumbprint_count > 0 with null thumbprints pointer (previously returned true).
    • Rejects overflowing thumbprint_count * size_of::<XNetworkingThumbprint>() > isize::MAX.
    • Rejects null or non-20-byte SHA-1 pin buffers even when another entry in the array matches.
    • Rejects unknown XNetworkingThumbprintType values (> 2) instead of falling back to matching any cert in the chain.
    • Fails closed with CERT_E_UNTRUSTEDROOT on plain-HTTP loopback if the caller requires certificate pinning (pin_count > 0). (Unpinned plain-HTTP loopback and Issuer chain-index matching are left unchanged in this focused PR.)
  • URL host parsing: handles userinfo@host and unclosed [ IPv6 literals cleanly.
  • Tests: added regression tests covering every hardened path above.

Verification

  • Target: rustc 1.100.0 (x86_64-pc-windows-msvc), Windows 10 Pro 10.0.19045.
  • cargo test -p xcl --lib hle::xgameruntime::networking: 6 passed, 0 failed.
  • Independently reviewed (read-only) by a second agent; fixed overflowing thumbprint_count, non-20-byte SHA-1 length validation, and odd/oversized WINHTTP_OPTION_URL byte counts before opening.
**@⁠certified-retart** on GitHub · 2026-11-23 01:22 UTC · [original](https://github.com/xcl-dev/xcl/pull/77) `certified-retart:fix/xnetworking-cert-verify` → `main` · +198 −32 · 1 files · 1 commits · merged 2026-11-23 10:29 UTC ## Summary Hardens `XNetworkingVerifyServerCertificate` and `verify_thumbprints` in [`crates/xcl/src/hle/xgameruntime/networking.rs`](crates/xcl/src/hle/xgameruntime/networking.rs) to fail closed on missing URLs/hostnames, zero `GetLastError()` codes, plain-HTTP loopback with pins, and malformed pin metadata (addressing the certificate verification items in [`docs/xnetworking-rust-review.md`](docs/xnetworking-rust-review.md)). ### What changed - **Fail closed on WinHTTP / CryptoAPI failures:** - `WINHTTP_OPTION_URL` failure, odd/empty/oversized byte counts, or empty extracted host now fail closed instead of proceeding with a null `server_name` (which disabled SSL hostname verification). - Failed `CertGetCertificateChain` (or null chain) and failed `CertVerifyCertificateChainPolicy` now map `GetLastError() == 0` to `E_FAIL` via `win32_failure_hr` rather than turning `hresult_from_win32(0)` into `S_OK`. - Positive non-zero `status.error` values from `CertVerifyCertificateChainPolicy` are converted via `policy_status_hr` so they never become positive `HRESULT`s. - **Strict SHA-1 thumbprint pin validation (`validate_thumbprint_metadata` / `check_thumbprints`):** - Rejects `thumbprint_count > 0` with null `thumbprints` pointer (previously returned `true`). - Rejects overflowing `thumbprint_count * size_of::<XNetworkingThumbprint>() > isize::MAX`. - Rejects null or non-20-byte SHA-1 pin buffers even when another entry in the array matches. - Rejects unknown `XNetworkingThumbprintType` values (`> 2`) instead of falling back to matching any cert in the chain. - Fails closed with `CERT_E_UNTRUSTEDROOT` on plain-HTTP loopback if the caller requires certificate pinning (`pin_count > 0`). (Unpinned plain-HTTP loopback and `Issuer` chain-index matching are left unchanged in this focused PR.) - **URL host parsing:** handles `userinfo@host` and unclosed `[` IPv6 literals cleanly. - **Tests:** added regression tests covering every hardened path above. ## Verification - Target: `rustc 1.100.0` (`x86_64-pc-windows-msvc`), Windows 10 Pro `10.0.19045`. - `cargo test -p xcl --lib hle::xgameruntime::networking`: **6 passed, 0 failed**. - Independently reviewed (read-only) by a second agent; fixed overflowing `thumbprint_count`, non-20-byte SHA-1 length validation, and odd/oversized `WINHTTP_OPTION_URL` byte counts before opening.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:08:19 +00:00
github manually merged commit ed37916d3e into gh-pr/77/base 2026-11-26 04:08:21 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 10:29 UTC · original

Merged. Tested on Windows 11 with an RX 9070 (RDNA4): cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), also with XCL_SPLIT_WAVE64=1 (the 32-lane split path forced on RDNA). Unicorn Overlord and XDefiant run with this round merged. Thanks!

**@⁠ivall** on GitHub · 2026-11-23 10:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/77#issuecomment-7098054939) Merged. Tested on Windows 11 with an RX 9070 (RDNA4): `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), also with `XCL_SPLIT_WAVE64=1` (the 32-lane split path forced on RDNA). Unicorn Overlord and XDefiant run with this round merged. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.