From 0ec1e6854849c554a49fb779a6c63f1356a11404 Mon Sep 17 00:00:00 2001 From: Kevin Kane Date: Thu, 15 Dec 2016 09:27:16 -0800 Subject: [PATCH 01/33] Replace Windows APIs that are banned in Windows Store apps CryptGenRandom and lstrlenW are not permitted in Windows Store apps, meaning apps that use mbedTLS can't ship in the Windows Store. Instead, use BCryptGenRandom and wcslen, respectively, which are permitted. Also make sure conversions between size_t, ULONG, and int are always done safely; on a 64-bit platform, these types are different sizes. Also suppress macro redefinition warning for intsafe.h: Visual Studio 2010 and earlier generates C4005 when including both and because a number of _MAX constants are redefined. This is fixed in later versions of Visual Studio. The constants are guaranteed to be the same between both files, however, so we can safely suppress the warning when including intsafe.h. Signed-off-by: Kevin Kane --- library/entropy_poll.c | 33 ++++++++++++++----- library/x509_crt.c | 19 +++++++++++ programs/pkey/CMakeLists.txt | 4 +++ programs/random/CMakeLists.txt | 4 +++ programs/ssl/CMakeLists.txt | 4 +++ programs/test/CMakeLists.txt | 4 +++ programs/x509/CMakeLists.txt | 3 ++ .../data_files/vs2013-app-template.vcxproj | 6 ++-- .../data_files/vs2013-main-template.vcxproj | 8 +++++ 9 files changed, 73 insertions(+), 12 deletions(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index bc71307f5..0ccc34fdf 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -50,26 +50,41 @@ #include #if _WIN32_WINNT >= 0x0501 /* _WIN32_WINNT_WINXP */ -#include +#include +#if _MSC_VER <= 1600 +/* Visual Studio 2010 and earlier issue a warning when both and are included, as they + * redefine a number of _MAX constants. These constants are guaranteed to be the same, though, so + * we suppress the warning when including intsafe.h. + */ +#pragma warning( push ) +#pragma warning( disable : 4005 ) +#endif +#include +#if _MSC_VER <= 1600 +#pragma warning( pop ) +#endif int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, size_t *olen) { - HCRYPTPROV provider; + ULONG len_as_ulong = 0; ((void) data); *olen = 0; - if (CryptAcquireContext(&provider, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == FALSE) { - return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + /* + * BCryptGenRandom takes ULONG for size, which is smaller than size_t on 64-bit platforms. + * Ensure len's value can be safely converted into a ULONG. + */ + if ( FAILED( SizeTToULong( len, &len_as_ulong ) ) ) + { + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); } - if (CryptGenRandom(provider, (DWORD) len, output) == FALSE) { - CryptReleaseContext(provider, 0); - return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + if ( !BCRYPT_SUCCESS( BCryptGenRandom( NULL, output, len_as_ulong, BCRYPT_USE_SYSTEM_PREFERRED_RNG ) ) ) + { + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); } - CryptReleaseContext(provider, 0); *olen = len; return 0; diff --git a/library/x509_crt.c b/library/x509_crt.c index 8d07694a2..136f60b4a 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -61,6 +61,18 @@ #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #define WIN32_LEAN_AND_MEAN #include +#if _MSC_VER <= 1600 +/* Visual Studio 2010 and earlier issue a warning when both and are included, as they + * redefine a number of _MAX constants. These constants are guaranteed to be the same, though, so + * we suppress the warning when including intsafe.h. + */ +#pragma warning( push ) +#pragma warning( disable : 4005 ) +#endif +#include +#if _MSC_VER <= 1600 +#pragma warning( pop ) +#endif #else #include #endif @@ -1541,6 +1553,7 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) char filename[MAX_PATH]; char *p; size_t len = strlen(path); + int lengthAsInt = 0; WIN32_FIND_DATAW file_data; HANDLE hFind; @@ -1556,6 +1569,9 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) p = filename + len; filename[len++] = '*'; + if (FAILED (SizeTToInt(len, &lengthAsInt))) + return(MBEDTLS_ERR_X509_FILE_IO_ERROR); + w_ret = MultiByteToWideChar(CP_ACP, 0, filename, (int) len, szDir, MAX_PATH - 3); if (w_ret == 0) { @@ -1579,6 +1595,9 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) -1, p, (int) len, NULL, NULL); + if (FAILED(SizeTToInt(wcslen(file_data.cFileName), &lengthAsInt))) + return(MBEDTLS_ERR_X509_FILE_IO_ERROR); + if (w_ret == 0) { ret = MBEDTLS_ERR_X509_FILE_IO_ERROR; goto cleanup; diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index 3ad56436e..81f4311c5 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,3 +1,7 @@ +if(MSVC) + set(libs ${libs} bcrypt) +endif() + set(executables_mbedtls dh_client dh_server diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index e5edf7b58..e78ce06b5 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,3 +1,7 @@ +if(MSVC) + set(libs ${libs} bcrypt) +endif() + set(executables gen_entropy gen_random_ctr_drbg diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index 280bbcf3d..9871952f2 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -5,6 +5,10 @@ set(libs ${mbedtls_target} ) +if(MSVC) + set(libs ${libs} bcrypt) +endif() + set(executables dtls_client dtls_server diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index a75f8d923..1853d7ff8 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -2,6 +2,10 @@ set(libs ${mbedtls_target} ) +if(MSVC) + set(libs ${libs} bcrypt) +endif() + set(executables_libs query_included_headers selftest diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt index 5876b8d21..30d272da9 100644 --- a/programs/x509/CMakeLists.txt +++ b/programs/x509/CMakeLists.txt @@ -1,6 +1,9 @@ set(libs ${mbedx509_target} ) +if(MSVC) + set(libs ${libs} bcrypt) +endif() set(executables cert_app diff --git a/scripts/data_files/vs2013-app-template.vcxproj b/scripts/data_files/vs2013-app-template.vcxproj index 039fd09a2..f6d4d4af3 100644 --- a/scripts/data_files/vs2013-app-template.vcxproj +++ b/scripts/data_files/vs2013-app-template.vcxproj @@ -99,7 +99,7 @@ INCLUDE_DIRECTORIES Console true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) Debug @@ -118,7 +118,7 @@ INCLUDE_DIRECTORIES Console true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) Debug @@ -142,7 +142,7 @@ INCLUDE_DIRECTORIES true true Release - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) diff --git a/scripts/data_files/vs2013-main-template.vcxproj b/scripts/data_files/vs2013-main-template.vcxproj index c0f3a3c1f..6f1b5dadb 100644 --- a/scripts/data_files/vs2013-main-template.vcxproj +++ b/scripts/data_files/vs2013-main-template.vcxproj @@ -91,6 +91,9 @@ INCLUDE_DIRECTORIES Windows true + NotSet + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + Debug @@ -106,6 +109,9 @@ INCLUDE_DIRECTORIES Windows true + NotSet + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + Debug @@ -124,6 +130,8 @@ INCLUDE_DIRECTORIES true true true + Release + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) From e068aa7ad54d4ecf92a0809c0c64901e937a9c7d Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Wed, 14 Mar 2018 15:10:31 +0000 Subject: [PATCH 02/33] Fix the build for mingw and CMake + VStudio Changes to the build to add the new Win32 Crypto API's inadvertently broke the build for mingw and Visual Studio builds when generated by CMake. Signed-off-by: Simon Butcher --- library/CMakeLists.txt | 2 +- library/Makefile | 2 +- library/entropy_poll.c | 4 ++-- library/x509_crt.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 83204f35e..62150779c 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -213,7 +213,7 @@ if(CMAKE_COMPILER_IS_MSVC) endif() if(WIN32) - set(libs ${libs} ws2_32) + set(libs ${libs} ws2_32 bcrypt) endif(WIN32) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") diff --git a/library/Makefile b/library/Makefile index 69ccbfd2c..5d645f7b7 100644 --- a/library/Makefile +++ b/library/Makefile @@ -302,7 +302,7 @@ libmbedcrypto.dylib: $(OBJS_CRYPTO) libmbedcrypto.dll: $(OBJS_CRYPTO) echo " LD $@" - $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS) + $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lbcrypt -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS) .c.o: echo " CC $<" diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 0ccc34fdf..1e465af76 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -51,7 +51,7 @@ #include #if _WIN32_WINNT >= 0x0501 /* _WIN32_WINNT_WINXP */ #include -#if _MSC_VER <= 1600 +#if defined(_MSC_VER) && _MSC_VER <= 1600 /* Visual Studio 2010 and earlier issue a warning when both and are included, as they * redefine a number of _MAX constants. These constants are guaranteed to be the same, though, so * we suppress the warning when including intsafe.h. @@ -60,7 +60,7 @@ #pragma warning( disable : 4005 ) #endif #include -#if _MSC_VER <= 1600 +#if defined(_MSC_VER) && _MSC_VER <= 1600 #pragma warning( pop ) #endif diff --git a/library/x509_crt.c b/library/x509_crt.c index 136f60b4a..8fc8a5273 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -61,7 +61,7 @@ #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #define WIN32_LEAN_AND_MEAN #include -#if _MSC_VER <= 1600 +#if defined(_MSC_VER) && _MSC_VER <= 1600 /* Visual Studio 2010 and earlier issue a warning when both and are included, as they * redefine a number of _MAX constants. These constants are guaranteed to be the same, though, so * we suppress the warning when including intsafe.h. @@ -70,7 +70,7 @@ #pragma warning( disable : 4005 ) #endif #include -#if _MSC_VER <= 1600 +#if defined(_MSC_VER) && _MSC_VER <= 1600 #pragma warning( pop ) #endif #else From 34b8d83a22ec5fd6a49a3862c8599331135a5ea1 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Wed, 14 Mar 2018 16:14:40 +0000 Subject: [PATCH 03/33] Update ChangeLog for PR #730 for Win32 API fixes Signed-off-by: Simon Butcher --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index bc1d32e4d..f3c13a2ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3016,6 +3016,8 @@ Changes * Clarify the documentation of mbedtls_ssl_setup. * Use (void) when defining functions with no parameters. Contributed by Joris Aerts. #678 + * Update Win32 APIs used to remove those not permitted by the Windows Store. + Fix provided by Kevin Kane, Microsoft. #635 = mbed TLS 2.7.0 branch released 2018-02-03 From 33425de12802407d2587efdd9534ec67360a0cba Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Wed, 14 Mar 2018 16:44:22 +0000 Subject: [PATCH 04/33] Correct check for WIN32 in cmake files for programs Condition was checking for Visual Studio, not use of WIN32 Signed-off-by: Simon Butcher --- programs/pkey/CMakeLists.txt | 8 ++++++-- programs/random/CMakeLists.txt | 8 ++++++-- programs/ssl/CMakeLists.txt | 4 ++-- programs/test/CMakeLists.txt | 4 ++-- programs/x509/CMakeLists.txt | 5 +++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index 81f4311c5..b95a330a0 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,6 +1,10 @@ -if(MSVC) +set(libs + mbedtls +) + +if(WIN32) set(libs ${libs} bcrypt) -endif() +endif(WIN32) set(executables_mbedtls dh_client diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index e78ce06b5..20fe7e1f4 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,6 +1,10 @@ -if(MSVC) +set(libs + mbedtls +) + +if(WIN32) set(libs ${libs} bcrypt) -endif() +endif(WIN32) set(executables gen_entropy diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index 9871952f2..cfa9a0f92 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -5,9 +5,9 @@ set(libs ${mbedtls_target} ) -if(MSVC) +if(WIN32) set(libs ${libs} bcrypt) -endif() +endif(WIN32) set(executables dtls_client diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 1853d7ff8..24829c719 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -2,9 +2,9 @@ set(libs ${mbedtls_target} ) -if(MSVC) +if(WIN32) set(libs ${libs} bcrypt) -endif() +endif(WIN32) set(executables_libs query_included_headers diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt index 30d272da9..f1a4a5afa 100644 --- a/programs/x509/CMakeLists.txt +++ b/programs/x509/CMakeLists.txt @@ -1,9 +1,10 @@ set(libs ${mbedx509_target} ) -if(MSVC) + +if(WIN32) set(libs ${libs} bcrypt) -endif() +endif(WIN32) set(executables cert_app From 1c0c5d2a625e2758fa31d2914cad1a6429f50c61 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Mon, 26 Mar 2018 22:25:12 +0100 Subject: [PATCH 05/33] Fix for building programs with mingw mingw build files were missing the dependency on the bcrypt library Signed-off-by: Simon Butcher --- programs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/Makefile b/programs/Makefile index 5f47e25bc..80637e9d6 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -45,7 +45,7 @@ endif ifdef WINDOWS_BUILD DLEXT=dll EXEXT=.exe -LOCAL_LDFLAGS += -lws2_32 +LOCAL_LDFLAGS += -lws2_32 -lbcrypt ifdef SHARED SHARED_SUFFIX=.$(DLEXT) endif From def90f49665f3fd9105adc7fc259c32ac6746c66 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Wed, 14 Mar 2018 17:02:16 +0000 Subject: [PATCH 06/33] Fix formatting and detail of comments in PR #730 Signed-off-by: Simon Butcher --- library/entropy_poll.c | 12 +++++++----- library/x509_crt.c | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 1e465af76..f11a0b822 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -52,9 +52,10 @@ #if _WIN32_WINNT >= 0x0501 /* _WIN32_WINNT_WINXP */ #include #if defined(_MSC_VER) && _MSC_VER <= 1600 -/* Visual Studio 2010 and earlier issue a warning when both and are included, as they - * redefine a number of _MAX constants. These constants are guaranteed to be the same, though, so - * we suppress the warning when including intsafe.h. +/* Visual Studio 2010 and earlier issue a warning when both and + * are included, as they redefine a number of _MAX constants. + * These constants are guaranteed to be the same, though, so we suppress the + * warning when including intsafe.h. */ #pragma warning( push ) #pragma warning( disable : 4005 ) @@ -72,8 +73,9 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, *olen = 0; /* - * BCryptGenRandom takes ULONG for size, which is smaller than size_t on 64-bit platforms. - * Ensure len's value can be safely converted into a ULONG. + * BCryptGenRandom takes ULONG for size, which is smaller than size_t on + * 64-bit Windows platforms. Ensure len's value can be safely converted into + * a ULONG. */ if ( FAILED( SizeTToULong( len, &len_as_ulong ) ) ) { diff --git a/library/x509_crt.c b/library/x509_crt.c index 8fc8a5273..f73e215c2 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -62,9 +62,10 @@ #define WIN32_LEAN_AND_MEAN #include #if defined(_MSC_VER) && _MSC_VER <= 1600 -/* Visual Studio 2010 and earlier issue a warning when both and are included, as they - * redefine a number of _MAX constants. These constants are guaranteed to be the same, though, so - * we suppress the warning when including intsafe.h. +/* Visual Studio 2010 and earlier issue a warning when both and + * are included, as they redefine a number of _MAX constants. + * These constants are guaranteed to be the same, though, so we suppress the + * warning when including intsafe.h. */ #pragma warning( push ) #pragma warning( disable : 4005 ) From bcb6cfb13d423a208f9a9358863ca227c35be67f Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Wed, 14 Mar 2018 17:45:45 +0000 Subject: [PATCH 07/33] Fix the tests build with mingw for the new Win32 APIs Add missing library dependency of bcrypt to the tests Makefile Signed-off-by: Simon Butcher --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 60ab27ec7..2249a55df 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -49,7 +49,7 @@ endif ifdef WINDOWS_BUILD DLEXT=dll EXEXT=.exe -LOCAL_LDFLAGS += -lws2_32 +LOCAL_LDFLAGS += -lws2_32 -lbcrypt ifdef SHARED SHARED_SUFFIX=.$(DLEXT) endif From 35e5dad8653b2221898a5f0f4c96e918ead7c9a8 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 15 Mar 2018 15:00:03 +0000 Subject: [PATCH 08/33] Add clarifying comment on use of MultiByteToWideChar() and CP_ACP Signed-off-by: Simon Butcher --- library/x509_crt.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/x509_crt.c b/library/x509_crt.c index f73e215c2..2ad051fda 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1573,6 +1573,14 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) if (FAILED (SizeTToInt(len, &lengthAsInt))) return(MBEDTLS_ERR_X509_FILE_IO_ERROR); + /* + * Note this function uses the code page CP_ACP, and assumes the incoming + * string is encoded in ANSI, before translating it into Unicode. If the + * incoming string were changed to be UTF-8, then the length check needs to + * change to check the number of characters, not the number of bytes, in the + * incoming string are less than MAX_PATH to avoid a buffer overrun with + * MultiByteToWideChar(). + */ w_ret = MultiByteToWideChar(CP_ACP, 0, filename, (int) len, szDir, MAX_PATH - 3); if (w_ret == 0) { From 949aa8fa3a56d00b636611a14e1f23bd49e264ea Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Sun, 25 Mar 2018 13:41:33 +0100 Subject: [PATCH 09/33] Remove redundant Visual Studio 6 data files Visual Studio 6 is no longer supported by the library. Signed-off-by: Simon Butcher --- scripts/data_files/vs6-app-template.dsp | 101 ------------------ scripts/data_files/vs6-main-template.dsp | 94 ---------------- scripts/data_files/vs6-workspace-template.dsw | 18 ---- 3 files changed, 213 deletions(-) delete mode 100644 scripts/data_files/vs6-app-template.dsp delete mode 100644 scripts/data_files/vs6-main-template.dsp delete mode 100644 scripts/data_files/vs6-workspace-template.dsw diff --git a/scripts/data_files/vs6-app-template.dsp b/scripts/data_files/vs6-app-template.dsp deleted file mode 100644 index 87dbea247..000000000 --- a/scripts/data_files/vs6-app-template.dsp +++ /dev/null @@ -1,101 +0,0 @@ -# Microsoft Developer Studio Project File - Name="" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG= - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f ".mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f ".mak" CFG=" - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE " - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE " - Win32 Debug" (based on "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == " - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "" -# PROP BASE Intermediate_Dir "temp" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "" -# PROP Intermediate_Dir "temp" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x40c /d "NDEBUG" -# ADD RSC /l 0x40c /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 - -!ELSEIF "$(CFG)" == " - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "" -# PROP BASE Intermediate_Dir "temp" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "" -# PROP Intermediate_Dir "temp" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD BASE RSC /l 0x40c /d "_DEBUG" -# ADD RSC /l 0x40c /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name " - Win32 Release" -# Name " - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\..\programs\.c -# ADD CPP /I "../../include" -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/scripts/data_files/vs6-main-template.dsp b/scripts/data_files/vs6-main-template.dsp deleted file mode 100644 index 89d3fc731..000000000 --- a/scripts/data_files/vs6-main-template.dsp +++ /dev/null @@ -1,94 +0,0 @@ -# Microsoft Developer Studio Project File - Name="mbedtls" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=mbedtls - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "mbedtls.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "mbedtls.mak" CFG="mbedtls - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "mbedtls - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "mbedtls - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "mbedtls - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "" -# PROP BASE Intermediate_Dir "temp" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "" -# PROP Intermediate_Dir "temp" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "../../include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD BASE RSC /l 0x40c /d "NDEBUG" -# ADD RSC /l 0x40c /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "mbedtls - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "" -# PROP BASE Intermediate_Dir "temp" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "" -# PROP Intermediate_Dir "temp" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /GX /Z7 /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD BASE RSC /l 0x40c /d "_DEBUG" -# ADD RSC /l 0x40c /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "mbedtls - Win32 Release" -# Name "mbedtls - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -SOURCE_ENTRIES -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -HEADER_ENTRIES -# End Group -# End Target -# End Project diff --git a/scripts/data_files/vs6-workspace-template.dsw b/scripts/data_files/vs6-workspace-template.dsw deleted file mode 100644 index ef90098f4..000000000 --- a/scripts/data_files/vs6-workspace-template.dsw +++ /dev/null @@ -1,18 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -APP_ENTRIES -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - From de573f56e57de0474d42e4a1ff424b47246d3d9b Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 5 Jul 2018 09:11:30 +0100 Subject: [PATCH 10/33] Fix coding style of length_as_int var in x509_crt.c Variable had the very Windows name of lengthAsInt, which is fine for C# but doesn't match the Mbed TLS coding standards. Signed-off-by: Simon Butcher --- library/x509_crt.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/library/x509_crt.c b/library/x509_crt.c index 2ad051fda..d9df4b220 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1554,7 +1554,7 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) char filename[MAX_PATH]; char *p; size_t len = strlen(path); - int lengthAsInt = 0; + int length_as_int = 0; WIN32_FIND_DATAW file_data; HANDLE hFind; @@ -1570,7 +1570,7 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) p = filename + len; filename[len++] = '*'; - if (FAILED (SizeTToInt(len, &lengthAsInt))) + if (FAILED (SizeTToInt(len, &length_as_int))) return(MBEDTLS_ERR_X509_FILE_IO_ERROR); /* @@ -1581,7 +1581,7 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) * incoming string are less than MAX_PATH to avoid a buffer overrun with * MultiByteToWideChar(). */ - w_ret = MultiByteToWideChar(CP_ACP, 0, filename, (int) len, szDir, + w_ret = MultiByteToWideChar(CP_ACP, 0, filename, length_as_int, szDir, MAX_PATH - 3); if (w_ret == 0) { return MBEDTLS_ERR_X509_BAD_INPUT_DATA; @@ -1600,14 +1600,15 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) continue; } - w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName, - -1, - p, (int) len, - NULL, NULL); - if (FAILED(SizeTToInt(wcslen(file_data.cFileName), &lengthAsInt))) + if (FAILED(SizeTToInt(wcslen(file_data.cFileName), &length_as_int))) return(MBEDTLS_ERR_X509_FILE_IO_ERROR); - if (w_ret == 0) { + w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName, + length_as_int, + p, (int) len - 1, + NULL, NULL); + if(w_ret == 0) + { ret = MBEDTLS_ERR_X509_FILE_IO_ERROR; goto cleanup; } From 769ee65f992af17e5daf2b6ac52ad0958edb8824 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Mon, 10 Dec 2018 22:12:28 +0000 Subject: [PATCH 11/33] Fix Visual Studio Release|x64 builds The shipped Visual Studio project files were misconfigured for build combinations of 64 bit Release builds. Signed-off-by: Simon Butcher --- scripts/data_files/vs2013-app-template.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/data_files/vs2013-app-template.vcxproj b/scripts/data_files/vs2013-app-template.vcxproj index f6d4d4af3..666c63916 100644 --- a/scripts/data_files/vs2013-app-template.vcxproj +++ b/scripts/data_files/vs2013-app-template.vcxproj @@ -162,7 +162,7 @@ INCLUDE_DIRECTORIES true true Release - %(AdditionalDependencies); + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) From b8d6b82df42e2a9b6ff76edc341590ad3125cbe7 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Wed, 9 Aug 2023 16:23:14 +0100 Subject: [PATCH 12/33] programs: Cleaned up bcrypt linking refererences. bcrypt is added to the cmake `libs` dependency at library\CMakeLists.txt Signed-off-by: Minos Galanakis --- programs/pkey/CMakeLists.txt | 4 ---- programs/random/CMakeLists.txt | 4 ---- programs/ssl/CMakeLists.txt | 4 ---- programs/test/CMakeLists.txt | 4 ---- programs/x509/CMakeLists.txt | 4 ---- 5 files changed, 20 deletions(-) diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index b95a330a0..c7ebcb0f4 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -2,10 +2,6 @@ set(libs mbedtls ) -if(WIN32) - set(libs ${libs} bcrypt) -endif(WIN32) - set(executables_mbedtls dh_client dh_server diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index 20fe7e1f4..e42ca8d8a 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -2,10 +2,6 @@ set(libs mbedtls ) -if(WIN32) - set(libs ${libs} bcrypt) -endif(WIN32) - set(executables gen_entropy gen_random_ctr_drbg diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index cfa9a0f92..280bbcf3d 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -5,10 +5,6 @@ set(libs ${mbedtls_target} ) -if(WIN32) - set(libs ${libs} bcrypt) -endif(WIN32) - set(executables dtls_client dtls_server diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 24829c719..a75f8d923 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -2,10 +2,6 @@ set(libs ${mbedtls_target} ) -if(WIN32) - set(libs ${libs} bcrypt) -endif(WIN32) - set(executables_libs query_included_headers selftest diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt index f1a4a5afa..5876b8d21 100644 --- a/programs/x509/CMakeLists.txt +++ b/programs/x509/CMakeLists.txt @@ -2,10 +2,6 @@ set(libs ${mbedx509_target} ) -if(WIN32) - set(libs ${libs} bcrypt) -endif(WIN32) - set(executables cert_app cert_req From a277b210ff68a930e6cebb4cf9740492c97df371 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Wed, 9 Aug 2023 16:32:22 +0100 Subject: [PATCH 13/33] Code style fixes Signed-off-by: Minos Galanakis --- library/entropy_poll.c | 17 ++++++++--------- library/x509_crt.c | 19 ++++++++++--------- .../data_files/vs2013-app-template.vcxproj | 4 ++-- .../data_files/vs2013-main-template.vcxproj | 8 ++++---- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index f11a0b822..8fb7f9eee 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -57,12 +57,12 @@ * These constants are guaranteed to be the same, though, so we suppress the * warning when including intsafe.h. */ -#pragma warning( push ) -#pragma warning( disable : 4005 ) +#pragma warning(push) +#pragma warning(disable : 4005) #endif #include #if defined(_MSC_VER) && _MSC_VER <= 1600 -#pragma warning( pop ) +#pragma warning(pop) #endif int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, @@ -77,14 +77,13 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, * 64-bit Windows platforms. Ensure len's value can be safely converted into * a ULONG. */ - if ( FAILED( SizeTToULong( len, &len_as_ulong ) ) ) - { - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + if (FAILED(SizeTToULong(len, &len_as_ulong))) { + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; } - if ( !BCRYPT_SUCCESS( BCryptGenRandom( NULL, output, len_as_ulong, BCRYPT_USE_SYSTEM_PREFERRED_RNG ) ) ) - { - return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + if (!BCRYPT_SUCCESS(BCryptGenRandom(NULL, output, len_as_ulong, + BCRYPT_USE_SYSTEM_PREFERRED_RNG))) { + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; } *olen = len; diff --git a/library/x509_crt.c b/library/x509_crt.c index d9df4b220..d4a6dbb77 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -67,12 +67,12 @@ * These constants are guaranteed to be the same, though, so we suppress the * warning when including intsafe.h. */ -#pragma warning( push ) -#pragma warning( disable : 4005 ) +#pragma warning(push ) +#pragma warning(disable : 4005) #endif #include #if defined(_MSC_VER) && _MSC_VER <= 1600 -#pragma warning( pop ) +#pragma warning(pop) #endif #else #include @@ -1570,8 +1570,9 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) p = filename + len; filename[len++] = '*'; - if (FAILED (SizeTToInt(len, &length_as_int))) - return(MBEDTLS_ERR_X509_FILE_IO_ERROR); + if (FAILED(SizeTToInt(len, &length_as_int))) { + return MBEDTLS_ERR_X509_FILE_IO_ERROR; + } /* * Note this function uses the code page CP_ACP, and assumes the incoming @@ -1600,15 +1601,15 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) continue; } - if (FAILED(SizeTToInt(wcslen(file_data.cFileName), &length_as_int))) - return(MBEDTLS_ERR_X509_FILE_IO_ERROR); + if (FAILED(SizeTToInt(wcslen(file_data.cFileName), &length_as_int))) { + return MBEDTLS_ERR_X509_FILE_IO_ERROR; + } w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName, length_as_int, p, (int) len - 1, NULL, NULL); - if(w_ret == 0) - { + if (w_ret == 0) { ret = MBEDTLS_ERR_X509_FILE_IO_ERROR; goto cleanup; } diff --git a/scripts/data_files/vs2013-app-template.vcxproj b/scripts/data_files/vs2013-app-template.vcxproj index 666c63916..eca9691ed 100644 --- a/scripts/data_files/vs2013-app-template.vcxproj +++ b/scripts/data_files/vs2013-app-template.vcxproj @@ -162,8 +162,8 @@ INCLUDE_DIRECTORIES true true Release - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + diff --git a/scripts/data_files/vs2013-main-template.vcxproj b/scripts/data_files/vs2013-main-template.vcxproj index 6f1b5dadb..c2d65cf2b 100644 --- a/scripts/data_files/vs2013-main-template.vcxproj +++ b/scripts/data_files/vs2013-main-template.vcxproj @@ -92,7 +92,7 @@ INCLUDE_DIRECTORIES Windows true NotSet - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) Debug @@ -110,7 +110,7 @@ INCLUDE_DIRECTORIES Windows true NotSet - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) Debug @@ -131,8 +131,8 @@ INCLUDE_DIRECTORIES true true Release - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - + bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + From e13775dedb066cefed5ad59d7c5552531a1f514b Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 11 Aug 2023 14:36:33 +0100 Subject: [PATCH 14/33] fuzzer Makefile: Added -lbcrypt linkage Signed-off-by: Minos Galanakis --- programs/fuzz/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/programs/fuzz/Makefile b/programs/fuzz/Makefile index 8477aa8cb..b4fc76ae1 100644 --- a/programs/fuzz/Makefile +++ b/programs/fuzz/Makefile @@ -27,6 +27,10 @@ ifdef FUZZINGENGINE LOCAL_LDFLAGS += -lFuzzingEngine endif +ifdef WINDOWS_BUILD +LOCAL_LDFLAGS += -lbcrypt +endif + # A test application is built for each suites/test_suite_*.data file. # Application name is same as .data file's base name and can be # constructed by stripping path 'suites/' and extension .data. From 24a1c16face5545de7090f3cacaf9b52ec68f6ee Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 11 Aug 2023 14:37:24 +0100 Subject: [PATCH 15/33] library Makefile: Moved -lbcrypt to LOCAL_LDFLAGS Signed-off-by: Minos Galanakis --- library/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/Makefile b/library/Makefile index 5d645f7b7..c3d8615cb 100644 --- a/library/Makefile +++ b/library/Makefile @@ -39,6 +39,10 @@ APPLE_BUILD ?= 1 endif endif +ifdef WINDOWS_BUILD +LOCAL_LDFLAGS += -lbcrypt +endif + # To compile as a shared library: ifdef SHARED # all code is position-indep with mingw, avoid warning about useless flag @@ -302,7 +306,7 @@ libmbedcrypto.dylib: $(OBJS_CRYPTO) libmbedcrypto.dll: $(OBJS_CRYPTO) echo " LD $@" - $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lbcrypt -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS) + $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS) .c.o: echo " CC $<" From 12b493f4dc6c74f65f47e3cf9cf1a176920ff462 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 11 Aug 2023 15:22:45 +0100 Subject: [PATCH 16/33] entropy_poll/x509_crt: Added MBEDTLS_POP_TARGET_PRAGMA define guards. Signed-off-by: Minos Galanakis --- library/entropy_poll.c | 9 ++++++++- library/x509_crt.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 8fb7f9eee..e5cf97034 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -52,6 +52,9 @@ #if _WIN32_WINNT >= 0x0501 /* _WIN32_WINNT_WINXP */ #include #if defined(_MSC_VER) && _MSC_VER <= 1600 +#define MBEDTLS_POP_TARGET_PRAGMA +#endif +#if defined(MBEDTLS_POP_TARGET_PRAGMA) /* Visual Studio 2010 and earlier issue a warning when both and * are included, as they redefine a number of _MAX constants. * These constants are guaranteed to be the same, though, so we suppress the @@ -61,7 +64,7 @@ #pragma warning(disable : 4005) #endif #include -#if defined(_MSC_VER) && _MSC_VER <= 1600 +#if defined(MBEDTLS_POP_TARGET_PRAGMA) #pragma warning(pop) #endif @@ -253,4 +256,8 @@ int mbedtls_nv_seed_poll(void *data, } #endif /* MBEDTLS_ENTROPY_NV_SEED */ +#if defined(MBEDTLS_POP_TARGET_PRAGMA) +#undef MBEDTLS_POP_TARGET_PRAGMA +#endif + #endif /* MBEDTLS_ENTROPY_C */ diff --git a/library/x509_crt.c b/library/x509_crt.c index d4a6dbb77..4beda54cb 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -62,6 +62,9 @@ #define WIN32_LEAN_AND_MEAN #include #if defined(_MSC_VER) && _MSC_VER <= 1600 +#define MBEDTLS_POP_TARGET_PRAGMA +#endif +#if defined(MBEDTLS_POP_TARGET_PRAGMA) /* Visual Studio 2010 and earlier issue a warning when both and * are included, as they redefine a number of _MAX constants. * These constants are guaranteed to be the same, though, so we suppress the @@ -71,7 +74,7 @@ #pragma warning(disable : 4005) #endif #include -#if defined(_MSC_VER) && _MSC_VER <= 1600 +#if defined(MBEDTLS_POP_TARGET_PRAGMA) #pragma warning(pop) #endif #else @@ -3333,4 +3336,8 @@ void mbedtls_x509_crt_restart_free(mbedtls_x509_crt_restart_ctx *ctx) } #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ +#if defined(MBEDTLS_POP_TARGET_PRAGMA) +#undef MBEDTLS_POP_TARGET_PRAGMA +#endif + #endif /* MBEDTLS_X509_CRT_PARSE_C */ From 8792717309572f6eed16b99576c0fe9554b2980c Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 11 Aug 2023 15:52:44 +0100 Subject: [PATCH 17/33] Changelog: Removed entry from root file Signed-off-by: Minos Galanakis --- ChangeLog | 2 -- ChangeLog.d/updated_windows_apis.txt | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 ChangeLog.d/updated_windows_apis.txt diff --git a/ChangeLog b/ChangeLog index f3c13a2ae..bc1d32e4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3016,8 +3016,6 @@ Changes * Clarify the documentation of mbedtls_ssl_setup. * Use (void) when defining functions with no parameters. Contributed by Joris Aerts. #678 - * Update Win32 APIs used to remove those not permitted by the Windows Store. - Fix provided by Kevin Kane, Microsoft. #635 = mbed TLS 2.7.0 branch released 2018-02-03 diff --git a/ChangeLog.d/updated_windows_apis.txt b/ChangeLog.d/updated_windows_apis.txt new file mode 100644 index 000000000..8df22978e --- /dev/null +++ b/ChangeLog.d/updated_windows_apis.txt @@ -0,0 +1,5 @@ +API changes + * Update Windows APIs to use BCryptGenRandom and wcslen and + ensure that conversions between size_t, ULONG, and int are + always done safely. Original contribution by Kevin Kane #635, + #730 followed by #Simon Butcher #1453. From e960365957e731e5bb37c322f47a6d6102cc3bb8 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 18 Aug 2023 15:18:54 +0100 Subject: [PATCH 18/33] ChangeLog.d: Reworded updated_windows_apis.txt. Signed-off-by: Minos Galanakis --- ChangeLog.d/updated_windows_apis.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog.d/updated_windows_apis.txt b/ChangeLog.d/updated_windows_apis.txt index 8df22978e..8a70958bd 100644 --- a/ChangeLog.d/updated_windows_apis.txt +++ b/ChangeLog.d/updated_windows_apis.txt @@ -1,5 +1,5 @@ -API changes +Requirement changes * Update Windows APIs to use BCryptGenRandom and wcslen and - ensure that conversions between size_t, ULONG, and int are - always done safely. Original contribution by Kevin Kane #635, - #730 followed by #Simon Butcher #1453. + ensure that conversions between size_t, ULONG, and int are + always done safely. Original contribution by Kevin Kane #635, + #730 followed by Simon Butcher #1453. From 4952f705eea3805f9d28fcfd5a30676f33bfa11d Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 18 Aug 2023 15:24:39 +0100 Subject: [PATCH 19/33] Removed unsupported Visual Studio related code in entropy_poll.c and x509_crt.c. Signed-off-by: Minos Galanakis --- library/entropy_poll.c | 19 ------------------- library/x509_crt.c | 19 ------------------- 2 files changed, 38 deletions(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index e5cf97034..8048ace0f 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -51,22 +51,7 @@ #include #if _WIN32_WINNT >= 0x0501 /* _WIN32_WINNT_WINXP */ #include -#if defined(_MSC_VER) && _MSC_VER <= 1600 -#define MBEDTLS_POP_TARGET_PRAGMA -#endif -#if defined(MBEDTLS_POP_TARGET_PRAGMA) -/* Visual Studio 2010 and earlier issue a warning when both and - * are included, as they redefine a number of _MAX constants. - * These constants are guaranteed to be the same, though, so we suppress the - * warning when including intsafe.h. - */ -#pragma warning(push) -#pragma warning(disable : 4005) -#endif #include -#if defined(MBEDTLS_POP_TARGET_PRAGMA) -#pragma warning(pop) -#endif int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, size_t *olen) @@ -256,8 +241,4 @@ int mbedtls_nv_seed_poll(void *data, } #endif /* MBEDTLS_ENTROPY_NV_SEED */ -#if defined(MBEDTLS_POP_TARGET_PRAGMA) -#undef MBEDTLS_POP_TARGET_PRAGMA -#endif - #endif /* MBEDTLS_ENTROPY_C */ diff --git a/library/x509_crt.c b/library/x509_crt.c index 4beda54cb..8c955cb26 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -61,22 +61,7 @@ #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #define WIN32_LEAN_AND_MEAN #include -#if defined(_MSC_VER) && _MSC_VER <= 1600 -#define MBEDTLS_POP_TARGET_PRAGMA -#endif -#if defined(MBEDTLS_POP_TARGET_PRAGMA) -/* Visual Studio 2010 and earlier issue a warning when both and - * are included, as they redefine a number of _MAX constants. - * These constants are guaranteed to be the same, though, so we suppress the - * warning when including intsafe.h. - */ -#pragma warning(push ) -#pragma warning(disable : 4005) -#endif #include -#if defined(MBEDTLS_POP_TARGET_PRAGMA) -#pragma warning(pop) -#endif #else #include #endif @@ -3336,8 +3321,4 @@ void mbedtls_x509_crt_restart_free(mbedtls_x509_crt_restart_ctx *ctx) } #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ -#if defined(MBEDTLS_POP_TARGET_PRAGMA) -#undef MBEDTLS_POP_TARGET_PRAGMA -#endif - #endif /* MBEDTLS_X509_CRT_PARSE_C */ From 7afebccf6996c504c2b6b40aace4ef405a7a96ac Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Wed, 6 Sep 2023 14:50:54 +0100 Subject: [PATCH 20/33] ChangeLog.d: Added mininum required Windows version. Signed-off-by: Minos Galanakis --- ChangeLog.d/updated_windows_apis.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog.d/updated_windows_apis.txt b/ChangeLog.d/updated_windows_apis.txt index 8a70958bd..a95641dd6 100644 --- a/ChangeLog.d/updated_windows_apis.txt +++ b/ChangeLog.d/updated_windows_apis.txt @@ -1,5 +1,8 @@ Requirement changes - * Update Windows APIs to use BCryptGenRandom and wcslen and + * Minimum required Windows version is now Windows Vista. + +Changes + * Update Windows code to use BCryptGenRandom and wcslen, and ensure that conversions between size_t, ULONG, and int are - always done safely. Original contribution by Kevin Kane #635, - #730 followed by Simon Butcher #1453. + always done safely. Original contribution by Kevin Kane #635, #730 + followed by Simon Butcher #1453. From 2c6e561ff8c8fc4069a96fb133771532d61fe499 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Wed, 6 Sep 2023 15:00:58 +0100 Subject: [PATCH 21/33] entropy_poll.c: Added looping logic to `mbedtls_platform_entropy_poll()`. Signed-off-by: Minos Galanakis --- library/entropy_poll.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 8048ace0f..52be9f550 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -56,7 +56,6 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, size_t *olen) { - ULONG len_as_ulong = 0; ((void) data); *olen = 0; @@ -65,16 +64,18 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, * 64-bit Windows platforms. Ensure len's value can be safely converted into * a ULONG. */ - if (FAILED(SizeTToULong(len, &len_as_ulong))) { - return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; - } + while (len != 0) { + unsigned long ulong_bytes = + (len > ULONG_MAX) ? ULONG_MAX : (unsigned long) len; - if (!BCRYPT_SUCCESS(BCryptGenRandom(NULL, output, len_as_ulong, - BCRYPT_USE_SYSTEM_PREFERRED_RNG))) { - return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; - } + if (!BCRYPT_SUCCESS(BCryptGenRandom(NULL, output, ulong_bytes, + BCRYPT_USE_SYSTEM_PREFERRED_RNG))) { + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + } - *olen = len; + *olen += ulong_bytes; + len -= ulong_bytes; + } return 0; } From ce33e7b22d54fc8dfbb7f0a7a1605f02c4d58b9b Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Wed, 6 Sep 2023 16:14:30 +0100 Subject: [PATCH 22/33] pkey Cmakelists: Updated the set libs to be consistent with others. Signed-off-by: Minos Galanakis --- programs/pkey/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index c7ebcb0f4..b747a3f33 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,5 +1,5 @@ set(libs - mbedtls + ${mbedtls_target} ) set(executables_mbedtls From 7f8e8c5ae27c83a48b9edbcef353d440d79d9e8a Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 8 Sep 2023 14:46:59 +0100 Subject: [PATCH 23/33] program-random: Updated Cmake libs variable Signed-off-by: Minos Galanakis --- programs/random/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index e42ca8d8a..95cd33f9c 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,5 +1,5 @@ set(libs - mbedtls + ${mbedtls_target} ) set(executables From e8a5d1afbd83dcec8470a61da81c535ec7685a9d Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 8 Sep 2023 14:47:37 +0100 Subject: [PATCH 24/33] entropy_poll: Updated documentation for entropy_poll loop. Signed-off-by: Minos Galanakis --- library/entropy_poll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 52be9f550..5eb6d7f55 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -61,8 +61,8 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, /* * BCryptGenRandom takes ULONG for size, which is smaller than size_t on - * 64-bit Windows platforms. Ensure len's value can be safely converted into - * a ULONG. + * 64-bit Windows platforms. Extract entropy in chunks of len (dependent + * on ULONG_MAX) size. */ while (len != 0) { unsigned long ulong_bytes = From a8b02ef79b4453ca6e5df87e3ce73300c41426f1 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Mon, 18 Sep 2023 11:01:40 +0100 Subject: [PATCH 25/33] pkey-random: Removed setting mbedtls_target in libs Signed-off-by: Minos Galanakis --- programs/pkey/CMakeLists.txt | 4 ---- programs/random/CMakeLists.txt | 4 ---- 2 files changed, 8 deletions(-) diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index b747a3f33..3ad56436e 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,7 +1,3 @@ -set(libs - ${mbedtls_target} -) - set(executables_mbedtls dh_client dh_server diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index 95cd33f9c..e5edf7b58 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,7 +1,3 @@ -set(libs - ${mbedtls_target} -) - set(executables gen_entropy gen_random_ctr_drbg From c91d847e0d9f2cf208c4aaa5390073612947e7bc Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Mon, 18 Sep 2023 11:04:09 +0100 Subject: [PATCH 26/33] ChangeLog: Adjusted the updated_windows_apis log Signed-off-by: Minos Galanakis --- ChangeLog.d/updated_windows_apis.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.d/updated_windows_apis.txt b/ChangeLog.d/updated_windows_apis.txt index a95641dd6..73b17df9d 100644 --- a/ChangeLog.d/updated_windows_apis.txt +++ b/ChangeLog.d/updated_windows_apis.txt @@ -1,5 +1,6 @@ Requirement changes - * Minimum required Windows version is now Windows Vista. + * Minimum required Windows version is now Windows Vista, or + Windows Server 2008. Changes * Update Windows code to use BCryptGenRandom and wcslen, and From fac45fbafefdfb77076018e6a5267df96c30c53e Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Mon, 18 Sep 2023 11:12:41 +0100 Subject: [PATCH 27/33] entropy_poll: Removed checks for windows versions < WINXP Signed-off-by: Minos Galanakis --- library/entropy_poll.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 5eb6d7f55..9d5b1e652 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -49,7 +49,6 @@ #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #include -#if _WIN32_WINNT >= 0x0501 /* _WIN32_WINNT_WINXP */ #include #include @@ -79,9 +78,6 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, return 0; } -#else /* !_WIN32_WINNT_WINXP */ -#error "Entropy not available before Windows XP, use MBEDTLS_NO_PLATFORM_ENTROPY" -#endif /* !_WIN32_WINNT_WINXP */ #else /* _WIN32 && !EFIX64 && !EFI32 */ /* From 40995e139069015fb912f279781057ebb200a5bd Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Mon, 18 Sep 2023 11:16:47 +0100 Subject: [PATCH 28/33] x509_crt: Removed checks for windows versions < WINXP Signed-off-by: Minos Galanakis --- library/x509_crt.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library/x509_crt.c b/library/x509_crt.c index 8c955cb26..93381a54a 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1536,7 +1536,6 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) { int ret = 0; #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) -#if _WIN32_WINNT >= 0x0501 /* _WIN32_WINNT_XP */ int w_ret; WCHAR szDir[MAX_PATH]; char filename[MAX_PATH]; @@ -1616,9 +1615,6 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) cleanup: FindClose(hFind); -#else /* !_WIN32_WINNT_XP */ -#error "mbedtls_x509_crt_parse_path not available before Windows XP" -#endif /* !_WIN32_WINNT_XP */ #else /* _WIN32 */ int t_ret; int snp_ret; From b17410d9756c6a4482b50a5228243c4057ce0437 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 22 Sep 2023 12:08:11 +0100 Subject: [PATCH 29/33] vs2013 templates: Set bcrypt to be the sole dependency. Signed-off-by: Minos Galanakis --- scripts/data_files/vs2013-app-template.vcxproj | 10 +++++----- scripts/data_files/vs2013-main-template.vcxproj | 13 ++++--------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/scripts/data_files/vs2013-app-template.vcxproj b/scripts/data_files/vs2013-app-template.vcxproj index eca9691ed..2fe9cf33b 100644 --- a/scripts/data_files/vs2013-app-template.vcxproj +++ b/scripts/data_files/vs2013-app-template.vcxproj @@ -99,7 +99,7 @@ INCLUDE_DIRECTORIES Console true - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + bcrypt.lib;%(AdditionalDependencies) Debug @@ -118,7 +118,7 @@ INCLUDE_DIRECTORIES Console true - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + bcrypt.lib;%(AdditionalDependencies) Debug @@ -142,7 +142,7 @@ INCLUDE_DIRECTORIES true true Release - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + bcrypt.lib;%(AdditionalDependencies) @@ -162,8 +162,8 @@ INCLUDE_DIRECTORIES true true Release - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - + bcrypt.lib;%(AdditionalDependencies) + diff --git a/scripts/data_files/vs2013-main-template.vcxproj b/scripts/data_files/vs2013-main-template.vcxproj index c2d65cf2b..51861e16c 100644 --- a/scripts/data_files/vs2013-main-template.vcxproj +++ b/scripts/data_files/vs2013-main-template.vcxproj @@ -91,9 +91,7 @@ INCLUDE_DIRECTORIES Windows true - NotSet - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - Debug + bcrypt.lib;%(AdditionalDependencies) @@ -109,9 +107,7 @@ INCLUDE_DIRECTORIES Windows true - NotSet - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - Debug + bcrypt.lib;%(AdditionalDependencies) @@ -130,9 +126,8 @@ INCLUDE_DIRECTORIES true true true - Release - bcrypt.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - + bcrypt.lib;%(AdditionalDependencies) + From 08a67ccefdace9612a79b07013dfd42636ae20b4 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Fri, 22 Sep 2023 16:00:06 +0100 Subject: [PATCH 30/33] x509_crt: Set WideCharToMultiByte to use -1 for length. Signed-off-by: Minos Galanakis WideCharToMultiByte --- library/x509_crt.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/library/x509_crt.c b/library/x509_crt.c index 93381a54a..162281dfa 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1562,12 +1562,9 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) } /* - * Note this function uses the code page CP_ACP, and assumes the incoming - * string is encoded in ANSI, before translating it into Unicode. If the - * incoming string were changed to be UTF-8, then the length check needs to - * change to check the number of characters, not the number of bytes, in the - * incoming string are less than MAX_PATH to avoid a buffer overrun with - * MultiByteToWideChar(). + * Note this function uses the code page CP_ACP which is the system default + * ANSI codepage. The input string is always described in BYTES and the + * output length is described in WCHARs. */ w_ret = MultiByteToWideChar(CP_ACP, 0, filename, length_as_int, szDir, MAX_PATH - 3); @@ -1587,14 +1584,8 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) if (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { continue; } - - if (FAILED(SizeTToInt(wcslen(file_data.cFileName), &length_as_int))) { - return MBEDTLS_ERR_X509_FILE_IO_ERROR; - } - w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName, - length_as_int, - p, (int) len - 1, + -1, p, (int) len - 1, NULL, NULL); if (w_ret == 0) { ret = MBEDTLS_ERR_X509_FILE_IO_ERROR; From 59108d3f4da48a7b76390b729427c6a80ca52fe2 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Mon, 25 Sep 2023 14:11:22 +0100 Subject: [PATCH 31/33] x509_crt: Adjusted the len of lpMultiByteStr arg in WideCharToMultiByte Signed-off-by: Minos Galanakis --- library/x509_crt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/x509_crt.c b/library/x509_crt.c index 162281dfa..4418dab76 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1585,8 +1585,7 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) continue; } w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName, - -1, p, (int) len - 1, - NULL, NULL); + -1, p, (int) len, NULL, NULL); if (w_ret == 0) { ret = MBEDTLS_ERR_X509_FILE_IO_ERROR; goto cleanup; From a9bb34cd7396584282ae931caa23f751c70a02ad Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Mon, 25 Sep 2023 14:41:12 +0100 Subject: [PATCH 32/33] x509_crt: Removed length_as_int intermediate variable Signed-off-by: Minos Galanakis --- library/x509_crt.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/library/x509_crt.c b/library/x509_crt.c index 4418dab76..43f5bb65c 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1541,7 +1541,6 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) char filename[MAX_PATH]; char *p; size_t len = strlen(path); - int length_as_int = 0; WIN32_FIND_DATAW file_data; HANDLE hFind; @@ -1557,16 +1556,12 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) p = filename + len; filename[len++] = '*'; - if (FAILED(SizeTToInt(len, &length_as_int))) { - return MBEDTLS_ERR_X509_FILE_IO_ERROR; - } - /* * Note this function uses the code page CP_ACP which is the system default * ANSI codepage. The input string is always described in BYTES and the * output length is described in WCHARs. */ - w_ret = MultiByteToWideChar(CP_ACP, 0, filename, length_as_int, szDir, + w_ret = MultiByteToWideChar(CP_ACP, 0, filename, (int) len, szDir, MAX_PATH - 3); if (w_ret == 0) { return MBEDTLS_ERR_X509_BAD_INPUT_DATA; From 21087754a5ec3383289efff517d7d7e495b489e1 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Mon, 25 Sep 2023 15:17:38 +0100 Subject: [PATCH 33/33] x509_crt: Removed unused intsafe.h Signed-off-by: Minos Galanakis --- library/x509_crt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/library/x509_crt.c b/library/x509_crt.c index 43f5bb65c..e9153e710 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -61,7 +61,6 @@ #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #define WIN32_LEAN_AND_MEAN #include -#include #else #include #endif