aboutsummaryrefslogtreecommitdiffstats
path: root/epan/secrets.c
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-18 18:11:42 +0100
committerAnders Broman <a.broman58@gmail.com>2018-11-20 05:14:35 +0000
commitdf7af28f39b5b104fb85f76ddd9b887a74cf2d63 (patch)
treeadec02417c312fdd4c5f59eb6e45c11b785bc9b6 /epan/secrets.c
parente2e0fd1dbdb07f2a1bd8822ab86bcd7144025f97 (diff)
Add new Secrets API and allow TLS to use pcapng decryption secrets
Add a new secrets API to the core, one that can outlive the lifetime of a single capture file. Expose decryption secrets from wiretap through a callback and let the secrets API route it to a dissector. Bug: 15252 Change-Id: Ie2f1867bdfd265bad11fc58f1e8d8e7295c0d1e7 Reviewed-on: https://code.wireshark.org/review/30705 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/secrets.c')
-rw-r--r--epan/secrets.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/epan/secrets.c b/epan/secrets.c
new file mode 100644
index 0000000000..08ed299a3e
--- /dev/null
+++ b/epan/secrets.c
@@ -0,0 +1,58 @@
+/* secrets.c
+ * Secrets management and processing.
+ * Copyright 2018, Peter Wu <peter@lekensteyn.nl>
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "secrets.h"
+#include <wiretap/wtap.h>
+
+/** Maps guint32 secrets_type -> secrets_block_callback_t. */
+static GHashTable *secrets_callbacks;
+
+void
+secrets_init(void)
+{
+ secrets_callbacks = g_hash_table_new(g_direct_hash, g_direct_equal);
+}
+
+void
+secrets_cleanup(void)
+{
+ g_hash_table_destroy(secrets_callbacks);
+ secrets_callbacks = NULL;
+}
+
+void
+secrets_register_type(guint32 secrets_type, secrets_block_callback_t cb)
+{
+ g_hash_table_insert(secrets_callbacks, GUINT_TO_POINTER(secrets_type), (gpointer)cb);
+}
+
+void
+secrets_wtap_callback(guint32 secrets_type, const void *secrets, guint size)
+{
+ secrets_block_callback_t cb = (secrets_block_callback_t)g_hash_table_lookup(
+ secrets_callbacks, GUINT_TO_POINTER(secrets_type));
+ if (cb) {
+ cb(secrets, size);
+ }
+}
+
+/*
+ * Editor modelines - https://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */