summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-09-18 14:49:24 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-09-18 14:49:28 +0200
commit18ac6db4b91dfda5e7ca5998d6ce74a06aca0620 (patch)
treea1dc1f2fbca6b4febc2209be709e4371b9b793c6
parent8691940ed97f340130d843b3d16dfc95836b4da4 (diff)
downloadgnutls-tmp-enhance-ext-handling.tar.gz
extensions: introduced functions to obtain currently parsed messagetmp-enhance-ext-handling
This allows the extension handling code to operate differently on different messages. Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r--lib/extensions.c20
-rw-r--r--lib/extensions.h11
-rw-r--r--lib/extv.c4
-rw-r--r--lib/gnutls_int.h1
-rw-r--r--lib/includes/gnutls/gnutls.h.in2
5 files changed, 38 insertions, 0 deletions
diff --git a/lib/extensions.c b/lib/extensions.c
index 2b94f016b7..b746353fe2 100644
--- a/lib/extensions.c
+++ b/lib/extensions.c
@@ -599,3 +599,23 @@ gnutls_ext_get_data(gnutls_session_t session,
{
return _gnutls_ext_get_session_data(session, id, data);
}
+
+/**
+ * gnutls_ext_get_current_msg:
+ * @session: a #gnutls_session_t opaque pointer
+ *
+ * This function allows an extension handler to obtain the message
+ * this extension is being called from. The returned value is a single
+ * entry of the %gnutls_ext_flags_t enumeration. That is, if an
+ * extension was registered with the %GNUTLS_EXT_FLAG_CT and
+ * %GNUTLS_EXT_FLAG_CR flags, the value when called during parsing of the
+ * certificate message will be %GNUTLS_EXT_FLAG_CT.
+ *
+ * If not called under an extension handler, its value is undefined.
+ *
+ * Since: 3.6.x
+ **/
+unsigned gnutls_ext_get_current_msg(gnutls_session_t session)
+{
+ return _gnutls_ext_get_msg(session);
+}
diff --git a/lib/extensions.h b/lib/extensions.h
index ce36a034a0..3252622b62 100644
--- a/lib/extensions.h
+++ b/lib/extensions.h
@@ -47,6 +47,17 @@ int _gnutls_ext_get_resumed_session_data(gnutls_session_t session,
uint16_t type,
gnutls_ext_priv_data_t * data);
+/* obtain the message this extension was received at */
+inline static gnutls_ext_flags_t _gnutls_ext_get_msg(gnutls_session_t session)
+{
+ return session->internals.ext_msg;
+}
+
+inline static void _gnutls_ext_set_msg(gnutls_session_t session, gnutls_ext_flags_t msg)
+{
+ session->internals.ext_msg = msg;
+}
+
/* for session packing */
int _gnutls_ext_pack(gnutls_session_t session, gnutls_buffer_st * packed);
int _gnutls_ext_unpack(gnutls_session_t session,
diff --git a/lib/extv.c b/lib/extv.c
index 5473f04288..4f1c8c91ca 100644
--- a/lib/extv.c
+++ b/lib/extv.c
@@ -201,6 +201,8 @@ _gnutls_extv_parse(gnutls_session_t session,
session, gnutls_ext_get_name(id), id,
size);
+ _gnutls_ext_set_msg(session, msg);
+
if ((ret = ext->recv_func(session, sdata, size)) < 0) {
gnutls_assert();
return ret;
@@ -257,6 +259,8 @@ int send_extension(gnutls_session_t session,
if (ret < 0)
return gnutls_assert_val(ret);
+ _gnutls_ext_set_msg(session, msg);
+
size_prev = extdata->length;
ret = p->send_func(session, extdata);
if (ret < 0 && ret != GNUTLS_E_INT_RET_0) {
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index db3d655b25..c5f00372e3 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -1143,6 +1143,7 @@ typedef struct {
/* extensions received during client or server hello */
tls_ext_vals_st hello_ext;
+ gnutls_ext_flags_t ext_msg; /* accessed through _gnutls_ext_get/set_msg() */
/* this is not the negotiated max_record_recv_size, but the actual maximum
* receive size */
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index d14dd9e3cd..9e99c3b05e 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -2634,6 +2634,8 @@ void gnutls_ext_set_data(gnutls_session_t session, unsigned type,
int gnutls_ext_get_data(gnutls_session_t session, unsigned type,
gnutls_ext_priv_data_t *);
+unsigned gnutls_ext_get_current_msg(gnutls_session_t session);
+
typedef int (*gnutls_ext_recv_func) (gnutls_session_t session,
const unsigned char *data,
size_t len);