diff options
author | Gerald Combs <gerald@wireshark.org> | 2012-10-16 18:14:16 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2012-10-16 18:14:16 +0000 |
commit | 403e6dc86a55a12f1cf586093d4b6a8fa62f91ba (patch) | |
tree | e5155f0cc0e573dda3d6055122dcd16b39440083 | |
parent | 5bcb56b21c1c102001a2b50651ed3e6c9815dc64 (diff) |
Move common SSL key export routines to ui/ssl_key_export.[ch]. Make the
exported keys a gchar *. Implement SSL key exports in the Qt UI. Remove
some no-longer-necessary packet-ssl*.h includes.
Change lastOpenDir().absolutePath() to .canonicalPath(). Get rid of the
"Export As PostScript" action.
svn path=/trunk/; revision=45589
-rw-r--r-- | ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ui/Makefile.common | 10 | ||||
-rw-r--r-- | ui/gtk/export_sslkeys.c | 75 | ||||
-rw-r--r-- | ui/gtk/export_sslkeys.h | 8 | ||||
-rw-r--r-- | ui/qt/main_window.h | 1 | ||||
-rw-r--r-- | ui/qt/main_window.ui | 5 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 62 | ||||
-rw-r--r-- | ui/ssl_key_export.c | 87 | ||||
-rw-r--r-- | ui/ssl_key_export.h | 51 | ||||
-rw-r--r-- | ui/win32/file_dlg_win32.c | 13 |
10 files changed, 224 insertions, 89 deletions
diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 21421d6347..aa9c0a228c 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -26,6 +26,7 @@ set(COMMON_UI_SRC alert_box.c help_url.c iface_lists.c + ssl_key_export.c text_import.c util.c ) diff --git a/ui/Makefile.common b/ui/Makefile.common index 5e5d990e14..bbe239e510 100644 --- a/ui/Makefile.common +++ b/ui/Makefile.common @@ -44,10 +44,11 @@ GENERATOR_FILES = \ text_import_scanner.l WIRESHARK_UI_SRC = \ - alert_box.c \ - iface_lists.c \ - help_url.c \ - text_import.c \ + alert_box.c \ + iface_lists.c \ + help_url.c \ + ssl_key_export.c \ + text_import.c \ util.c noinst_HEADERS = \ @@ -62,6 +63,7 @@ noinst_HEADERS = \ recent.h \ recent_utils.h \ simple_dialog.h \ + ssl_key_export.h \ text_import.h \ text_import_scanner.h \ ui_util.h \ diff --git a/ui/gtk/export_sslkeys.c b/ui/gtk/export_sslkeys.c index 3eafbc51af..7d0183dc0f 100644 --- a/ui/gtk/export_sslkeys.c +++ b/ui/gtk/export_sslkeys.c @@ -50,8 +50,6 @@ #include <epan/epan_dissect.h> #include <epan/charsets.h> #include <epan/prefs.h> -#include <epan/dissectors/packet-ssl.h> -#include <epan/dissectors/packet-ssl-utils.h> #include "../isprint.h" @@ -60,6 +58,7 @@ #include "ui/progress_dlg.h" #include "ui/recent.h" #include "ui/simple_dialog.h" +#include "ui/ssl_key_export.h" #include "ui/ui_util.h" #include "ui/gtk/keys.h" @@ -79,59 +78,6 @@ #include "ui/win32/file_dlg_win32.h" #endif -static void -ssl_export_sessions_func(gpointer key, gpointer value, gpointer user_data) -{ - guint i; - size_t offset; - StringInfo* sslid = (StringInfo*)key; - StringInfo* mastersecret = (StringInfo*)value; - StringInfo* keylist = (StringInfo*)user_data; - - offset = strlen(keylist->data); - - /* - * XXX - should this be a string that grows as necessary to hold - * everything in it? - */ - g_snprintf(keylist->data+offset,(gulong)(keylist->data_len-offset),"RSA Session-ID:"); - offset += 15; - - for( i=0; i<sslid->data_len; i++) { - g_snprintf(keylist->data+offset,(gulong)(keylist->data_len-offset),"%.2x",sslid->data[i]&255); - offset += 2; - } - - g_snprintf(keylist->data+offset,(gulong)(keylist->data_len-offset)," Master-Key:"); - offset += 12; - - for( i=0; i<mastersecret->data_len; i++) { - g_snprintf(keylist->data+offset,(gulong)(keylist->data_len-offset),"%.2x",mastersecret->data[i]&255); - offset += 2; - } - - g_snprintf(keylist->data+offset,(gulong)(keylist->data_len-offset),"\n"); -} - -StringInfo* -ssl_export_sessions(GHashTable *session_hash) -{ - StringInfo* keylist; - - /* Output format is: - * "RSA Session-ID:xxxx Master-Key:yyyy\n" - * Where xxxx is the session ID in hex (max 64 chars) - * Where yyyy is the Master Key in hex (always 96 chars) - * So in total max 3+1+11+64+1+11+96+2 = 189 chars - */ - keylist = g_malloc0(sizeof(StringInfo)+189*g_hash_table_size (session_hash)); - keylist->data = ((guchar*)keylist+sizeof(StringInfo)); - keylist->data_len = sizeof(StringInfo)+189*g_hash_table_size (session_hash); - - g_hash_table_foreach(session_hash, ssl_export_sessions_func, (gpointer)keylist); - - return keylist; -} static GtkWidget *savesslkeys_dlg=NULL; static void @@ -146,7 +92,7 @@ savesslkeys_save_clicked_cb(GtkWidget * w _U_, gpointer data _U_) { int fd; char *file; - StringInfo *keylist; + gchar *keylist; file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(savesslkeys_dlg)); @@ -162,19 +108,18 @@ savesslkeys_save_clicked_cb(GtkWidget * w _U_, gpointer data _U_) /* XXX: Must check if file name exists first */ - /* - * Retrieve the info we need - */ - keylist = ssl_export_sessions(ssl_session_hash); - - if (keylist->data_len == 0 ) { + if (ssl_session_key_count() < 1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No SSL Session Keys to export!"); - g_free(keylist); g_free(file); return TRUE; } + /* + * Retrieve the info we need + */ + keylist = ssl_export_sessions(); + fd = ws_open(file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666); if (fd == -1) { open_failure_alert_box(file, errno, TRUE); @@ -186,7 +131,7 @@ savesslkeys_save_clicked_cb(GtkWidget * w _U_, gpointer data _U_) * Thanks, Microsoft, for not using size_t for the third argument to * _write(). Presumably this string will be <= 4GiB long.... */ - if (ws_write(fd, keylist->data, (unsigned int)strlen(keylist->data)) < 0) { + if (ws_write(fd, keylist, (unsigned int)strlen(keylist)) < 0) { write_failure_alert_box(file, errno); ws_close(fd); g_free(keylist); @@ -223,7 +168,7 @@ savesslkeys_cb(GtkWidget * w _U_, gpointer data _U_) GtkWidget *dlg_lb; guint keylist_len; - keylist_len = g_hash_table_size(ssl_session_hash); + keylist_len = ssl_session_key_count(); /* don't show up the dialog, if no data has to be saved */ if (keylist_len==0) { /* shouldn't happen as the menu item should have been greyed out */ diff --git a/ui/gtk/export_sslkeys.h b/ui/gtk/export_sslkeys.h index eb81130aaa..1327d13d38 100644 --- a/ui/gtk/export_sslkeys.h +++ b/ui/gtk/export_sslkeys.h @@ -34,10 +34,4 @@ */ extern void savesslkeys_cb(GtkWidget * w, gpointer data); -/** Dump the SSL Session Keys to a StringInfo string - * - * @param session_hash contains all the SSL Session Keys - */ -extern StringInfo* ssl_export_sessions(GHashTable *session_hash); - -#endif /* __MAIN_PROTO_DRAW_H__ */ +#endif /* __EXPORT_SSLKEYS_H__ */ diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 5ab990109f..a16c3e0b83 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -193,6 +193,7 @@ private slots: void on_goToLineEdit_returnPressed(); void on_actionStartCapture_triggered(); void on_actionStopCapture_triggered(); + void on_actionFileExportSSLSessionKeys_triggered(); }; diff --git a/ui/qt/main_window.ui b/ui/qt/main_window.ui index 45940d9284..105e15f635 100644 --- a/ui/qt/main_window.ui +++ b/ui/qt/main_window.ui @@ -693,11 +693,6 @@ <string>As Plain &Text...</string> </property> </action> - <action name="actionFileExportAsPostScript"> - <property name="text"> - <string>As PostScript...</string> - </property> - </action> <action name="actionFileExportAsCSV"> <property name="text"> <string>As CSV...</string> diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 6d4fc4ccd9..33f1b711cd 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -56,6 +56,7 @@ #include "ui/capture_globals.h" #include "ui/help_url.h" #include "ui/main_statusbar.h" +#include "ui/ssl_key_export.h" #include "wireshark_application.h" #include "capture_file_dialog.h" @@ -724,7 +725,7 @@ void MainWindow::on_actionFileExportPacketBytes_triggered() file_name = QFileDialog::getSaveFileName(this, tr("Wireshark: Export Selected Packet Bytes"), - wsApp->lastOpenDir().absolutePath(), + wsApp->lastOpenDir().canonicalPath(), tr("Raw data (*.bin *.dat *.raw);;Any File (*.*)") ); @@ -754,6 +755,65 @@ void MainWindow::on_actionFileExportPacketBytes_triggered() } } +void MainWindow::on_actionFileExportSSLSessionKeys_triggered() +{ + QString file_name; + QString save_title; + int keylist_len; + + keylist_len = ssl_session_key_count(); + /* don't show up the dialog, if no data has to be saved */ + if (keylist_len < 1) { + /* shouldn't happen as the menu item should have been greyed out */ + QMessageBox::warning( + this, + tr("No Keys"), + tr("There are no SSL Session Keys to save."), + QMessageBox::Ok + ); + return; + } + + save_title.append("Wireshark: Export SSL Session Keys (%1 key%2"). + arg(keylist_len).arg(plurality(keylist_len, "", "s")); + file_name = QFileDialog::getSaveFileName(this, + save_title, + wsApp->lastOpenDir().canonicalPath(), + tr("SSL Session Keys (*.keys *.txt);;Any File (*.*)") + ); + if (file_name.length() > 0) { + gchar *keylist; + int fd; + + keylist = ssl_export_sessions(); + fd = ws_open(file_name.toUtf8().constData(), O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666); + if (fd == -1) { + open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE); + g_free(keylist); + return; + } + /* + * Thanks, Microsoft, for not using size_t for the third argument to + * _write(). Presumably this string will be <= 4GiB long.... + */ + if (ws_write(fd, keylist, (unsigned int)strlen(keylist)) < 0) { + write_failure_alert_box(file_name.toUtf8().constData(), errno); + ::close(fd); + g_free(keylist); + return; + } + if (::close(fd) < 0) { + write_failure_alert_box(file_name.toUtf8().constData(), errno); + g_free(keylist); + return; + } + + /* Save the directory name for future file dialogs. */ + wsApp->setLastOpenDir(&file_name); + g_free(keylist); + } +} + // View Menu // Expand / collapse slots in proto_tree diff --git a/ui/ssl_key_export.c b/ui/ssl_key_export.c new file mode 100644 index 0000000000..ab5773b6c4 --- /dev/null +++ b/ui/ssl_key_export.c @@ -0,0 +1,87 @@ +/* export_sslkeys.c + * + * $Id$ + * + * Export SSL Session Keys dialog + * by Sake Blok <sake@euronet.nl> (20110526) + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <glib.h> + +#include <epan/address.h> +#include <epan/dissectors/packet-ssl.h> +#include <epan/dissectors/packet-ssl-utils.h> + + +int +ssl_session_key_count(void) +{ + return g_hash_table_size(ssl_session_hash); +} + +static void +ssl_export_sessions_func(gpointer key, gpointer value, gpointer user_data) +{ + guint i; + StringInfo* sslid = (StringInfo*)key; + StringInfo* mastersecret = (StringInfo*)value; + GString* keylist = (GString*)user_data; + + /* + * XXX - should this be a string that grows as necessary to hold + * everything in it? + */ + g_string_append(keylist, "RSA Session-ID:"); + + for( i=0; i<sslid->data_len; i++) { + g_string_append_printf(keylist, "%.2x", sslid->data[i]&255); + } + + g_string_append(keylist, " Master-Key:"); + + for( i=0; i<mastersecret->data_len; i++) { + g_string_append_printf(keylist, "%.2x", mastersecret->data[i]&255); + } + + g_string_append_c(keylist, '\n'); +} + +gchar* +ssl_export_sessions(void) +{ + GString* keylist = g_string_new(""); + gchar *session_keys; + + /* Output format is: + * "RSA Session-ID:xxxx Master-Key:yyyy\n" + * Where xxxx is the session ID in hex (max 64 chars) + * Where yyyy is the Master Key in hex (always 96 chars) + * So in total max 3+1+11+64+1+11+96+2 = 189 chars + */ + + g_hash_table_foreach(ssl_session_hash, ssl_export_sessions_func, (gpointer)keylist); + + session_keys = keylist->str; + g_string_free(keylist, FALSE); + return session_keys; +} diff --git a/ui/ssl_key_export.h b/ui/ssl_key_export.h new file mode 100644 index 0000000000..a782dd9ace --- /dev/null +++ b/ui/ssl_key_export.h @@ -0,0 +1,51 @@ +/* export_sslkeys.h + * + * $Id$ + * + * SSL session key utilities. Copied from ui/gkt/export_sslkeys.c + * by Sake Blok <sake@euronet.nl> (20110526) + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __SSL_KEY_EXPORT_H__ +#define __SSL_KEY_EXPORT_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** Return the number of available SSL session keys. + * + * @return The number of available SSL session keys. + */ +extern int ssl_session_key_count(); + +/** Dump our SSL Session Keys to a string + * + * @return A string containing all the SSL Session Keys. Must be freed with + * g_free(). + */ +extern gchar* ssl_export_sessions(); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __SSL_KEY_EXPORT_H__ */ diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index 3ec0a3f9f8..88341eb7d3 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -43,8 +43,6 @@ #include "epan/filesystem.h" #include "epan/addr_resolv.h" #include "epan/prefs.h" -#include "epan/dissectors/packet-ssl.h" -#include "epan/dissectors/packet-ssl-utils.h" #include "wsutil/file_util.h" #include "wsutil/unicode-utils.h" @@ -57,6 +55,7 @@ #include "ui/file_dialog.h" #include "ui/last_open_dir.h" #include "ui/simple_dialog.h" +#include "ui/ssl_key_export.h" #include "ui/util.h" #include "ui/gtk/main.h" @@ -809,7 +808,7 @@ win32_export_sslkeys_file(HWND h_wnd) { OPENFILENAME *ofn; TCHAR file_name[MAX_PATH] = _T(""); char *dirname; - StringInfo *keylist; + gchar *keylist; char *file_name8; int fd; int ofnsize; @@ -818,7 +817,7 @@ win32_export_sslkeys_file(HWND h_wnd) { OSVERSIONINFO osvi; #endif - keylist_size = g_hash_table_size(ssl_session_hash); + keylist_size = ssl_session_key_count(); if (keylist_size==0) { /* This shouldn't happen */ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No SSL Session Keys to export."); @@ -864,7 +863,7 @@ win32_export_sslkeys_file(HWND h_wnd) { if (GetSaveFileName(ofn)) { g_free( (void *) ofn); file_name8 = utf_16to8(file_name); - keylist = ssl_export_sessions(ssl_session_hash); + keylist = ssl_export_sessions(); fd = ws_open(file_name8, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666); if (fd == -1) { open_failure_alert_box(file_name8, errno, TRUE); @@ -875,7 +874,7 @@ win32_export_sslkeys_file(HWND h_wnd) { * Thanks, Microsoft, for not using size_t for the third argument to * _write(). Presumably this string will be <= 4GiB long.... */ - if (ws_write(fd, keylist->data, (unsigned int)strlen(keylist->data)) < 0) { + if (ws_write(fd, keylist, (unsigned int)strlen(keylist)) < 0) { write_failure_alert_box(file_name8, errno); ws_close(fd); g_free(keylist); @@ -1927,7 +1926,7 @@ range_update_dynamics(HWND dlg_hwnd, packet_range_t *range) { StringCchPrintf(static_val, STATIC_LABEL_CHARS, _T("%u"), range->user_range_cnt); } SetWindowText(cur_ctrl, static_val); - + cur_ctrl = GetDlgItem(dlg_hwnd, EWFD_RANGE_DISP); EnableWindow(cur_ctrl, filtered_active); if (range->remove_ignored) { |