Skip to content

feat(cargo-wdk): add --signtool-args passthrough to customize driver signing#699

Open
svasista-ms wants to merge 14 commits into
microsoft:mainfrom
svasista-ms:test-signing
Open

feat(cargo-wdk): add --signtool-args passthrough to customize driver signing#699
svasista-ms wants to merge 14 commits into
microsoft:mainfrom
svasista-ms:test-signing

Conversation

@svasista-ms

@svasista-ms svasista-ms commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Adds --signtool-args passthrough so driver signing can be customized (certificate selection, digest algorithm, timestamping, extra file operands).

When --signtool-args is omitted, cargo-wdk signs with the auto-generated WDR test certificate and default switches.
When --signtool-args is provided, the caller owns the full signtool sign option set except the sign verb and the trailing file operand (spplied by cargo-wdk). Supplying it with --sign-mode=off is rejected.

⚠️ Behavior change

Packaging removes any existing <target>/<profile>/<name>_package folder at the start of each build and recreates it, so stale signing artifacts (e.g. a WDRLocalTestCert.cer from a previous --sign-mode=test build) don't persist across rebuilds.

Screenshots

image

Resolves #605

Copilot AI review requested due to automatic review settings July 7, 2026 11:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a cargo wdk build --signtool-args passthrough so driver signing can be customized (certificate selection, digest, timestamping, extra operands), and adjusts packaging to stage artifacts in a fresh directory and assemble the final package folder last—preventing stale signing artifacts from persisting across rebuilds.

Changes:

  • Add --signtool-args to the CLI and plumb it through to signtool sign invocation.
  • Rework packaging to build in a clean per-build staging directory and rename into the final package folder at the end (fixes stale cert artifact scenarios).
  • Expand integration/unit tests and documentation to cover the new signing behavior and staging semantics.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/cargo-wdk/tests/build_command_test.rs Adds regression + functional integration tests for staging behavior and --signtool-args.
crates/cargo-wdk/src/providers/mod.rs Extends filesystem error enum to cover directory removal failures.
crates/cargo-wdk/src/providers/fs.rs Adds remove_dir_all wrapper to the FS provider for testable directory cleanup.
crates/cargo-wdk/src/cli.rs Introduces --signtool-args and validates signing flag combinations via TryFrom<&BuildArgs> for SignMode.
crates/cargo-wdk/src/actions/build/tests.rs Updates build action unit test expectations for staging-dir + final assembly flow and new SignMode shape.
crates/cargo-wdk/src/actions/build/package_task.rs Implements staging directory flow, package folder assembly, signtool argument tokenization + passthrough, and updates signing behavior.
crates/cargo-wdk/src/actions/build/mod.rs Adjusts BuildAction to clone SignMode (now contains owned data).
crates/cargo-wdk/README.md Documents --signtool-args, quoting/tokenization rules, and updated signing/staging semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/tests/build_command_test.rs
@codecov-commenter

codecov-commenter commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.87%. Comparing base (21ec8f8) to head (3e87ce0).

Files with missing lines Patch % Lines
crates/cargo-wdk/src/actions/build/package_task.rs 96.72% 0 Missing and 6 partials ⚠️
crates/cargo-wdk/src/cli.rs 99.40% 1 Missing ⚠️
crates/cargo-wdk/src/providers/exec.rs 80.00% 0 Missing and 1 partial ⚠️
crates/cargo-wdk/src/providers/fs.rs 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #699      +/-   ##
==========================================
+ Coverage   79.93%   80.87%   +0.93%     
==========================================
  Files          26       26              
  Lines        5633     5923     +290     
  Branches     5633     5923     +290     
==========================================
+ Hits         4503     4790     +287     
  Misses       1002     1002              
- Partials      128      131       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings July 8, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/README.md
Copilot AI review requested due to automatic review settings July 12, 2026 05:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/src/providers/exec.rs
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Copilot AI review requested due to automatic review settings July 12, 2026 12:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs
@svasista-ms
svasista-ms marked this pull request as ready for review July 13, 2026 04:27
Copilot AI review requested due to automatic review settings July 14, 2026 17:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/tests/build_command_test.rs Outdated
Comment thread crates/cargo-wdk/src/cli.rs

/// Builds a `clap::Error` with the given message, rendered with the standard
/// `cargo wdk build` usage for a consistent CLI experience.
fn build_error(message: impl std::fmt::Display) -> clap::Error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: we could inline this at call site, no need of a separate function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was inline initially. But I added the function because ArgumentConflict error can be constructed from multiple places (2 in try_from for SignMode). Once args for all tools are added we could use anyhow to construct CLI errors.

Comment thread crates/cargo-wdk/src/cli.rs Outdated

/// Arguments to `signtool sign` for signing the driver binary and catalog file.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SigntoolArgs(pub Vec<String>);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move this declaration to the top to keep all arg type declarations at one place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done✅

Comment thread crates/cargo-wdk/src/cli.rs Outdated
.expect("args parse");
let err = SignMode::try_from(&args).expect_err("should be rejected");
assert!(
err.to_string().contains("`--sign-mode=off`"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. use the exact message for assertion
`--signtool-args` cannot be used with `--sign-mode=off`.
  1. Can we not match exactly and avoid using contains?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed ✅, using the full message for assertion 👍

Comment thread crates/cargo-wdk/src/cli.rs Outdated
}

#[test]
fn build_off_mode_maps_to_off() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn build_off_mode_maps_to_off() {
fn build_sign_mode_off_maps_correctly() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed ✅

Comment thread crates/cargo-wdk/src/cli.rs Outdated
let err = parse_build_args(&["--signtool-args", "/n \"CN=Contoso"])
.expect_err("unterminated quote should be rejected");
assert!(
err.to_string().contains("unterminated"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Try and use exact message assertion

Similar suggestion as this: https://github.com/microsoft/windows-drivers-rs/pull/699/changes#r3579259207

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed ✅

Comment thread crates/cargo-wdk/src/cli.rs Outdated
}

#[test]
fn build_signtool_args_with_verify_signature_maps_both() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn build_signtool_args_with_verify_signature_maps_both() {
fn build_verify_signature_works_with_signtool_args() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed ✅

Comment thread crates/cargo-wdk/src/cli.rs Outdated
@@ -304,25 +402,119 @@ mod tests {

#[test]
fn build_rejects_verify_signature_when_sign_mode_is_off() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As we have multiple tests for build sub command, We should move all the build tests to a submodule here and avoid using build as prefix for each test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done ✅ , moved to a separate mod

Copilot AI review requested due to automatic review settings July 15, 2026 04:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs
Copilot AI review requested due to automatic review settings July 15, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Copilot AI review requested due to automatic review settings July 15, 2026 11:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/tests/build_command_test.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Copilot AI review requested due to automatic review settings July 15, 2026 12:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs
Comment thread crates/cargo-wdk/src/cli.rs
Copilot AI review requested due to automatic review settings July 15, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs
Comment thread crates/cargo-wdk/src/cli.rs
Comment thread crates/cargo-wdk/src/cli.rs Outdated
Comment thread crates/cargo-wdk/README.md
Copilot AI review requested due to automatic review settings July 15, 2026 13:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment on lines +74 to +78
Driver Signing:
--signtool-args <ARGS> Additional arguments forwarded verbatim to
`signtool sign`, as a single quoted string
(e.g. `--signtool-args "/fd SHA256 /f cert.pfx"`)

Copilot AI review requested due to automatic review settings July 15, 2026 13:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs
Comment thread crates/cargo-wdk/tests/build_command_test.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support to pass custom certificate details for signing through cargo-wdk

4 participants