Skip to content
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

Replace Windows APIs that are banned in Windows Store apps #730

Closed
wants to merge 1 commit into from

Conversation

kevinmkane
Copy link
Contributor

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 differnt
sizes.

@thiagomacieira
Copy link

ping. What's holding this back?

@thiagomacieira
Copy link

One week has gone by. ping again.

@simonbutcher
Copy link
Contributor

Hi @thiagomacieira and thanks for the interest in mbed TLS. It's nice to see Intel following the project.

If you look have a look, you'll see we currently have a large number of open pull requests from the community. As a security and cryptography library, we carefully review all contributions, and we only have so much capacity to make such reviews. That means a far slower adoption and take up of contributions than we'd like, which is frustrating both for us and the community.

We're currently expanding the team, and revising both how we accept contributions and our CI system to make it easier and faster to accept contributions, which I hope will resolve the problem in the near future, but in the meantime it means that we're less responsive in accepting contributions than we'd like.

@thiagomacieira
Copy link

Hi, it's been one month. Are there any updates?

@RonEld
Copy link
Contributor

RonEld commented Jul 20, 2017

Hi @thiagomacieira Thanks again for the reminder
As you can probably see, we have been recently working on several pull requests in the backlog, Unfortunately, no update regarding this pull request yet.
Thank you for your patience!

@RonEld
Copy link
Contributor

RonEld commented Nov 16, 2017

Hi @kevinmkane,
Thank you for your contribution!
I apologize for delay in the review.
There is a redefinition between stdint.h definition and intsafe.h:

c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(144): warning C4005: 'INT8_MIN' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(72) : see previous definition of 'INT8_MIN'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(146): warning C4005: 'INT16_MIN' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(73) : see previous definition of 'INT16_MIN'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(148): warning C4005: 'INT32_MIN' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(74) : see previous definition of 'INT32_MIN'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(152): warning C4005: 'INT64_MIN' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(149) : see previous definition of 'INT64_MIN'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(167): warning C4005: 'INT8_MAX' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(76) : see previous definition of 'INT8_MAX'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(168): warning C4005: 'UINT8_MAX' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(79) : see previous definition of 'UINT8_MAX'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(171): warning C4005: 'INT16_MAX' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(77) : see previous definition of 'INT16_MAX'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(173): warning C4005: 'UINT16_MAX' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(80) : see previous definition of 'UINT16_MAX'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(176): warning C4005: 'INT32_MAX' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(78) : see previous definition of 'INT32_MAX'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(178): warning C4005: 'UINT32_MAX' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(81) : see previous definition of 'UINT32_MAX'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(184): warning C4005: 'INT64_MAX' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(150) : see previous definition of 'INT64_MAX'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(189): warning C4005: 'UINT64_MAX' : macro redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(151) : see previous definition of 'UINT64_MAX'

@kevinmkane
Copy link
Contributor Author

Hi @RonEld,

Those definitions between stdint.h and intsafe.h will always be the same per a comment in Visual Studio's version of stdint.h. According to https://connect.microsoft.com/VisualStudio/feedback/details/621653 this issue existed in VS2010 but was fixed as of VS2012. Is it acceptable to suppress the warning when intsafe.h is included with an explanatory comment?

The alternative would be to copy the definitions of the macros and inline functions I'm introducing directly into the code and not include intsafe.h at all.

@RonEld
Copy link
Contributor

RonEld commented Nov 26, 2017

@kevinmkane Thank you for your explanation

Is it acceptable to suppress the warning when intsafe.h is included with an explanatory comment?

I think this would be the lesser of two evils. If possible, surround the pragma with _MSC_VER check.

@kevinmkane
Copy link
Contributor Author

I have now pushed a follow-up commit to suppress the warning as we discussed.

@@ -54,28 +54,41 @@
#define _WIN32_WINNT 0x0400
#endif
#include <windows.h>
#include <wincrypt.h>
#include <bcrypt.h>
#if defined(_MSC_VER)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be #if _MSC_VER <= 1600?
I believe visual studio 2010 _MSC_VER value is 1600

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's a good idea. That way we'll catch any legitimate instances of duplicated definitions with later versions of the compiler. I've overwritten the last commit with this change.

@RonEld
Copy link
Contributor

RonEld commented Dec 18, 2017

@kevinmkane Thank you for considering my comments.
Please confirm you have used generate_visualc_files.pl script to generate the project files.

Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

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

In the commit message, please fix spelling of different

- these types are differnt
+ these types are different

Except for minor trailing white space issue and misspelling in the commit message, this looks good to me.

Gatekeeper Note: this adds a requirement on bcrypt, which is available since Windows Vista.

((void) data);
*olen = 0;

if( CryptAcquireContext( &provider, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE )
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't add trailing white space in any commits of this PR.

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
<intsafe.h> and <stdint.h> because a number of <TYPE>_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.
@kevinmkane
Copy link
Contributor Author

@RonEld I did use generate_visualc_files.pl.

@mbed-ci
Copy link

mbed-ci commented Jan 2, 2018

Automatic CI verification build not done, please verify manually.

@kevinmkane
Copy link
Contributor Author

@Patater Both commits squashed into one with this latest update, which includes your requested corrections.

@Patater
Copy link
Contributor

Patater commented Jan 4, 2018

Thanks!

Copy link
Contributor

@RonEld RonEld left a comment

Choose a reason for hiding this comment

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

@kevinmkane Thank you for your confirmation.

@fire
Copy link

fire commented Feb 23, 2018

This breaks mingw64 on centos 7.4.

@simonbutcher
Copy link
Contributor

As per the published policy on Windows API support, this is now approved for the development branch. No back ports required.

* 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 ) ) )
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm Mar 13, 2018

Choose a reason for hiding this comment

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

SizeTToUlong doesn't exist in MinGW 5.3 so either the code using it must be under #ifdef _MSC_VER guards or an implementation must be provided. Do newer versions of MinGW support it? It could be acceptable to require a more recent version going forward.

@@ -1122,7 +1135,10 @@ 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, &lengthAsInt ) ) )
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

This breaks the build with MinGW 5.3, so we can't merge it in the current state.

simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Mar 14, 2018
Fix merge mistakes introduced when rebasing the PR Mbed-TLS#730.
@simonbutcher simonbutcher mentioned this pull request Mar 14, 2018
2 tasks
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Mar 14, 2018
@simonbutcher
Copy link
Contributor

Opened up a new PR, #1453, to address the issues building with mingw and Visual Studio when using cmake generated files. The PR builds on this one and has some small mods to fix these issues.

This PR can now be closed as development will continue there.

simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Mar 14, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Mar 26, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Mar 26, 2018
Patater pushed a commit to simonbutcher/mbedtls that referenced this pull request Mar 27, 2018
Patater pushed a commit to simonbutcher/mbedtls that referenced this pull request Mar 27, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Jun 14, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Jun 14, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Jun 14, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Jun 14, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Dec 24, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Dec 24, 2018
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Jan 6, 2020
simonbutcher added a commit to simonbutcher/mbedtls that referenced this pull request Jan 6, 2020
minosgalanakis pushed a commit to minosgalanakis/mbedtls that referenced this pull request Aug 9, 2023
minosgalanakis pushed a commit to minosgalanakis/mbedtls that referenced this pull request Aug 9, 2023
@minosgalanakis minosgalanakis mentioned this pull request Aug 9, 2023
3 tasks
minosgalanakis pushed a commit to minosgalanakis/mbedtls that referenced this pull request Aug 9, 2023
minosgalanakis pushed a commit to minosgalanakis/mbedtls that referenced this pull request Aug 9, 2023
minosgalanakis pushed a commit to minosgalanakis/mbedtls that referenced this pull request Sep 18, 2023
minosgalanakis pushed a commit to minosgalanakis/mbedtls that referenced this pull request Sep 18, 2023
minosgalanakis pushed a commit to minosgalanakis/mbedtls that referenced this pull request Sep 25, 2023
minosgalanakis pushed a commit to minosgalanakis/mbedtls that referenced this pull request Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants