Skip to content

Commit

Permalink
Update esp-hal to 0.23.0, esp-wifi to 0.12.0. Deduplicate mTLS exampl…
Browse files Browse the repository at this point in the history
…es (#66)

* chore: Update esp-hal to 0.23.0, esp-wifi to 0.12.0

* clippy

* chore: Deduplicate mTLS examples behind a feature.

mTLS and non-mTLS examples are essentially the same, structurally, but with different parameters.
This merge removes a huge maintenance burden by reducing the amount of example files.

* Update README.md
  • Loading branch information
AnthonyGrondin authored Jan 20, 2025
1 parent 9cce6c2 commit 1806f8f
Show file tree
Hide file tree
Showing 22 changed files with 276 additions and 1,143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: dtolnay/rust-toolchain@v1
with:
target: riscv32imc-unknown-none-elf
toolchain: nightly-2024-12-01
toolchain: nightly
components: rust-src,rustfmt
- uses: esp-rs/[email protected]
with:
Expand Down
84 changes: 46 additions & 38 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["bjoernQ <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.82"
rust-version = "1.84"

[profile.release]
debug = true
Expand All @@ -24,39 +24,32 @@ opt-level = "z"
opt-level = 3

[dependencies]
esp-hal = { version = "0.22.0", optional = true }
esp-backtrace = { version = "0.14.0", optional = true, features = [
esp-hal = { version = "0.23.0", optional = true }
esp-backtrace = { version = "0.15.0", optional = true, features = [
"panic-handler",
"println",
"exception-handler",
] }
esp-println = { version = "0.12.0", optional = true, features = ["log"] }
esp-hal-embassy = { version = "0.5.0", optional = true }
esp-println = { version = "0.13.0", optional = true, features = ["log"] }
esp-hal-embassy = { version = "0.6.0", optional = true }

embassy-time = { version = "0.3.0", optional = true }
embassy-executor = { version = "0.6", package = "embassy-executor", features = [
embassy-time = { version = "0.4.0", optional = true }
embassy-executor = { version = "0.7", package = "embassy-executor", features = [
"nightly",
"integrated-timers",
], optional = true }
embassy-net = { version = "0.5.0", features = [
embassy-net = { version = "0.6.0", features = [
"tcp",
"udp",
"dhcpv4",
"medium-ethernet",
], optional = true }

esp-wifi = { version = "0.11.0", optional = true, features = ["sys-logs", "utils", "wifi"] }
blocking-network-stack = { git = "https://github.com/bjoernQ/blocking-network-stack", rev = "1c581661d78e0cf0f17b936297179b993fb149d7" }
smoltcp11 = { package = "smoltcp", version = "0.11.0", optional = true, default-features = false, features = [
"proto-ipv4",
"socket-tcp",
"socket-icmp",
"socket-udp",
"medium-ethernet",
"proto-dhcpv4",
"socket-raw",
"socket-dhcpv4",
esp-wifi = { version = "0.12.0", optional = true, features = [
"sys-logs",
"utils",
"wifi",
] }
blocking-network-stack = { git = "https://github.com/bjoernQ/blocking-network-stack", rev = "b3ecefc222d8806edd221f266999ca339c52d34e" }
smoltcp = { version = "0.12.0", optional = true, default-features = false, features = [
"proto-ipv4",
"socket-tcp",
Expand All @@ -76,17 +69,15 @@ static_cell = { version = "2.1", features = ["nightly"] }

esp-mbedtls = { path = "./esp-mbedtls" }

edge-http = { version = "0.4.0", optional = true }
edge-nal = { version = "0.4.0", optional = true }
edge-nal-embassy = { version = "0.4.0", optional = true }
edge-http = { version = "0.5.0", optional = true }
edge-nal = { version = "0.5.0", optional = true }
edge-nal-embassy = { version = "0.5.0", optional = true }
cfg-if = "1.0.0"
esp-alloc = { version = "0.5.0", optional = true}
esp-alloc = { version = "0.6.0", optional = true }
enumset = { version = "1", default-features = false }

tinyrlibc = { version = "0.5", optional = true, default-features = false }

[target.'cfg(target_os = "espidf")'.dependencies]
esp-idf-svc = { version = "0.50", features = ["binstart"] }
esp-idf-svc = { version = "0.51", features = ["binstart"] }

[[example]]
name = "crypto_self_test"
Expand All @@ -99,25 +90,35 @@ name = "crypto_self_test_std"
name = "async_client"
required-features = ["examples-async"]

[[example]]
name = "async_client_mTLS"
required-features = ["examples-async"]

[[example]]
name = "async_server"
required-features = ["examples-async"]

[[example]]
name = "async_server_mTLS"
required-features = ["examples-async"]

[[example]]
name = "edge_server"
required-features = ["examples-async", "edge-http"]

[features]
examples = ["esp-hal", "esp-backtrace", "esp-println", "esp-wifi", "smoltcp", "smoltcp11", "esp-alloc"]
examples-async = ["examples", "esp-hal-embassy", "embassy-time", "embassy-executor", "embassy-net", "edge-http", "edge-nal", "edge-nal-embassy", "esp-mbedtls/async", "esp-mbedtls/edge-nal"]
examples = [
"esp-hal",
"esp-backtrace",
"esp-println",
"esp-wifi",
"smoltcp",
"esp-alloc",
]
examples-async = [
"examples",
"esp-hal-embassy",
"embassy-time",
"embassy-executor",
"embassy-net",
"edge-http",
"edge-nal",
"edge-nal-embassy",
"esp-mbedtls/async",
"esp-mbedtls/edge-nal",
]
examples-std = ["critical-section/std"]

esp32 = [
Expand All @@ -135,7 +136,6 @@ esp32c3 = [
"esp-println?/esp32c3",
"esp-wifi?/esp32c3",
"esp-mbedtls/esp32c3",
"tinyrlibc/memchr",
]
esp32s2 = [
"esp-hal?/esp32s2",
Expand All @@ -154,5 +154,13 @@ esp32s3 = [
"esp-mbedtls/esp32s3",
]

# Enable mTLS for the running example. See example documentation for further details.
# Applies to:
# - async_client
# - async_server
# - sync_client
# - sync_server
mtls = []

[build-dependencies]
embuild = { version = "0.33", features = ["espidf"] }
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ It comes with mbedtls precompiled to avoid the need for a complete C toolchain.

This should work together with `esp-wifi`. It currently won't work without. However it's not well tested yet besides the included examples.

See the examples for how to use it. A key thing is to [set a bigger heap size](https://github.com/esp-rs/esp-wifi/blob/main/esp-wifi/docs/tuning.md) for esp-wifi since more heap memory is needed to get this working.

In general this is heavy in terms of heap memory used and code size. If you can, you should prefer using something like `embedded-tls`.

For now it's missing advanced configuration options which will be added step-by-step.

Currently this won't work on ESP32-S2 - getting it to work will require tweaking the memory usage a lot!

The examples use one hard-coded address of `www.google.com` which might not always work.

### Certificates
Expand All @@ -30,10 +26,9 @@ Examples are available for:

- esp32
- esp32c3
- esp32s2
- esp32s3

Limited support is also available for `esp32s2` but it won't compile for async.

To run examples, you need to specify the architecture as a feature, the example name, the target and the toolchain.

You also need to set `SSID` and `PASSWORD` as your environment variables
Expand All @@ -58,20 +53,21 @@ Here's a table of the architectures with their corresponding target for quick re
| ------------ | --------------------------- | ------------------ |
| esp32 | xtensa-esp32-none-elf | esp |
| esp32c3 | riscv32imc-unknown-none-elf | nightly |
| esp32s2 | xtensa-esp32s2-none-elf | esp |
| esp32s3 | xtensa-esp32s3-none-elf | esp |

Heres's a list of all the examples with their description:

| Example | Description |
| :---------------- | ------------------------------------------------------------ |
| async_client | Example of a HTTPS connection using the async client. |
| async_client_mTLS | Example of a HTTPS connection using the async client, with certificate authentication. This sends client certificates to a server, and the response indicates informations about the certificates. |
| sync_client | Example of a HTTPS connection using the sync client. |
| sync_client_mTLS | Example of a HTTPS connection using the sync client, with certificate authentication. This sends client certificates to a server, and the response indicates informations about the certificates. |
| async_server | Example of a simple async server with HTTPS support. This uses self-signed certificates, so you will need to enable an exception in your browser. |
| async_server_mTLS | Example of a simple async server with HTTPS support, with client authentication. You will need to pass client certificates in your request in order to have a successful connection. Refer to the documentation inside the example. |
| sync_server | Example of a simple sync server with HTTPS support. This uses self-signed certificates, so you will need to enable an exception in your browser. |
| sync_server_mTLS | Example of a simple sync server with HTTPS support, with client authentication. You will need to pass client certificates in your request in order to have a successful connection. Refer to the documentation inside the example. |
Heres's a list of all the examples with their description, and the required features to enable them:

| Example | Features | Description |
| :----------------------- | -------- | ------------------------------------------------------------ |
| async_client | - | Example of a HTTPS connection using the async client. |
| async_client (with mTLS) | mtls | Example of a HTTPS connection using the async client, with certificate authentication. This sends client certificates to a server, and the response indicates informations about the certificates. |
| sync_client | - | Example of a HTTPS connection using the sync client. |
| sync_client (with mTLS) | mtls | Example of a HTTPS connection using the sync client, with certificate authentication. This sends client certificates to a server, and the response indicates informations about the certificates. |
| async_server | - | Example of a simple async server with HTTPS support. This uses self-signed certificates, so you will need to enable an exception in your browser. |
| async_server (with mTLS) | mtls | Example of a simple async server with HTTPS support, with client authentication. You will need to pass client certificates in your request in order to have a successful connection. Refer to the documentation inside the example. |
| sync_server | - | Example of a simple sync server with HTTPS support. This uses self-signed certificates, so you will need to enable an exception in your browser. |
| sync_server (with mTLS) | mtls | Example of a simple sync server with HTTPS support, with client authentication. You will need to pass client certificates in your request in order to have a successful connection. Refer to the documentation inside the example. |

This needs `espflash` version 2.x. If you are using version 1.x you need to remove the `flash` command from the runner in `.cargo/config.toml`

Expand Down
4 changes: 2 additions & 2 deletions esp-mbedtls-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
links = "mbedtls"
license = "MIT OR Apache-2.0"
rust-version = "1.82"
rust-version = "1.84"

[build-dependencies]
anyhow = "1.0.68"
Expand All @@ -19,7 +19,7 @@ embuild = "0.33"
# For malloc/free
# TODO: Replace with `esp-alloc` once `esp-alloc` starts to provide `malloc` and `free` in future
# ... or switch to our own `mbedtls_malloc/free`
esp-wifi = { version = "0.11.0", default-features = false, optional = true }
esp-wifi = { version = "0.12.0", default-features = false, optional = true }

# ESP-IDF: The mbedtls lib distributed with ESP-IDF is used
[target.'cfg(target_os = "espidf")'.dependencies]
Expand Down
20 changes: 12 additions & 8 deletions esp-mbedtls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "esp-mbedtls"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.82"
rust-version = "1.84"

[lib]
harness = false
Expand All @@ -14,23 +14,27 @@ log = { version = "0.4.17", default-features = false }
enumset = { version = "1", default-features = false }
embedded-io = { version = "0.6.1" }
embedded-io-async = { version = "0.6.0", optional = true }
esp-hal = { version = "0.22.0", optional = true }
esp-hal = { version = "0.23.0", optional = true }
# For malloc/free
# TODO: Replace with `esp-alloc` once `esp-alloc` starts to provide `malloc` and `free` in future
# ... or switch to our own `mbedtls_malloc/free`
esp-wifi = { version = "0.11.0", default-features = false, optional = true }
esp-wifi = { version = "0.12.0", default-features = false, optional = true }
cfg-if = "1.0.0"
edge-nal = { version = "0.4.0", optional = true }
edge-nal = { version = "0.5.0", optional = true }
critical-section = "1.1.3"
crypto-bigint = { version = "0.5.3", optional = true, default-features = false, features = ["extra-sizes"] }
nb = { version = "1.1.0", optional = true }

[features]
default = ["edge-nal"]
async = ["dep:embedded-io-async"]
esp32 = ["esp-hal/esp32", "esp-wifi/esp32", "esp-mbedtls-sys/esp32", "crypto-bigint"]
esp32c3 = ["esp-hal/esp32c3", "esp-wifi/esp32c3", "esp-mbedtls-sys/esp32c3", "crypto-bigint"]
esp32s2 = ["esp-hal/esp32s2", "esp-wifi/esp32s2", "esp-mbedtls-sys/esp32s2", "crypto-bigint"]
esp32s3 = ["esp-hal/esp32s3", "esp-wifi/esp32s3", "esp-mbedtls-sys/esp32s3", "crypto-bigint"]
esp32 = ["esp-hal/esp32", "esp-wifi/esp32", "esp-mbedtls-sys/esp32"]
esp32c3 = ["esp-hal/esp32c3", "esp-wifi/esp32c3", "esp-mbedtls-sys/esp32c3"]
esp32s2 = ["esp-hal/esp32s2", "esp-wifi/esp32s2", "esp-mbedtls-sys/esp32s2"]
esp32s3 = ["esp-hal/esp32s3", "esp-wifi/esp32s3", "esp-mbedtls-sys/esp32s3"]

# Implement the traits defined in the latest HEAD of `edge-nal`
edge-nal = ["dep:edge-nal", "async"]

# Enable dependencies related to esp-hal (baremetal)
esp-hal = ["dep:esp-hal", "crypto-bigint", "nb"]
1 change: 0 additions & 1 deletion esp-mbedtls/src/esp_hal/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use core::ffi::c_int;

use esp_hal::prelude::nb;
use esp_hal::rsa::{operand_sizes, RsaModularExponentiation};

use crypto_bigint::*;
Expand Down
1 change: 0 additions & 1 deletion esp-mbedtls/src/esp_hal/sha/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use esp_hal::prelude::nb;
use esp_hal::sha::{Context, ShaDigest};

mod sha1;
Expand Down
2 changes: 1 addition & 1 deletion esp-mbedtls/src/esp_hal/sha/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use esp_hal::sha::Sha1;

use crate::esp_hal::SHARED_SHA;

use super::{nb, Context, ShaDigest};
use super::{Context, ShaDigest};

#[allow(non_camel_case_types)]
#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion esp-mbedtls/src/esp_hal/sha/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use esp_hal::sha::{Sha224, Sha256};

use crate::esp_hal::SHARED_SHA;

use super::{nb, Context, ShaDigest};
use super::{Context, ShaDigest};

#[allow(non_camel_case_types)]
#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion esp-mbedtls/src/esp_hal/sha/sha512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use esp_hal::sha::{Sha384, Sha512};

use crate::esp_hal::SHARED_SHA;

use super::{nb, Context, ShaDigest};
use super::{Context, ShaDigest};

#[allow(non_camel_case_types)]
#[repr(C)]
Expand Down
Loading

0 comments on commit 1806f8f

Please sign in to comment.