dabeaz / curio

Good Curio!
Other
4.02k stars 241 forks source link

Subtle error in do_handshake_on_connect handling can potentially compromise curio.ssl's security #206

Closed njsmith closed 6 years ago

njsmith commented 7 years ago

When curio.ssl creates an ssl-wrapped socket, it always passes do_handshake_on_connect=False to the underlying ssl module, and also makes a record of what the user actually requested, and uses this to attempt to reimplement the semantics on top. Specifically, the Socket.connect method checks whether the user requested do_handshake_on_connect=True, and if so then it calls do_handshake at that time.

However, two things:

These two things together mean that if you perform the following sequence of actions:

then with the stdlib ssl module you're safe, but with curio now you're silently vulnerable to MITM attacks.

Fortunately it looks like curio's open_connection and open_unix_connection utility functions do unconditionally call do_handshake, so I don't think they're affected. But probably curio's wrap_socket function and method should grow some logic for calling do_handshake if do_handshake_on_connect=True and they're passed a socket that's already connected. (I guess this also means wrap_socket needs to become async.)

dabeaz commented 7 years ago

Ah. Good catch. I'll take a look at it.

dabeaz commented 7 years ago

Pushed a fix that changes wrap_socket to an async method and patches the network related functions accordingly. Still needs a unit test for the specific case mentioned here.