tls: Flush record buffers on l_tls_close
Andrew Zaborowski
PATCH 1/3 tls: Flush record buffers on l_tls_close
We probably don't want to handle data fragments we received before an l_tls_close if the TLS tunnel gets restarted in the future.
--- ell/tls.c | 3 +++ 1 file changed, 3 insertions(+)
ell/tls.c +3 -0
@@ -2852,6 +2852,9 @@ LIB_EXPORT bool l_tls_start(struct l_tls *tls) LIB_EXPORT void l_tls_close(struct l_tls *tls) { + tls->record_buf_len =0 ; + tls->message_buf_len =0 ; +TLS_DISCONNECT (TLS_ALERT_CLOSE_NOTIFY ,0 ,"Closing session" ); }
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 2/3 tls: Add l_tls_reset function
Add API to reset the tunnel to initial state without triggering any callbacks or sending an alert like l_tls_close() does.
--- ell/ell.sym | 1 + ell/tls.c | 20 ++++++++++++++++++++ ell/tls.h | 3 +++ 3 files changed, 24 insertions(+)
ell/ell.sym +1 -0
@@ -513,6 +513,7 @@ global: l_tls_write; l_tls_start; l_tls_close; + l_tls_reset; l_tls_set_cacert; l_tls_set_auth_data; l_tls_set_version_range;
ell/tls.c +20 -0
@@ -2858,6 +2858,26 @@ LIB_EXPORT void l_tls_close(struct l_tls *tls)TLS_DISCONNECT (TLS_ALERT_CLOSE_NOTIFY ,0 ,"Closing session" ); } +LIB_EXPORT void l_tls_reset(struct l_tls *tls) +{ +/* +* Similar to l_tls_close but without sending the alert or a +* disconnect callback. +*/ + +tls_reset_handshake (tls); +tls_cleanup_handshake (tls); + +tls_reset_cipher_spec (tls,0 ); +tls_reset_cipher_spec (tls,1 ); + + tls->negotiated_version =0 ; + tls->ready = false; + tls->record_flush = true; + tls->record_buf_len =0 ; + tls->message_buf_len =0 ; +} + LIB_EXPORT bool l_tls_set_cacert(struct l_tls *tls, struct l_queue *ca_certs) {if (tls->ca_certs) {
ell/tls.h +3 -0
@@ -92,6 +92,9 @@ bool l_tls_start(struct l_tls *tls);/* Properly disconnect a connected session */ void l_tls_close (struct l_tls *tls); +/* Reset to initial state without a graceful disconnect or callback */ +void l_tls_reset (struct l_tls *tls); +/* Submit plaintext data to be encrypted and transmitted */ void l_tls_write (struct l_tls *tls,const uint8_t *data,size_t len);
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 3/3 tls: Fix state check on Client Hello
In reply to Andrew ZaborowskiA Client Hello message is allowed in the WAIT_HELLO and DONE states, apparently this check had a typo.
--- ell/tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ell/tls.c +1 -1
@@ -2740,7 +2740,7 @@ bool tls_handle_message(struct l_tls *tls, const uint8_t *message,/* Start hashing the handshake contents on first message */ if (tls->server && message[0 ] ==TLS_CLIENT_HELLO && (tls->state ==TLS_HANDSHAKE_WAIT_HELLO || - tls->state !=TLS_HANDSHAKE_DONE )) + tls->state ==TLS_HANDSHAKE_DONE ))if (!tls_init_handshake_hash (tls))return false;
Signature · 1 line
2.32.0
Denis Kenzior
Hi Andrew,
Quoted 6 lines · Andrew Zaborowski
We probably don't want to handle data fragments we received before an
l_tls_closeif the TLS tunnel gets restarted in the future.--- ell/tls.c | 3 +++ 1 file changed, 3 insertions(+)
All applied, thanks.
Regards,
-Denis