Bugfix Decryption Key Management dialog, bug 8446 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8446)
Needed to convert use of old IEEE802.11 preference strings to UAT. Since UAT is self-contained within its own file, the entire preference file doesn't need to be rewritten/saved when UAT values are changed. svn path=/trunk/; revision=48308
This commit is contained in:
parent
fc6e505dac
commit
3a48e7e1e2
123
airpcap_loader.c
123
airpcap_loader.c
|
@ -40,6 +40,8 @@
|
|||
#include <epan/packet.h>
|
||||
#include <epan/prefs.h>
|
||||
#include <epan/prefs-int.h>
|
||||
#include <epan/uat-int.h>
|
||||
#include <epan/dissectors/packet-ieee80211.h>
|
||||
#include <epan/crypt/wep-wpadefs.h>
|
||||
#include <epan/crypt/airpdcap_ws.h>
|
||||
#include <epan/strutil.h>
|
||||
|
@ -150,40 +152,56 @@ get_wep_key(pref_t *pref, gpointer ud)
|
|||
gchar *key_string = NULL;
|
||||
guint8 key_type = AIRPDCAP_KEY_TYPE_WEP;
|
||||
keys_cb_data_t* user_data;
|
||||
|
||||
uat_t *uat;
|
||||
guint i;
|
||||
const char* err = NULL;
|
||||
uat_wep_key_record_t* wep_keys;
|
||||
decryption_key_t* new_key;
|
||||
|
||||
/* Retrieve user data info */
|
||||
user_data = (keys_cb_data_t*)ud;
|
||||
|
||||
if (g_ascii_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
|
||||
if (g_ascii_strcasecmp(pref->name, "wep_key_table") == 0 && pref->type == PREF_UAT)
|
||||
{
|
||||
/* strip out key type */
|
||||
if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WEP ":", 4) == 0) {
|
||||
key_string = (gchar*)(*pref->varp.string)+4;
|
||||
}
|
||||
else if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WPA_PWD ":", 8) == 0) {
|
||||
key_string = (gchar*)(*pref->varp.string)+8;
|
||||
key_type = AIRPDCAP_KEY_TYPE_WPA_PWD;
|
||||
}
|
||||
else if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WPA_PSK ":", 8) == 0) {
|
||||
key_string = (gchar*)(*pref->varp.string)+8;
|
||||
key_type = AIRPDCAP_KEY_TYPE_WPA_PSK;
|
||||
}
|
||||
else {
|
||||
key_type = AIRPDCAP_KEY_TYPE_WEP;
|
||||
key_string = (gchar*)*pref->varp.string;
|
||||
}
|
||||
|
||||
/* Here we have the string describing the key... */
|
||||
new_key = parse_key_string(key_string, key_type);
|
||||
|
||||
if (new_key != NULL)
|
||||
uat = (uat_t *)pref->varp.uat;
|
||||
/* This is just a sanity check. UAT should be loaded */
|
||||
if (!uat->loaded)
|
||||
{
|
||||
/* Key is added only if not null ... */
|
||||
user_data->list = g_list_append(user_data->list,new_key);
|
||||
user_data->number_of_keys++;
|
||||
user_data->current_index++;
|
||||
uat_load(uat, &err);
|
||||
if (err != NULL)
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0, wep_keys = (uat_wep_key_record_t*)*uat->user_ptr; i < *uat->nrows_p; i++, wep_keys++)
|
||||
{
|
||||
/* strip out key type if present */
|
||||
if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WEP ":", 4) == 0) {
|
||||
key_type = AIRPDCAP_KEY_TYPE_WEP;
|
||||
key_string = (gchar*)wep_keys->string+4;
|
||||
}
|
||||
else if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WPA_PWD ":", 8) == 0) {
|
||||
key_string = (gchar*)wep_keys->string+8;
|
||||
key_type = AIRPDCAP_KEY_TYPE_WPA_PWD;
|
||||
}
|
||||
else if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WPA_PSK ":", 8) == 0) {
|
||||
key_string = (gchar*)wep_keys->string+8;
|
||||
key_type = AIRPDCAP_KEY_TYPE_WPA_PSK;
|
||||
}
|
||||
else {
|
||||
key_type = wep_keys->key;
|
||||
key_string = (gchar*)wep_keys->string;
|
||||
}
|
||||
|
||||
/* Here we have the string describing the key... */
|
||||
new_key = parse_key_string(key_string, key_type);
|
||||
|
||||
if (new_key != NULL)
|
||||
{
|
||||
/* Key is added only if not null ... */
|
||||
user_data->list = g_list_append(user_data->list,new_key);
|
||||
user_data->number_of_keys++;
|
||||
user_data->current_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -228,48 +246,39 @@ wep_key_is_valid(char* key)
|
|||
static guint
|
||||
set_wep_key(pref_t *pref, gpointer ud _U_)
|
||||
{
|
||||
gchar *my_string = NULL;
|
||||
keys_cb_data_t* user_data;
|
||||
gint wep_key_number = 0;
|
||||
uat_t *uat;
|
||||
gint i;
|
||||
char* err = NULL;
|
||||
uat_wep_key_record_t uat_key;
|
||||
|
||||
decryption_key_t* new_key;
|
||||
|
||||
/* Retrieve user data info */
|
||||
user_data = (keys_cb_data_t*)ud;
|
||||
|
||||
if (g_ascii_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
|
||||
if (g_ascii_strcasecmp(pref->name, "wep_key_table") == 0 && pref->type == PREF_UAT)
|
||||
{
|
||||
/* Ok, the pref we're gonna set is a wep_key ... but what number? */
|
||||
sscanf(pref->name,"wep_key%d",&wep_key_number);
|
||||
uat = (uat_t *)pref->varp.uat;
|
||||
/* UAT must be loaded */
|
||||
if (!uat->loaded)
|
||||
return 1;
|
||||
|
||||
if (user_data->current_index < user_data->number_of_keys)
|
||||
/* Free the old records */
|
||||
uat_clear(uat);
|
||||
|
||||
for (i = 0; i < user_data->number_of_keys; i++)
|
||||
{
|
||||
if (wep_key_number == (user_data->current_index+1))
|
||||
{
|
||||
/* Retrieve the nth decryption_key_t structure pointer */
|
||||
new_key = (decryption_key_t*)g_list_nth_data(user_data->list,user_data->current_index);
|
||||
new_key = (decryption_key_t*)g_list_nth_data(user_data->list,i);
|
||||
|
||||
/* Free the old key string */
|
||||
g_free((void *)*pref->varp.string);
|
||||
|
||||
/* Create the new string describing the decryption key */
|
||||
my_string = get_key_string(new_key);
|
||||
|
||||
/* Duplicate the string, and assign it to the variable pointer */
|
||||
*pref->varp.string = (void *)g_strdup(my_string);
|
||||
|
||||
/* Free the previously allocated string */
|
||||
g_free(my_string);
|
||||
}
|
||||
uat_key.string = get_key_string(new_key);
|
||||
uat_key.key = new_key->type;
|
||||
uat_add_record(uat, &uat_key);
|
||||
}
|
||||
else /* If the number of keys has been reduced somehow, we need to delete all the other keys
|
||||
* (remember that the new ones have been probably overwritten)
|
||||
*/
|
||||
{
|
||||
g_free((void *)*pref->varp.string);
|
||||
*pref->varp.string = (void *)g_strdup(""); /* Do not just free memory!!! Put an 'empty' string! */
|
||||
}
|
||||
user_data->current_index++;
|
||||
|
||||
uat_save(uat, &err);
|
||||
if (err != NULL)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1989,18 +1989,17 @@ get_key_string(decryption_key_t* dk)
|
|||
|
||||
switch(dk->type) {
|
||||
case AIRPDCAP_KEY_TYPE_WEP:
|
||||
output_string = g_strdup_printf("%s:%s",STRING_KEY_TYPE_WEP,dk->key->str);
|
||||
output_string = g_strdup(dk->key->str);
|
||||
break;
|
||||
case AIRPDCAP_KEY_TYPE_WPA_PWD:
|
||||
if(dk->ssid == NULL)
|
||||
output_string = g_strdup_printf("%s:%s",STRING_KEY_TYPE_WPA_PWD,dk->key->str);
|
||||
output_string = g_strdup(dk->key->str);
|
||||
else
|
||||
output_string = g_strdup_printf("%s:%s:%s",
|
||||
STRING_KEY_TYPE_WPA_PWD, dk->key->str,
|
||||
format_uri(dk->ssid, ":"));
|
||||
output_string = g_strdup_printf("%s:%s",
|
||||
dk->key->str, format_uri(dk->ssid, ":"));
|
||||
break;
|
||||
case AIRPDCAP_KEY_TYPE_WPA_PMK:
|
||||
output_string = g_strdup_printf("%s:%s",STRING_KEY_TYPE_WPA_PSK,dk->key->str);
|
||||
output_string = g_strdup(dk->key->str);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
|
|
|
@ -143,12 +143,6 @@ static struct _wlan_stats wlan_stats;
|
|||
* UAT for WEP decoder
|
||||
*-------------------------------------
|
||||
*/
|
||||
/* UAT entry structure. */
|
||||
typedef struct {
|
||||
guint8 key;
|
||||
gchar *string;
|
||||
} uat_wep_key_record_t;
|
||||
|
||||
static uat_wep_key_record_t *uat_wep_key_records = NULL;
|
||||
static uat_t *wep_uat = NULL;
|
||||
static guint num_wepkeys_uat = 0;
|
||||
|
|
|
@ -64,3 +64,9 @@ typedef struct _wlan_hdr {
|
|||
#define WLANCAP_MAGIC_COOKIE_BASE 0x80211000
|
||||
#define WLANCAP_MAGIC_COOKIE_V1 0x80211001
|
||||
#define WLANCAP_MAGIC_COOKIE_V2 0x80211002
|
||||
|
||||
/* UAT entry structure. */
|
||||
typedef struct {
|
||||
guint8 key;
|
||||
gchar *string;
|
||||
} uat_wep_key_record_t;
|
||||
|
|
|
@ -35,13 +35,11 @@
|
|||
#include <epan/filesystem.h>
|
||||
#include <epan/emem.h>
|
||||
#include <epan/prefs.h>
|
||||
#include <epan/prefs-int.h>
|
||||
#include <epan/frequency-utils.h>
|
||||
#include <epan/crypt/wep-wpadefs.h>
|
||||
|
||||
#include <pcap.h>
|
||||
|
||||
#include "ui/preference_utils.h"
|
||||
#include "ui/simple_dialog.h"
|
||||
|
||||
#include "ui/gtk/main.h"
|
||||
|
@ -67,36 +65,6 @@ typedef struct{
|
|||
gint row;
|
||||
}airpcap_key_ls_selected_info_t;
|
||||
|
||||
/*
|
||||
* This function is used to write the preferences to the preferences file.
|
||||
* It has the same behaviour as prefs_main_write() in prefs_dlg.c
|
||||
*/
|
||||
static void
|
||||
write_prefs_to_file(void)
|
||||
{
|
||||
int err;
|
||||
char *pf_dir_path;
|
||||
char *pf_path;
|
||||
|
||||
/* Create the directory that holds personal configuration files, if
|
||||
necessary. */
|
||||
if (create_persconffile_dir(&pf_dir_path) == -1) {
|
||||
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
||||
"Can't create directory\n\"%s\"\nfor preferences file: %s.", pf_dir_path,
|
||||
g_strerror(errno));
|
||||
g_free(pf_dir_path);
|
||||
} else {
|
||||
/* Write the preferencs out. */
|
||||
err = write_prefs(&pf_path);
|
||||
if (err != 0) {
|
||||
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
||||
"Can't open preferences file\n\"%s\": %s.", pf_path,
|
||||
g_strerror(err));
|
||||
g_free(pf_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for the select row event in the key list widget
|
||||
*/
|
||||
|
@ -1958,9 +1926,6 @@ on_key_management_ok_bt_clicked(GtkWidget *button, gpointer data)
|
|||
/* Apply the current decryption preferences */
|
||||
on_key_management_apply_bt_clicked(button, data);
|
||||
|
||||
/* Save the preferences to preferences file!!! */
|
||||
write_prefs_to_file();
|
||||
|
||||
gtk_widget_destroy(key_management_w);
|
||||
}
|
||||
|
||||
|
@ -2383,9 +2348,6 @@ on_merge_bt_clicked (GtkWidget* button _U_, gpointer user_data)
|
|||
/* Set up this new list as default for Wireshark and Adapters... */
|
||||
airpcap_save_decryption_keys(merged_list,airpcap_if_list);
|
||||
|
||||
/* Write the preferences to the preferences file */
|
||||
write_prefs_to_file();
|
||||
|
||||
free_key_list(wireshark_keys);
|
||||
free_key_list(driver_keys);
|
||||
|
||||
|
@ -2425,9 +2387,6 @@ on_keep_bt_clicked (GtkWidget *button _U_, gpointer user_data)
|
|||
/* Set up this new list as default for Wireshark and Adapters... */
|
||||
airpcap_save_decryption_keys(merged_keys,airpcap_if_list);
|
||||
|
||||
/* Write the preferences to the preferences file (here is not needed, by the way)*/
|
||||
write_prefs_to_file();
|
||||
|
||||
/* Free the memory */
|
||||
free_key_list(wireshark_keys);
|
||||
|
||||
|
@ -2491,9 +2450,6 @@ on_import_bt_clicked (GtkWidget* button _U_, gpointer user_data)
|
|||
/* Set up this new list as default for Wireshark and Adapters... */
|
||||
airpcap_save_decryption_keys(merged_list,airpcap_if_list);
|
||||
|
||||
/* Write the preferences to the preferences file */
|
||||
write_prefs_to_file();
|
||||
|
||||
free_key_list(wireshark_keys);
|
||||
free_key_list(driver_keys);
|
||||
|
||||
|
|
Loading…
Reference in New Issue