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: Update esp-mbedtls compatiblity with latest HEAD #97

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ pub struct TlsConfig<'a, const RX_SIZE: usize = 4096, const TX_SIZE: usize = 409
/// Client certificates. See [esp_mbedtls::Certificates]
certificates: crate::Certificates<'a>,

/// Will use hardware acceleration on the ESP32 if it contains the RSA peripheral.
rsa: Option<&'a mut esp_mbedtls::hal::peripherals::RSA>,

/// Buffer for the reading side of the TLS connection
read_buffer: &'a mut [u8; RX_SIZE],

/// Buffer for the writing side of the TLS connection
write_buffer: &'a mut [u8; TX_SIZE],
/// A reference to instance of the MbedTLS library.
tls_reference: esp_mbedtls::TlsReference<'a>,
}

/// Type for TLS configuration of HTTP client.
Expand Down Expand Up @@ -78,18 +72,14 @@ impl<'a> TlsConfig<'a> {
#[cfg(feature = "esp-mbedtls")]
impl<'a, const RX_SIZE: usize, const TX_SIZE: usize> TlsConfig<'a, RX_SIZE, TX_SIZE> {
pub fn new(
read_buffer: &'a mut [u8; RX_SIZE],
write_buffer: &'a mut [u8; TX_SIZE],
version: crate::TlsVersion,
certificates: crate::Certificates<'a>,
rsa: Option<&'a mut esp_mbedtls::hal::peripherals::RSA>,
tls_reference: crate::TlsReference<'a>,
) -> Self {
Self {
version,
certificates,
rsa,
read_buffer,
write_buffer,
tls_reference,
}
}
}
Expand Down Expand Up @@ -141,21 +131,20 @@ where
if url.scheme() == UrlScheme::HTTPS {
#[cfg(feature = "esp-mbedtls")]
if let Some(tls) = self.tls.as_mut() {
let mut servername = host.as_bytes().to_vec();
servername.push(0);
let mut session = esp_mbedtls::asynch::Session::new(
conn,
host,
esp_mbedtls::Mode::Client,
esp_mbedtls::Mode::Client {
servername: unsafe { core::ffi::CStr::from_bytes_with_nul_unchecked(&servername) },
},
tls.version,
tls.certificates,
tls.read_buffer,
tls.write_buffer,
tls.tls_reference,
)?;

if let Some(rsa) = tls.rsa.as_mut() {
session = session.with_hardware_rsa(rsa as &mut esp_mbedtls::hal::peripherals::RSA);
}

Ok(HttpConnection::Tls(session.connect().await?))
session.connect().await?;
Ok(HttpConnection::Tls(session))
} else {
Ok(HttpConnection::Plain(conn))
}
Expand Down Expand Up @@ -234,7 +223,7 @@ where
Plain(C),
PlainBuffered(BufferedWrite<'conn, C>),
#[cfg(feature = "esp-mbedtls")]
Tls(esp_mbedtls::asynch::AsyncConnectedSession<'conn, C, 4096, 4096>),
Tls(esp_mbedtls::asynch::Session<'conn, C>),
#[cfg(feature = "embedded-tls")]
Tls(embedded_tls::TlsConnection<'conn, C, embedded_tls::Aes128GcmSha256>),
#[cfg(all(not(feature = "embedded-tls"), not(feature = "esp-mbedtls")))]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl From<embedded_tls::TlsError> for Error {

/// Re-export those members since they're used for [client::TlsConfig].
#[cfg(feature = "esp-mbedtls")]
pub use esp_mbedtls::{Certificates, TlsVersion, X509};
pub use esp_mbedtls::{Certificates, TlsVersion, X509, TlsReference};

#[cfg(feature = "esp-mbedtls")]
impl From<esp_mbedtls::TlsError> for Error {
Expand Down