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

Add support for datagram packing #1918

Merged
merged 89 commits into from
Aug 29, 2018

Conversation

hanno-becker
Copy link

@hanno-becker hanno-becker commented Aug 3, 2018

Summary: This PR adds support for stacking multiple records in a single datagram, based on the ongoing work to support outgoing handshake fragmentation in #1939. The first new commit is 5aa4e2c.

Hanno Becker added 2 commits August 3, 2018 10:07
`mbedtls_ssl_get_record_expansion()` is supposed to return the maximum
difference between the size of a protected record and the size of the
encapsulated plaintext.

It had the following two bugs:
(1) It did not consider the new ChaChaPoly ciphersuites, returning
    the error code #MBEDTLS_ERR_SSL_INTERNAL_ERROR in this case.
(2) It did not correctly estimate the maximum record expansion in case
    of CBC ciphersuites in (D)TLS versions 1.1 and higher, in which
    case the ciphertext is prefixed by an explicit IV.

This commit fixes both bugs.
@hanno-becker hanno-becker changed the title [DRAFT] Datagram packing [DRAFT] Add support for datagram packing Aug 3, 2018
@hanno-becker hanno-becker changed the title [DRAFT] Add support for datagram packing Add support for datagram packing Aug 6, 2018
@hanno-becker
Copy link
Author

This is on hold until the test failures in #1879 have been resolved.

@hanno-becker
Copy link
Author

hanno-becker commented Aug 10, 2018

All CI interoperability failures on the underlying #1879 have been understood and seen as not caused by an issue in Mbed TLS; see IOTSSL-2401. Testing this again.

@hanno-becker
Copy link
Author

retest

@hanno-becker hanno-becker added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Aug 10, 2018
@hanno-becker
Copy link
Author

@mpg @AndrzejKurek Do you think you will have time to review this?

@mpg
Copy link
Contributor

mpg commented Aug 11, 2018

Yes, I'll review this next week!

@hanno-becker
Copy link
Author

The introduction of datagram packing significantly changes the nature of the proxy tests in ssl-opt.sh since the UDP proxy works on the basis of datagrams: where it was previously capable of reordering or dropping some messages from flights, this is no longer possible if the entire flight is sent within a single datagram - as is the default behavior now. For example, without further changes to the proxy, or without the possibility to disable datagram packing, it is no longer possible to simulate a delayed CCS message. This is also the reason why we see the CI succeeding albeit it fails for the underlying fragmentation PR #1879.

I believe we should consider ways around this, for example

  1. Allow static enabling/disabling of datagram packing at compile time.
  2. Allow dynamic enabling/disabling of datagram packing at run time.
  3. Improve the UDP proxy by having it dissect datagrams into records prior to performing its other operations.

Leaving tests aside, the only practical reason I see for allowing to disable datagram packing are potential interoperability issues with peers that happen to have problems receiving packed datagrams, but this seems quite unlikely.

Going through the options, the following are the consequences to the test system for each of them:

  1. For static enabling/disabling of datagram packing, we'd need another build + test in all.sh. Some tests in ssl-opt.sh would need to be disabled for datagram packing (such as the one for delayed CCS's).
  2. For dynamic enabling/disabling of datagram packing, this could be controlled through a new parameter to ssl_client2 and ssl_server2, so that we could (a) disable datagram packing for the tests conflicting with it, and (b) duplicate tests which are meaningful with and without datagram packing.
  3. When the UDP proxy not only supports packing but also splitting of datagrams, we'd need to turn that on in those tests that conflict with datagram packing, and duplicate the tests which are meaningful with and without datagram packing.

@mpg What do you think?

@mpg
Copy link
Contributor

mpg commented Aug 13, 2018

@hanno-arm I'll reply to those question later because I have to go now, but I wanted to let you know I've put up a new PR with the fragmentation work here: #1918 It has a cleaner history, fixes for a few bugs, more tests for MTU settings, and should pass CI (as it doesn't have the problematic interop tests yet).

I'd like to suggest you rebase your work on the new branch of mine, in order to have a cleaner history (currently there are a number of WIP/temporary/revert commits in the history) and the bug fixes.

@hanno-becker
Copy link
Author

Thanks @mpg, I will do the rebase in the meantime.

@mpg
Copy link
Contributor

mpg commented Aug 14, 2018

Leaving tests aside, the only practical reason I see for allowing to disable datagram packing are potential interoperability issues with peers that happen to have problems receiving packed datagrams, but this seems quite unlikely.

I'm not sure. IIRC, OpenSSL starts by sending packed datagrams, then if it has to retransmit tries unpacked, then it if has to retransmit again, it starts lowering the "estimated handshake MTU" and fragmenting if necessary. I don't think I've seen it stated anywhere, but I always assumed this was in order to enhance compatibility with peers that might not support datagram packing. However perhaps I'm misinterpreting, and even if I'm not, perhaps this is no longer a concern these days.

Anyway, I'm inclined to go for option 2 (dynamic setting of this behaviour) unless you think that will make the code too complex.

If we don't got for option 2, I quite dislike option 1 (static setting) as we have too many build options to test already, but before we go for option 3 I'd like to suggest option 4: find a peer that doesn't pack (I think you mentioned recently that openssl s_server -debug is such a peer) and use it for the tests that need it, so that we don't have to make the proxy smarter for now.

@hanno-becker
Copy link
Author

@mpg Thank you for your feedback. I don't expect it to be difficult to enable/disable datagram packing dynamically, and I'll do the corresponding change. In the meantime, I implemented datagram splitting on the UDP proxy, which I think is a feature worth having in any case, complementing the datagram packing ability of the UDP proxy that we already have; in conjunction, both would e.g. allow to reorder records within a single datagram, which is not something you would practically expect to happen, but still worth testing, as it tests that we don't make make any ordering assumptions from the fact that records come within the same datagram.

@mpg
Copy link
Contributor

mpg commented Aug 14, 2018

Aw, github is now showing commit in the wrong order. Apparently it does this on purpose because it's "a space for discussion" - well I find it much easier to discuss a series of commits when it's presented in its logical order.

Anyway, reviewers beware of the github interface. Thankfully git log --patch --reverse is our reliable friend.

@mpg
Copy link
Contributor

mpg commented Aug 14, 2018

@hanno-arm Thanks for reworking the history! However I'm afraid you didn't quite rebase on top of #1939, but rather cherry-picked it or something. As a result, all the commits from #1939 are present with a different commit ID, which means when both PRs are merged, the history will contains "duplicate" commits with the same title and date but different hashes, which I tend to find pretty annoying when searching the history later on.

I fixed the issue by reset-harding my branch to 8c75a5d6a06f then force-pushing it, so you don't have anything do to here, but I wanted to let you know.

In the future, tempted to base a branch on two other branches (that are also going to be merged independently), we should base on one and merge the other in, in order to avoid near-duplicate commits in the overall history.

@hanno-becker hanno-becker force-pushed the datagram_packing branch 2 times, most recently from 138648f to c5438d8 Compare August 14, 2018 14:38
@hanno-becker
Copy link
Author

@mpg I have pushed some commits to address your comments, and left a comment on your point in regards to the length check in ssl_encrypt_buf().

Hanno Becker added 2 commits August 24, 2018 11:48
This commit introduces some tests to ssl-opt.sh checking that
setting the MFL limits the MTU to MFL + { Maximum Record Expansion }.
@hanno-becker
Copy link
Author

@mpg Tests checking the MFL effectively restricting the MTU are currently failing, I am investigating.

The negotiated MFL is always the one suggested by the client, even
if the server has a smaller MFL configured locally. Hence, in the test
where the client asks for an MFL of 4096 bytes while the server locally
has an MFL of 512 bytes configured, the client will still send datagrams
of up to ~4K size.
@hanno-becker
Copy link
Author

One of the tests I just added to ssl-opt.sh had wrong expectations, I removed it in 69ca0ad.

tests/ssl-opt.sh Outdated
@@ -5020,6 +5020,10 @@ run_test "DTLS fragmenting: server only (max_frag_len)" \
-c "found fragmented DTLS handshake message" \
-C "error"

# With the MFL extension, the server has no way of forcing
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you just re-discovered our biggest issue with the MFL extension :) Fortunately the IETF has a replacement underway: https://tools.ietf.org/html/draft-ietf-tls-record-limit-03#section-3

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.

Thanks for making the requested changes! I'm happy with the result.

@mpg
Copy link
Contributor

mpg commented Aug 24, 2018

Note: all.sh -k -r -m passed locally on the latest commit 69ca0ad

Copy link
Contributor

@simonbutcher simonbutcher left a comment

Choose a reason for hiding this comment

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

I'm okay with the PR -as-is- but I'd like to document our use of --insecure in gnutls-cli. I don't want to delay merging this PR, so @hanno-arm, can you please raise a secondary PR to fix this? (Assuming you don't disagree!). If you don't agree, please reply to this PR.

tests/ssl-opt.sh Outdated
@@ -5459,35 +5515,31 @@ run_test "DTLS fragmenting: gnutls server, DTLS 1.0" \
-c "fragmenting handshake message" \
-C "error"

# gnutls-cli always tries IPv6 first, and doesn't fall back to IPv4 with DTLS
requires_ipv6
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to have a comment here that explains and justifies the use of --insecure here and below.

Copy link
Author

Choose a reason for hiding this comment

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

@sbutcher-arm I don't mind changing this here, but the change was introduced by @mpg in #1939, and if your feedback on that PR leads to a 'fork' of #1939 being created anyway, I think it's better to add the change you requested here in that new PR, too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please liaise with @mpg and do what you think is best. I'd prefer it if you could do it, as I think you'll have more time than @mpg, but I'll leave it to you to decide. Just do it as a new PR, so I can get this one in without more rework.

@simonbutcher simonbutcher added approved Design and code approved - may be waiting for CI or backports approved for design and removed needs-design-approval needs-review Every commit must be reviewed by at least two team members, labels Aug 25, 2018
@simonbutcher simonbutcher merged commit 69ca0ad into Mbed-TLS:development Aug 29, 2018
RonEld pushed a commit to RonEld/mbedtls that referenced this pull request Jan 15, 2019
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.
RonEld pushed a commit to RonEld/mbedtls that referenced this pull request Sep 26, 2019
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.
jeannotlapin pushed a commit to jeannotlapin/mbedtls that referenced this pull request Apr 23, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.
jeannotlapin pushed a commit to jeannotlapin/mbedtls that referenced this pull request Apr 23, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
jeannotlapin pushed a commit to jeannotlapin/mbedtls that referenced this pull request May 6, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
jeannotlapin pushed a commit to jeannotlapin/mbedtls that referenced this pull request Aug 22, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
ycyang1229 pushed a commit to ycyang1229/mbedtls that referenced this pull request Sep 1, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.
jeannotlapin pushed a commit to jeannotlapin/mbedtls that referenced this pull request Sep 10, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
jeannotlapin pushed a commit to jeannotlapin/mbedtls that referenced this pull request Oct 9, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
jeannotlapin pushed a commit to jeannotlapin/mbedtls that referenced this pull request Oct 26, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
jeannotlapin pushed a commit to jeannotlapin/mbedtls that referenced this pull request Oct 29, 2020
Force using IPv4 in the GNU_CLI SRTP tests, as introduced for
other tests in Mbed-TLS#1918.

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
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-tls enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants