summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-10-03 08:58:59 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-11-14 15:00:33 +0100
commit87b848194a2f1438d6ababd174415cb18161a638 (patch)
tree95cb2cc3316c783e0c3734979623d657971f53e0
parentc3af99f35624e57ab5edf2f915088b8a812a3b72 (diff)
downloadgnutls-87b848194a2f1438d6ababd174415cb18161a638.tar.gz
extensions: enhanced extension lib with pack and unpack functions
That allows the functionality to be used for the majority of extensions. Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r--lib/hello_ext_lib.c48
-rw-r--r--lib/hello_ext_lib.h33
2 files changed, 79 insertions, 2 deletions
diff --git a/lib/hello_ext_lib.c b/lib/hello_ext_lib.c
index a9ae28caed..547f63a391 100644
--- a/lib/hello_ext_lib.c
+++ b/lib/hello_ext_lib.c
@@ -78,3 +78,51 @@ _gnutls_hello_ext_get_datum(gnutls_session_t session,
return 0;
}
+int
+_gnutls_hello_ext_get_resumed_datum(gnutls_session_t session,
+ extensions_t id, gnutls_datum_t *data /* constant contents */)
+{
+ gnutls_ext_priv_data_t epriv;
+ int ret;
+
+ ret = _gnutls_hello_ext_get_resumed_sdata(session, id, &epriv);
+ if (ret < 0 || epriv == NULL)
+ return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
+
+ data->size = _gnutls_read_uint16(epriv);
+ data->data = ((uint8_t*)epriv)+2;
+
+ return 0;
+}
+
+int
+_gnutls_hello_ext_default_pack(gnutls_ext_priv_data_t epriv, gnutls_buffer_st *ps)
+{
+ size_t size;
+
+ size = _gnutls_read_uint16(epriv);
+
+ return _gnutls_buffer_append_data(ps, epriv, size+2);
+}
+
+int
+_gnutls_hello_ext_default_unpack(gnutls_buffer_st *ps, gnutls_ext_priv_data_t *epriv)
+{
+ gnutls_datum_t data;
+ uint8_t *store;
+ int ret;
+
+ ret = _gnutls_buffer_pop_datum_prefix16(ps, &data);
+ if (ret < 0)
+ return gnutls_assert_val(ret);
+
+ store = gnutls_calloc(1, data.size+2);
+ if (store == NULL)
+ return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+
+ _gnutls_write_uint16(data.size, store);
+ memcpy(store+2, data.data, data.size);
+
+ *epriv = store;
+ return 0;
+}
diff --git a/lib/hello_ext_lib.h b/lib/hello_ext_lib.h
index 6f1a5c21aa..9ae2be8572 100644
--- a/lib/hello_ext_lib.h
+++ b/lib/hello_ext_lib.h
@@ -26,8 +26,9 @@
#include <gnutls/gnutls.h>
#include "hello_ext.h"
-void _gnutls_hello_ext_default_deinit(gnutls_ext_priv_data_t priv);
-
+/* Functions to use at the send() or recv() extension function to temporarily
+ * store and retrieve data related to the extension.
+ */
int
_gnutls_hello_ext_set_datum(gnutls_session_t session,
extensions_t id, const gnutls_datum_t *data);
@@ -35,4 +36,32 @@ int
_gnutls_hello_ext_get_datum(gnutls_session_t session,
extensions_t id, gnutls_datum_t *data /* constant contents */);
+int
+_gnutls_hello_ext_get_resumed_datum(gnutls_session_t session,
+ extensions_t id, gnutls_datum_t *data /* constant contents */);
+
+/* clear up any set data for the extension */
+#if 0 /* defined in hello_ext.h */
+void
+_gnutls_hello_ext_unset_sdata(gnutls_session_t session,
+ extensions_t id);
+#endif
+
+/* Function that will deinitialize the temporal data. Must be set
+ * as the deinit_func in the hello_ext_entry_st if the functions above
+ * are used.
+ */
+void _gnutls_hello_ext_default_deinit(gnutls_ext_priv_data_t priv);
+
+/* Functions to pack and unpack data if they need to be stored at
+ * session resumption data. Must be set as the pack_func and unpack_func
+ * of hello_ext_entry_st if the set and get functions above are used,
+ * and data must be accessible on resumed sessions.
+ */
+int
+_gnutls_hello_ext_default_pack(gnutls_ext_priv_data_t epriv, gnutls_buffer_st *ps);
+
+int
+_gnutls_hello_ext_default_unpack(gnutls_buffer_st *ps, gnutls_ext_priv_data_t *epriv);
+
#endif