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 Rustls provider including examples #1899

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bjoernQ
Copy link
Contributor

@bjoernQ bjoernQ commented Aug 2, 2024

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

This adds two examples using Rustls (a client and a server) for ESP32, ESP32-S3 and ESP32-C6.

It is impossible to compile Rustls for targets w/o atomics - there is an issue opened and there were several attempts to tackle it. Currently it looks like they might accept a PR to make forks replacing Arc easy and maintainable (i.e. we will need a fork for now) - they are considering to make the core Arc free and we could build upon that (but that won't happen too soon for sure)

Please note: While this seems to work fine it's just the beginning. But we need to start somewhere.

This needs to support async and long-term we want this to support HW-acceleration

Testing

Running the examples on supported targets

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Aug 2, 2024

Fixes #1836

While Rustls will also work on H2 no examples are added for H2

@bjoernQ bjoernQ linked an issue Aug 2, 2024 that may be closed by this pull request
@AnthonyGrondin
Copy link
Contributor

Given that, I'm not sure if these examples are something we currently want to have in the repo? I am also happy to extract the examples and the supporting code into its own repo in my personal GitHub space fow now otherwise

TLS is the next major part after getting the HAL and drivers running. Many protocols and systems use/require it, especially in IoT development. Now the question lies down to; What is the roadmap?

Should esp-hal come with an "official" supported (maintained by the organization) TLS solution, using either rustls, embedded-tls, esp-mbedtls, etc. Or should there be an interface like ESP-TLS to ensure compatibility across multiple TLS providers and libraries. These are discussions pertaining to TLS in general and not specifically rustls.

All three of the above mentionned TLS suites support a different set of features, and compatibility. I believe both Rustls and embedded-tls to be the future of TLS on bare-metal, since they are more lightweight and pure Rust implementation. This should be documented for new users who come across needing to use TLS on bare-metal.

Rustls

  • Pure rust implementation
  • Requires alloc and atomics
  • Supports TLS1.2 and TLS1.3
  • Supports both client and server
  • Supports mTLS
  • Hardware acceleration possible (not currently implemented)

embedded-tls

  • Pure rust implementation, for embedded systems
  • Can work without alloc
  • Only supports TLS 1.3
  • Only supports client, doesn't support server yet.
  • Supports client certificate authentication
  • Hardware acceleration possible (not currently implemented)

esp-mbedtls

  • C library used through Rust FFI
  • Doesn't require alloc. Requires malloc(), calloc(), free() from esp-wifi
  • Supports both TLS1.2 and TLS1.3
  • Supports both client and server
  • Supports mTLS
  • Hardware acceleration possible (currently only using hardware RSA)

@AnthonyGrondin
Copy link
Contributor

I can build both examples for esp32s3, but they need a custom partition table because they exceed the default 1MB partition size.

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Aug 2, 2024

I totally agree that TLS is an important topic

We don't have an official TLS roadmap ,yet - but I'd say both, Rustls and embedded-tls (both HW accelerated) is something I personally want.

After my vacation I'll look into lifting the atomics requirement for Rustls so it will work on all our targets

@MabezDev
Copy link
Member

MabezDev commented Aug 7, 2024

I've converted to draft until we can support all chips, hopefully it won't take too long to get upstream to allow using portable-atomic 🤞

@MabezDev MabezDev added the status:blocked Unable to progress - dependent on another task label Aug 7, 2024
@MabezDev
Copy link
Member

Just taking another look at this, maybe we should merge this in it's current state? We know the upstream issue needs to be resolved for the non-atomic targets, but that doesn't mean we can't land support for the atomic's target now, I think?

@bjoernQ bjoernQ closed this Nov 26, 2024
@bjoernQ bjoernQ deleted the rustls-example branch November 26, 2024 08:42
@MabezDev
Copy link
Member

Did you mean to close this, or are you planning on opening a new one?

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Nov 27, 2024

Did you mean to close this, or are you planning on opening a new one?

oh - that was a mistake

@bjoernQ bjoernQ restored the rustls-example branch November 27, 2024 10:33
@bjoernQ bjoernQ reopened this Nov 27, 2024
@bjoernQ bjoernQ force-pushed the rustls-example branch 2 times, most recently from 74a327f to 60c6e15 Compare January 23, 2025 09:44
@bjoernQ
Copy link
Contributor Author

bjoernQ commented Jan 23, 2025

Just taking another look at this, maybe we should merge this in it's current state? We know the upstream issue needs to be resolved for the non-atomic targets, but that doesn't mean we can't land support for the atomic's target now, I think?

I remove the blocked label and mark this as RfR

@bjoernQ bjoernQ removed the status:blocked Unable to progress - dependent on another task label Jan 23, 2025
@bjoernQ bjoernQ marked this pull request as ready for review January 23, 2025 11:48
Copy link
Member

@MabezDev MabezDev 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 looking into this again!


This means that ESP32-S2, ESP32-C2 and ESP32-C3 are NOT supported.

## Status
Copy link
Member

Choose a reason for hiding this comment

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

Could we remove this and break it out into issues instead? I think we'll need a new label for the esp-rustls-provider package.

My fear is that we'll never check this again :D, if we have it in separate issues we can at least be aware.

Copy link
Member

Choose a reason for hiding this comment

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

We can create the issues after the PR is merged of course, there is no rush to do it now.

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 removed the TODOs here - we shouldn't forget about creating separate issues after the merge (since creating them before is kind of weird?)

esp-rustls-provider/src/adapter/server.rs Outdated Show resolved Hide resolved
esp-rustls-provider/src/adapter/server.rs Outdated Show resolved Hide resolved
examples/src/bin/wifi_rustls_client.rs Outdated Show resolved Hide resolved

/// Assume the RNG is actually producing true random numbers - which is the case
/// when radio peripherals are enabled
struct ProbablyTrng;
Copy link
Contributor

Choose a reason for hiding this comment

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

I love the name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Me too 😄

@bugadani
Copy link
Contributor

I only have micronits to pick right now - like the fact that this PR isn't about the examples I think, but the provider crate 🤔 What are the long term plans, are we to provide hardware acceleration through the provider crate, where we can?

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Jan 23, 2025

I only have micronits to pick right now - like the fact that this PR isn't about the examples I think, but the provider crate 🤔 What are the long term plans, are we to provide hardware acceleration through the provider crate, where we can?

Good point about the PR title 👍

Yes - we definitely want to support HW-crypto long-term (it's hidden in a vague sentence in the README - should have written it in the PR description)

@bjoernQ bjoernQ changed the title Add Rustls examples Add Rustls provider including examples Jan 23, 2025
Copy link
Member

@MabezDev MabezDev 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 addressing my comments, LGTM.

Please don't forget to file the relevant issues once this is merged 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore Rustls and create an example
4 participants