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 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <epan/address.h>
30 #include <epan/dissectors/packet-ssl.h>
31 #include <epan/dissectors/packet-ssl-utils.h>
33 #include "ui/ssl_key_export.h"
36 ssl_session_key_count(void)
38 return g_hash_table_size(ssl_session_hash) +
39 g_hash_table_size(ssl_crandom_hash);
43 ssl_export_sessions_func(gpointer key, gpointer value, gpointer user_data)
46 StringInfo *sslid = (StringInfo *)key;
47 StringInfo *master_secret = (StringInfo *)value;
48 GString *keylist = (GString *)user_data;
50 g_string_append(keylist, "RSA Session-ID:");
52 for (i = 0; i < sslid->data_len; i++) {
53 g_string_append_printf(keylist, "%.2x", sslid->data[i]);
56 g_string_append(keylist, " Master-Key:");
58 for (i = 0; i < master_secret->data_len; i++) {
59 g_string_append_printf(keylist, "%.2x", master_secret->data[i]);
62 g_string_append_c(keylist, '\n');
66 ssl_export_client_randoms_func(gpointer key, gpointer value, gpointer user_data)
69 StringInfo *client_random = (StringInfo *)key;
70 StringInfo *master_secret = (StringInfo *)value;
71 GString *keylist = (GString *)user_data;
73 g_string_append(keylist, "CLIENT_RANDOM ");
75 for (i = 0; i < client_random->data_len; i++) {
76 g_string_append_printf(keylist, "%.2x", client_random->data[i]);
79 g_string_append_c(keylist, ' ');
81 for (i = 0; i < master_secret->data_len; i++) {
82 g_string_append_printf(keylist, "%.2x", master_secret->data[i]);
85 g_string_append_c(keylist, '\n');
89 ssl_export_sessions(void)
92 * "RSA Session-ID:xxxx Master-Key:yyyy\n"
93 * Where xxxx is the session ID in hex (max 64 chars)
94 * Where yyyy is the Master Key in hex (always 96 chars)
95 * So in total max 3+1+11+64+1+11+96+2 = 189 chars
97 * "CLIENT_RANDOM zzzz yyyy\n"
98 * Where zzzz is the client random (always 64 chars)
99 * Where yyyy is same as above
100 * So length will always be 13+1+64+1+96+2 = 177 chars
102 * Wireshark can read CLIENT_RANDOM since v1.8.0.
103 * Both values are exported in case you use the Session-ID for resuming a
104 * session in a different capture.
106 gsize len = 189 * g_hash_table_size(ssl_session_hash) +
107 177 * g_hash_table_size(ssl_crandom_hash);
108 GString *keylist = g_string_sized_new(len);
110 g_hash_table_foreach(ssl_session_hash, ssl_export_sessions_func, (gpointer)keylist);
111 g_hash_table_foreach(ssl_crandom_hash, ssl_export_client_randoms_func, (gpointer)keylist);
113 return g_string_free(keylist, FALSE);
122 * indent-tabs-mode: nil
125 * ex: set shiftwidth=4 tabstop=8 expandtab:
126 * :indentSize=4:tabSize=8:noTabs=true: