-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/update win crypto apis #8047
Changes from 31 commits
0ec1e68
e068aa7
34b8d83
33425de
1c0c5d2
def90f4
bcb6cfb
35e5dad
949aa8f
de573f5
769ee65
b8d6b82
a277b21
e13775d
24a1c16
12b493f
8792717
e960365
4952f70
7afebcc
2c6e561
ce33e7b
7f8e8c5
e8a5d1a
a8b02ef
c91d847
fac45fb
40995e1
b17410d
08a67cc
59108d3
a9bb34c
2108775
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Requirement changes | ||
* Minimum required Windows version is now Windows Vista, or | ||
Windows Server 2008. | ||
|
||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ | |
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
#include <intsafe.h> | ||
#else | ||
#include <time.h> | ||
#endif | ||
|
@@ -1535,12 +1536,12 @@ 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]; | ||
char *p; | ||
size_t len = strlen(path); | ||
int length_as_int = 0; | ||
|
||
WIN32_FIND_DATAW file_data; | ||
HANDLE hFind; | ||
|
@@ -1556,7 +1557,16 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) | |
p = filename + len; | ||
filename[len++] = '*'; | ||
|
||
w_ret = MultiByteToWideChar(CP_ACP, 0, filename, (int) len, szDir, | ||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re-reading this change, I'm not sure why we're bothering with the whole This would be a concern if So the cast in the (original) line 1559 is totally fine. We also do a similar cast in (new) line 1588 - admittedly this is now "length remaining in buffer", which is a horrible re-use of variable with opposite meaning, but if we are happy with the cast at 1588 we should be happy with the cast at 1559. (And fewer changes => better, IMO) Supporting "Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions" would be a bigger, separate, set of changes |
||
MAX_PATH - 3); | ||
if (w_ret == 0) { | ||
return MBEDTLS_ERR_X509_BAD_INPUT_DATA; | ||
|
@@ -1574,11 +1584,8 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path) | |
if (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | ||
continue; | ||
} | ||
|
||
w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName, | ||
-1, | ||
p, (int) len, | ||
NULL, NULL); | ||
-1, p, (int) len, NULL, NULL); | ||
if (w_ret == 0) { | ||
ret = MBEDTLS_ERR_X509_FILE_IO_ERROR; | ||
goto cleanup; | ||
|
@@ -1598,9 +1605,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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ endif | |
ifdef WINDOWS_BUILD | ||
DLEXT=dll | ||
EXEXT=.exe | ||
LOCAL_LDFLAGS += -lws2_32 | ||
LOCAL_LDFLAGS += -lws2_32 -lbcrypt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we not adding this for cmake? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because in cmake we can set it once and it propagates throuth the mbedtls_target. |
||
ifdef SHARED | ||
SHARED_SUFFIX=.$(DLEXT) | ||
endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,10 @@ ifdef FUZZINGENGINE | |
LOCAL_LDFLAGS += -lFuzzingEngine | ||
endif | ||
|
||
ifdef WINDOWS_BUILD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this, under CMake, the fuzz build is explicitly removed for windows builds, and I am presuming this is why you have not added bcrypt to the cmake libs for fuzz. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has been removed was not needed for Make either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update. The ci is failing when removing this code
The test snippet from all.sh is set as:
So linking against the new library is required at least for make. I will be rebasing and removing commit 800223c . We could address the different behaviour between make and cmake in a follow up pr? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The purpose of this PR is to update to later versions of Windows APIs, so let's not make changes to behaviour unless necessary when updating to the later APIs. (i.e. changing different Make vs CMake behaviour would require design review - specifically, why was it done in the first place? and is that reason still relevant?) |
||
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. | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this change :) or can't we bear the thought of another update? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if it clears CI, and I could try to push a last commit to remove that. Re reviewing an include could be simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(note that the only functional changes to this file now are the #if changes)