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

Fix a bug in XAsyncSockets.py #98

Merged
merged 1 commit into from
Dec 21, 2023
Merged

Fix a bug in XAsyncSockets.py #98

merged 1 commit into from
Dec 21, 2023

Conversation

ekondayan
Copy link

The bug is in function IsSSL where the _socket object is tested to be an instance of SSLSocket. The correct is to test if the object is of class SSLContext.

#95

The SSLSocket attribute is not available in micropython for port esp32 and when initiating a simple GET crashes the server.

Unhandled exception in thread started by <bound_method>
Traceback (most recent call last):
File "MicroWebSrv2/libs/XAsyncSockets.py", line 131, in _processWaitEvents
File "MicroWebSrv2/libs/XAsyncSockets.py", line 587, in OnReadyForReading
File "MicroWebSrv2/libs/XAsyncSockets.py", line 830, in IsSSL
AttributeError: 'module' object has no attribute 'SSLSocket'

 * IsSSL() - compare the instance of _socket with SSLContext instead of SSLSocket
@jczic jczic merged commit d540efc into jczic:master Dec 21, 2023
@DracoTomes
Copy link

This is still not entirely fixed, I ran into issues on my ESP32 because SSLSocket is still used a few lines below it.

@property
def IsSSL(self) :
return ( hasattr(ssl, 'SSLContext') and \
isinstance(self._socket, ssl.SSLSocket) )

Replacing that will SSLContext as well (as actually checked in the function) works for me.

@jczic
Copy link
Owner

jczic commented Jan 23, 2024

Ok @DracoTomes, that means that in MicroPython you have "SSLContext" as a socket attribute, otherwise the IF wouldn't go any further.
However, self._socket is in no way part of the SSLContext class. I will therefore also test "SSLSocket" as an attribute.

I know that the latest version of MicroPython implements SSL (TLS) with context and asynchronously, because this didn't exist before. But I haven't checked yet.

So I guess you don't use SSL in MicroPython at all?

@jczic
Copy link
Owner

jczic commented Jan 23, 2024

b6f0799

The line "hasattr(ssl, 'SSLContext')" indicates that the system manages SSL "contexts".
I know this worked on MicroPython but there must have been a change in some versions.

@DracoTomes
Copy link

DracoTomes commented Jan 23, 2024

I'm running the newest 1.22.1 so it's probably something to do with the changes in newer version.
I have not used SSL yet (except for outgoing requests but I don't think that should matter).

@jczic
Copy link
Owner

jczic commented Jan 25, 2024

@DracoTomes : But it should work now, shouldn't it?

@jczic jczic self-assigned this Jan 25, 2024
@jczic jczic added bug Something isn't working fixed This issue is fixed labels Jan 25, 2024
@DracoTomes
Copy link

Oh yeah my bad. After implementing that change everything worked.

@jczic
Copy link
Owner

jczic commented Jan 25, 2024

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed This issue is fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants