Repository navigation
Conversation
f7c6a4b to
6d5f552
Compare
|
diff --git a/lib/ldap.c b/lib/ldap.c
index 51a32dc96..13b684104 100644
--- a/lib/ldap.c
+++ b/lib/ldap.c
@@ -37,6 +37,8 @@
* OpenLDAP library versions, USE_OPENLDAP shall not be defined.
*/
+#include "urldata.h"
+
#ifdef USE_WIN32_LDAP /* Use Windows LDAP implementation. */
# include <winldap.h>
# ifndef LDAP_VENDOR_NAME
@@ -56,7 +58,6 @@
# endif /* HAVE_LDAP_SSL && HAVE_LDAP_SSL_H */
#endif
-#include "urldata.h"
#include <curl/curl.h>
#include "sendf.h"
#include "escape.h"
diff --git a/lib/vtls/schannel.h b/lib/vtls/schannel.h
index 0b4c4d934..45ecb029b 100644
--- a/lib/vtls/schannel.h
+++ b/lib/vtls/schannel.h
@@ -28,12 +28,12 @@
#ifdef USE_SCHANNEL
+#include "urldata.h"
+
#include <schnlsp.h>
#include <schannel.h>
#include "curl_sspi.h"
-#include "urldata.h"
-
/* <wincrypt.h> has been included via the above <schnlsp.h>.
* Or in case of ldap.c, it was included via <winldap.h>.
* And since <wincrypt.h> has this: |
6d5f552 to
f51fe7b
Compare
Same issue as here [1], but this time when building curl with BoringSSL for Windows with LDAP(S) or Schannel support enabled. Apply the same fix [2] for these source files as well. This can also be fixed by moving `#include "urldata.h"` _before_ including `winldap.h` and `schnlsp.h` respectively. This seems like a cleaner fix, though I'm not sure why it works and if it has any downside. [1] curl#5669 [2] curl@fbe07c6
f51fe7b to
6eea6a7
Compare
|
Interesting. Could boringssl have fixed it to undefine the symbols? For all versions we have the way that works, I would just copy that, note it must come after curl_setup.h which always comes first. Lines 36 to 46 in 45ac4d0 |
|
Probably could be fixed in BoringSSL, but I see little chance getting it fixed there. Likely Google don't mix it with |
Its downside is that this isn't supposed to be used as a dependency, has no versioning or formal releases. TLS-SRP also isn't supported, but its advantages outweigh it. A smaller downside is that it uses pthread even on Windows, which has an issue with static linking, possibly in combination with UCRT builds with the cross-toolchain I tested it with. With this fixed, it's the most promising alternative TLS backend. Binary size is also 2MB lower for both curl EXE and DLL. curl needs two patches, one merged [1], one fixing new iterations of a known issue [2] pending. [1] curl/curl#9109 [2] curl/curl#9110 curl would probably use a third patch from a CMake expert: ngtcp2 detection is broken, so we need to use an local workaround. curl autotools doesn't support BoringSSL because I've found no way to tell libtool to link pthread DLL instead of the static version.
|
Found this in This was a similar bug where apparently the exact reverse action (i.e. moving |
|
I would explicitly include wincrypt, followed by the undefines, as early as possible so that something that includes something that includes BoringSSL can't come before it. |
|
@jay: Do you have an alternative patch suggestion? |
|
I mean this, it's not really an alternative I just added the include diff --git a/lib/ldap.c b/lib/ldap.c
index 51a32dc..292684b 100644
--- a/lib/ldap.c
+++ b/lib/ldap.c
@@ -26,6 +26,18 @@
#if !defined(CURL_DISABLE_LDAP) && !defined(USE_OPENLDAP)
+/* Wincrypt must be included before anything that could include OpenSSL. */
+#if defined(USE_WIN32_CRYPTO)
+#include <wincrypt.h>
+/* Undefine wincrypt conflicting symbols for BoringSSL. */
+#undef X509_NAME
+#undef X509_EXTENSIONS
+#undef PKCS7_ISSUER_AND_SERIAL
+#undef PKCS7_SIGNER_INFO
+#undef OCSP_REQUEST
+#undef OCSP_RESPONSE
+#endif
+
/*
* Notice that USE_OPENLDAP is only a source code selection switch. When
* libcurl is built with USE_OPENLDAP defined the libcurl source code that
diff --git a/lib/vtls/schannel.h b/lib/vtls/schannel.h
index 0b4c4d9..05323c7 100644
--- a/lib/vtls/schannel.h
+++ b/lib/vtls/schannel.h
@@ -28,6 +28,18 @@
#ifdef USE_SCHANNEL
+/* Wincrypt must be included before anything that could include OpenSSL. */
+#if defined(USE_WIN32_CRYPTO)
+#include <wincrypt.h>
+/* Undefine wincrypt conflicting symbols for BoringSSL. */
+#undef X509_NAME
+#undef X509_EXTENSIONS
+#undef PKCS7_ISSUER_AND_SERIAL
+#undef PKCS7_SIGNER_INFO
+#undef OCSP_REQUEST
+#undef OCSP_RESPONSE
+#endif
+
#include <schnlsp.h>
#include <schannel.h>
#include "curl_sspi.h"either that or maybe it could just be included once in whatever curl header is actually causing this problem by including boringssl, rather than putting it in each unit |
|
@jay: Thanks, got it. But, speaking of MinGW, both |
That works in openssl.c but maybe WIN32 is the right check in ldap. |
|
Tried with But, it resolves the problem, so for me this version is also fine. |
|
I re-set it to use |
Ref: curl/curl@4c46c82 Ref: curl/curl#9110 Follow-up of: 8a3a331
- 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
Same issue as here [1], but this time when building curl with BoringSSL
for Windows with LDAP(S) or Schannel support enabled.
Apply the same fix [2] for these source files as well.
This can also be fixed by moving
#include "urldata.h"beforeincluding
winldap.handschnlsp.hrespectively. This seems likea cleaner fix, though I'm not sure why it works and if it has any
downside. (see below)
[1] #5669
[2] fbe07c6