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

Test TLS 1.2 builds with each encryption type #6374

Merged
merged 23 commits into from
Oct 12, 2022

Conversation

mprse
Copy link
Contributor

@mprse mprse commented Sep 27, 2022

Description

Resolves #6313

Status

READY

Requires Backporting

Yes/2.28
#6394

Migrations

NO

Additional comments

Any additional information that could be of interest

Todos

  • null cipher
  • only CBC-legacy (no EtM)
  • only CBC-legacy and CBC-EtM

Both functions are used when MBEDTLS_SSL_SOME_SUITES_USE_MAC is defined not MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC.

Signed-off-by: Przemek Stekiel <[email protected]>
…e() functions

Both functions are calling mbedtls_cipher_auth_[encrypt/decrypt]_ext() functions. These functions are guarded with MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C flags - make it consistent.
As a result ssl_server2 won't build now with MBEDTLS_SSL_SESSION_TICKETS enabled (mbedtls_cipher_auth_[encrypt/decrypt]_ext() functions not available).
Mark MBEDTLS_SSL_SESSION_TICKETS as dependent on MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C and disable MBEDTLS_SSL_SESSION_TICKETS in stream cipher only build.

Signed-off-by: Przemek Stekiel <[email protected]>
It is done to have MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH macro available (used in tests)

Signed-off-by: Przemek Stekiel <[email protected]>
@mprse mprse added needs-work needs-ci Needs to pass CI tests priority-high High priority - will be reviewed soon labels Sep 27, 2022
@mprse
Copy link
Contributor Author

mprse commented Sep 27, 2022

@mpg I wasn't sure if this is going in the right direction a specially part with disabling MBEDTLS_SSL_SESSION_TICKETS, so I created this work in progress PR.
Currently I am able to build default configuration with stream cipher only, but still one test is failing:

DTLS Handshake with serialization, tls1_2 ......................... FAILED
  mbedtls_ssl_context_save( &(server.ssl), NULL, 0, &context_buf_len ) == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL
  at step 1, line 2303, suites/test_suite_ssl.function
  lhs = 0xffffffffffff8f00 = -28928
  rhs = 0xffffffffffff9600 = -27136

It is failing because mbedtls_ssl_context_save() function returns MBEDTLS_ERR_SSL_BAD_INPUT_DATA due to the fillowing check:

mbedtls/library/ssl_tls.c

Lines 3807 to 3812 in 5596c74

/* We must be using an AEAD ciphersuite */
if( mbedtls_ssl_transform_uses_aead( ssl->transform ) != 1 )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "Only AEAD ciphersuites supported" ) );
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
}

I assume that the check fails correctly as AEAD is disabled, so probably this test should be skipped.
The condition to check AEAD is also unclear to me (is MBEDTLS_SSL_SOME_SUITES_USE_MAC guard correct):

mbedtls/library/ssl_misc.h

Lines 1041 to 1050 in 5596c74

static inline int mbedtls_ssl_transform_uses_aead(
const mbedtls_ssl_transform *transform )
{
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
return( transform->maclen == 0 && transform->taglen != 0 );
#else
(void) transform;
return( 1 );
#endif
}

@gilles-peskine-arm
Copy link
Contributor

I assume that the check fails correctly as AEAD is disabled, so probably this test should be skipped.

Right, it makes sense that mbedtls_ssl_context_save returns a “I can't do this at all” error in this situation, which has precedence over the usual “I could do this if the buffer was bigger”. Since handshake serialization is only implemented with AEAD, there should probably be a requirement in check_config.h (and then MBEDTLS_SSL_CONTEXT_SERIALIZATION should be disabled in this non-AEAD build).

is MBEDTLS_SSL_SOME_SUITES_USE_MAC guard correct

Looks correct to me: all supported cipher suites either have a MAC or an AEAD tag (we don't implement the NULL_NULL cipher suite which has no security at all, only cipher suites with authentication but where the encryption may be NULL). If there are MAC cipher suites in the build then we check whether the selected cipher suite uses AEAD; if there are no MAC cipher suites then the selected cipher suite must be AEAD.

@mprse mprse changed the title Test TLS 1.2 builds with stream(null) encryption type Test TLS 1.2 builds with each encryption type Sep 28, 2022
@mprse mprse added needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review and removed needs-work labels Sep 28, 2022
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

Just a first quick review for early feedback.

@@ -1274,6 +1274,38 @@ component_test_crypto_full_no_cipher () {
make test
}

component_test_crypto_default_stream_cipher_only () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming: I'm not sure "crypto" is meaningful here. Since this test (and the other two that are coming) are motivated by the risk for issues with TLS 1.2 when only one of its encryption modes is active, I think tls1_2 would make more sense.

scripts/config.py unset MBEDTLS_CHACHAPOLY_C
# CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
scripts/config.py unset MBEDTLS_AES_C
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to disable all those ciphers, just disabling CIPHER_MODE_CBC is enough. I think also disabling the ciphers just add clutter (especially with things that depend on AES).

# CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
# stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER)
scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it potentially confusing that unset this here and set is a few lines below.

tests/scripts/all.sh Show resolved Hide resolved
library/ssl_ticket.c Outdated Show resolved Hide resolved
library/psa_crypto.c Show resolved Hide resolved
tests/scripts/all.sh Outdated Show resolved Hide resolved
@mprse
Copy link
Contributor Author

mprse commented Sep 29, 2022

While addressing review comments and optimizing components setup I encountered strange failure:

CMAC init #7 Camellia: wrong cipher ............................... FAILED
  ( cipher_info = mbedtls_cipher_info_from_type( cipher_type ) ) != NULL
  at line 112, suites/test_suite_cmac.function

Test case:

CMAC init #7 Camellia: wrong cipher
depends_on:MBEDTLS_CAMELLIA_C
mbedtls_cmac_setkey:MBEDTLS_CIPHER_ID_CAMELLIA:128:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA

MBEDTLS_CIPHER_ID_CAMELLIA is cipher id and it is used as cipher type? This is wrong usage. It is probably done to achieve MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA returned by mbedtls_cipher_cmac(), but now mbedtls_cipher_info_from_type() fails.
MBEDTLS_CIPHER_ID_CAMELLIA is treated as MBEDTLS_CIPHER_AES_128_CBC which in stream cipher only config is disabled.

The test case description says CMAC init #7 Camellia: wrong cipher , but it is unclear to me that we are testing here.

@mpg
Copy link
Contributor

mpg commented Sep 29, 2022

Ah, each time we add tests we uncover new and in this case pretty unexpected bugs!

I think test cases 5 to 7 are wrong in that they use a cipher ID where a cipher type is expected, as you say. I think cases 5 and 6 should use MBEDTLS_CIPHER_AES_128_ECB and case 7 should use MBEDTLS_CIPHER_CAMELLIA_128_ECB - this test is about checking that only AES and 3DES are accepted (because CMAC is defined by NIST, and AES and 3DES are the only NIST-approved block ciphers).

mpg
mpg previously approved these changes Oct 10, 2022
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

LGTM

@mpg mpg added approved Design and code approved - may be waiting for CI or backports needs-backports Backports are missing or are pending review and approval. and removed needs-review Every commit must be reviewed by at least two team members, labels Oct 10, 2022
@@ -874,6 +874,11 @@
#error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites"
#endif

#if defined(MBEDTLS_SSL_TICKET_C) && \
!( defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) || defined(MBEDTLS_CHACHAPOLY_C) )
#error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites"
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: double space

@@ -1404,7 +1404,7 @@ int main( int argc, char *argv[] )
#if defined(MBEDTLS_SSL_CACHE_C)
mbedtls_ssl_cache_context cache;
#endif
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_TICKET_C)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ifdef at line 286 - missing MBEDTLS_SSL_TICKET_C

Copy link
Contributor

Choose a reason for hiding this comment

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

@mprse I believe it's about the guards around USAGE_TICKETS near the top of the file. It's not a major issue (the worst that will happen is that the usage message will mention options that are not actually available in some configs), but not that Andrzej spotted it, we might as well fix it.

Copy link
Contributor Author

@mprse mprse Oct 11, 2022

Choose a reason for hiding this comment

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

Yup. I hope it is ok now (force-pushed the last commit).

@AndrzejKurek AndrzejKurek added needs-work and removed approved Design and code approved - may be waiting for CI or backports labels Oct 10, 2022
Copy link
Contributor

@AndrzejKurek AndrzejKurek left a comment

Choose a reason for hiding this comment

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

Please fix the missing ifdef around the usage text.

@mprse mprse added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Oct 11, 2022
@mprse mprse requested review from AndrzejKurek and mpg October 11, 2022 06:42
Signed-off-by: Przemek Stekiel <[email protected]>
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

LGTM

@mpg mpg added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, needs-backports Backports are missing or are pending review and approval. labels Oct 11, 2022
@mprse
Copy link
Contributor Author

mprse commented Oct 12, 2022

This one together with backport seems to be ready for merge, but I'm not sure about the CI. There is windows build failure, but looks unrelated.

@gilles-peskine-arm
Copy link
Contributor

The Windows failure on OpenCI is an infrastructure glitch and the armcc failure is a known infrastructure issue. The Arm CI passed so this PR has passed the CI.

@gilles-peskine-arm gilles-peskine-arm removed the needs-ci Needs to pass CI tests label Oct 12, 2022
@gilles-peskine-arm gilles-peskine-arm merged commit 8fd3254 into Mbed-TLS:development Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports priority-high High priority - will be reviewed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test TLS 1.2 builds with each encryption type
4 participants