Open paravoid opened 4 years ago
FWIW, in theory an an SSLContext + SSLObject API would allow this to work with asyncio. Sadly, I haven't managed to make that work with the above code, however. The OpenSSL library calls are never made and I haven't figured out why yet...
This makes it possible to add PSK support to paho-mqtt client.
A problem only appears with PSK ciphers, and context.set_ciphers('PSK')
didn't help till I patched sslpsk a bit to work with python3.8.
Thanks a lot!
I'm trying to make work the proposed by @paravoid on the paho-mqtt client. So far I haven't been able to achieve it. Here is what I have done so far: https://github.com/maovidal/paho_sslpsk2_demo/blob/main/paho_sslpsk2_demo.py
Any help would be much appreciated.
Wouldn't it be great to see this whole thing as an effort against https://github.com/python/cpython/issues/63284
It states:
Please feel free to re-open it with a patch ...
@drbild I just submitted a tested PR with this fix and this works great. I would really appreciate it if you could review it
The Python ssl module documentation says:
It'd be nice if sslpsk followed suit and provided a similar API. It seems that 3.7+ provides some core API improvements that would make this possible. I played around and this seemed to work:
(It seems like SSLPSKSocket alone is useful to replace the existing functionality. I think SSLPSKObject is useful only under certain frameworks. I could not test that, so perhaps it'd be smarter to even avoid including that for now.)
With that, one can use
SSLPSKContext
where they'd useSSLContext
before, andSSLPSKContext.psk = …
to set the PSK (and.hint = …
for the hint).A backwards-compatible
sslpsk.wrap_socket()
can still be offered with: