Skip to content

cli_hx_download: add Schannel support - #20556

Closed
vszakats wants to merge 7 commits into
curl:masterfrom
vszakats:hxdlschannel
Closed

vszakats wants to merge 7 commits into
curl:masterfrom
vszakats:hxdlschannel

Conversation

@vszakats

@vszakats vszakats commented Feb 11, 2026 •

Copy link
Copy Markdown
Member

Fixes:

$ wine libtests.exe cli_hx_download https://curl.se/
[...]
Assertion failed: t->checked_ssl, file .../curl/tests/libtest/cli_hx_download.c, line 563

into:

[t-0] info Schannel TLS version 0x00000800

Refs:
https://learn.microsoft.com/windows/win32/secauthn/querycontextattributes--general
https://learn.microsoft.com/windows/win32/api/schannel/ns-schannel-secpkgcontext_connectioninfo

Ref: c220674 #20564
Follow-up to ba9ddb9 #18066

@vszakats vszakats added TLS tests Windows Windows-specific labels Feb 11, 2026
@vszakats
vszakats marked this pull request as draft February 11, 2026 01:35
@vszakats vszakats changed the title cli_hx_download: try adding Schannel support cli_hx_download: add Schannel support Feb 11, 2026
@vszakats
vszakats marked this pull request as ready for review February 11, 2026 03:00
@bagder
bagder requested a review from Copilot February 11, 2026 07:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the cli_hx_download libtest client to recognize the Schannel TLS backend when validating CURLINFO_TLS_SSL_PTR, allowing the test to query and print the negotiated TLS protocol via SSPI instead of failing an internal assertion under Wine/Schannel.

Changes:

  • Add Schannel-specific includes for SSPI/SChannel APIs in cli_hx_download.c.
  • Include USE_SCHANNEL in the “check TLS internals” progress-callback compilation guard.
  • Implement a Schannel backend case that calls QueryContextAttributes(SECPKG_ATTR_CONNECTION_INFO) and logs dwProtocol.

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

Comment thread tests/libtest/cli_hx_download.c Outdated
Comment on lines +46 to +47
#include <subauth.h> /* for [P]UNICODE_STRING */
#define SECURITY_WIN32 /* for sspi.h */

Copilot AI Feb 11, 2026 •

Copy link

Choose a reason for hiding this comment

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

Including <subauth.h> directly can trigger MSVC warning C4201 (treated as error when CURL_WERROR enables -WX). lib/vtls/schannel.h wraps this include with #pragma warning(push)/disable:4201/pop; please apply the same guard here to keep Windows/MSVC builds warning-clean.

C4201 is: nonstandard extension used : nameless struct/union

Copilot uses AI. Check for mistakes.

@vszakats vszakats Feb 11, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This warning is no longer seen in CI, and CI hits the full range of supported Windows compilers and SDKs.

It's been added in 8beff43 #8419 (which was later reverted I think fully since. edit: no, some parts remained)
I'll also double-check if SCHANNEL_USE_BLACKLISTS is still necessary, which triggered this avalanche.
And also if subauth.h is still necessary. Prob a separate PR if there is something to cleanup here.

@vszakats vszakats Feb 11, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

update: SCHANNEL_USE_BLACKLISTS is necessary for SCH_CREDENTIALS. SCH_CREDENTIALS uses [P]UNICODE_STRINGS, and subauth.h is necessary for [P]UNICODE_STRINGS. The warning suppression no longer seems necessary as confirmed by a green CI.

Comment thread tests/libtest/cli_hx_download.c Outdated
Comment on lines +47 to +49
#define SECURITY_WIN32 /* for sspi.h */
#include <sspi.h> /* for CtxtHandle, QueryContextAttributes() */
#include <schannel.h> /* SecPkgContext_ConnectionInfo,

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

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

SSPI headers are expected to be included with SECURITY_WIN32 set and with <security.h> included before <sspi.h> (see lib/curl_sspi.h:30-40). Consider mirroring that pattern here (undef SECURITY_* then define SECURITY_WIN32 1, include <security.h>, then <sspi.h>) to avoid toolchain/header inconsistencies.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll try moving this define to curl_setup.h to avoid having to deal with this file-by-file. It's also a global setting.

@vszakats vszakats Feb 11, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I also purposefully tried not to replicate everything from there, just the necessary minimum.

Comment on lines +45 to +51
#ifdef USE_SCHANNEL
#include <subauth.h> /* for [P]UNICODE_STRING */
#define SECURITY_WIN32 /* for sspi.h */
#include <sspi.h> /* for CtxtHandle, QueryContextAttributes() */
#include <schannel.h> /* SecPkgContext_ConnectionInfo,
SECPKG_ATTR_CONNECTION_INFO */
#endif

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

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

This file may be built with multiple TLS backends enabled (e.g., USE_OPENSSL and USE_SCHANNEL). lib/vtls/schannel.h notes that Wincrypt/Schannel headers must be included before anything that could include OpenSSL to avoid macro/type clashes (notably with BoringSSL/AWS-LC). With the current include order, OpenSSL headers are included earlier; please reorder includes or apply the same undef/guard strategy used in lib/vtls/schannel.h to keep multi-backend builds compiling.

Copilot uses AI. Check for mistakes.

@vszakats vszakats Feb 11, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In MultiSSL builds I have a feeling this order is already not enforced when
compiling in unity mode (and it works). This case is the same as that, just
within a single physical source file. I'll try making a test with OpenSSL to
double-check.

@vszakats vszakats Feb 11, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed working with MultiSSL Schannel + LibreSSL and OpenSSL 3.6.0.

If this is causing an issue with other combinations, we can fix once a report
for it arrives.

@vszakats

Copy link
Copy Markdown
Member Author

PR #20564 opened to tidy up the things that mislead the LLM, and
which may mislead humans too.

vszakats added a commit that referenced this pull request Feb 11, 2026
- define `SECURITY_WIN32` globally in `curl_setup.h`.
  To make sure it applies to all includes.

- document which Windows headers require `SECURITY_WIN32`.

- stop suppressing MSVC warning:
  `C4201 is: nonstandard extension used : nameless struct/union`
  The warning is no longer seen in supported build envs with the current
  codebase.
  Follow-up to 8beff43 #8419

- document why `SCHANNEL_USE_BLACKLISTS` is needed.

- just define `SCHANNEL_USE_BLACKLISTS`, drop the unnecessary value `1`.

- stop defining unused `SCH_CRED_MAX_SUPPORTED*` fallback macros.
  Follow-up to 8beff43 #8419

- document why `subauth.h` is included (where missing).

- move and de-dupe `subauth.h` include into `curl_setup.h`, limit to
  Schannel builds.

- stop include `schnlsp.h`. It is a 1-to-1 compatibility wrapper for
  `schannel.h`.

- curl_sspi.h: clarify comment about `SP_NAME_` macros.
  They are local macros, their SDK names are different and curl does not
  use them.

- curl_sspi.h: drop superfluous includes `security.h` and `rpc.h`.

Cherry-picked from #20556

Closes #20564
@vszakats vszakats closed this in 85a895c Feb 11, 2026
@vszakats
vszakats deleted the hxdlschannel branch February 11, 2026 17:01
@vszakats

vszakats commented Feb 12, 2026 •

Copy link
Copy Markdown
Member Author

Re: #20556 (comment)

I tested with BoringSSL and AWS-LC (MultiSSL with Schannel), also LDAP
enabled, and they build fine. What breaks it is moving schannel first.
LLM is suggesting this solution based on comments in the code, but that's
only true if the #undef workaround is also placed between them. It's
also not the only solution, just the one practical in vtls/openssl.c.

In lib in general, the point is to have those #undefs between the first
wincrypt.h include [*] and the first OpenSSL include [**], within a single
compilation unit. For non-unity builds the only such source is openssl.c.
For unity ones, depending on batch size, in theory the #undef should
be used after each wincrypt.h include. In practice this is overkill and
most cases are covered by #undef-fing first in vtls/openssl.c, and
#undef in ldap.c. It's not impossible that more undefs need to be added
after more wincrypt.h includes to cover so far undiscovered build cases
[***]. Though I could not find any with the current sources and their order.

[*] it can be indirect, e.g. via schannel.h, winldap.h, iphlpapi.h.
[**] with BoringSSL/AWS-LC: any include (due to openssl/base.h.
OpenSSL: openssl/ssl.h, openssl/x509v3.h, and some others affected,
but including openssl/ossl_typ.h does the #undef automatically.
Since 3.1.0+ it's doing it on each inclusion, in 3.0.x (and earlier) it only did it on first inclusion.
LibreSSL 2.3.0+ is not affected, though to suppress another warning 3.8.2+
and a define is necessary.
[***] The order of unity sources are defined by Makefile.inc.

For libtests, the case is simpler: There is always one compilation unit, with
a fixed order, and at the moment cli_hx_download.c is including
OpenSSL first, then wincrypt, and in this order they don't bother each
other. Also, at the moment lib758.c is the only other OpenSSL header
user, but its compiled after cli_hx_download.c so the include is skipped
there. This needs to be revisited if either header gets included before it.

Refs:
4c46c82 #9110
fbe07c6 #5669 #5857

vszakats added a commit that referenced this pull request Feb 12, 2026
- openssl: move and expand explanatory comment.

- openssl: drop duplicate workaround.

- schannel: drop workaround. Unnecessary, because OpenSSL headers are
  not included in or after schannel code.

- schannel: drop explicit `wincrypt.h` include. It's indirectly
  included by system `<schannel.h>`.

- ldap: drop explicit `wincrypt.h` include.
  It isn't used there, and also not required for the workaround.
  `winldap.h` keeps including it indirectly.

Tested with BoringSSL and AWS-LC (MultiSSL with Schannel), also LDAP
enabled, and H3, unity and non-unity, and all tested cases build fine.

In lib in general, the point is to have the `#undef`s between the first
`wincrypt.h` include [1] and the first OpenSSL include [2], within a
single compilation unit. For non-unity builds the only such source is
`openssl.c`. For unity ones, depending on batch size, in theory we
should `#undef` after each `wincrypt.h` include. In practice this is
overkill and most cases are covered by `#undef`-fing _first_ in
`vtls/openssl.c`, and `#undef` in `ldap.c`. It's not impossible that we
need to add more undefs after further `wincrypt.h` includes to cover so
far undiscovered build cases [3]. Though I could not find more with the
current sources and source order.

It's also an option to include OpenSSL first, then `wincrypt.h`, as
done in libtests, but for lib and `vtls/openssl.c` it's more practical
to do the opposite.

[1] can be indirect, e.g. via `iphlpapi.h`, `schannel.h`, `winldap.h`.

[2] in
- BoringSSL/AWS-LC: any include (due to `openssl/base.h`).
  Original fix removed by BoringSSL in year
  [2014](google/boringssl@ded9358#diff-878093ea6426091505b4c49c59b78924f42859af0eb4ce39b8089bda9577e013).
- OpenSSL: `openssl/ssl.h`, `openssl/x509v3.h`, and some more affected,
  and including `openssl/ossl_typ.h` does the `#undef` automatically.
  Since [3.1.0+](openssl/openssl@fbb9a1f)
  each inclusion does the `#undef`, in 3.0.x (and earlier) only
  the first inclusion did. Initially fixed in
  [0.9.6d](openssl/openssl@1955b87)
- LibreSSL [2.3.0+](libressl/portable@0fa826d):
  not affected, though to suppress another warning 3.8.2+ and
  a [define](libressl/portable@e7fe6ca)
  is necessary.

[3] `lib/Makefile.inc` defines the order of unity sources.

For libtests, the case is simpler: There is always one compilation unit,
with a fixed order, and at the moment `cli_hx_download.c` is including
OpenSSL first, then wincrypt, and in this order they don't bother each
other. Also, at the moment `lib758.c` is the only other OpenSSL header
user, but it's compiled after `cli_hx_download.c` so the include is
skipped there. We may need to revisit this if either header gets
included before it.

All this said it'd be nice if BoringSSL/AWS-LC restored the built-in
workaround to behave like LibreSSL and OpenSSL and not require local
workarounds like these.

Ref: #20556 (comment)

Follow-up to 4c46c82 #9110
Follow-up to fbe07c6 #5669 #5857

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

Labels

tests TLS Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

2 participants