3 * Export SSL Session Keys dialog
4 * by Sake Blok <sake@euronet.nl> (20110526)
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <epan/address.h>
18 #include <epan/dissectors/packet-ssl.h>
19 #include <epan/dissectors/packet-ssl-utils.h>
21 #include "ui/ssl_key_export.h"
24 ssl_session_key_count(void)
26 return g_hash_table_size(ssl_session_hash) +
27 g_hash_table_size(ssl_crandom_hash);
31 ssl_export_sessions_func(gpointer key, gpointer value, gpointer user_data)
34 StringInfo *sslid = (StringInfo *)key;
35 StringInfo *master_secret = (StringInfo *)value;
36 GString *keylist = (GString *)user_data;
38 g_string_append(keylist, "RSA Session-ID:");
40 for (i = 0; i < sslid->data_len; i++) {
41 g_string_append_printf(keylist, "%.2x", sslid->data[i]);
44 g_string_append(keylist, " Master-Key:");
46 for (i = 0; i < master_secret->data_len; i++) {
47 g_string_append_printf(keylist, "%.2x", master_secret->data[i]);
50 g_string_append_c(keylist, '\n');
54 ssl_export_client_randoms_func(gpointer key, gpointer value, gpointer user_data)
57 StringInfo *client_random = (StringInfo *)key;
58 StringInfo *master_secret = (StringInfo *)value;
59 GString *keylist = (GString *)user_data;
61 g_string_append(keylist, "CLIENT_RANDOM ");
63 for (i = 0; i < client_random->data_len; i++) {
64 g_string_append_printf(keylist, "%.2x", client_random->data[i]);
67 g_string_append_c(keylist, ' ');
69 for (i = 0; i < master_secret->data_len; i++) {
70 g_string_append_printf(keylist, "%.2x", master_secret->data[i]);
73 g_string_append_c(keylist, '\n');
77 ssl_export_sessions(void)
80 * "RSA Session-ID:xxxx Master-Key:yyyy\n"
81 * Where xxxx is the session ID in hex (max 64 chars)
82 * Where yyyy is the Master Key in hex (always 96 chars)
83 * So in total max 3+1+11+64+1+11+96+2 = 189 chars
85 * "CLIENT_RANDOM zzzz yyyy\n"
86 * Where zzzz is the client random (always 64 chars)
87 * Where yyyy is same as above
88 * So length will always be 13+1+64+1+96+2 = 177 chars
90 * Wireshark can read CLIENT_RANDOM since v1.8.0.
91 * Both values are exported in case you use the Session-ID for resuming a
92 * session in a different capture.
94 gsize len = 189 * g_hash_table_size(ssl_session_hash) +
95 177 * g_hash_table_size(ssl_crandom_hash);
96 GString *keylist = g_string_sized_new(len);
98 g_hash_table_foreach(ssl_session_hash, ssl_export_sessions_func, (gpointer)keylist);
99 g_hash_table_foreach(ssl_crandom_hash, ssl_export_client_randoms_func, (gpointer)keylist);
101 return g_string_free(keylist, FALSE);
110 * indent-tabs-mode: nil
113 * ex: set shiftwidth=4 tabstop=8 expandtab:
114 * :indentSize=4:tabSize=8:noTabs=true: