-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add basic handshake defragmentation tests in ssl-opt #9989
Add basic handshake defragmentation tests in ssl-opt #9989
Conversation
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.
(Posting partial early review.)
6e261a1
to
aeba05a
Compare
5bf1ff3
to
5c8cbb2
Compare
aee03e9
to
765755a
Compare
Quick update: I have addressed all the comments, cleaned up the commit history to make it easier to review, and increased coverage. I will be sharing a table with what is covered for design review purposes. |
Thanks! Now that #9872 is merged, can you rebase on top of it? Also, can you add a commit disabling (by prepending Once we've agreed on a solution to the underlying problem, we'll re-enable those tests in some form (probably just assert failure when using 1.2 and with fragment length < 16, but we can't do that right now, as the handshake succeeds with ChachaPoly). |
Tests uses openssl s_server with a mix of max_send_frag and split_send_frag options. Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
* Add tests for the server side. * Remove restriction for TLS 1.2 so that we can test TLS 1.2 & 1.3. * Use latest version of openSSL to make sure -max_send_frag & -split_send_frag flags are supported. Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
…entation tests Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
…on tests. Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
To faciliate the reiview and design review purposes I have compiled a table for the coverage.
|
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
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. I have some minor feedback that can either be addressed here (while the 3.6 backport is being prepared) or left for a follow-up - no blocker so far IMO.
I'd still like to make another pass tomorrow before I formally approve, as the relatively high volume makes it hard to remain focused and easy to overlook things.
|
||
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3 | ||
requires_certificate_authentication | ||
run_test "Handshake defragmentation on client: len=512, TLS 1.3" \ |
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.
Thought: we have several very similar test where the only thing that changes in the fragment size, and it have to be changed in multiple places (message, OpenSSL command line, asserts). I wonder if we should use a helper function for those tests.
(We could have a function for server-side taking as argument the TLS version (and adjusting requires_xxx
based on it) and the fragment size, and another for client-side.)
Not requesting any change here, if think a function would help we can do it in a follow-up.
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.
Generally speaking, I'm in favor of less repetitive code. Having nearly-identical blocks of ~10 lines has a high risk of mistakes and can obscure the forest for the trees.
Regarding the method, I'm not so keen on a shell function, but not fundamentally opposed. They have several pitfalls:
- The shell is limited as a programming language, and not very well known.
- It's harder to locate and figure out test cases that are generated on the fly.
- The function must not depend on the library configuration or the environment — it must always emit the same test cases as
ssl-opt.sh --list-test-cases
. For example, it must makerequires_xxx
calls and a final call torun_test
, never return early.
There's another possible approach, which is to generate test cases from a Python script, with an intermediate file containing the individual test cases. It's a bit heavier weight to get going, but then has fewer pitfalls.
In terms of existing infrastructure, we currently have a few functions (run_test_psa
, run_test_memory_after_handshake
and their variants) and one Python script generate_tls13_compat_tests.py
.
tests/ssl-opt.sh
Outdated
-c "handshake fragment: 0 \\.\\. 512 of [0-9]\\+ msglen 512" \ | ||
-c "waiting for more fragments (512 of [0-9]\\+" | ||
|
||
# Since the removal of the DHE-RSA key exchange, the default openssl server |
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.
I think the comment is confusing outside the context where you first wrote it. I'd suggest a simpler and less context-specific explanation: "The server uses an ECDSA cert, so make sure we have a compatible key exchange".
(Can also wait for a follow-up.)
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.
Not just confusing, but the comment would be wrong in the 3.6 backport, whereas the ECDSA requirement is needed there as well. So I think we should fix the comment here at the same time we make the 3.6 backport.
tests/ssl-opt.sh
Outdated
-s "handshake fragment: 0 \\.\\. 128 of [0-9]\\+ msglen 128" \ | ||
-s "waiting for more fragments (128" | ||
|
||
# Server-side ClientHello degfragmentation is only supported for MBEDTLS_SSL_PROTO_TLS1_3. For TLS 1.2 testing |
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.
Typo: deGfragmentation
tests/ssl-opt.sh
Outdated
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 | ||
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3 | ||
requires_certificate_authentication | ||
run_test "Handshake defragmentation on server: len=3, TLS 1.3 Client-Hallo -> 1.2 Handhsake" \ |
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.
Typo: s/Hallo/Hello/ - also no dash: ClientHello. (Multiple occurrences.)
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.
I've reviewed only for correctness, not for completeness, since we don't have a clear coverage objective here.
I'd like to fix the copypasta and the comment that would be wrong in 3.6. The rest can wait until follow-ups.
@@ -3,3 +3,10 @@ Bugfix | |||
by the spec. Lack of support was causing handshake failures with some | |||
servers, especially with TLS 1.3 in practice (though both protocol | |||
version could be affected in principle, and both are fixed now). | |||
The initial fragment for each handshake message must be at least 4 bytes. | |||
|
|||
Server-side, defragmentation of the ClientHello message is only |
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.
For a follow-up: I think we should document the limitations of defragmentation in the versioned, rendered documentation — so presumably in a Doxygen comment in ssl.h
. Especially if this evolves over time, users and maintainers shouldn't have to puzzle out the result from a series of changelog entries. And we then don't need to list all the limitations in the changelog entry.
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.
Good point. Generally speaking, we (and I'm as guilty of it as anyone) tend to put too much information in the ChangeLog that should really be in the documentation.
In this case though, I'm not entirely sure where this would fit in ssl.h
. In the documentation of ssl_handshake()
?
Ideally, I think in addition to doxygen comments, we should have a (versioned) summary document for what's implemented or not or partially for TLS 1.2, DTLS and for X.509. I think we have something like this for TLS 1.3 (docs/architecture/tls13-support.md
). For TLS 1.2 I thought there was something (as list of implemented RFCs, probably outdated) in the old Knowledge Base but I can't find it any more.
tests/ssl-opt.sh
Outdated
-c "handshake fragment: 0 \\.\\. 512 of [0-9]\\+ msglen 512" \ | ||
-c "waiting for more fragments (512 of [0-9]\\+" | ||
|
||
# Since the removal of the DHE-RSA key exchange, the default openssl server |
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.
Not just confusing, but the comment would be wrong in the 3.6 backport, whereas the ECDSA requirement is needed there as well. So I think we should fix the comment here at the same time we make the 3.6 backport.
-c "waiting for more fragments (512 of [0-9]\\+" | ||
|
||
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3 | ||
requires_certificate_authentication |
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.
Why is there no ECDSA requirement in TLS 1.3? I guess because we never run ssl-opt.sh
in a configuration with TLS 1.3 and ECDH and RSA but not ECDSA?
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.
Because since #9917 the supported openssl ciphers for TLS.1.2 and what our server provides, do not have any cipher in common when ECDSA is removed.
With TLS1.3 there are plenty of alternatives
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.
Surely we have RSA-ECDHE cipher suites in common? You can configure the library with ECDH but not ECDSA. Maybe we don't run TLS tests in such a configuration from all.sh
, but it is possible.
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.
Surely we have RSA-ECDHE cipher suites in common?
Yes but not when the server only has an ECC cert.
I think the reason we don't need to add an ECDSA requirement for 1.3 is that there the autodetection logic works: it sees one party using server5 and requires ECDSA.
I also think the reason the autodetection does not work for 1.2 is that there things are more complex: if both peers are Mbed TLS, then ECC cert doesn't necessarily mean ECDHE-ECDSA key exchange, a static ECDH key exchange could be used as well so we require any key exchange that can use an ECC cert.
Except OpenSSL doesn't allow static ECDH by default (or even doesn't support it at all, didn't check recently). So the autodetection logic should notice that on of the peers doesn't support static ECDH, and require ECDHE-ECDSA, but apparently it doesn't, so we find ourselves adding the requirement manually. (Or perhaps it's the part that detects the version that's broken?)
I've not actually tested whether this reasoning is correct, but that's what I'm thinking so far based on reading the code. Anyway, from CI failures in past version of this PR, it would appear that the autodetection logic is working for the TLS 1.3 test cases but not for the 1.2 test cases in this series, whatever the reason.
tests/ssl-opt.sh
Outdated
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 | ||
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3 | ||
requires_certificate_authentication | ||
run_test "Handshake defragmentation on server: len=32, TLS 1.3 Client-Hallo -> 1.2 Handhsake" \ | ||
"$P_SRV debug_level=4 force_version=tls12 auth_mode=required" \ |
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.
Copypasta: this is testing a 1.2 ClientHello with the 1.2 parser.
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 | |
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3 | |
requires_certificate_authentication | |
run_test "Handshake defragmentation on server: len=32, TLS 1.3 Client-Hallo -> 1.2 Handhsake" \ | |
"$P_SRV debug_level=4 force_version=tls12 auth_mode=required" \ | |
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 | |
requires_certificate_authentication | |
run_test "Handshake defragmentation on server: len=32, TLS 1.2 ClientHello" \ | |
"$P_SRV debug_level=4 force_version=tls12 auth_mode=required" \ |
1 \ | ||
-s "The SSL configuration is tls12 only" \ | ||
-s "bad client hello message" \ | ||
-s "SSL - A message could not be parsed due to a syntactic error" |
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.
Can wait for a follow-up: We should check "ClientHello fragmentation not supported"
in the log.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
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.
There's still one spurious dependency on requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
: #9989 (comment) . Other than that LGTM
tests/ssl-opt.sh
Outdated
|
||
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 | ||
requires_certificate_authentication | ||
requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED |
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.
I had missed this spurious dependency, good call for removing it from the backport: the negative test for handshake too small doesn't require ECDSA support. In fact it doesn't need certificate authentication at all. We can fix this later.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
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
One test failedin |
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
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, thanks!
@@ -14220,12 +14217,12 @@ run_test "Handshake defragmentation on server: len=128, TLS 1.3" \ | |||
-s "handshake fragment: 0 \\.\\. 128 of [0-9]\\+ msglen 128" \ | |||
-s "waiting for more fragments (128" | |||
|
|||
# Server-side ClientHello degfragmentation is only supported for MBEDTLS_SSL_PROTO_TLS1_3. For TLS 1.2 testing | |||
# Server-side ClientHello defragmentationis only supported for MBEDTLS_SSL_PROTO_TLS1_3. For TLS 1.2 testing |
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.
Introducing a typo: missing space defragmentationis (no need to fix if there's nothing else).
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.
We'll need to have some tests around fragmentation that run with PSK, but ok for now.
6eabe58
into
Mbed-TLS:features/tls-defragmentation/development
Description
Implements a portion of the testing needed for #9872. This pr extends #9928 and resolves #9887
PR checklist
Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.