Skip to content

crypto: Add native windows backend for pkcs7, use it in uefi#3265

Open
smalis-msft wants to merge 2 commits intomicrosoft:mainfrom
smalis-msft:win-pkcs7
Open

crypto: Add native windows backend for pkcs7, use it in uefi#3265
smalis-msft wants to merge 2 commits intomicrosoft:mainfrom
smalis-msft:win-pkcs7

Conversation

@smalis-msft
Copy link
Copy Markdown
Contributor

Add a native win32 backend to the crypto crate for pkcs7. firmware_uefi is the only user of this algorithm currently, and this support allows us to remove a feature that previously made it optional.

Also remove some unhelpful tracing that AI snuck in previously.

This PR deserves some careful review, as I'm really not familiar with the win32 crypt APIs. It was mostly written by claude, but I did go read the docs afterwards to attempt to verify it and it looks right to me.

@smalis-msft smalis-msft requested a review from a team as a code owner April 13, 2026 18:38
Copilot AI review requested due to automatic review settings April 13, 2026 18:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Add a Windows-native PKCS#7 verification backend to the crypto crate and make authenticated-variable verification in firmware_uefi unconditional (no longer feature-gated), while removing noisy tracing during verification failures.

Changes:

  • Added support/crypto PKCS#7 Windows backend and selected backend by target OS.
  • Removed the auth-var-verify-crypto feature gating in firmware_uefi and downstream feature wiring (encryption).
  • Simplified PKCS#7 verification failure handling (removed trace-level logging).

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
vmm_core/vmotherboard/Cargo.toml Removes encryption feature that previously toggled auth-var crypto verification.
vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/mod.rs Removes feature-gated auth var crypto paths; makes the crypto error variants/structs unconditional.
vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/auth_var_crypto.rs Removes crate-level cfg gating so module is always compiled.
vm/devices/firmware/firmware_uefi/fuzz/Cargo.toml Drops auth-var-verify-crypto feature from fuzz target configuration.
vm/devices/firmware/firmware_uefi/Cargo.toml Makes crypto/der non-optional dependencies; removes crypto feature flag.
support/crypto/src/pkcs7/win.rs Introduces Windows CryptoAPI implementation for PKCS#7 parsing and verification.
support/crypto/src/pkcs7/ossl.rs Removes trace logging on verification error and returns Ok(false) directly.
support/crypto/src/pkcs7/mod.rs Selects PKCS#7 backend by OS (ossl on unix, win on windows).
support/crypto/src/lib.rs Makes pkcs7 module available beyond unix-only builds.
support/crypto/Cargo.toml Removes tracing dependency from the crypto crate.
openvmm/openvmm_entry/Cargo.toml Removes encryption feature passthrough.
openvmm/openvmm/Cargo.toml Removes encryption feature passthrough.
openhcl/underhill_core/Cargo.toml Removes encryption feature from linux dependency feature set.

@github-actions
Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

@github-actions github-actions bot added the unsafe Related to unsafe code label Apr 13, 2026
let mut policy_para: CERT_CHAIN_POLICY_PARA = unsafe { std::mem::zeroed() };
policy_para.cbSize = size_of::<CERT_CHAIN_POLICY_PARA>() as u32;

if uefi_mode {
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.

"uefi mode"?

Copy link
Copy Markdown
Contributor Author

@smalis-msft smalis-msft Apr 13, 2026

Choose a reason for hiding this comment

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

Yeah. This isn't new, openssl needs this flag too. Basically uefi requires some steps of the normal cert validation process be skipped. Couldn't think of a better name for it, but I didn't want to make it the default. Currently the one and only place we call into pkcs7 code passes true.

};

if verify_result.is_err() {
return Ok(false);
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.

Do we really want to treat all errors as Ok(false)?

let signer_cert =
unsafe { CertGetSubjectCertificateFromStore(msg_store.0, ENCODING, cert_info) };
if signer_cert.is_null() {
return Ok(false);
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.

Ditto here, is this the right return value?

};

if chain_result.is_err() {
return Ok(false);
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.

Like this just can't be right...

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

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants