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

Backport 2.28: Run ssl-opt.sh in more reduced configurations #5730

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7c45b67
Fix the build when MBEDTLS_PLATFORM_C is unset
gilles-peskine-arm Feb 25, 2022
a132beb
Minimal TLS configuration: documentation improvements
gilles-peskine-arm Feb 25, 2022
8c5c293
New sample/test configuration: small DTLS 1.2
gilles-peskine-arm Feb 25, 2022
83f7108
Small DTLS 1.2 config: timing is a default entropy source
gilles-peskine-arm Apr 8, 2022
e5f4958
ssl-opt: automatically skip DTLS tests in builds without DTLS
gilles-peskine-arm Feb 25, 2022
4502671
Automatically skip tests for some absent features: tickets, ALPN
gilles-peskine-arm Feb 25, 2022
df4ad90
ssl-opt: check for protocol version support
gilles-peskine-arm Apr 8, 2022
dff48c1
Only run "Default" tests if the ciphersuite is enabled
gilles-peskine-arm Feb 25, 2022
111fde4
Add some missing dependencies: EXTENDED_MASTER_SECRET, CACHE
gilles-peskine-arm Feb 25, 2022
89d892f
Adapt tests for PSK in PSK-only builds
gilles-peskine-arm Feb 25, 2022
dcb13af
ssl-opt needs debug messages
gilles-peskine-arm Feb 25, 2022
291372f
Add a missing requires_max_content_len
gilles-peskine-arm Feb 25, 2022
20e25b9
Simplify the logic to select configurations
gilles-peskine-arm Feb 26, 2022
def0e14
test-ref-configs: clarify configuration-related traces
gilles-peskine-arm Mar 14, 2022
64c683f
calc_verify is only called in some configurations
gilles-peskine-arm Mar 14, 2022
22cc649
Skip some DTLS reordering tests in PSK-only builds
gilles-peskine-arm Mar 14, 2022
e719d17
Minor documentation improvement
gilles-peskine-arm Apr 5, 2022
d5b1a30
Documentation improvements
gilles-peskine-arm Apr 5, 2022
de4cb35
Add requirements of "Default"
gilles-peskine-arm Apr 5, 2022
f2e1f47
set_maybe_calc_verify: $1 is intended to be auth_mode
gilles-peskine-arm Apr 6, 2022
736d91d
Fix buffer size calculation
gilles-peskine-arm Apr 6, 2022
a30439a
Fix off-by-one in buffer_size usage
gilles-peskine-arm Apr 6, 2022
5a1b3bd
Make mbedtls_ssl_get_bytes_avail tests more independent
gilles-peskine-arm Apr 6, 2022
e70605c
Add requirement for RC4 tests
gilles-peskine-arm Apr 8, 2022
511fdf4
Prepare to generalize maybe_requires_ciphersuite_enabled
gilles-peskine-arm Apr 8, 2022
3c985f6
Move ticket, alpn detection into maybe_requires_ciphersuite_enabled
gilles-peskine-arm Apr 8, 2022
4b137d1
Automatically detect protocol version requirement from force_version
gilles-peskine-arm Apr 8, 2022
bba3b4c
Add or fix requirements on FALLBACK_SCSV
gilles-peskine-arm Apr 8, 2022
bcb2ab0
Add a few more protocol version support requirements
gilles-peskine-arm Apr 8, 2022
a6f99a1
Fix crash with DTLS_CONNECTION_ID but not other SSL features
gilles-peskine-arm Apr 13, 2022
6e257b0
Detect requirement on DTLS_BADMAC_LIMIT
gilles-peskine-arm Apr 13, 2022
9220fee
Enable DTLS_BADMAC_LIMIT
gilles-peskine-arm Apr 13, 2022
add21ad
Fix typo in config symbol
gilles-peskine-arm Apr 15, 2022
719a652
Fix REMOVE_ARC4 test case dependencies
gilles-peskine-arm Apr 15, 2022
e8133cb
test_cmake_out_of_source: validate that ssl-opt passed
gilles-peskine-arm Apr 15, 2022
36019d5
Use terse output from lsof
gilles-peskine-arm Apr 15, 2022
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
5 changes: 5 additions & 0 deletions ChangeLog.d/dtls-cid-null.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix
* In configurations with MBEDTLS_SSL_DTLS_CONNECTION_ID enabled but none of
MBEDTLS_SSL_HW_RECORD_ACCEL, MBEDTLS_SSL_EXPORT_KEYS or MBEDTLS_DEBUG_C,
DTLS handshakes using CID would crash due to a null pointer dereference.
Fix this. Fixes #3998.
110 changes: 110 additions & 0 deletions configs/config-ccm-psk-dtls1_2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* \file config-ccm-psk-dtls1_2.h
*
* \brief Small configuration for DTLS 1.2 with PSK and AES-CCM ciphersuites
*/
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Minimal configuration for DTLS 1.2 with PSK and AES-CCM ciphersuites
*
* Distinguishing features:
* - Optimized for small code size, low bandwidth (on an unreliable transport),
* and low RAM usage.
* - No asymmetric cryptography (no certificates, no Diffie-Hellman key
* exchange).
* - Fully modern and secure (provided the pre-shared keys are generated and
* stored securely).
* - Very low record overhead with CCM-8.
* - Includes several optional DTLS features typically used in IoT.
*
* See README.txt for usage instructions.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H

/* System support */
//#define MBEDTLS_HAVE_TIME /* Optionally used in Hello messages */
/* Other MBEDTLS_HAVE_XXX flags irrelevant for this configuration */

/* Mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_MD_C
#define MBEDTLS_NET_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_COOKIE_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_TIMING_C

/* TLS protocol feature support */
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_PROTO_DTLS
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
#define MBEDTLS_SSL_DTLS_BADMAC_LIMIT
#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
#define MBEDTLS_SSL_DTLS_CONNECTION_ID
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH

/*
* Use only CCM_8 ciphersuites, and
* save ROM and a few bytes of RAM by specifying our own ciphersuite list
*/
#define MBEDTLS_SSL_CIPHERSUITES \
MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, \
MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8

/*
* Save RAM at the expense of interoperability: do this only if you control
* both ends of the connection! (See comments in "mbedtls/ssl.h".)
* The optimal size here depends on the typical size of records.
*/
#define MBEDTLS_SSL_MAX_CONTENT_LEN 256

/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES

/* Save some RAM by adjusting to your exact needs */
#define MBEDTLS_PSK_MAX_LEN 16 /* 128-bits keys are generally enough */

/*
* You should adjust this to the exact number of sources you're using: default
* is the "platform_entropy_poll" source plus a weak clock source, but you may
* want to add other ones. Minimum is 3 for the entropy test suite.
*/
#define MBEDTLS_ENTROPY_MAX_SOURCES 3

/* These defines are present so that the config modifying scripts can enable
* them during tests/scripts/test-ref-configs.pl */
//#define MBEDTLS_USE_PSA_CRYPTO
//#define MBEDTLS_PSA_CRYPTO_C

/* Error messages and TLS debugging traces
* (huge code size increase, needed for tests/ssl-opt.sh) */
//#define MBEDTLS_DEBUG_C
//#define MBEDTLS_ERROR_C

#include "mbedtls/check_config.h"

#endif /* MBEDTLS_CONFIG_H */
51 changes: 30 additions & 21 deletions configs/config-ccm-psk-tls1_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
*/
/*
* Minimal configuration for TLS 1.2 with PSK and AES-CCM ciphersuites
*
* Distinguishing features:
* - no bignum, no PK, no X509
* - fully modern and secure (provided the pre-shared keys have high entropy)
* - very low record overhead with CCM-8
* - optimized for low RAM usage
* - Optimized for small code size, low bandwidth (on a reliable transport),
* and low RAM usage.
* - No asymmetric cryptography (no certificates, no Diffie-Hellman key
* exchange).
* - Fully modern and secure (provided the pre-shared keys are generated and
* stored securely).
* - Very low record overhead with CCM-8.
*
* See README.txt for usage instructions.
*/
Expand All @@ -36,11 +40,7 @@
//#define MBEDTLS_HAVE_TIME /* Optionally used in Hello messages */
/* Other MBEDTLS_HAVE_XXX flags irrelevant for this configuration */

/* mbed TLS feature support */
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_SSL_PROTO_TLS1_2

/* mbed TLS modules */
/* Mbed TLS modules */
#define MBEDTLS_AES_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
Expand All @@ -53,18 +53,9 @@
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C

/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES

/* Save some RAM by adjusting to your exact needs */
#define MBEDTLS_PSK_MAX_LEN 16 /* 128-bits keys are generally enough */

/*
* You should adjust this to the exact number of sources you're using: default
* is the "platform_entropy_poll" source, but you may want to add other ones
* Minimum is 2 for the entropy test suite.
*/
#define MBEDTLS_ENTROPY_MAX_SOURCES 2
/* TLS protocol feature support */
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_SSL_PROTO_TLS1_2

/*
* Use only CCM_8 ciphersuites, and
Expand All @@ -81,11 +72,29 @@
*/
#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024

/* Save RAM at the expense of ROM */
#define MBEDTLS_AES_ROM_TABLES

/* Save some RAM by adjusting to your exact needs */
#define MBEDTLS_PSK_MAX_LEN 16 /* 128-bits keys are generally enough */

/*
* You should adjust this to the exact number of sources you're using: default
* is the "platform_entropy_poll" source, but you may want to add other ones
* Minimum is 2 for the entropy test suite.
*/
#define MBEDTLS_ENTROPY_MAX_SOURCES 2

/* These defines are present so that the config modifying scripts can enable
* them during tests/scripts/test-ref-configs.pl */
//#define MBEDTLS_USE_PSA_CRYPTO
//#define MBEDTLS_PSA_CRYPTO_C

/* Error messages and TLS debugging traces
* (huge code size increase, needed for tests/ssl-opt.sh) */
//#define MBEDTLS_DEBUG_C
//#define MBEDTLS_ERROR_C

#include "mbedtls/check_config.h"

#endif /* MBEDTLS_CONFIG_H */
5 changes: 5 additions & 0 deletions configs/config-mini-tls1_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@
#endif
#include "mbedtls/check_config.h"

/* Error messages and TLS debugging traces
* (huge code size increase, needed for tests/ssl-opt.sh) */
//#define MBEDTLS_DEBUG_C
//#define MBEDTLS_ERROR_C

#endif /* MBEDTLS_CONFIG_H */
5 changes: 5 additions & 0 deletions configs/config-suite-b.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
#define MBEDTLS_PK_WRITE_C
#endif

/* Error messages and TLS debugging traces
* (huge code size increase, needed for tests/ssl-opt.sh) */
//#define MBEDTLS_DEBUG_C
//#define MBEDTLS_ERROR_C

#include "mbedtls/check_config.h"

#endif /* MBEDTLS_CONFIG_H */
1 change: 1 addition & 0 deletions library/ssl_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,

#if !defined(MBEDTLS_SSL_HW_RECORD_ACCEL) && \
!defined(MBEDTLS_SSL_EXPORT_KEYS) && \
!defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
!defined(MBEDTLS_DEBUG_C)
ssl = NULL; /* make sure we don't use it except for those cases */
(void) ssl;
Expand Down
29 changes: 22 additions & 7 deletions programs/ssl/ssl_server2.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ int main( void )

/*
* Size of the basic I/O buffer. Able to hold our default response.
*
* You will need to adapt the mbedtls_ssl_get_bytes_avail() test in ssl-opt.sh
* if you change this value to something outside the range <= 100 or > 500
*/
#define DFL_IO_BUF_LEN 200

Expand Down Expand Up @@ -2032,10 +2029,26 @@ int main( int argc, char *argv[] )
#if defined(MBEDTLS_DEBUG_C)
mbedtls_debug_set_threshold( opt.debug_level );
#endif
buf = mbedtls_calloc( 1, opt.buffer_size + 1 );

/* buf will alternatively contain the input read from the client and the
* response that's about to be sent, plus a null byte in each case. */
size_t buf_content_size = opt.buffer_size;
/* The default response contains the ciphersuite name. Leave enough
* room for that plus some margin. */
if( buf_content_size < strlen( HTTP_RESPONSE ) + 80 )
{
buf_content_size = strlen( HTTP_RESPONSE ) + 80;
}
if( opt.response_size != DFL_RESPONSE_SIZE &&
buf_content_size < (size_t) opt.response_size )
{
buf_content_size = opt.response_size;
}
buf = mbedtls_calloc( 1, buf_content_size + 1 );
if( buf == NULL )
{
mbedtls_printf( "Could not allocate %u bytes\n", opt.buffer_size );
mbedtls_printf( "Could not allocate %lu bytes\n",
(unsigned long) buf_content_size + 1 );
ret = 3;
goto exit;
}
Expand Down Expand Up @@ -3451,7 +3464,7 @@ int main( int argc, char *argv[] )
do
{
int terminated = 0;
len = opt.buffer_size - 1;
len = opt.buffer_size;
memset( buf, 0, opt.buffer_size );
ret = mbedtls_ssl_read( &ssl, buf, len );

Expand Down Expand Up @@ -3552,7 +3565,7 @@ int main( int argc, char *argv[] )
}
else /* Not stream, so datagram */
{
len = opt.buffer_size - 1;
len = opt.buffer_size;
memset( buf, 0, opt.buffer_size );

do
Expand Down Expand Up @@ -3654,6 +3667,8 @@ int main( int argc, char *argv[] )
mbedtls_printf( " > Write to client:" );
fflush( stdout );

/* If the format of the response changes, make sure there is enough
* room in buf (buf_content_size calculation above). */
len = sprintf( (char *) buf, HTTP_RESPONSE,
mbedtls_ssl_get_ciphersuite( &ssl ) );

Expand Down
3 changes: 2 additions & 1 deletion programs/test/dlopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
#include MBEDTLS_CONFIG_FILE
#endif

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#if !defined(MBEDTLS_PLATFORM_C)
#else
#include <stdio.h>
#include <stdlib.h>
#define mbedtls_fprintf fprintf
Expand Down
5 changes: 3 additions & 2 deletions tests/scripts/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2983,11 +2983,12 @@ component_test_cmake_out_of_source () {
# "No such file or directory", which would indicate that some required
# file is missing (ssl-opt.sh tolerates the absence of some files so
# may exit with status 0 but emit errors).
./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
grep PASS ssl-opt.out
cat ssl-opt.err >&2
# If ssl-opt.err is non-empty, record an error and keep going.
[ ! -s ssl-opt.err ]
rm ssl-opt.err
rm ssl-opt.out ssl-opt.err
cd "$MBEDTLS_ROOT_DIR"
rm -rf "$OUT_OF_SOURCE_DIR"
}
Expand Down
Loading