python / asyncio

asyncio historical repository
https://docs.python.org/3/library/asyncio.html
1.03k stars 178 forks source link

Wrapping an existing transport in SSL #492

Open kyuupichan opened 7 years ago

kyuupichan commented 7 years ago

I hope a question is acceptable here; I've googled and not found an answer.

I want to connect to a remote Tor server listening on an SSL socket with asyncio.

I have created an asyncio SocksProtocol to handle the negotation with the local tor proxy, and this works fine to establish a connection with the remote Tor server via loop.create_connection. However that leaves me with a transport, protocol pair, and I need to wrap the transport in SSL for the app to communicate properly with the remote server.

I don't see a clean way to do this. One thing I tried was another loop.connection passing the transport's socket and an ssl arg, but that didn't work as it ends up triggering checks in asyncio because 2 transports are using the same base socket. Am I missing something obvious?

FranciscoSilveira commented 7 years ago

Asyncio has support for SSL itself, so instead of creating a TCP transport and then wrapping that around SSL, you could just create a SSL transport from the beginning.

kyuupichan commented 7 years ago

That would be an SSL transport to the tor proxy, which I believe only expects TCP by default, not an SSL transport to the remote Tor server, which is the goal.