-
Notifications
You must be signed in to change notification settings - Fork 26
Add client authentication with certificates #3
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
Conversation
I tested this on ESP32-C3 with debug output (we are not able to get debug output on Xtensa currently because there is a problem with variadic args)
-0x4290 is likely |
I made some progress. First thing was increasing the heap ( https://github.com/esp-rs/esp-wifi/blob/cce6738220f4f12ab4db92f74295e762f5425e99/esp-wifi/src/lib.rs#L96 ) to 110k Then I was able to get through the handshake on ESP32-C3 but I wasn't able to receive data afterwards. Since there might be problems with the async IO I basically did the same things you did for async for the sync API. Now on ESP32-C3 I get this with a
However, no luck so far with ESP32-S3 and ESP32. |
Seems there is really some mis-compilation / mis-optimization. Building mbedtls in debug mode made it kind of work on ESP32-S3
But the handshake takes forever to complete - also on ESP32 it still doesn't seem to work |
Some interesting observations - probably more as a note to self:
|
After rebasing this should work now |
Great! I'm gonna test it on my side and finish this PR. |
Oops didn't mean to do that. |
- Add example for sync esp32s3 - Enable usage of encrypted key with password - Move certificates to a struct
Everything seems to work for now. I'm waiting for a first review before doing the other examples. Not sure if it's related to this PR, but it seems like the closing of connection isn't done properly. The given error is:
|
I'm wondering if we should unify it under a single function to reduce duplication. Most of the body for |
Agreed - I think I wanted to do it like that in the beginning but when the problems with the pre-compiled binaries kicked in I just went that way The new examples seem to work fine for me on ESP32-S3 - the other examples need adjustments because of the changes to the constructor Great work! |
- Fix existing examples to use the new Certificates struct
Nice! Seems like the new examples for ESP32 and ESP32-C3 are missing an `use esp_mbedtls::Certificates;´ - I probably should setup CI in this repo @MabezDev works fine with our Rust 1.68 but with Rust 1.69 I see it gets stuck at the connection to the access point on ESP32-S3, again 😢 I tried tinkering with opt-level and lto etc. without success |
I added the imports that I missed. I've only tested on esp32s3, as it's the only device I have on hand. I think some optimizations could be made, by not allocating memory for certificates, if we don't use them. This would be especially useful when not using client certificates, but I'm not sure about the behavior of freeing memory that hasn't been allocated, when dropping the Session struct. |
I tested on ESP32 and ESP32-C3 - everything fine now. I'd say this is fine to get merged now. The suggested optimization totally makes sense - if some memory isn't allocated there would be a null-pointer which should get checked in Would be perfectly fine to do the optimization in a follow-up PR and we merge this - not sure what option you'd prefer. Just let me know and I'll approve and merge this |
I think we should merge this, then do the optimizations in another PR. I've implemented the functionnalities that I needed, and I would leave you with the optimization part. |
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.
LGTM
Enable the ability to pass a client certificate for client authentication.
Testing:
cargo run --release --example async_client --features=async
Testing the certs with curl:
curl https://certauth.cryptomix.com/json/ --key <PRIVATE_KEY>.pem --cert <Certificate>.pem -v
Currently, this returns an error,MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE
, and I don't know why it happens,with
MBEDTLS_SSL_VERIFY_OPTIONAL
the error changes forMBEDTLS_ERR_SSL_BAD_CONFIG
.FIXED
TODOs:
struct
.This would make breaking changes less frequents in the future, and reduce the number of arguments
The functions about certificates could also be moved there to reduce complexity
We can allow the passing of a key, but that would increase the number of arguments even more,
hence the discussion of using a
struct
to handle certs.