-
Notifications
You must be signed in to change notification settings - Fork 397
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
Request for BearSSL library support. #95
Comments
@Adam5Wu Can you please share something with us... If your fork is working fine and can be tested.. ? |
Hi @arihantdaga the situation of my fork is a little complicated. Yes, the client side function is working. But you must use my fork of Arduino, because the official fork have merged a version of Bearssl that is only compatible with synchronized workflow. However my fork of Arduino is sliding behind the upstream, due to another problem. The upstream introduced another feature which moves the sketch stack into the SDK reserved stack space to save 4KB of memory. However I found this causes problems with certain SDK functions such as WPS and maybe WPA2 Enterprise. In my Arduino fork I have undone the stack changes, however I think it may drift too far away from the official Arduino upstream and cause maintenance problem. I hope the upstream will eventually make the stack location configurable so I don't have to maintain too much of my own private changes in my fork. So I am just waiting at the moment... |
Is there an open issue to fix the "a version of Bearssl that is only compatible with synchronized workflow" problem? |
I think the latest revision of BearSSL by @earlephilhower should be compatible with both cont and async, just I do not have time to integrate with my fork. Maybe in a couple of weeks... |
I have installed @Adam5Wu 's fork of Arduino, and placed his modified versions of ESPAsyncTCP, and Async-MQTT-Client in the "libraries" folder, everything compiles just fine. However, I am running into issues where I cannot connect to a broker using SSL, though non-SSL works fine. I believe async_config.h (from ESPAsyncTCP) is configured properly, and I am setting the MQTT client to be secure. The onMqttDisconnect callback appears to fire immediately after attempting to connect. I am using a free instance of CloudMQTT to test the modified files by @Adam5Wu , and this is what is shown in the log. @hdrut @arihantdaga @tve Have any of you tried implementing the modified Async-MQTT-Client library, and successfully connected with SSL? I'm not exactly sure what I am missing, but any help would be much appreciated. |
@thekurtovic I think you maybe missing the cert validation callbacks. By default there was no validation, and all connections are automatically rejected. Yes it is quite "unfriendly", and I should spend more time to improve it. But at least it is safe, compare to making the default accept anything -- people may unknowingly put the broken logic in their door sensor code and broadcast to the Internet that no one is at home tonight... Anyway, to successfully establish TLS connection, please do the following:
Sorry for the rough API interface, @earlephilhower did a much better job providing API for operating a repository of certificates which makes cert matching easier. |
Here is a piece of code that I have in one of my own private project. I haven't published it because I haven't completed the first round implementation, but given my current work & life schedule, it may take longer time to reach the finish line... Edit: The following code partially referred to @earlephilhower's certificate API. The main difference is that the actual certificate loading operation is deferred into the timer callback context. The reason is that, to conserve memory resource, async operated BearSSL does not allocate 2nd stack, instead only use sys stack, which is available in callbacks. Anyway, this code provide a slightly easier to use wrapper for cert validation:
To use this class with the server cert validation procedure:
|
@Adam5Wu Thank you for taking the time to provide such a detailed response. I appreciate the information which you have shared. Your assumption was correct, I was not making use of certificate validation callbacks. Over the last few days I've been trying to wrap my head around the certificate validation wrapper which you provided, but I think it may be too much for me to understand. I have been trying to resolve each compiler error I am seeing, by including the libraries which I seem to be missing, and changing your LOG commands to Serial.printf/println, but I've not been able to successfully compile a test sketch. I'm not sure where things like br_pem_decoder_context/init/event/name, or br_Sha256_context are originating from to name a few examples. |
@Adam5Wu, drop me a note if there's something I can change in the BearSSL port to make it easier for you to use with AsyncTCP. I thought the thunking stuff would actually help you out, but I guess not. |
Hi @earlephilhower, actually the thunking does help (although I recently had no time to try, but I am pretty confident it will work perfectly with async). The problem with certificate validation is that, opening a certificate would require some heavy crypto operations, which needs lots of stack, and the g_cont stack may not be enough. There are two choices:
In non-async esp8266 Arduino, with g_cont stack relocated to overlap sys context stack, one can choose approach 1; But in async workflow, because lots of activities happen in the callback context, including heavy crypto, I think it is best not to relocate g_cont stack, instead just use sys context stack directly. Now the problem comes when one needs to open a certificate in g_cont context:
So instead, I try to queue certificate operations in a callback, effectively convert a sync job into pseudo-async, so that it can directly use the sys context. It can save ~6KB of memory. In other words, once one decided to use async style bearSSL, then EVERY and ALL bearSSL operations must be in async style, which is why your existing implementations of certificate helpers cannot be directly used. |
@thekurtovic Sorry, forgot to putting the include while extracting code.
|
Is the situation any different now that core 2.5.0 has shipped with BearSSL as default? |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
FYI there's some work being done on this by @mcspr in https://github.com/mcspr/ESPAsyncTCP/tree/bearssl |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
I assume you saw #48? Or is there a reason it has to be bearssl? |
It is already packaged by the framework, so why not? |
Sorry, my bad, got esp8266 ESPAsyncTCP and esp32 AsyncTCP mixed-up (I get notifications for both in my inbox). |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
Oh stale bot.... So I am currently running into an issue with this library where it would screw up tls1.2 and hang... (but works fine with tls1.1) so it would be interesting to try if bearssl would solve this.... need to do further debugging though... but this issue should definitly not be closed by the stale bot ;-) |
How much memory would be saved using bearssl instead? |
Hi, I know you are really busy, but please consider adding support for BearSSL as it's apparently going to be the default choice for Arduino TLS. I think @Adam5Wu has done some interesting progress.
Thank you.
The text was updated successfully, but these errors were encountered: