uSockets icon indicating copy to clipboard operation
uSockets copied to clipboard

Upgrade socket from TCP to TLS mid-use

Open partyblob opened this issue 1 year ago • 0 comments

Many protocols support upgrading after initial data has been sent, for example SMTP which will upgrade after a STARTTLS command Allow an option to upgrade an unencrypted socket to an encrypted one (and possibly vice versa).

Something like void us_socket_upgrade(us_socket_t *t) (future calls on this socket object would need to set the ssl parameter to 1). Whether a socket has been upgraded or not should be up to the user to keep track of (via the socket extension, for example)

Another possible implementation would be to add a separate handler when the TLS connection has been established, which will get fired after on_open on sockets that use tls, something like void us_socket_context_on_ssl_established(us_socket_t *t), along with a method to send raw bytes over tcp rather than to encrypt them (actually I suppose this might be possible by passing ssl=0 to us_socket_write but the way I understand it this is currently likely undefined behaviour)

partyblob avatar Jun 11 '24 16:06 partyblob