eduardsui / tlse

Single C file TLS 1.2/1.3 implementation, using tomcrypt as crypto library
Other
545 stars 90 forks source link

Async sockets. #77

Closed Velho closed 1 year ago

Velho commented 1 year ago

Hello! Is it possible to run the SSL compatibility interface as asynchronous or non blocking? How is now.. Doesn't the SSL_accept returns WANT_READ and WANT_WRITE incase there is more to do. Would you have any tips? Does the examples support non blocking?

eduardsui commented 1 year ago

Hello!

TLSe is async by design. You should switch to tls APIs. The SSL_* APIs are just for basic libssl compatibility. Check tlsclienthello.c and tlshelloworld.c. libssl compatibility is basic at most.

Velho commented 1 year ago

@eduardsui Thanks for the response! I'll do as you suggested.

I have question about the tls_hellowrold.c. As I assume the tls_consume_stream(..) does the handshake from the recv(..) data? Afterwards using the tls_read(..) from the tlse implementation to read from the socket?

Thanks

Velho commented 1 year ago

It seems to work, I do a loop until the connection is established, but for some reason tlse writes the headers to the stream. Is there something I am doing wrong? Screenshot from 2023-01-23 00-36-05

Velho commented 1 year ago

My bad, I had echo there somewhere in the async event handler 😬. Thanks for the support @eduardsui. Everything seems to be working as intended.

I am currently handling my writing as,

rc = tls_write (..)
if (rc  < 0)
  // error
else
  tls_close_notify(..)
  send_pending(..)

Is that correct?

eduardsui commented 1 year ago

Yes, perfect.