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

Fix DTLS 1.2 session resumption #5915

Merged

Conversation

AndrzejKurek
Copy link
Contributor

Previously, the transforms were populated before extension parsing, which resulted in the client rejecting a server hello that contained a connection ID.
Fixes #5872.

Previously, the transforms were populated before extension
parsing, which resulted in the client rejecting a server
hello that contained a connection ID.
Signed-off-by: Andrzej Kurek <[email protected]>
@AndrzejKurek AndrzejKurek added bug needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review priority-high High priority - will be reviewed soon labels Jun 14, 2022
@AndrzejKurek
Copy link
Contributor Author

Changelog entry added, I'll add a backport once there's at least one approval on this approach.

@ronald-cron-arm ronald-cron-arm self-requested a review July 5, 2022 08:54
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

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

The fix looks good to me. I have two improvement suggestions.

@@ -1654,6 +1644,19 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
}
}

if( ssl->state == MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC )
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if( ssl->state == MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC )
/*
* mbedtls_ssl_derive_keys() has to be called after the parsing of the
* extensions. It sets the transform data for the resumed session which in
* case of DTLS includes the server CID extracted from the CID extension.
*/
if( ssl->handshake->resume )

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'm not really sure if only session resumption was affected. The set of conditions that could lead to the early key derivation was a bit longer:

        ssl->handshake->resume == 0 || n == 0 ||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
        ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE ||
#endif
        ssl->session_negotiate->ciphersuite != i ||
        ssl->session_negotiate->compression != comp ||
        ssl->session_negotiate->id_len != n ||
        memcmp( ssl->session_negotiate->id, buf + 35, n ) != 0 )

Can there be a different set of extensions with, for example, renegotiation here?

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 it is ok and clearer to check on the ssl->handshake->resume flag. The checks you mention just above are just all the necessary conditions to go ahead with a session resumption. That's why if the check fails ssl->handshake->resume is reset to zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed :)

@@ -0,0 +1,4 @@
Bugfix
* Fix a bug where the connection ID extension on client side would not work
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Fix a bug where the connection ID extension on client side would not work
* Fix server connection identifier setting for outgoing encrypted records
on DTLS 1.2 session resumption. After DTLS 1.2 session resumption with
connection identifier, the Mbed TLS client now sends properly the server
connection identifier in encrypted record headers. Fix #5872.

Andrzej Kurek added 2 commits July 5, 2022 10:49
Co-authored-by: Ronald Cron <[email protected]>
Signed-off-by: Andrzej Kurek <[email protected]>
…parsing

Use a more straightforward condition to note that session resumption
is happening.
Co-authored-by: Ronald Cron <[email protected]>
Signed-off-by: Andrzej Kurek <[email protected]>
@paul-elliott-arm paul-elliott-arm self-requested a review July 6, 2022 08:52
Bugfix
* Fix server connection identifier setting for outgoing encrypted records
on DTLS 1.2 session resumption. After DTLS 1.2 session resumption with
connection identifier, the Mbed TLS client now sends properly the server
Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm Jul 6, 2022

Choose a reason for hiding this comment

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

(minor)

Suggested change
connection identifier, the Mbed TLS client now sends properly the server
connection identifier, the Mbed TLS client now properly sends the server

or: should it be "sends the correct server connection identifier"? Not sure what it is doing wrong currently...

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest not to restart the CI cycle just for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed (hence "minor")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we require a CI rerun if the change will contain just this rewording?

Copy link
Contributor

@ronald-cron-arm ronald-cron-arm Jul 6, 2022

Choose a reason for hiding this comment

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

That's indeed an option: not require a CI rerun. I am ok with that.

Copy link
Member

Choose a reason for hiding this comment

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

Not really. There is presumably a backport forthcoming as well?

ronald-cron-arm
ronald-cron-arm previously approved these changes Jul 6, 2022
@ronald-cron-arm
Copy link
Contributor

The Internal CI ran successfully.

@ronald-cron-arm ronald-cron-arm removed needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review labels Jul 6, 2022
@AndrzejKurek AndrzejKurek changed the title Rearrange the session resumption code Fix DTLS 1.2 session resumption Jul 6, 2022
Signed-off-by: Andrzej Kurek <[email protected]>
@AndrzejKurek
Copy link
Contributor Author

Backport added here: #6067. Sorry for not doing this earlier!
Rewording added, verified that local ./tests/scripts/check_files.py passes, as this would be the one most likely to complain.

Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-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

@ronald-cron-arm
Copy link
Contributor

The internal CI has run successfully on this PR and its backport. One more review on the backport needed and then both can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-review Every commit must be reviewed by at least two team members, priority-high High priority - will be reviewed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session resumption not working when Connection ID is used
4 participants