-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
esp32: SSL handshake fails in latest build: esp32-idf3-v1.12-68-g3032ae115 on 2020-01-15 #5543
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
Comments
Thanks for the report. The main change since yesterday's build is #5524 which updates the IDF version (which would possibly include a newer version of mbedtls). |
I don't know, the host is my computer that listens on a ssl wrapped socket (Python 3) But I've just flashed the latest build and run this http_client_ssl.py example from the repo and gives this error (I saved the script with another name but it is the same code)
After a machine reset works well:
Then I tried to disable key, cert authentication (since the example does not use them) Now the handshake is done well, but after a few messages esp32 freezes and STA resets:
So I guess there are two problems here:
As you said this is something related to the new IDF version since the previous build worked well. Finally are these issues related maybe (from esp-idf repo)? |
Hi @jimmo I got this working but without key/cert. |
@Carglglz I tested the If you could provide a full working example (server and client code) that shows the issue then we can look further into the problem. |
@dpgeorge Thanks for taking the time,
Yes I should have done that in first place. Here is the test example : SSL_server_client_test.py
Then I uploaded key and cert to the esp32 (build idf3 from 2020-01-14)
MicroPython 1.12 (client side):
So until that build this worked ok, but after that client authentication does not work.
In MicroPython by:
Without authentication ( Python 3 server side (I tried with 3.6 and 3.7 too):
MicroPython client side:
So maybe there is something different in how mbedtls handles certificates in the new version? |
OK, I think I "solved" this or at least I found out why authentication is not working in the latest builds.
|
@dpgeorge @jimmo
So here is the reason why Handshake fails, why using a smaller RSA key does work, and probably why STA resets while trying to send a "long message" (and not just randomly or from time to time as I initially thought). For "long message" I mean something like this:
Which seems odd, because this doesn't look like a 4kB of data message, however after encryption, the encrypted message probably takes more than 4kB and then connection may fail. From jimmo's PR:
So right now the actual configuration limits:
It is possible to increase If there is no workaround to this then I think it should be specified the next parameters:
From Wikipedia entry on Cipher suites:
I can see that |
hi @Carglglz -- thanks for digging into this and for the excellent summary. I had a very brief look also and came to the same conclusion. When you look at the memory regions (i.e. the same information as what I showed in #5303) it seems that enabling BLE and NimBLE in IDF 3.3.1 has caused a significant amount of additional fragmentation (similar but perhaps marginally worse than what we saw in the move to 4.x as discussed in #5303). I agree that increasing the buffer size to 8kiB will address the issue here, but will possibly impact the number of concurrent SSL sockets (as discussed in #5303) if it's unable to find 8kiB regions. Anyway when I get some time I can measure this and see what the impact is. I also saw a report on the forum from someone seeing issues on a PSRAM build which I need to investigate. Some areas that I want to investigate:
Perhaps we need to provide non-BLE builds...but this is starting to get a bit crazy having to juggle all the tradeoffs. |
@jimmo @dpgeorge
Generate a ec key and cert with openssl : Upload key/cert to the esp32, and set the cipher in the python3 server side: I tested this in the latest idf4
In idf3 only works without client authentication, with client authentication throws this error:
Also in both idf3 and idf4 a soft reset won't release any memory in the output buffer, which makes a new ssl connection crash and the only way to make it work again is a hard reset. If there any chance to make output buffer 8kB?, at least to test?
Is there any chance to use some of this "RAM available for dynamic allocation" or it is not possible/already used after MicroPython boots? (This is really way out of my scope, so I have literally no clue...) [EDITED, I've just read your last message jimmo, thanks for the extensive explanation] I've found this PR to mbedtls : Let input and output buffers len be set at runtime, per connection But I guess this needs to be implemented in mbedtls library and not in MicroPython? Anyway I don't really need this to work on new releases of idf3-idf4 right now, I just wanted to know why it was failing and if I could do something about.
Thanks again for taking the time
I wish I could help but C is out of my scope right now... (I started with MicroPython/embedded "developing" a year ago :( ) PD: sorry for the TL;DR messages, I just wanted to be as clear as possible |
Thanks for all the long explanations! SSL is just a PITA on small devices... I need to do more testing specifically with the PSK cipher suites... IMHO, this is the best avenue in the medium term:
I'm actually wondering: wouldn't it be best if all of ESP-IDF used the MP heap so there's only one heap and not multiple? Maybe that's tricky to init given that the esp-idf starts before MP, so to speak. |
Yes, it is indeed true :( , but I think that down the road it would be good for MicroPython to have "state of the art" support for SSL/TLS and therefore some sort of IoT "security" (if this is actually possible...)
Yes this would be nice to implement, mbedtls supports [EDIT I've just
8000
read your PR #5544 on this and "upvoted" 👍 ] But I will leave here some useful links that I've found during this SSL/TLS "crash course week" that may be helpful for developing/general info (for you or anybody that steps into this issue): Just for clarity SSL and TLS refers to the "same" protocol but different release versions which I think is: (1994) SSLv1 (Never released) --> (1995) SSLv2 --> (1996) SSLv3-->(Renamed)-->(1999)TLSv1---> TLSv1.1 (2006) --> TLSv1.2 (2008) ---> TLSv1.3 (2018)
So right now the common practice would be support TLSv1.2 and work towards TLSv1.3 compatibility/optimisations using the most suitable cipher suites for embedded devices I guess? From the PR docs:
In Google cloud VPN docs they recommend to use openssl
As I said I will keep an eye on this in case I can help with more documentation of SSL/TLS or help with MicroPython / Python implementation side. 👍 |
Something that would be interesting to test is to see how blocking the TLS connect is. I assume you saw my timings in my PSK PR. What happens if you run the TLS wrap_socket in a separate thread while the main thread blinks an LED at 10Hz? Does it hiccup or continue blinking? |
@tve
After the handshake the connection should be practically as fast as a normal tcp socket connection Looking at Wireshark for the time that takes the client handshake with
First Application Data (End of the handshake): at second 61.82 In TLSv1.3 this is improved and takes only 2 messages to do the handshake.
And It seems that with PSK is even faster.
I'm not sure about this but I guess that at the "C level" the handshake can be done in an asynchronously manner maybe? Like keep on doing "main tasks" until it needs to send/receive handshake messages? kind of non-blocking handshake? so the LED does not hiccup?. |
Also you may be interested in the "Session Resumption" feature which improves further client handshakes after the initial one:
|
I think its related:
mbedtls_ssl_handshake error: -71 using esp32-idf3-20200207-v1.12-154-gce40abcf2 rolling back to last stable resolved the issue |
I see the same issue as @andymule when using the latest firmware -
|
Quick FYI: I have a number of TLS fixes/improvements in the PR queue. They don't reduce memory consumption however. I want to make a further change, which is to delete the server certificate which will free up some storage. Whether it's enough for this specific use-case, we will only find out once this is implemented. There are a couple of other avenues we could pursue, I'm not sure which ends up being the best. I think the sticking point here is that for new users the upip install is convenient and should work out-of-the-box. I have the feeling that long term MP users don't use upip. Anyway, thoughts:
|
This issue is now being tracked in #8940. |
Uh oh!
There was an error while loading. Please reload this page.
SSL handshake fails with error:
The previous build : esp32-idf3-20200114-v1.12-63-g1c849d63a.bin works well.
Are there any significant changes in the ssl module in the latest build?
Is it related to this issue maybe?
I checked the error code here and I think it points to this (but still not sure how to read the error code since '-0x10d6' does not appear anywhere)
Maybe the previous build uses
modussl_axtls.c
by default instead ofmodussl_mbedtls.c
and the latest is the other way around ?The text was updated successfully, but these errors were encountered: