($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski at intel.com>
To: ell at lists.01.org
Subject: [PATCH 2/3] tls: Add l_tls_reset function
Date: Thu, 26 May 2022 17:56:56 +0200	[thread overview]
Message-ID: <20220526155657.63641-2-andrew.zaborowski@intel.com> (raw)
In-Reply-To: 20220526155657.63641-1-andrew.zaborowski@intel.com

[-- Attachment #1: Type: text/plain, Size: 1833 bytes --]

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(+)

diff --git a/ell/ell.sym b/ell/ell.sym
index 3b11f41..0e0c194 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -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;
diff --git a/ell/tls.c b/ell/tls.c
index c072afb..fa00075 100644
--- a/ell/tls.c
+++ b/ell/tls.c
@@ -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) {
diff --git a/ell/tls.h b/ell/tls.h
index 683c54c..a4fd414 100644
--- a/ell/tls.h
+++ b/ell/tls.h
@@ -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);
 
-- 
2.32.0

                 reply	other threads:[~2022-05-26 15:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220526155657.63641-2-andrew.zaborowski@intel.com \
    --to=ell@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).