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

Implement modified key export API for Mbed TLS 3.0 #4552

Merged

Conversation

hanno-becker
Copy link

This resolves #4363 and implements the API proposed therein. See #4363 and the documentation for more information.

@hanno-becker hanno-becker added needs-review Every commit must be reviewed by at least two team members, component-tls mbedtls-3 needs-reviewer This PR needs someone to pick it up for review labels May 24, 2021
@hanno-becker hanno-becker added the size-s Estimated task size: small (~2d) label May 24, 2021
@mpg mpg self-requested a review May 25, 2021 09:41
@daverodgman daverodgman self-requested a review May 25, 2021 15:22
@hanno-becker
Copy link
Author

CI only failing because of the API break.

Copy link
Contributor

@daverodgman daverodgman left a comment

Choose a reason for hiding this comment

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

A couple of minor points, otherwise looks good

* \param client_random The client random bytes.
* \param server_random The server random bytes.
* \param tls_prf_type The identifier for the PRF used in the handshake
* to which the key belongs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing docs for secret and secret_len

Copy link
Author

Choose a reason for hiding this comment

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

Fixing

typedef enum
{
MBEDTLS_SSL_TLS_PRF_NONE,
MBEDTLS_SSL_TLS_PRF_TLS1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is MBEDTLS_SSL_TLS_PRF_TLS1 still needed after TLS 1.0 and 1.1 have been removed?

Copy link
Author

@hanno-becker hanno-becker May 28, 2021

Choose a reason for hiding this comment

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

No, it's not. I've removed it.

@daverodgman daverodgman removed the needs-reviewer This PR needs someone to pick it up for review label May 27, 2021
@hanno-becker
Copy link
Author

@daverodgman Thank you for your review. I believe to have addressed your comments. Could you please re-review?

@hanno-becker
Copy link
Author

@ronald-cron-arm Why was this removed from the Mbed TLS 3.0 Optional EPIC?

@ronald-cron-arm
Copy link
Contributor

ronald-cron-arm commented Jun 1, 2021

@ronald-cron-arm Why was this removed from the Mbed TLS 3.0 Optional EPIC?

Because it is linked to the issue #4363 that is in the Mbed TLS 3.0 Optional EPIC and thus in the EPIC we can still see this PR through the issue. When a PR is linked to an issue that is an EPIC we prefer not to add the PR to the EPIC as well. EPICs are better organized that way.

@hanno-becker
Copy link
Author

@ronald-cron-arm Got it!

@hanno-becker hanno-becker force-pushed the mbedtls_3_0_key_export branch from d63ab59 to 6b7bb36 Compare June 1, 2021 07:44
daverodgman
daverodgman previously approved these changes Jun 1, 2021
Copy link
Contributor

@daverodgman daverodgman left a comment

Choose a reason for hiding this comment

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

Looks good, comments have been addressed - thanks!

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

I've read the discussion in #2188 and #4363 and reviewed the proposal here.

I think the callback should have access to the SSL context. This was proposed in #2188 and I think this is both simpler and more future-proof than the proposed alternatives such as identifying a connection by its random. I don't see any rationale for the current choice of parameters for the callback.

ChangeLog.d/key-export.txt Outdated Show resolved Hide resolved
include/mbedtls/ssl.h Show resolved Hide resolved
* \brief Callback type: Export key alongside random values for
* session identification, and PRF for
* implementation of TLS key exporters.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

(Doesn't necessarily need to be answered now, but it may matter to the design of the API.) With MBEDTLS_USE_PSA_CRYPTO, at some point, it will become possible to have session secrets that cannot be exported. Are we planning to just not call the callback?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the answer might be "don't call it", should we document now that under some circumstances (that we don't need to define at this point), the callback may not be called?

include/mbedtls/ssl.h Show resolved Hide resolved
* to which the key belongs.
*
* \return \c 0 if successful.
* \return A negative error code on failure.
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the callback fails? Right now the failure is ignored. Maybe the callback should return void? If not I think the effect of a failure should be a documented aspect of the API.

Copy link
Author

@hanno-becker hanno-becker Jun 8, 2021

Choose a reason for hiding this comment

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

Hmm, good point. At first I thought we should change the return type to void, but perhaps it's a convenient for the user to be able to signal a fatal error to the stack when something goes wrong in the export. I'll implement and document the latter for now.

Let's wait for @mpg's opinion before changing anything.

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 returning void is the right thing to do for this kind of callback. If anything goes wrong with the export for some reason, it doesn't invalidate anything in the connection - it might be a problem for the application, and then the application will decide what to do (including closing the connection if desired).

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 I agree with @mpg - not sure what Mbed TLS could usefully do with the error.

Copy link
Author

Choose a reason for hiding this comment

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

Changing to void.

Copy link
Author

Choose a reason for hiding this comment

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

For the record, I agree with @mpg's analysis.

@gilles-peskine-arm gilles-peskine-arm added needs-work and removed needs-review Every commit must be reviewed by at least two team members, labels Jun 7, 2021
Hanno Becker added 7 commits June 18, 2021 18:40
This saves some code when compiling for Thumb, where access to
fields with offset index > 127 requires intermediate address
computations. Frequently used fields should therefore be located
at the top of the structure, while less frequently used ones --
such as the export callback -- can be moved to the back.

Signed-off-by: Hanno Becker <[email protected]>
@daverodgman daverodgman force-pushed the mbedtls_3_0_key_export branch from b62ad8f to 46b0217 Compare June 18, 2021 17:41
@daverodgman
Copy link
Contributor

daverodgman commented Jun 18, 2021

Trivial rebase onto latest development to try re-running the CI

@hanno-becker hanno-becker force-pushed the mbedtls_3_0_key_export branch from 46b0217 to 296fefe Compare June 21, 2021 08:33
@hanno-becker
Copy link
Author

Yet another try...

daverodgman
daverodgman previously approved these changes Jun 21, 2021
Copy link
Contributor

@daverodgman daverodgman left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-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 except for one omission in the migration guide.

Those APIs have been removed and replaced by the new API
`mbedtls_ssl_set_export_keys_cb()`. This API differs from
the previous key export API in the following ways:

Copy link
Contributor

Choose a reason for hiding this comment

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

Another way is that the new callback returns void, whereas the old callbacks returned an int value that was ignored. Since the old value was ignored, that's minor enough not to be mentioned in the changelog which is a high-level semantic overview, but I think it should be listed in the migration guide, because I'd expect the list here to be a complete list of steps to migrate existing code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair point, I've discussed wording with @hanno-arm & pushed a commit with the addition to the migration guide.

@mpg mpg removed the needs-ci Needs to pass CI tests label Jun 22, 2021
@daverodgman daverodgman added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Jun 22, 2021
@daverodgman
Copy link
Contributor

Sorry, typo in my first attempt.

@gilles-peskine-arm gilles-peskine-arm removed the needs-review Every commit must be reviewed by at least two team members, label Jun 22, 2021
@gilles-peskine-arm gilles-peskine-arm merged commit e9bc857 into Mbed-TLS:development Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-tls size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify SSL key exporter API and prepare for TLS 1.3
5 participants