eduardsui / tlse

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

Examples: tlshelloworld.c, tls_read or recv? #85

Open Velho opened 1 year ago

Velho commented 1 year ago

Greetings!

I was going through the examples and I noticed that the tlshelloworld.c does not make use of the tls_read nor tls_write, should these be used to populate the application buffer or is the tls consume stream enough?

Thanks!

eduardsui commented 1 year ago

Hello!

tls_read and tls_write work on the TLS buffer itself. tls_consume_stream writes the protocol bytes to the internal TLS buffer (after deciphering, validating and authorizing). So, we should have: recv => tls_consume_stream and then tls_read. Same way we use tls_write to write actual payload data. Then use tls_get_write_buffer to get the actual TLS bytes to write on the socket (or any other medium).

It should be also safe to use tls_write while calling tls_consume_stream (reading).

SSL_read and SSL_write are performing both socket I/O and TLS protocol I/O using recv, tls_read, send and tls_write.

Thank you!