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

Correct ssl recv #1

Merged
merged 4 commits into from
Jul 29, 2020
Merged

Conversation

moritzj29
Copy link

fixes esphome compilation issue when ssl fingerprint is enabled
as discussed here: esphome/issues#786

Syncing with me-no-dev repo
…rver::_poll().

And other missed edit for errorTracker around ASYNC_TCP_SSL_ENABLED.
This should resolve @kasedy comment me-no-dev#115 (comment)
and @mcspr.

Tested ASYNC_TCP_SSL_ENABLED using marvinroger/async-mqtt-client/
.. examples/FullyFeaturedSSL. Ran test against test.mosquitto.org's
server. Thanks to @mcspr for suggesting.

Updated tcp_ssl_read() to check for fd_data being freed by callback
functions. I observed this with asyncmqttclient example. When finger
print did not match during fd_data->on_handshake callback, the mqtt
library did a close(true) which rippled down to an tcp_ssl_free().

Improvements in debug printing to handle debug print from tcp.axtls.c.
#if defined(DEBUG_ESP_PORT) && !defined(DEBUG_GENERIC)
#define DEBUG_GENERIC( module, format, ... ) \
do { \
struct _DEBUG_TIME_STAMP st = debugTimeStamp(); \
DEBUG_ESP_PORT.printf( DEBUG_TIME_STAMP_FMT module " " format, st.whole, st.dec, ##__VA_ARGS__ ); \
DEBUG_ESP_PORT_PRINTF( (DEBUG_TIME_STAMP_FMT module " " format), st.whole, st.dec, ##__VA_ARGS__ ); \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these changes relating to logging?

I'd prefer them to be filed in a separate PR to make reviewing easier.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes were needed to generalize the debug print macro a little more so I could get them to work from tcp_axtls.c.

// fd_data may have been freed in callback
fd_data = tcp_ssl_get(tcp);
if(NULL == fd_data)
return SSL_CLOSE_NOTIFY;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment on where the actual fix is? I see a lot of changed lines, but I'd like to know where the fixed happened so that I can review this accurately.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is at line 418 through 420 and 404 through 407.
The problem occurs when the client does a delete on _client from a callback and fd_data becomes invalid.

@moritzj29
Copy link
Author

I'm sorry, I cannot comment on any of the changes made, since I did not make them. This is a pending PR of the base repository by @mhightower83. Also @jeroenst did work on this.

Merging these changes into ESPAsyncTCP for esphome helped solving my issues described earlier. Shame on me, I have not worked through the code of these libraries. I'm just thankfully using them.

Feel free to close this PR and pull from the original repo as soon as the changes are merged.

@s00500
Copy link

s00500 commented Dec 8, 2019

Hi everyone, super nice work! , I just tested this and it works great. I understand the question of separating logging related changes and the actual fix. But I think merging them together makes sense in this case...
Since this fixes general TLS functionality on ESPHome, can this be merged ? Or is the plan to wait for me-no-dev#129 ? (Also not ideal for ESPHome)

@Variour
Copy link

Variour commented Jan 19, 2020

While this is waiting to be merged, can someone tell me where (i can figure out the how) to manually replace these files with the modified versions in my local installation (HASS.io AddOn or pip setup)?

@moritzj29
Copy link
Author

While this is waiting to be merged, can someone tell me where (i can figure out the how) to manually replace these files with the modified versions in my local installation (HASS.io AddOn or pip setup)?

I can't comment on HASS.io but on CLI: When you want to compile & upload your project, the compilation usually fails due these MQTT SSL errors. At this time platformio already created folders within your project directory storing the dependencies and also the platformio.ini file for your project. Within these (hidden) folders there should be the ESPAsyncTCP library. Look for the corresponding files and replace them. Aftwerwards compile and upload. I used platformio directly instead of esphome for this step.
Everytime platformio re-downloads the libraries, the changes are lost.
There are probably more sophisticated methods telling platfomio which libraries to use, but it works.

@moritzj29 moritzj29 requested a review from OttoWinter January 20, 2020 12:57
Copy link
Owner

@OttoWinter OttoWinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

And sorry for the delay

@OttoWinter OttoWinter merged commit 145cac2 into OttoWinter:master Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants