-
Notifications
You must be signed in to change notification settings - Fork 13
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
TLS & DTLS fixes #445
base: RSDK-8990-platform-modernization
Are you sure you want to change the base?
TLS & DTLS fixes #445
Conversation
micro-rdk/src/esp32/certificate.rs
Outdated
@@ -235,6 +237,15 @@ impl GeneratedWebRtcCertificateBuilder { | |||
)) | |||
}?; | |||
|
|||
let mut serial_number = [0xAB_u8; 12]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required now to generate a webrtc cert
use futures_lite::{AsyncRead, AsyncWrite, Future}; | ||
use log::{log, Level}; | ||
use thiserror::Error; | ||
|
||
use super::tcp::Esp32TLSContext; | ||
|
||
const MBEDTLS_ERR_NET_SEND_FAILED: i32 = -0x4E; | ||
const MBEDTLS_ERR_NET_RECV_FAILED: i32 = -0x4C; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had to manually add them, not sure if esp-rs will update their code to include these symbols
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did file an issue upstream with them: https://github.com/viamrobotics/micro-rdk/pull/445/files, but at the time we weren't prioritizing ESP-IDF 5 and following up fell off my todo list. Do you want me to re-engage with them and see if they are willing to make a fix?
Also, do you have any thoughts on the package they indicated: https://github.com/esp-rs/esp-mbedtls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, can we add a comment here explaining why we are doing this, and maybe referencing the upstream issue?
@@ -228,7 +231,7 @@ extern "C" fn mbedtls_timing_dtls_set_delay<S>( | |||
} else if let Some(ssl_ctx) = ctx.ssl_ctx { | |||
let (_, cx) = unsafe { | |||
// TODO(RSDK-10196): The `p_bio` field doesn't exist in ESP-IDF 5. Maybe it should be `private_p_bio`? | |||
let state = SSLStreamInner::<S>::from_raw((*ssl_ctx).p_bio); | |||
let state = SSLStreamInner::<S>::from_raw((*ssl_ctx).private_p_bio); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't do that. We could use a user_data field in the ssl context struct alternatively (it is private as well) however it's accessor functions are inline and therefore not exported by bindgen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this hinting that we are somehow misusing mbedtls, that we suddenly need access to "private" state? Or do you think this is more a flaw in the rust bindings, in that we can't make use of the user_data field?
@@ -350,13 +336,13 @@ where | |||
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? | |||
}; | |||
|
|||
unsafe { | |||
mbedtls_ssl_conf_read_timeout( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit : it's doable but I hate it. I want to remove it unless there is a strong opinion against
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't you like it? what's the implication of us not having it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like answers to Matt's questions too. Are you proposing removing setting the SSL read timeout entirely, rather than accessing private_conf
(about which I share your distaste)? Are we sure there isn't some other mechanism to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
notes from offline discussion:
- as we're bypassing the (unavailable) access methods, there are no guarantees
- would need to propose a stub or two in esp-idf-sys to actually get those access methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move forward with this in the interest of unblocking our efforts, but overall I'm uncomfortable with many of the choices we have been forced to make. I hope we can revisit this work later and work with upstream to understand whether some of these are things we should be approaching differently, or to get them to expose more where that would help.
Procedurally, this closes out several tickets, but it also has open TODOs against those tickets, which is a bit awkward. If you want, I can go ahead and make a new ticket to commit this work under, and a ticket for follow-up work on TLS/DTLS, and then all the TODOs that referenced the older tickets can be adjusted to refer to the follow-up ticket?
use futures_lite::{AsyncRead, AsyncWrite, Future}; | ||
use log::{log, Level}; | ||
use thiserror::Error; | ||
|
||
use super::tcp::Esp32TLSContext; | ||
|
||
const MBEDTLS_ERR_NET_SEND_FAILED: i32 = -0x4E; | ||
const MBEDTLS_ERR_NET_RECV_FAILED: i32 = -0x4C; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did file an issue upstream with them: https://github.com/viamrobotics/micro-rdk/pull/445/files, but at the time we weren't prioritizing ESP-IDF 5 and following up fell off my todo list. Do you want me to re-engage with them and see if they are willing to make a fix?
Also, do you have any thoughts on the package they indicated: https://github.com/esp-rs/esp-mbedtls?
use futures_lite::{AsyncRead, AsyncWrite, Future}; | ||
use log::{log, Level}; | ||
use thiserror::Error; | ||
|
||
use super::tcp::Esp32TLSContext; | ||
|
||
const MBEDTLS_ERR_NET_SEND_FAILED: i32 = -0x4E; | ||
const MBEDTLS_ERR_NET_RECV_FAILED: i32 = -0x4C; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, can we add a comment here explaining why we are doing this, and maybe referencing the upstream issue?
@@ -228,7 +231,7 @@ extern "C" fn mbedtls_timing_dtls_set_delay<S>( | |||
} else if let Some(ssl_ctx) = ctx.ssl_ctx { | |||
let (_, cx) = unsafe { | |||
// TODO(RSDK-10196): The `p_bio` field doesn't exist in ESP-IDF 5. Maybe it should be `private_p_bio`? | |||
let state = SSLStreamInner::<S>::from_raw((*ssl_ctx).p_bio); | |||
let state = SSLStreamInner::<S>::from_raw((*ssl_ctx).private_p_bio); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this hinting that we are somehow misusing mbedtls, that we suddenly need access to "private" state? Or do you think this is more a flaw in the rust bindings, in that we can't make use of the user_data field?
std::ptr::null_mut(), | ||
0, | ||
cfg.get_cfg_ptr() as *const c_void, | ||
esp!(esp_tls_server_session_create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see the write_unaligned
's are no longer needed.
@@ -350,13 +336,13 @@ where | |||
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? | |||
}; | |||
|
|||
unsafe { | |||
mbedtls_ssl_conf_read_timeout( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like answers to Matt's questions too. Are you proposing removing setting the SSL read timeout entirely, rather than accessing private_conf
(about which I share your distaste)? Are we sure there isn't some other mechanism to do this?
covers
RSDK-10196
RSDK-10197
RSDK-10198
RSDK-10200
RSDK-10201