-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Side-port from crypto: programs/ #3038
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
Side-port from crypto: programs/ #3038
Conversation
This makes it easier to add or remove programs as well as see which programs were added or removed in diffs. Side port of 30fae8e in mbed-crypto.
There is some commented out X.509 certificate writing code present in rsa_genkey. It looks like it has been commented out since the beginning of time. Let's remove it, since commented out code is not in good style.
As the SSL programs, like ssl_client2 and ssl_server2, are dependent on SSL and therefore about to be removed, the only consumer of query_config is the query_compile_time_config test. As such, it makes sense to move query_config to be next to what uses it.
When building with CMake, for sample programs that only use functionality in libmbedcrypto (i.e. crypto and platform), link with libmbedcrypto, not with libmbedtls. This doesn't change the result, because the linker skips libraries in which no symbol is used, but it changes the build dependencies, and it has the advantage of bringing programs/*/CMakeLists.txt closer to the corresponding files under crypto/. The programs concerned are crypto sample and test programs, and programs that only use (potential) platform functions such as mbedtls_printf. dh_client and dh_server keep linking with mbedtls because they use functions from the net_sockets module.
When building with CMake, for sample programs that only use functionality in libmbedcrypto and libmbedx509, link with libmbedx509, not with libmbedtls. cert_app makes a TLS connection, so do link it with libmbedtls.
You can't reuse a CTR_DRBG context without free()ing it and re-init()ing. This generally happened to work, but was never guaranteed. It could have failed with alternative implementations of the AES module because mbedtls_ctr_drbg_seed() calls mbedtls_aes_init() on a context which is already initialized if mbedtls_ctr_drbg_seed() hasn't been called before, plausibly causing a memory leak. Calling free() and seed() with no intervening init fails when MBEDTLS_THREADING_C is enabled and all-bits-zero is not a valid mutex representation. So add the missing free() and init().
Add a very basic test of calloc to the selftest program. The selftest program acts in its capacity as a platform compatibility checker rather than in its capacity as a test of the library. The main objective is to report whether calloc returns NULL for a size of 0. Also observe whether a free/alloc sequence returns the address that was just freed and whether a size overflow is properly detected.
Exercise the library functions with calloc returning NULL for a size
of 0. Make this a separate job with UBSan (and ASan) to detect
places where we try to dereference the result of calloc(0) or to do
things like
buf = calloc(size, 1);
if (buf == NULL && size != 0) return INSUFFICIENT_MEMORY;
memcpy(buf, source, size);
which has undefined behavior when buf is NULL at the memcpy call even
if size is 0.
This is needed because other test components jobs either use the system
malloc which returns non-NULL on Linux and FreeBSD, or the
memory_buffer_alloc malloc which returns NULL but does not give as
useful feedback with ASan (because the whole heap is a single C
object).
I think this figure makes things look less encouraging that they are, by counting context lines. Using git diff stat makes things look brighter: |
mpg
left a comment
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.
LGTM
yanesca
left a comment
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.
LGTM.
Side-port changes made in mbed-crypto under
programs/. The goal of this pull request is to bring in bug fixes and enhancements made in mbed-crypto to files that exist both in mbed-crypto and in mbedtls. The goal of this pull request is not to be exhaustive, though it is close apart from the build scripts, generated files, and references to files that only exist on one side.programs/Makefilereproduced from 30fae8e from Break non-crypto dependencies ARMmbed/mbed-crypto#74.CMakeLists.txt, don't link x509-only programs withlibmbedtls. The linker would optimize it away anyway, but this is analogous to linking crypto-only programs with onlylibmbedcryptowhich mbed-crypto had to do.query_configtoprograms/test. Cherry-picked from Break non-crypto dependencies ARMmbed/mbed-crypto#74.all.sh, also run part ofssl-opt.sh.(excluding a very long automatically generated file) is now 576 lines long, which approaches something manageable.