From: Samuel Lee Date: Mon, 11 Apr 2022 14:36:16 +0000 (+0100) Subject: Move types.h #undefs for wincrypt.h compatibility X-Git-Tag: openssl-3.2.0-alpha1~2599 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c58d447497b37f7b4f458aaa2956a7e226c6d65;p=thirdparty%2Fopenssl.git Move types.h #undefs for wincrypt.h compatibility + Always undef the symbols that may have been #define-d by wincrypt.h after the first inclusion of types.h to avoid errors from wincrypt.h symbols being used to compile OpenSSL code + Also need to remove #pragma once for this approach to work + Define WINCRYPT_USE_SYMBOL_PREFIX to enable wincrypt symbol prefix at some point in future Fixes #9981 Reviewed-by: Tomas Mraz Reviewed-by: Matthias St. Pierre (Merged from https://github.com/openssl/openssl/pull/18131) --- diff --git a/include/openssl/types.h b/include/openssl/types.h index de9f1665249..c28028681fc 100644 --- a/include/openssl/types.h +++ b/include/openssl/types.h @@ -7,9 +7,21 @@ * https://www.openssl.org/source/license.html */ +/* + * Unfortunate workaround to avoid symbol conflict with wincrypt.h + * See https://github.com/openssl/openssl/issues/9981 + */ +#ifdef _WIN32 +# define WINCRYPT_USE_SYMBOL_PREFIX +# undef X509_NAME +# undef X509_EXTENSIONS +# undef PKCS7_SIGNER_INFO +# undef OCSP_REQUEST +# undef OCSP_RESPONSE +#endif + #ifndef OPENSSL_TYPES_H # define OPENSSL_TYPES_H -# pragma once # include @@ -70,15 +82,6 @@ typedef struct ASN1_ITEM_st ASN1_ITEM; typedef struct asn1_pctx_st ASN1_PCTX; typedef struct asn1_sctx_st ASN1_SCTX; -# ifdef _WIN32 -# undef X509_NAME -# undef X509_EXTENSIONS -# undef PKCS7_ISSUER_AND_SERIAL -# undef PKCS7_SIGNER_INFO -# undef OCSP_REQUEST -# undef OCSP_RESPONSE -# endif - # ifdef BIGNUM # undef BIGNUM # endif diff --git a/test/build.info b/test/build.info index a6dffe280e6..fd728905399 100644 --- a/test/build.info +++ b/test/build.info @@ -58,7 +58,7 @@ IF[{- !$disabled{tests} -}] recordlentest drbgtest rand_status_test sslbuffertest \ time_offset_test pemtest ssl_cert_table_internal_test ciphername_test \ http_test servername_test ocspapitest fatalerrtest tls13ccstest \ - sysdefaulttest errtest ssl_ctx_test \ + sysdefaulttest errtest ssl_ctx_test build_wincrypt_test \ context_internal_test aesgcmtest params_test evp_pkey_dparams_test \ keymgmt_internal_test hexstr_test provider_status_test defltfips_test \ bio_readbuffer_test user_property_test pkcs7_test upcallstest \ @@ -930,6 +930,10 @@ ENDIF INCLUDE[ssl_ctx_test]=../include ../apps/include DEPEND[ssl_ctx_test]=../libcrypto ../libssl libtestutil.a + SOURCE[build_wincrypt_test]=build_wincrypt_test.c + INCLUDE[build_wincrypt_test]=../include + DEPEND[build_wincrypt_test]=../libssl ../libcrypto + {- use File::Spec::Functions; use File::Basename; diff --git a/test/build_wincrypt_test.c b/test/build_wincrypt_test.c new file mode 100644 index 00000000000..5bd75e6a432 --- /dev/null +++ b/test/build_wincrypt_test.c @@ -0,0 +1,42 @@ +/* + * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * Simple buildtest to check for symbol collisions between wincrypt and + * OpenSSL headers + */ + +#include + +#ifdef _WIN32 +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include +# include +# ifndef X509_NAME +# ifndef PEDANTIC +# warning "wincrypt.h no longer defining X509_NAME before OpenSSL headers" +# endif +# endif +#endif + +#include +#ifndef OPENSSL_NO_STDIO +# include +#endif + +#include +#include +#include + +int main(void) +{ + return 0; +}