Skip to content

Need solution for asyncio SSL/TLS connections #8647

Description

@RuofengX

I am running esp32c3-usb-20220117-v1.18.bin

TL;DR

How to open a SSL or TLS connection using uasyncio?


I am tryign to port a CPython project onto Micropython.

In CPython asyncio, we could open a SSL connection easily by using ssl argument in asyncio.open_connection() method.
When I am trying to use uasyncio.open_connection(..., ssl=True), it raises an exception saying that there's no ssl argument. We can confirm it on the doc page here.

Then I try to use ssl module to warp the socket in StreamWriter.get_extra_info("socket")(I never test this, I don't know whether this would work, just have a try), but I cannot get the "raw" socket of this connection, because function uasyncio.Stream.get_extra_info only accept "peername" as a param, no support for "socket". We can check it here.

If there's a method to open an SSL/TLS connection by using uasyncio? I really want to use asyncio because I think that is the best part of python language.

Activity

  1. changed the title [-]Module uasyncio is lack of support for SSL/TLS support.[/-] [+]Need solution for asyncio SSL/TLS connections[/+] on May 10, 2022
  2. peterhinch commented on May 10, 2022

    @peterhinch
    Contributor

    You might like to look at mqtt_as which uses nonblocking sockets and works over TLS.

  3. hyx0329 commented on May 10, 2022

    @hyx0329

    I implemented a workaround for my project here. It's basically a custom connection maker based on the original one.

  4. stephanelsmith commented on May 18, 2022

    @stephanelsmith
    SponsorContributor

    I ran into this last week and also implemented my own asyncio friendly implementation. My version is optimized for my application, but asyncio ssl open_connection is surely something that would be apprecaited by future travelers.

    I will also agree asyncio is my favorite part of python language! Game changer for microcontroller dev.

  5. dpgeorge commented on Dec 14, 2023

    @dpgeorge
    Member

    Asyncio SSL server and client are now supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions