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

Merged
certified-retart merged 1 commit from upstream-pr/77 into main 2026-11-23 10:29:16 +00:00
certified-retart commented 2026-11-23 01:22:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by certified-retart on 2026-11-23T01:22:00Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6550338549 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/77). Originally posted by [certified-retart](https://github.com/certified-retart) on 2026-11-23T01:22:00Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 06:57:03 +00:00
ivall commented 2026-11-24 07:00:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T10:29:31Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7098054939 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/77#issuecomment-7098054939). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T10:29:31Z. --- 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!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!76
No description provided.