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

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Apr 13, 2022

This is an incremental improvement to the ability to run tests/ssl-opt.sh in reduced configurations. The main completeness goals is for it to pass on config/config-ccm-psk-dtls1_2.h and config-suite-b.h, and to be roughly aligned with the 3.1 version. Beyond that, there are a few miscellaneous improvements in automatic requirement detection.

Changes in the 2.28 version compared to the 3.1 version:

  • No MBEDTLS_SHA224_C.
  • MBEDTLS_SSL_MAX_CONTENT_LEN instead of {IN,OUT}.
  • Adapted the new configs/config-ccm-psk-dtls1_2.h so that it's a DTLS
    adaptation of 2.28's configs/config-ccm-psk-tls1_2.h rather than a
    direct drop-in of the 3.1 version.
  • configs/config-ccm-psk-dtls1_2.h has an extra entropy source (hardclock)
    which was removed in 3.0.
  • ssl-opt.sh had fewer requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 so I made an additional commit for that. Most of those were introduced in 3.x in ab08290 from TLS1.3:Enable tls13 only build #5362, but that was about 1.2 vs 1.3 and many of the places that added "needs 1.2" are actually "needs ≤1.2" and thus should not be there in 2.28. As a result of not needing a specific version for many test cases, there are many rebase conflicts in commits that add some other config requirement to test cases.
  • "Remove negative check for a message that no longer exists" does not apply
    in 2.28 where the message in question exists.
  • "Fix unused function warning" touches code that does not exist in 2.28.
  • Additional commits to handle some RC4-specific stuff.
  • Additional commit to handle fallback SCSV.
  • Additional commit "Add a few more protocol version support requirements".
  • Handle MBEDTLS_SSL_DTLS_BADMAC_LIMIT (which was removed in 3.0) in
    ssl-opt.sh. Enable it in configs/config-ccm-psk-dtls1_2.h anyway.
  • Fix Null pointer usage in ssl_tls.c in a non-default config #3998 (we'd fixed it in development but not backported the fix).

An additional reference config exists: configs/config-mini-tls1_1.h. It would be good to run ssl-opt.sh in this configuration, but this would require a lot of extra work in ssl-opt.sh. I've started working on it, but it would delay and grow this backport significantly, so I've filed it for future work.

Some of the options have been moved around, but there are no semantic
changes.

Signed-off-by: Gilles Peskine <[email protected]>
1. Copy config-ccm-psk-tls1_2.h
2. Add DTLS support
3. Add some TLS and DTLS features that are useful in low-bandwidth,
   low-reliability networks
4. Reduce the SSL buffer to a very small size

Signed-off-by: Gilles Peskine <[email protected]>
Since MBEDTLS_TIMING_C is enabled, mbedtls_entropy_init() adds the weak
source MBEDTLS_ENTROPY_MAX_SOURCES(). With mbedtls_platform_entropy_poll(),
this makes two sources. The unit tests need room for a third source.

Signed-off-by: Gilles Peskine <[email protected]>
Skip tests that require a specific version of the protocol if that version
is disabled at compile time.

This commit only partially does the job, mostly covering tests that check
the protocol version in client or server logs. It is not intended to be
exhaustive; in particular many uses of force_version are not covered (I
think they should instead be covered automatically, but this is out of scope
of the current commit).

Signed-off-by: Gilles Peskine <[email protected]>
These tests ensure that a certain cipher suite is in use, so they fail in
builds that lack one of the corresponding algorithms.

Signed-off-by: Gilles Peskine <[email protected]>
This commit is not necessarily complete, but it's a step forward.

Signed-off-by: Gilles Peskine <[email protected]>
In a PSK-only build:
* Skip tests that rely on a specific non-PSK cipher suite.
* Skip tests that exercise a certificate authentication feature.
* Pass a pre-shared key in tests that don't mind the key exchange type.

This commit only considers PSK-only builds vs builds with certificates. It
does not aim to do something useful for builds with an asymmetric key
exchange and a pre-shared key for authentication.

Signed-off-by: Gilles Peskine <[email protected]>
Many test cases in ssl-opt.sh need error messages (MBEDTLS_ERROR_C) or SSL
traces (MBEDTLS_DEBUG_C). Some sample configurations don't include these
options. When running ssl-opt.sh on those configurations, enable the
required options. They must be listed in the config*.h file, commented out.

Run ssl-opt in the following configurations with debug options:
ccm-psk-tls1_2, ccm-psk-dtls1_2, suite-b. Skip mini-tls1_1 for now because
it requires significant improvements to ssl-opt.sh (lots of missing
requires_xxx).

Signed-off-by: Gilles Peskine <[email protected]>
Slightly reduce the amount of data so that the test passes with 512.

Signed-off-by: Gilles Peskine <[email protected]>
User-visible changes:
* With no argument, configurations are now tested in a deterministic order.
* When given arguments, configurations are now tested in the order given.
* When given arguments, if the same configuration is passed multiple times,
  it will now be tested multiple times.

Signed-off-by: Gilles Peskine <[email protected]>
When doing builds with PSA enabled or with debug traces enabled, convey this
in $MBEDTLS_TEST_CONFIGURATION and in the terminal logs.

This fixes a bug that the outcome file did not distinguish entries from
test cases run in a reference configuration with or without PSA.

Signed-off-by: Gilles Peskine <[email protected]>
If MBEDTLS_SSL_EXTENDED_MASTER_SECRET is disabled or the feature is disabled
at runtime, and if client authentication is not used, then calc_verify is not
called, so don't require the corresponding debug trace.

Signed-off-by: Gilles Peskine <[email protected]>
Some DTLS reordering tests rely on certificate authentication messages. It
is probably possible to adapt them to rely on different messages, but for
now, skip them in PSK-only builds.

Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
The log checks require a specific hash and a specific curve.

Signed-off-by: Gilles Peskine <[email protected]>
Document that this is what it is. Don't allow made-up numerical values.

Signed-off-by: Gilles Peskine <[email protected]>
Make sure that buf always has enough room for what it will contain. Before,
this was not the case if the buffer was smaller than the default response,
leading to memory corruption in ssl_server2.

Signed-off-by: Gilles Peskine <[email protected]>
The added null byte was accounted for twice, once by taking
opt.buffer_size+1 when allocating the buffer and once by taking opt.buffer-1
when filling the buffer. Make opt.buffer_size the size that is actually
read, it's less confusing that way.

Signed-off-by: Gilles Peskine <[email protected]>
Don't depend on the default sizes in the test programs: pass explicit
request and buffer sizes.

Don't depend on MAX_CONTENT_LEN (other than it not being extremely small:
this commit assumes that it will never be less than 101).

Signed-off-by: Gilles Peskine <[email protected]>
The automatic ciphersuite detection deliberately doesn't operate on test
cases that verify that the test suite is rejected, but some RC4 test cases
only apply to configurations where the algorithm must be enabled at compile
time (otherwise the connection would fail in a different way).

Signed-off-by: Gilles Peskine <[email protected]>
Rename maybe_requires_ciphersuite_enabled() to detect_required_features()
and refactor its code a little. No intended behavior change. In subsequent
commits, this function will detect other requirements in a similar way.

Signed-off-by: Gilles Peskine <[email protected]>
No intended behavior change.

Signed-off-by: Gilles Peskine <[email protected]>
When the client or server uses a specific protocol version, automatically
require that version to be enabled at compile time.

An explicit call is still needed in test cases that require a specific
protocol version (due to analyzing version-specific behavior, or checking
the version in logs), but do not force that specific protocol version, or that
force a specific version only on the openssl/gnutls side.

Signed-off-by: Gilles Peskine <[email protected]>
Automatically detect when an mbedtls or openssl client enables fallback
SCSV.

For test cases with a hard-coded ClientHello with FALLBACK_SCSV, declare the
dependency manually. Remove the erroneous requirement on openssl in these
test cases.

Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
tests/ssl-opt.sh Outdated
Comment on lines 1727 to 1729
requires_ciphersuite_enabled TLS-RSA-WITH-RC4-128-SHA
run_test "RC4: server enabled, client disabled" \
"$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this PR, this test case is no longer running in configurations that where this RC4 ciphersuite is usable, but disabled by default at runtime due to MBEDTLS_REMOVE_ARC4_CIPHERSUITES. This is a quirk of how ciphersuites are detected: ssl-opt.sh calls ssl_client2 help, which calls mbedtls_ssl_list_ciphersuites, which omits ciphersuites removed through MBEDTLS_REMOVE_ARC4_CIPHERSUITES.

This test case validates that a client won't try to use RC4 when MBEDTLS_REMOVE_ARC4_CIPHERSUITES is enabled, so it should run in configurations where the ciphersuite is available upon request but disabled by default, which includes the default configuration. So I'll change the dependencies and explain.

The same quirk exists for 3DES ciphersuites, but it doesn't make a difference to ssl-opt.sh since it never tries to use DES.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed a commit that fixes the RC4 test cases: 719a652.

I'm not very happy with this hack. How about expanding query_compile_time_config to list all ciphersuites (not just the ones enabled by default)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about expanding query_compile_time_config to list all ciphersuites (not just the ones enabled by default)?

Done in https://github.com/gilles-peskine-arm/mbedtls/tree/ssl-opt-auto-psk-2.28-query_ciphersuites . But I'm not very happy with the way I've done it. It causes query_compile_time_config to require functions in libmbedtls (and so as it stands it'll fail in shared library builds). Rather, I should copy the ciphersuite_definitions array from ssl_ciphersuites.c.

When ARC4 ciphersuites are compiled in, but removed from the default list,
requires_ciphersuite_enabled does not consider them to be enabled. Therefore
test cases for MBEDTLS_REMOVE_ARC4_CIPHERSUITES, which must run in such
configurations, must not use requires_ciphersuite_enabled.

Instead, require the corresponding cryptographic mechanisms. In addition,
for the test case "RC4: both enabled", bypass the automatic ciphersuite
support detection based on force_ciphersuite= that would otherwise cause
this test case to be skipped. (This automatic detection doesn't cause the
negative tests to be skipped because it has an exception whenthe handshake
is supposed to fail.)

Signed-off-by: Gilles Peskine <[email protected]>
Comment on lines -2821 to 3005
requires_openssl_with_fallback_scsv
requires_config_enabled MBEDTLS_SSL_FALLBACK_SCSV
run_test "Fallback SCSV: beginning of list" \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing the dependency of this test case is causing a CI failure on FreeBSD. The failure isn't happening on the base branch because of the incorrect dependency. #5731

@gilles-peskine-arm
Copy link
Contributor Author

As of 719a652, the set of ssl-opt.sh test cases that run across various configurations is satisfactory. However the failure of test_cmake_out_of_source is not a transitory issue, it's an infrastructure problem that we didn't run into until now because of a bug in a test script that this PR fixes. See #5730 (comment)

If the ssl-opt test case was skipped, the test was ineffective.

Signed-off-by: Gilles Peskine <[email protected]>
This both simplifies parsing a little, and suppresses warnings. Suppressing
warnings is both good and bad: on the one hand it resolves problems such as
Mbed-TLS#5731, on the other hand it may
hide clues as to why lsof wouldn't be working as expected.

Signed-off-by: Gilles Peskine <[email protected]>
@gilles-peskine-arm gilles-peskine-arm requested a review from mpg April 16, 2022 12:00
@gilles-peskine-arm gilles-peskine-arm removed needs-work needs-ci Needs to pass CI tests labels Apr 16, 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

@gilles-peskine-arm gilles-peskine-arm added the needs-reviewer This PR needs someone to pick it up for review label Apr 19, 2022
@paul-elliott-arm paul-elliott-arm self-requested a review April 19, 2022 16:14
@gilles-peskine-arm gilles-peskine-arm removed the needs-reviewer This PR needs someone to pick it up for review label Apr 20, 2022
Copy link
Member

@paul-elliott-arm paul-elliott-arm left a comment

Choose a reason for hiding this comment

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

Looks like a faithful backport, only one question.

Copy link
Member

@paul-elliott-arm paul-elliott-arm left a comment

Choose a reason for hiding this comment

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

LGTM

@gilles-peskine-arm gilles-peskine-arm 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, labels Apr 21, 2022
@gilles-peskine-arm gilles-peskine-arm merged commit f7a101a into Mbed-TLS:mbedtls-2.28 Apr 21, 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 component-test Test framework and CI scripts enhancement size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants