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

Extend "full" config to non-boolean options and pass Clang+Asan #2684

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
95f5cbc
Don't systematically rebuild programs
gilles-peskine-arm Jun 7, 2019
5d26e7c
Pass -m32 to the linker as well
gilles-peskine-arm Jun 7, 2019
c00d4a1
Move config.h boolean options to their appropriate section
gilles-peskine-arm Jun 7, 2019
606dec0
Test suites: cope with psa_crypto_init failure
gilles-peskine-arm Jun 7, 2019
1c18472
Test PSA functions against PSA_SUCCESS, not 0
gilles-peskine-arm Jun 7, 2019
9088867
Make test suites compatible with #include <assert.h>
gilles-peskine-arm Jun 7, 2019
deaa5c6
Support MBEDTLS_CHECK_PARAMS defined as assert
gilles-peskine-arm Jun 7, 2019
a7d9d16
config.pl full: enable non-boolean options as well
gilles-peskine-arm Jun 7, 2019
f0d5e73
Fix misuse of signed ints in the HAVEGE module
gilles-peskine-arm Jun 7, 2019
1b5a9f4
Document CSR memory management for mbedtls_x509_csr_parse
gilles-peskine-arm Jun 7, 2019
621c92b
Fix memory leak in x509_csr_check_opaque
gilles-peskine-arm Jun 7, 2019
af8f902
Add Clang+Asan component in the full configuration
gilles-peskine-arm Jun 7, 2019
b0d799e
Don't set PSA_CRYPTO_C if it isn't going to be used
gilles-peskine-arm Jun 7, 2019
49997f5
Update crypto submodule to the precursor branch
gilles-peskine-arm Jun 7, 2019
8a5bf34
Only "veryfull" enables module configuration options
gilles-peskine-arm Jun 11, 2019
8ec70a1
Switch some tests to the veryfull config
gilles-peskine-arm Jun 11, 2019
a27a6f7
Remove obsolete options from config.pl
gilles-peskine-arm Jun 11, 2019
5823888
Document why configuration options are excluded from full
gilles-peskine-arm Jun 11, 2019
6a0668d
Remove redundant comment
gilles-peskine-arm Jun 11, 2019
fe00d0a
Don't uncomment MBEDTLS_SSL_CIPHERSUITES in veryfull config
gilles-peskine-arm Jun 11, 2019
bf8525e
config.pl full: enable MBEDTLS_PLATFORM_xxx_yyy_ALT too
gilles-peskine-arm Jun 11, 2019
e33c713
Remove mbedtls_param_failed from programs
gilles-peskine-arm Jun 12, 2019
9d79d83
Move MBEDTLS_PARAM_FAILED to the "System support" section
gilles-peskine-arm Jun 12, 2019
83c1121
Add all.sh component that exercises invalid_param checks
gilles-peskine-arm Jun 12, 2019
84847d5
Macros with arguments aren't features
gilles-peskine-arm Jun 12, 2019
e902502
Update crypto submodule on the precursor branch
gilles-peskine-arm Jun 12, 2019
4e84309
config.pl full: Exclude MBEDTLS_ENTROPY_FORCE_SHA256
gilles-peskine-arm Jun 12, 2019
24ecfba
all.sh: Test MBEDTLS_ENTROPY_FORCE_SHA256
gilles-peskine-arm Jun 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ Bugfix
* Set the next sequence of the subject_alt_name to NULL when deleting
sequence on failure. Found and fix suggested by Philippe Antoine.
Credit to OSS-Fuzz.
* Support MBEDTLS_CHECK_PARAMS defined as assert as suggested in config.h.
#2671
* Fix misuse of signed arithmetic in the HAVEGE module. #2598

API Changes
* Extend the MBEDTLS_SSL_EXPORT_KEYS to export the handshake randbytes,
and the used tls-prf.
* Add public API for tls-prf function, according to requested enum.
* The HAVEGE state type now uses uint32_t elements instead of int.

Changes
* Server's RSA certificate in certs.c was SHA-1 signed. In the default
Expand Down
200 changes: 100 additions & 100 deletions include/mbedtls/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@
*/
#define MBEDTLS_HAVE_TIME_DATE

/**
* Uncomment the macro to let Mbed TLS use your alternate implementation of
* mbedtls_platform_gmtime_r(). This replaces the default implementation in
* platform_util.c.
*
* gmtime() is not a thread-safe function as defined in the C standard. The
* library will try to use safer implementations of this function, such as
* gmtime_r() when available. However, if Mbed TLS cannot identify the target
* system, the implementation of mbedtls_platform_gmtime_r() will default to
* using the standard gmtime(). In this case, calls from the library to
* gmtime() will be guarded by the global mutex mbedtls_threading_gmtime_mutex
* if MBEDTLS_THREADING_C is enabled. We recommend that calls from outside the
* library are also guarded with this mutex to avoid race conditions. However,
* if the macro MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, Mbed TLS will
* unconditionally use the implementation for mbedtls_platform_gmtime_r()
* supplied at compile time.
*/
//#define MBEDTLS_PLATFORM_GMTIME_R_ALT

/**
* \def MBEDTLS_PLATFORM_MEMORY
*
Expand Down Expand Up @@ -230,6 +249,26 @@
//#define MBEDTLS_PLATFORM_NV_SEED_ALT
//#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT

/**
* Uncomment the macro to let mbed TLS use your alternate implementation of
* mbedtls_platform_zeroize(). This replaces the default implementation in
* platform_util.c.
*
* mbedtls_platform_zeroize() is a widely used function across the library to
* zero a block of memory. The implementation is expected to be secure in the
* sense that it has been written to prevent the compiler from removing calls
* to mbedtls_platform_zeroize() as part of redundant code elimination
* optimizations. However, it is difficult to guarantee that calls to
* mbedtls_platform_zeroize() will not be optimized by the compiler as older
* versions of the C language standards do not provide a secure implementation
* of memset(). Therefore, MBEDTLS_PLATFORM_ZEROIZE_ALT enables users to
* configure their own implementation of mbedtls_platform_zeroize(), for
* example by using directives specific to their compiler, features from newer
* C standards (e.g using memset_s() in C11) or calling a secure memset() from
* their system (e.g explicit_bzero() in BSD).
*/
//#define MBEDTLS_PLATFORM_ZEROIZE_ALT

/**
* \def MBEDTLS_DEPRECATED_WARNING
*
Expand Down Expand Up @@ -299,6 +338,36 @@
*/
//#define MBEDTLS_CHECK_PARAMS

/**
* \brief This macro is invoked by the library when an invalid parameter
* is detected that is only checked with MBEDTLS_CHECK_PARAMS
* (see the documentation of that option for context).
*
* When you leave this undefined here, a default definition is
* provided that invokes the function mbedtls_param_failed(),
* which is declared in platform_util.h for the benefit of the
* library, but that you need to define in your application.
*
* When you define this here, this replaces the default
* definition in platform_util.h (which no longer declares the
* function mbedtls_param_failed()) and it is your responsibility
* to make sure this macro expands to something suitable (in
* particular, that all the necessary declarations are visible
* from within the library - you can ensure that by providing
* them in this file next to the macro definition).
*
* Note that you may define this macro to expand to nothing, in
* which case you don't have to worry about declarations or
* definitions. However, you will then be notified about invalid
* parameters only in non-void functions, and void function will
* just silently return early on invalid parameters, which
* partially negates the benefits of enabling
* #MBEDTLS_CHECK_PARAMS in the first place, so is discouraged.
*
* \param cond The expression that should evaluate to true, but doesn't.
*/
//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )

/* \} name SECTION: System support */

/**
Expand Down Expand Up @@ -1701,6 +1770,37 @@
*/
//#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT

/**
* Allow SHA-1 in the default TLS configuration for certificate signing.
* Without this build-time option, SHA-1 support must be activated explicitly
* through mbedtls_ssl_conf_cert_profile. Turning on this option is not
* recommended because of it is possible to generate SHA-1 collisions, however
* this may be safe for legacy infrastructure where additional controls apply.
*
* \warning SHA-1 is considered a weak message digest and its use constitutes
* a security risk. If possible, we recommend avoiding dependencies
* on it, and considering stronger message digests instead.
*
*/
// #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES

/**
* Allow SHA-1 in the default TLS configuration for TLS 1.2 handshake
* signature and ciphersuite selection. Without this build-time option, SHA-1
* support must be activated explicitly through mbedtls_ssl_conf_sig_hashes.
* The use of SHA-1 in TLS <= 1.1 and in HMAC-SHA-1 is always allowed by
* default. At the time of writing, there is no practical attack on the use
* of SHA-1 in handshake signatures, hence this option is turned on by default
* to preserve compatibility with existing peers, but the general
* warning applies nonetheless:
*
* \warning SHA-1 is considered a weak message digest and its use constitutes
* a security risk. If possible, we recommend avoiding dependencies
* on it, and considering stronger message digests instead.
*
*/
#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE

/**
* \def MBEDTLS_THREADING_ALT
*
Expand Down Expand Up @@ -3226,36 +3326,6 @@
//#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
//#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */

/**
* \brief This macro is invoked by the library when an invalid parameter
* is detected that is only checked with MBEDTLS_CHECK_PARAMS
* (see the documentation of that option for context).
*
* When you leave this undefined here, a default definition is
* provided that invokes the function mbedtls_param_failed(),
* which is declared in platform_util.h for the benefit of the
* library, but that you need to define in your application.
*
* When you define this here, this replaces the default
* definition in platform_util.h (which no longer declares the
* function mbedtls_param_failed()) and it is your responsibility
* to make sure this macro expands to something suitable (in
* particular, that all the necessary declarations are visible
* from within the library - you can ensure that by providing
* them in this file next to the macro definition).
*
* Note that you may define this macro to expand to nothing, in
* which case you don't have to worry about declarations or
* definitions. However, you will then be notified about invalid
* parameters only in non-void functions, and void function will
* just silently return early on invalid parameters, which
* partially negates the benefits of enabling
* #MBEDTLS_CHECK_PARAMS in the first place, so is discouraged.
*
* \param cond The expression that should evaluate to true, but doesn't.
*/
//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )

/* SSL Cache options */
//#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */
//#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */
Expand Down Expand Up @@ -3376,76 +3446,6 @@
//#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */
//#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum length of a path/filename string in bytes including the null terminator character ('\0'). */

/**
* Allow SHA-1 in the default TLS configuration for certificate signing.
* Without this build-time option, SHA-1 support must be activated explicitly
* through mbedtls_ssl_conf_cert_profile. Turning on this option is not
* recommended because of it is possible to generate SHA-1 collisions, however
* this may be safe for legacy infrastructure where additional controls apply.
*
* \warning SHA-1 is considered a weak message digest and its use constitutes
* a security risk. If possible, we recommend avoiding dependencies
* on it, and considering stronger message digests instead.
*
*/
// #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES

/**
* Allow SHA-1 in the default TLS configuration for TLS 1.2 handshake
* signature and ciphersuite selection. Without this build-time option, SHA-1
* support must be activated explicitly through mbedtls_ssl_conf_sig_hashes.
* The use of SHA-1 in TLS <= 1.1 and in HMAC-SHA-1 is always allowed by
* default. At the time of writing, there is no practical attack on the use
* of SHA-1 in handshake signatures, hence this option is turned on by default
* to preserve compatibility with existing peers, but the general
* warning applies nonetheless:
*
* \warning SHA-1 is considered a weak message digest and its use constitutes
* a security risk. If possible, we recommend avoiding dependencies
* on it, and considering stronger message digests instead.
*
*/
#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE

/**
* Uncomment the macro to let mbed TLS use your alternate implementation of
* mbedtls_platform_zeroize(). This replaces the default implementation in
* platform_util.c.
*
* mbedtls_platform_zeroize() is a widely used function across the library to
* zero a block of memory. The implementation is expected to be secure in the
* sense that it has been written to prevent the compiler from removing calls
* to mbedtls_platform_zeroize() as part of redundant code elimination
* optimizations. However, it is difficult to guarantee that calls to
* mbedtls_platform_zeroize() will not be optimized by the compiler as older
* versions of the C language standards do not provide a secure implementation
* of memset(). Therefore, MBEDTLS_PLATFORM_ZEROIZE_ALT enables users to
* configure their own implementation of mbedtls_platform_zeroize(), for
* example by using directives specific to their compiler, features from newer
* C standards (e.g using memset_s() in C11) or calling a secure memset() from
* their system (e.g explicit_bzero() in BSD).
*/
//#define MBEDTLS_PLATFORM_ZEROIZE_ALT

/**
* Uncomment the macro to let Mbed TLS use your alternate implementation of
* mbedtls_platform_gmtime_r(). This replaces the default implementation in
* platform_util.c.
*
* gmtime() is not a thread-safe function as defined in the C standard. The
* library will try to use safer implementations of this function, such as
* gmtime_r() when available. However, if Mbed TLS cannot identify the target
* system, the implementation of mbedtls_platform_gmtime_r() will default to
* using the standard gmtime(). In this case, calls from the library to
* gmtime() will be guarded by the global mutex mbedtls_threading_gmtime_mutex
* if MBEDTLS_THREADING_C is enabled. We recommend that calls from outside the
* library are also guarded with this mutex to avoid race conditions. However,
* if the macro MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, Mbed TLS will
* unconditionally use the implementation for mbedtls_platform_gmtime_r()
* supplied at compile time.
*/
//#define MBEDTLS_PLATFORM_GMTIME_R_ALT

/* \} name SECTION: Customisation configuration options */

/* Target and application specific configurations
Expand Down
7 changes: 4 additions & 3 deletions include/mbedtls/havege.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#endif

#include <stddef.h>
#include <stdint.h>

#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024

Expand All @@ -43,9 +44,9 @@ extern "C" {
*/
typedef struct mbedtls_havege_state
{
int PT1, PT2, offset[2];
int pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
int WALK[8192];
uint32_t PT1, PT2, offset[2];
uint32_t pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
uint32_t WALK[8192];
}
mbedtls_havege_state;

Expand Down
4 changes: 4 additions & 0 deletions include/mbedtls/platform_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ extern "C" {

#if defined(MBEDTLS_CHECK_PARAMS)

/* Allow the user to define MBEDTLS_PARAM_FAILED to something like assert
* (which is what our config.h suggests). */
#include <assert.h>

#if defined(MBEDTLS_PARAM_FAILED)
/** An alternative definition of MBEDTLS_PARAM_FAILED has been set in config.h.
*
Expand Down
30 changes: 21 additions & 9 deletions include/mbedtls/x509_csr.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ mbedtls_x509write_csr;
*
* \note CSR attributes (if any) are currently silently ignored.
*
* \param csr CSR context to fill
* \param buf buffer holding the CRL data
* \param buflen size of the buffer
* \param csr CSR context to fill. This must be a pointer to a
* structure which does not need to be already initialized
* and which must not be already in use. You must eventually
* free it with mbedtls_x509_csr_free() whether this function
* succeeds or fails.
* \param buf Buffer holding the CRL data.
* \param buflen Size of the buffer.
*
* \return 0 if successful, or a specific X509 error code
*/
Expand All @@ -100,10 +104,14 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
*
* \note See notes for \c mbedtls_x509_csr_parse_der()
*
* \param csr CSR context to fill
* \param buf buffer holding the CRL data
* \param buflen size of the buffer
* (including the terminating null byte for PEM data)
* \param csr CSR context to fill. This must be a pointer to a
* structure which does not need to be already initialized
* and which must not be already in use. You must eventually
* free it with mbedtls_x509_csr_free() whether this function
* succeeds or fails.
* \param buf Buffer holding the CRL data.
* \param buflen Size of the buffer
* (including the terminating null byte for PEM data).
*
* \return 0 if successful, or a specific X509 or PEM error code
*/
Expand All @@ -115,8 +123,12 @@ int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, siz
*
* \note See notes for \c mbedtls_x509_csr_parse()
*
* \param csr CSR context to fill
* \param path filename to read the CSR from
* \param csr CSR context to fill. This must be a pointer to a
* structure which does not need to be already initialized
* and which must not be already in use. You must eventually
* free it with mbedtls_x509_csr_free() whether this function
* succeeds or fails.
* \param path File name to read the CSR from.
*
* \return 0 if successful, or a specific X509 or PEM error code
*/
Expand Down
12 changes: 12 additions & 0 deletions library/version_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ static const char *features[] = {
#if defined(MBEDTLS_HAVE_TIME_DATE)
"MBEDTLS_HAVE_TIME_DATE",
#endif /* MBEDTLS_HAVE_TIME_DATE */
#if defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)
"MBEDTLS_PLATFORM_GMTIME_R_ALT",
#endif /* MBEDTLS_PLATFORM_GMTIME_R_ALT */
#if defined(MBEDTLS_PLATFORM_MEMORY)
"MBEDTLS_PLATFORM_MEMORY",
#endif /* MBEDTLS_PLATFORM_MEMORY */
Expand Down Expand Up @@ -81,6 +84,9 @@ static const char *features[] = {
#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
"MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT",
#endif /* MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
#if defined(MBEDTLS_PLATFORM_ZEROIZE_ALT)
"MBEDTLS_PLATFORM_ZEROIZE_ALT",
#endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */
#if defined(MBEDTLS_DEPRECATED_WARNING)
"MBEDTLS_DEPRECATED_WARNING",
#endif /* MBEDTLS_DEPRECATED_WARNING */
Expand Down Expand Up @@ -528,6 +534,12 @@ static const char *features[] = {
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT)
"MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT",
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT */
#if defined(MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES)
"MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES",
#endif /* MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES */
#if defined(MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE)
"MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE",
#endif /* MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE */
#if defined(MBEDTLS_THREADING_ALT)
"MBEDTLS_THREADING_ALT",
#endif /* MBEDTLS_THREADING_ALT */
Expand Down
4 changes: 2 additions & 2 deletions programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ LOCAL_CFLAGS += -I../crypto/include
LOCAL_CXXFLAGS += -I../crypto/include

ifndef SHARED
DEP=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
DEP=../crypto/library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
else
DEP=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
DEP=../crypto/library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
endif

ifdef DEBUG
Expand Down
Loading