Skip to content

Commit 1806f8f

Browse files
Update esp-hal to 0.23.0, esp-wifi to 0.12.0. Deduplicate mTLS examples (#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
1 parent 9cce6c2 commit 1806f8f

22 files changed

+276
-1143
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- uses: dtolnay/rust-toolchain@v1
2929
with:
3030
target: riscv32imc-unknown-none-elf
31-
toolchain: nightly-2024-12-01
31+
toolchain: nightly
3232
components: rust-src,rustfmt
3333
- uses: esp-rs/[email protected]
3434
with:

Cargo.toml

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
authors = ["bjoernQ <[email protected]>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
7-
rust-version = "1.82"
7+
rust-version = "1.84"
88

99
[profile.release]
1010
debug = true
@@ -24,39 +24,32 @@ opt-level = "z"
2424
opt-level = 3
2525

2626
[dependencies]
27-
esp-hal = { version = "0.22.0", optional = true }
28-
esp-backtrace = { version = "0.14.0", optional = true, features = [
27+
esp-hal = { version = "0.23.0", optional = true }
28+
esp-backtrace = { version = "0.15.0", optional = true, features = [
2929
"panic-handler",
3030
"println",
3131
"exception-handler",
3232
] }
33-
esp-println = { version = "0.12.0", optional = true, features = ["log"] }
34-
esp-hal-embassy = { version = "0.5.0", optional = true }
33+
esp-println = { version = "0.13.0", optional = true, features = ["log"] }
34+
esp-hal-embassy = { version = "0.6.0", optional = true }
3535

36-
embassy-time = { version = "0.3.0", optional = true }
37-
embassy-executor = { version = "0.6", package = "embassy-executor", features = [
36+
embassy-time = { version = "0.4.0", optional = true }
37+
embassy-executor = { version = "0.7", package = "embassy-executor", features = [
3838
"nightly",
39-
"integrated-timers",
4039
], optional = true }
41-
embassy-net = { version = "0.5.0", features = [
40+
embassy-net = { version = "0.6.0", features = [
4241
"tcp",
4342
"udp",
4443
"dhcpv4",
4544
"medium-ethernet",
4645
], optional = true }
4746

48-
esp-wifi = { version = "0.11.0", optional = true, features = ["sys-logs", "utils", "wifi"] }
49-
blocking-network-stack = { git = "https://github.com/bjoernQ/blocking-network-stack", rev = "1c581661d78e0cf0f17b936297179b993fb149d7" }
50-
smoltcp11 = { package = "smoltcp", version = "0.11.0", optional = true, default-features = false, features = [
51-
"proto-ipv4",
52-
"socket-tcp",
53-
"socket-icmp",
54-
"socket-udp",
55-
"medium-ethernet",
56-
"proto-dhcpv4",
57-
"socket-raw",
58-
"socket-dhcpv4",
47+
esp-wifi = { version = "0.12.0", optional = true, features = [
48+
"sys-logs",
49+
"utils",
50+
"wifi",
5951
] }
52+
blocking-network-stack = { git = "https://github.com/bjoernQ/blocking-network-stack", rev = "b3ecefc222d8806edd221f266999ca339c52d34e" }
6053
smoltcp = { version = "0.12.0", optional = true, default-features = false, features = [
6154
"proto-ipv4",
6255
"socket-tcp",
@@ -76,17 +69,15 @@ static_cell = { version = "2.1", features = ["nightly"] }
7669

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

79-
edge-http = { version = "0.4.0", optional = true }
80-
edge-nal = { version = "0.4.0", optional = true }
81-
edge-nal-embassy = { version = "0.4.0", optional = true }
72+
edge-http = { version = "0.5.0", optional = true }
73+
edge-nal = { version = "0.5.0", optional = true }
74+
edge-nal-embassy = { version = "0.5.0", optional = true }
8275
cfg-if = "1.0.0"
83-
esp-alloc = { version = "0.5.0", optional = true}
76+
esp-alloc = { version = "0.6.0", optional = true }
8477
enumset = { version = "1", default-features = false }
8578

86-
tinyrlibc = { version = "0.5", optional = true, default-features = false }
87-
8879
[target.'cfg(target_os = "espidf")'.dependencies]
89-
esp-idf-svc = { version = "0.50", features = ["binstart"] }
80+
esp-idf-svc = { version = "0.51", features = ["binstart"] }
9081

9182
[[example]]
9283
name = "crypto_self_test"
@@ -99,25 +90,35 @@ name = "crypto_self_test_std"
9990
name = "async_client"
10091
required-features = ["examples-async"]
10192

102-
[[example]]
103-
name = "async_client_mTLS"
104-
required-features = ["examples-async"]
105-
10693
[[example]]
10794
name = "async_server"
10895
required-features = ["examples-async"]
10996

110-
[[example]]
111-
name = "async_server_mTLS"
112-
required-features = ["examples-async"]
113-
11497
[[example]]
11598
name = "edge_server"
11699
required-features = ["examples-async", "edge-http"]
117100

118101
[features]
119-
examples = ["esp-hal", "esp-backtrace", "esp-println", "esp-wifi", "smoltcp", "smoltcp11", "esp-alloc"]
120-
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"]
102+
examples = [
103+
"esp-hal",
104+
"esp-backtrace",
105+
"esp-println",
106+
"esp-wifi",
107+
"smoltcp",
108+
"esp-alloc",
109+
]
110+
examples-async = [
111+
"examples",
112+
"esp-hal-embassy",
113+
"embassy-time",
114+
"embassy-executor",
115+
"embassy-net",
116+
"edge-http",
117+
"edge-nal",
118+
"edge-nal-embassy",
119+
"esp-mbedtls/async",
120+
"esp-mbedtls/edge-nal",
121+
]
121122
examples-std = ["critical-section/std"]
122123

123124
esp32 = [
@@ -135,7 +136,6 @@ esp32c3 = [
135136
"esp-println?/esp32c3",
136137
"esp-wifi?/esp32c3",
137138
"esp-mbedtls/esp32c3",
138-
"tinyrlibc/memchr",
139139
]
140140
esp32s2 = [
141141
"esp-hal?/esp32s2",
@@ -154,5 +154,13 @@ esp32s3 = [
154154
"esp-mbedtls/esp32s3",
155155
]
156156

157+
# Enable mTLS for the running example. See example documentation for further details.
158+
# Applies to:
159+
# - async_client
160+
# - async_server
161+
# - sync_client
162+
# - sync_server
163+
mtls = []
164+
157165
[build-dependencies]
158166
embuild = { version = "0.33", features = ["espidf"] }

README.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ It comes with mbedtls precompiled to avoid the need for a complete C toolchain.
88

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

11-
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.
12-
1311
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`.
1412

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

17-
Currently this won't work on ESP32-S2 - getting it to work will require tweaking the memory usage a lot!
18-
1915
The examples use one hard-coded address of `www.google.com` which might not always work.
2016

2117
### Certificates
@@ -30,10 +26,9 @@ Examples are available for:
3026

3127
- esp32
3228
- esp32c3
29+
- esp32s2
3330
- esp32s3
3431

35-
Limited support is also available for `esp32s2` but it won't compile for async.
36-
3732
To run examples, you need to specify the architecture as a feature, the example name, the target and the toolchain.
3833

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

63-
Heres's a list of all the examples with their description:
64-
65-
| Example | Description |
66-
| :---------------- | ------------------------------------------------------------ |
67-
| async_client | Example of a HTTPS connection using the async client. |
68-
| 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. |
69-
| sync_client | Example of a HTTPS connection using the sync client. |
70-
| 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. |
71-
| 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. |
72-
| 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. |
73-
| 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. |
74-
| 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. |
59+
Heres's a list of all the examples with their description, and the required features to enable them:
60+
61+
| Example | Features | Description |
62+
| :----------------------- | -------- | ------------------------------------------------------------ |
63+
| async_client | - | Example of a HTTPS connection using the async client. |
64+
| 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. |
65+
| sync_client | - | Example of a HTTPS connection using the sync client. |
66+
| 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. |
67+
| 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. |
68+
| 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. |
69+
| 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. |
70+
| 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. |
7571

7672
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`
7773

esp-mbedtls-sys/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55
links = "mbedtls"
66
license = "MIT OR Apache-2.0"
7-
rust-version = "1.82"
7+
rust-version = "1.84"
88

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

2424
# ESP-IDF: The mbedtls lib distributed with ESP-IDF is used
2525
[target.'cfg(target_os = "espidf")'.dependencies]

esp-mbedtls/Cargo.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "esp-mbedtls"
33
version = "0.1.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
6-
rust-version = "1.82"
6+
rust-version = "1.84"
77

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

2728
[features]
2829
default = ["edge-nal"]
2930
async = ["dep:embedded-io-async"]
30-
esp32 = ["esp-hal/esp32", "esp-wifi/esp32", "esp-mbedtls-sys/esp32", "crypto-bigint"]
31-
esp32c3 = ["esp-hal/esp32c3", "esp-wifi/esp32c3", "esp-mbedtls-sys/esp32c3", "crypto-bigint"]
32-
esp32s2 = ["esp-hal/esp32s2", "esp-wifi/esp32s2", "esp-mbedtls-sys/esp32s2", "crypto-bigint"]
33-
esp32s3 = ["esp-hal/esp32s3", "esp-wifi/esp32s3", "esp-mbedtls-sys/esp32s3", "crypto-bigint"]
31+
esp32 = ["esp-hal/esp32", "esp-wifi/esp32", "esp-mbedtls-sys/esp32"]
32+
esp32c3 = ["esp-hal/esp32c3", "esp-wifi/esp32c3", "esp-mbedtls-sys/esp32c3"]
33+
esp32s2 = ["esp-hal/esp32s2", "esp-wifi/esp32s2", "esp-mbedtls-sys/esp32s2"]
34+
esp32s3 = ["esp-hal/esp32s3", "esp-wifi/esp32s3", "esp-mbedtls-sys/esp32s3"]
3435

3536
# Implement the traits defined in the latest HEAD of `edge-nal`
3637
edge-nal = ["dep:edge-nal", "async"]
38+
39+
# Enable dependencies related to esp-hal (baremetal)
40+
esp-hal = ["dep:esp-hal", "crypto-bigint", "nb"]

esp-mbedtls/src/esp_hal/bignum.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use core::ffi::c_int;
44

5-
use esp_hal::prelude::nb;
65
use esp_hal::rsa::{operand_sizes, RsaModularExponentiation};
76

87
use crypto_bigint::*;

esp-mbedtls/src/esp_hal/sha/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use esp_hal::prelude::nb;
21
use esp_hal::sha::{Context, ShaDigest};
32

43
mod sha1;

esp-mbedtls/src/esp_hal/sha/sha1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use esp_hal::sha::Sha1;
44

55
use crate::esp_hal::SHARED_SHA;
66

7-
use super::{nb, Context, ShaDigest};
7+
use super::{Context, ShaDigest};
88

99
#[allow(non_camel_case_types)]
1010
#[repr(C)]

esp-mbedtls/src/esp_hal/sha/sha256.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use esp_hal::sha::{Sha224, Sha256};
44

55
use crate::esp_hal::SHARED_SHA;
66

7-
use super::{nb, Context, ShaDigest};
7+
use super::{Context, ShaDigest};
88

99
#[allow(non_camel_case_types)]
1010
#[repr(C)]

esp-mbedtls/src/esp_hal/sha/sha512.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use esp_hal::sha::{Sha384, Sha512};
44

55
use crate::esp_hal::SHARED_SHA;
66

7-
use super::{nb, Context, ShaDigest};
7+
use super::{Context, ShaDigest};
88

99
#[allow(non_camel_case_types)]
1010
#[repr(C)]

0 commit comments

Comments
 (0)