summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2020-03-24 17:51:56 +0100
committerDaiki Ueno <ueno@gnu.org>2020-05-12 11:12:05 +0200
commitbb3e18e90697cfb2a583aab62aa3ae2b4552b974 (patch)
treef022eaec6be2d67dbc64a475795301a30b4f7a1e
parent0958603e5a827468f2d8a7b8b6e662fb9d3a7909 (diff)
downloadgnutls-tmp-quic.tar.gz
alert: add callback to intercept alert messagestmp-quic
This adds gnutls_alert_set_read_function(), to allow QUIC implementations to be notified when an alert message is sent. Signed-off-by: Daiki Ueno <dueno@redhat.com>
-rw-r--r--devel/libgnutls-latest-x86_64.abi1
-rw-r--r--devel/symbols.last1
-rw-r--r--doc/Makefile.am2
-rw-r--r--doc/manpages/Makefile.am1
-rw-r--r--lib/alert.c16
-rw-r--r--lib/gnutls_int.h1
-rw-r--r--lib/includes/gnutls/gnutls.h.in22
-rw-r--r--lib/libgnutls.map1
-rw-r--r--lib/state.c17
9 files changed, 62 insertions, 0 deletions
diff --git a/devel/libgnutls-latest-x86_64.abi b/devel/libgnutls-latest-x86_64.abi
index 8d516e11f1..c00ee5d5bb 100644
--- a/devel/libgnutls-latest-x86_64.abi
+++ b/devel/libgnutls-latest-x86_64.abi
@@ -77,6 +77,7 @@
<elf-symbol name='gnutls_alert_get_strname' version='GNUTLS_3_4' is-default-version='yes' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='gnutls_alert_send' version='GNUTLS_3_4' is-default-version='yes' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='gnutls_alert_send_appropriate' version='GNUTLS_3_4' is-default-version='yes' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
+ <elf-symbol name='gnutls_alert_set_read_function' version='GNUTLS_QUIC_3_6_13' is-default-version='yes' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='gnutls_alpn_get_selected_protocol' version='GNUTLS_3_4' is-default-version='yes' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='gnutls_alpn_set_protocols' version='GNUTLS_3_4' is-default-version='yes' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='gnutls_anon_allocate_client_credentials' version='GNUTLS_3_4' is-default-version='yes' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
diff --git a/devel/symbols.last b/devel/symbols.last
index 9b9b3d1482..00c24df0a5 100644
--- a/devel/symbols.last
+++ b/devel/symbols.last
@@ -25,6 +25,7 @@ gnutls_alert_get_name@GNUTLS_3_4
gnutls_alert_get_strname@GNUTLS_3_4
gnutls_alert_send@GNUTLS_3_4
gnutls_alert_send_appropriate@GNUTLS_3_4
+gnutls_alert_set_read_function@GNUTLS_QUIC_3_6_13
gnutls_alpn_get_selected_protocol@GNUTLS_3_4
gnutls_alpn_set_protocols@GNUTLS_3_4
gnutls_anon_allocate_client_credentials@GNUTLS_3_4
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 67a79e5422..92bf3cce2d 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -658,6 +658,8 @@ FUNCS += functions/gnutls_alert_send
FUNCS += functions/gnutls_alert_send.short
FUNCS += functions/gnutls_alert_send_appropriate
FUNCS += functions/gnutls_alert_send_appropriate.short
+FUNCS += functions/gnutls_alert_set_read_function
+FUNCS += functions/gnutls_alert_set_read_function.short
FUNCS += functions/gnutls_alpn_get_selected_protocol
FUNCS += functions/gnutls_alpn_get_selected_protocol.short
FUNCS += functions/gnutls_alpn_set_protocols
diff --git a/doc/manpages/Makefile.am b/doc/manpages/Makefile.am
index fa3a54d161..7568ea5186 100644
--- a/doc/manpages/Makefile.am
+++ b/doc/manpages/Makefile.am
@@ -130,6 +130,7 @@ APIMANS += gnutls_alert_get_name.3
APIMANS += gnutls_alert_get_strname.3
APIMANS += gnutls_alert_send.3
APIMANS += gnutls_alert_send_appropriate.3
+APIMANS += gnutls_alert_set_read_function.3
APIMANS += gnutls_alpn_get_selected_protocol.3
APIMANS += gnutls_alpn_set_protocols.3
APIMANS += gnutls_anon_allocate_client_credentials.3
diff --git a/lib/alert.c b/lib/alert.c
index cfd1205d01..7efc0a5af5 100644
--- a/lib/alert.c
+++ b/lib/alert.c
@@ -165,6 +165,22 @@ gnutls_alert_send(gnutls_session_t session, gnutls_alert_level_t level,
_gnutls_record_log("REC: Sending Alert[%d|%d] - %s\n", data[0],
data[1], name);
+ if (session->internals.a_read_func) {
+ record_parameters_st *params;
+
+ ret = _gnutls_epoch_get(session, EPOCH_WRITE_CURRENT, &params);
+ if (ret < 0)
+ return gnutls_assert_val(ret);
+ ret = session->internals.a_read_func(session,
+ params->write.level,
+ level,
+ desc);
+ if (ret < 0)
+ return gnutls_assert_val(ret);
+
+ return ret;
+ }
+
if ((ret =
_gnutls_send_int(session, GNUTLS_ALERT, -1,
EPOCH_WRITE_CURRENT, data, 2,
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index 26bbd22e56..cd4ee06887 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -1247,6 +1247,7 @@ typedef struct {
int16_t h_post; /* whether post-generation/receive */
gnutls_handshake_read_func h_read_func;
gnutls_handshake_secret_func h_secret_func;
+ gnutls_alert_read_func a_read_func;
gnutls_keylog_func keylog_func;
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 07df8e272d..cc82a4a986 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -3256,6 +3256,28 @@ void
gnutls_handshake_set_secret_function(gnutls_session_t session,
gnutls_handshake_secret_func func);
+ /**
+ * gnutls_alert_read_func:
+ * @session: the current session
+ * @level: #gnutls_record_encryption_level_t
+ * @alert_level: the level of the alert
+ * @alert_desc: the alert description
+ *
+ * Function prototype for alert intercepting hooks. It is set using
+ * gnutls_alert_set_read_function().
+ *
+ * Returns: Non zero on error.
+ * Since: 3.6.14
+ */
+typedef int (*gnutls_alert_read_func) (gnutls_session_t session,
+ gnutls_record_encryption_level_t level,
+ gnutls_alert_level_t alert_level,
+ gnutls_alert_description_t alert_desc);
+
+void
+gnutls_alert_set_read_function(gnutls_session_t session,
+ gnutls_alert_read_func func);
+
/* FIPS140-2 related functions */
unsigned gnutls_fips140_mode_enabled(void);
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index 4b23dfed27..15871d5aaa 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -1333,6 +1333,7 @@ GNUTLS_3_6_14
GNUTLS_QUIC_3_6_13
{
global:
+ gnutls_alert_set_read_function;
gnutls_handshake_set_read_function;
gnutls_handshake_write;
gnutls_handshake_set_secret_function;
diff --git a/lib/state.c b/lib/state.c
index b751735e5a..6a96f05c15 100644
--- a/lib/state.c
+++ b/lib/state.c
@@ -1480,6 +1480,23 @@ gnutls_handshake_set_read_function(gnutls_session_t session,
}
/**
+ * gnutls_alert_set_read_function:
+ * @session: is #gnutls_session_t type
+ * @func: is the function to be called
+ *
+ * This function will set a callback to be called when an alert
+ * message is being sent.
+ *
+ * Since: 3.6.14
+ */
+void
+gnutls_alert_set_read_function(gnutls_session_t session,
+ gnutls_alert_read_func func)
+{
+ session->internals.a_read_func = func;
+}
+
+/**
* gnutls_record_get_state:
* @session: is a #gnutls_session_t type
* @read: if non-zero the read parameters are returned, otherwise the write