From ea284e57f6326331db69699d25312faa8afa47c4 Mon Sep 17 00:00:00 2001 From: Appelmans Date: Mon, 18 Dec 2023 15:26:40 -0800 Subject: [PATCH 1/7] Adds new API to rust bindings --- bindings/rust/s2n-tls/src/connection.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bindings/rust/s2n-tls/src/connection.rs b/bindings/rust/s2n-tls/src/connection.rs index 7ec418260bd..211531dff40 100644 --- a/bindings/rust/s2n-tls/src/connection.rs +++ b/bindings/rust/s2n-tls/src/connection.rs @@ -914,6 +914,15 @@ impl Connection { }?; Ok(self) } + + /// Allows the quic library to check if session tickets are expected + pub fn client_resumption_enabled(&self) -> bool { + if let Some(config) = self.config() { + let ctx = config.context(); + return ctx.session_ticket_callback.is_some(); + } + false + } } impl AsRef for Connection { From 904db740351f01bda5e0bce169fb87e31a4b3bb5 Mon Sep 17 00:00:00 2001 From: Appelmans Date: Wed, 20 Dec 2023 12:26:02 -0800 Subject: [PATCH 2/7] PR feedback --- bindings/rust/s2n-tls/src/connection.rs | 14 ++++++++++---- tls/s2n_quic_support.c | 5 +++++ tls/s2n_quic_support.h | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/bindings/rust/s2n-tls/src/connection.rs b/bindings/rust/s2n-tls/src/connection.rs index 211531dff40..9a4065f67f3 100644 --- a/bindings/rust/s2n-tls/src/connection.rs +++ b/bindings/rust/s2n-tls/src/connection.rs @@ -916,10 +916,16 @@ impl Connection { } /// Allows the quic library to check if session tickets are expected - pub fn client_resumption_enabled(&self) -> bool { - if let Some(config) = self.config() { - let ctx = config.context(); - return ctx.session_ticket_callback.is_some(); + pub fn is_client_resumption_enabled(&self) -> bool { + unsafe { + let result = s2n_connection_is_resumption_enabled(self.connection.as_ptr()); + if !result { + return false; + } + if let Some(config) = self.config() { + let ctx = config.context(); + return ctx.session_ticket_callback.is_some(); + } } false } diff --git a/tls/s2n_quic_support.c b/tls/s2n_quic_support.c index 246a9398326..138ff00ae48 100644 --- a/tls/s2n_quic_support.c +++ b/tls/s2n_quic_support.c @@ -54,6 +54,11 @@ bool s2n_connection_is_quic_enabled(struct s2n_connection *conn) return (conn && conn->quic_enabled) || (conn && conn->config && conn->config->quic_enabled); } +bool s2n_connection_is_resumption_enabled(struct s2n_connection *conn) +{ + return conn && conn->config->use_tickets; +} + int s2n_connection_set_quic_transport_parameters(struct s2n_connection *conn, const uint8_t *data_buffer, uint16_t data_len) { diff --git a/tls/s2n_quic_support.h b/tls/s2n_quic_support.h index b9106a914f3..5fb93a951ef 100644 --- a/tls/s2n_quic_support.h +++ b/tls/s2n_quic_support.h @@ -32,7 +32,7 @@ S2N_API int s2n_config_enable_quic(struct s2n_config *config); S2N_API int s2n_connection_enable_quic(struct s2n_connection *conn); S2N_API bool s2n_connection_is_quic_enabled(struct s2n_connection *conn); - +S2N_API bool s2n_connection_is_resumption_enabled(struct s2n_connection *conn); /* * Set the data to be sent in the quic_transport_parameters extension. * The data provided will be copied into a buffer owned by S2N. From 21192b2662ff36725142806a70c9de71034bd68b Mon Sep 17 00:00:00 2001 From: Appelmans Date: Wed, 20 Dec 2023 15:10:05 -0800 Subject: [PATCH 3/7] PR feedback --- bindings/rust/s2n-tls/src/connection.rs | 11 ++--------- tls/s2n_quic_support.c | 4 ++-- tls/s2n_quic_support.h | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/bindings/rust/s2n-tls/src/connection.rs b/bindings/rust/s2n-tls/src/connection.rs index 9a4065f67f3..1c373ee7f8f 100644 --- a/bindings/rust/s2n-tls/src/connection.rs +++ b/bindings/rust/s2n-tls/src/connection.rs @@ -918,16 +918,9 @@ impl Connection { /// Allows the quic library to check if session tickets are expected pub fn is_client_resumption_enabled(&self) -> bool { unsafe { - let result = s2n_connection_is_resumption_enabled(self.connection.as_ptr()); - if !result { - return false; - } - if let Some(config) = self.config() { - let ctx = config.context(); - return ctx.session_ticket_callback.is_some(); - } + let result = s2n_connection_is_client_resumption_enabled(self.connection.as_ptr()); + return result; } - false } } diff --git a/tls/s2n_quic_support.c b/tls/s2n_quic_support.c index 138ff00ae48..33bd1cc6949 100644 --- a/tls/s2n_quic_support.c +++ b/tls/s2n_quic_support.c @@ -54,9 +54,9 @@ bool s2n_connection_is_quic_enabled(struct s2n_connection *conn) return (conn && conn->quic_enabled) || (conn && conn->config && conn->config->quic_enabled); } -bool s2n_connection_is_resumption_enabled(struct s2n_connection *conn) +bool s2n_connection_is_client_resumption_enabled(struct s2n_connection *conn) { - return conn && conn->config->use_tickets; + return conn && conn->config && conn->config->use_tickets && conn->config->session_ticket_cb; } int s2n_connection_set_quic_transport_parameters(struct s2n_connection *conn, diff --git a/tls/s2n_quic_support.h b/tls/s2n_quic_support.h index 5fb93a951ef..ad1eded3708 100644 --- a/tls/s2n_quic_support.h +++ b/tls/s2n_quic_support.h @@ -32,7 +32,7 @@ S2N_API int s2n_config_enable_quic(struct s2n_config *config); S2N_API int s2n_connection_enable_quic(struct s2n_connection *conn); S2N_API bool s2n_connection_is_quic_enabled(struct s2n_connection *conn); -S2N_API bool s2n_connection_is_resumption_enabled(struct s2n_connection *conn); +S2N_API bool s2n_connection_is_client_resumption_enabled(struct s2n_connection *conn); /* * Set the data to be sent in the quic_transport_parameters extension. * The data provided will be copied into a buffer owned by S2N. From 441047ef602410360c19a35a84c7e6f6faa0f989 Mon Sep 17 00:00:00 2001 From: Appelmans Date: Thu, 21 Dec 2023 12:09:28 -0800 Subject: [PATCH 4/7] Undo toolchain change --- bindings/rust/s2n-tls/src/connection.rs | 4 ++-- tls/s2n_quic_support.c | 4 ++-- tls/s2n_quic_support.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bindings/rust/s2n-tls/src/connection.rs b/bindings/rust/s2n-tls/src/connection.rs index 1c373ee7f8f..3b25c4955bb 100644 --- a/bindings/rust/s2n-tls/src/connection.rs +++ b/bindings/rust/s2n-tls/src/connection.rs @@ -916,9 +916,9 @@ impl Connection { } /// Allows the quic library to check if session tickets are expected - pub fn is_client_resumption_enabled(&self) -> bool { + pub fn are_session_tickets_enabled(&self) -> bool { unsafe { - let result = s2n_connection_is_client_resumption_enabled(self.connection.as_ptr()); + let result = s2n_connection_is_resumption_enabled(self.connection.as_ptr()); return result; } } diff --git a/tls/s2n_quic_support.c b/tls/s2n_quic_support.c index 33bd1cc6949..b9e21eca52f 100644 --- a/tls/s2n_quic_support.c +++ b/tls/s2n_quic_support.c @@ -54,9 +54,9 @@ bool s2n_connection_is_quic_enabled(struct s2n_connection *conn) return (conn && conn->quic_enabled) || (conn && conn->config && conn->config->quic_enabled); } -bool s2n_connection_is_client_resumption_enabled(struct s2n_connection *conn) +bool s2n_connection_is_resumption_enabled(struct s2n_connection *conn) { - return conn && conn->config && conn->config->use_tickets && conn->config->session_ticket_cb; + return conn && conn->config && conn->config->use_tickets; } int s2n_connection_set_quic_transport_parameters(struct s2n_connection *conn, diff --git a/tls/s2n_quic_support.h b/tls/s2n_quic_support.h index ad1eded3708..5fb93a951ef 100644 --- a/tls/s2n_quic_support.h +++ b/tls/s2n_quic_support.h @@ -32,7 +32,7 @@ S2N_API int s2n_config_enable_quic(struct s2n_config *config); S2N_API int s2n_connection_enable_quic(struct s2n_connection *conn); S2N_API bool s2n_connection_is_quic_enabled(struct s2n_connection *conn); -S2N_API bool s2n_connection_is_client_resumption_enabled(struct s2n_connection *conn); +S2N_API bool s2n_connection_is_resumption_enabled(struct s2n_connection *conn); /* * Set the data to be sent in the quic_transport_parameters extension. * The data provided will be copied into a buffer owned by S2N. From 789ea3ad34f340374f7557d3547211ad3b6f60ca Mon Sep 17 00:00:00 2001 From: Appelmans Date: Thu, 21 Dec 2023 13:14:14 -0800 Subject: [PATCH 5/7] PR feedback --- bindings/rust/s2n-tls/src/connection.rs | 3 +-- tls/s2n_quic_support.c | 2 +- tls/s2n_quic_support.h | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/rust/s2n-tls/src/connection.rs b/bindings/rust/s2n-tls/src/connection.rs index 3b25c4955bb..e70692316af 100644 --- a/bindings/rust/s2n-tls/src/connection.rs +++ b/bindings/rust/s2n-tls/src/connection.rs @@ -918,8 +918,7 @@ impl Connection { /// Allows the quic library to check if session tickets are expected pub fn are_session_tickets_enabled(&self) -> bool { unsafe { - let result = s2n_connection_is_resumption_enabled(self.connection.as_ptr()); - return result; + return s2n_connection_are_session_tickets_enabled(self.connection.as_ptr()); } } } diff --git a/tls/s2n_quic_support.c b/tls/s2n_quic_support.c index b9e21eca52f..210c9f72a6c 100644 --- a/tls/s2n_quic_support.c +++ b/tls/s2n_quic_support.c @@ -54,7 +54,7 @@ bool s2n_connection_is_quic_enabled(struct s2n_connection *conn) return (conn && conn->quic_enabled) || (conn && conn->config && conn->config->quic_enabled); } -bool s2n_connection_is_resumption_enabled(struct s2n_connection *conn) +bool s2n_connection_are_session_tickets_enabled(struct s2n_connection *conn) { return conn && conn->config && conn->config->use_tickets; } diff --git a/tls/s2n_quic_support.h b/tls/s2n_quic_support.h index 5fb93a951ef..3b43c51993d 100644 --- a/tls/s2n_quic_support.h +++ b/tls/s2n_quic_support.h @@ -32,7 +32,8 @@ S2N_API int s2n_config_enable_quic(struct s2n_config *config); S2N_API int s2n_connection_enable_quic(struct s2n_connection *conn); S2N_API bool s2n_connection_is_quic_enabled(struct s2n_connection *conn); -S2N_API bool s2n_connection_is_resumption_enabled(struct s2n_connection *conn); +S2N_API bool s2n_connection_are_session_tickets_enabled(struct s2n_connection *conn); + /* * Set the data to be sent in the quic_transport_parameters extension. * The data provided will be copied into a buffer owned by S2N. From 635768b1c9d0583dba11ad39ce385f93db55ae97 Mon Sep 17 00:00:00 2001 From: Appelmans Date: Thu, 21 Dec 2023 13:24:42 -0800 Subject: [PATCH 6/7] Remove extra return --- bindings/rust/s2n-tls/src/connection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/rust/s2n-tls/src/connection.rs b/bindings/rust/s2n-tls/src/connection.rs index e70692316af..1a0d4ee2267 100644 --- a/bindings/rust/s2n-tls/src/connection.rs +++ b/bindings/rust/s2n-tls/src/connection.rs @@ -918,7 +918,7 @@ impl Connection { /// Allows the quic library to check if session tickets are expected pub fn are_session_tickets_enabled(&self) -> bool { unsafe { - return s2n_connection_are_session_tickets_enabled(self.connection.as_ptr()); + s2n_connection_are_session_tickets_enabled(self.connection.as_ptr()) } } } From c55761ca4a057feb0a34d7426b2218dc3a1efe2f Mon Sep 17 00:00:00 2001 From: Appelmans Date: Thu, 21 Dec 2023 14:20:55 -0800 Subject: [PATCH 7/7] cargo fmt --- bindings/rust/s2n-tls/src/connection.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bindings/rust/s2n-tls/src/connection.rs b/bindings/rust/s2n-tls/src/connection.rs index 1a0d4ee2267..071de8e4916 100644 --- a/bindings/rust/s2n-tls/src/connection.rs +++ b/bindings/rust/s2n-tls/src/connection.rs @@ -917,9 +917,7 @@ impl Connection { /// Allows the quic library to check if session tickets are expected pub fn are_session_tickets_enabled(&self) -> bool { - unsafe { - s2n_connection_are_session_tickets_enabled(self.connection.as_ptr()) - } + unsafe { s2n_connection_are_session_tickets_enabled(self.connection.as_ptr()) } } }