Skip to content

Feature-gate schannel and windows-sys deps for windows-static-ssl only - #668

Open
ns-ylambert wants to merge 1 commit into
sagebind:mainfrom
ns-ylambert:fix-schannel-gate
Open

ns-ylambert wants to merge 1 commit into
sagebind:mainfrom
ns-ylambert:fix-schannel-gate

Conversation

@ns-ylambert

Copy link
Copy Markdown

Summary

schannel and windows-sys are unconditional [target.'cfg(target_env = "msvc")'.dependencies] in the curl wrapper crate. Both crates are consumed only by src/easy/windows.rs, which enumerates the Windows ROOT cert store and injects the DER-encoded certs into an OpenSSL SSL_CTX at TLS context creation time.

This bridge is only meaningful when curl is compiled against OpenSSL on Windows (i.e. windows-static-ssl):

  • Under ssl on Windows, libcurl uses Schannel as the TLS backend, which reads the Windows trust store natively. No SSL_CTX bridge is needed and the code path is never called.
  • Under rustls, there is no OpenSSL SSL_CTX at all.
  • Under bare (no TLS feature) builds, same.

Yet both crates are currently compiled into every MSVC build regardless of the active TLS backend, inflating the dep graph and the final binary.

Change

Introduce a windows-cert-store intermediate feature that opts in both crates via dep: (making them optional), and have windows-static-ssl enable it. Tighten the #[cfg] guards on windows.rs to require the feature, so the entire schannel-crate-based code path compiles out under ssl, rustls, and bare builds.

windows-cert-store = [
    "dep:schannel",
    "dep:windows-sys",
]
windows-static-ssl = [
    "static-curl",
    "curl-sys/windows-static-ssl",
    "windows-cert-store",           # <-- new
]

Verification

cargo check --target x86_64-pc-windows-msvc --features windows-static-ssl continues to compile the windows.rs bridge.

cargo check --target x86_64-pc-windows-msvc (default ssl, Schannel path) and cargo check --target x86_64-pc-windows-msvc --features rustls,static-curl compile. schannel is removed from the dep graph; the wrapper crate's windows-sys features (Cryptography/LibraryLoader) are removed; curl-sys retains its own windows-sys dep for Winsock types and that is out of scope.

CI coverage for windows-static-ssl builds is kept out of this PR to keep the diff minimal. It is available in the companion fix-windows-static-ssl branch (#666).

Related

…cert-store

The `schannel` and `windows-sys` crates are used only by `src/easy/windows.rs`
to bridge Windows' ROOT cert store into OpenSSL's SSL_CTX trust store. That
bridge is only meaningful when curl is built against OpenSSL on Windows via
the `windows-static-ssl` feature:

- Under `ssl` on Windows, libcurl uses Schannel, which reads the Windows trust
  store natively. No OpenSSL SSL_CTX bridge is needed.
- Under `rustls`, there is no OpenSSL SSL_CTX at all.
- Under bare (no TLS) builds, same: no OpenSSL, no bridge needed.

Introduce a `windows-cert-store` intermediate feature that opts in both crates
via `dep:` and have `windows-static-ssl` enable it. Tighten the `#[cfg]` guards
on `windows.rs` to require the feature so the entire schannel-crate-based code
path compiles out for `ssl`, `rustls`, and bare builds.

This branch has not been deployed

No deployments
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.

1 participant