Fix WEP key bug in the AirPcap code that could cause a crash. Enable

AirPcap by default. Add initial support for the "Any" device in AirPcap
(more to come).

svn path=/trunk/; revision=19401
This commit is contained in:
Gerald Combs 2006-10-02 23:44:10 +00:00
parent 6cde05da1b
commit 2649d26145
10 changed files with 150 additions and 44 deletions

View File

@ -67,6 +67,12 @@ extern "C" {
*/
#define AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING "\\\\.\\airpcap%u"
/*!
\brief This string is the scanf modifier to extract the adapter "Any" string from an adapter name.
It can be used to parse the name field in an AirpcapDeviceDescription structure with scanf.
*/
#define AIRPCAP_DEVICE_ANY_EXTRACT_STRING "\\\\.\\airpcap_any"
/*!
\brief Entry in the list returned by \ref AirpcapGetDeviceList();
*/

View File

@ -261,7 +261,7 @@ airpcap_if_info_t *
airpcap_if_info_new(char *name, char *description)
{
PAirpcapHandle ad;
char* ebuf = NULL;
gchar ebuf[AIRPCAP_ERRBUF_SIZE];
airpcap_if_info_t *if_info;
@ -493,27 +493,39 @@ return NULL;
}
/*
* Returns the ASCII string of a key given the key bites
* Returns the ASCII string of a key given the key bytes
*/
gchar*
airpcap_get_key_string(AirpcapKey key)
{
unsigned int j = 0;
gchar *s,*s1;
unsigned int l = 0;
gchar *dst,*src;
s = NULL;
s1 = NULL;
src = NULL;
if(key.KeyType == AIRPCAP_KEYTYPE_WEP)
{
s = g_strdup_printf("");
for(j = 0; j < key.KeyLen != 0; j++)
{
s1 = g_strdup_printf("%.2x", key.KeyData[j]);
g_strlcat(s,s1,WEP_KEY_MAX_SIZE);
}
if(key.KeyLen != 0)
{
/* Allocate the string used to store the ASCII representation of the WEP key */
dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
/* Make sure that the first char is '\0' in order to make g_strlcat() work */
dst[0]='\0';
for(j = 0; j < key.KeyLen; j++)
{
src = g_strdup_printf("%.2x\0", key.KeyData[j]);
/*
* XXX - use g_strconcat() instead ???
*/
l = g_strlcat(dst,src,WEP_KEY_MAX_CHAR_SIZE+1);
}
g_free(src);
}
}
return s;
return dst;
}
/*
@ -558,8 +570,21 @@ airpcap_get_if_string_number(airpcap_if_info_t* if_info)
int a;
a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
number = g_strdup_printf("%.2u\0",n);
/* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
* Otherwise, check if it is the "Any" adapter...
*/
if(a == 0)
{
if(g_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
number = g_strdup_printf("??");
else
number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
}
else
{
number = g_strdup_printf("%.2u\0",n);
}
return number;
}

View File

@ -34,6 +34,14 @@
#define MAX_ENCRYPTION_KEYS 64
#define AIRPCAP_CHANNEL_ANY_NAME "ANY"
/*
* WEP_KEY_MAX_SIZE is in bytes. but each byte is rapresented in strings with an ascii char
* 4 bit are needed to store an exadecimal number, 8 bit to store a char...
*/
#define WEP_KEY_MAX_CHAR_SIZE (WEP_KEY_MAX_SIZE*2)
typedef PCHAR (*AirpcapGetLastErrorHandler)(PAirpcapHandle AdapterHandle);
typedef BOOL (*AirpcapGetDeviceListHandler)(PAirpcapDeviceDescription *PPAllDevs, PCHAR Ebuf);
typedef VOID (*AirpcapFreeDeviceListHandler)(PAirpcapDeviceDescription PAllDevs);

View File

@ -238,7 +238,7 @@ GETTEXT_DIR=$(WIRESHARK_LIBS)\gettext-runtime-0.13.1
# If you don't have the AirPcap developer's pack, comment this line out,
# so that AIRPCAP_DIR isn't defined.
#
# AIRPCAP_DIR=$(WIRESHARK_LIBS)\AirPcap
AIRPCAP_DIR=$(WIRESHARK_LIBS)\AirPcap

View File

@ -8,7 +8,7 @@ dnl Check for CPU / vendor / OS
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(wireshark, 0.99.4)
AM_INIT_AUTOMAKE(wireshark, 0.99.4-Freightliner-19394)
AM_DISABLE_STATIC

View File

@ -32,11 +32,14 @@
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <string.h>
#include <epan/filesystem.h>
#include <pcap.h>
#include "gtk/main.h"
#include "dlg_utils.h"
#include "gui_utils.h"
@ -264,7 +267,6 @@ if(keys_in_list > 0)
/*
* Allocate the collection
* We use malloc so it's easier to reuse the code in C programs
*/
KeysCollection = (PAirpcapKeysCollection)malloc(KeysCollectionSize);
if(!KeysCollection)
@ -304,7 +306,7 @@ if(keys_in_list > 0)
}
/*
* XXX - Free the old adapter key collection!
* Free the old adapter key collection!
*/
if(airpcap_if_selected->keysCollection != NULL)
g_free(airpcap_if_selected->keysCollection);
@ -315,6 +317,8 @@ if(keys_in_list > 0)
airpcap_if_selected->keysCollection = KeysCollection;
airpcap_if_selected->keysCollectionSize = KeysCollectionSize;
}
return;
}
@ -528,7 +532,7 @@ void update_blink(gpointer data _U_)
{
airpcap_if_info_t* sel;
PAirpcapHandle ad;
char* ebuf = NULL;
gchar ebuf[AIRPCAP_ERRBUF_SIZE];
sel = (airpcap_if_info_t*)data;
@ -556,7 +560,7 @@ void
blink_cb( GtkWidget *blink_bt _U_, gpointer if_data )
{
PAirpcapHandle ad = NULL;
char* ebuf = NULL;
gchar ebuf[AIRPCAP_ERRBUF_SIZE];
if(airpcap_if_selected != NULL)
if(!(airpcap_if_selected->blinking))
@ -596,7 +600,7 @@ static void
airpcap_if_destroy_cb(GtkWidget *w _U_, gpointer user_data _U_)
{
PAirpcapHandle ad = NULL;
char* ebuf = NULL;
gchar ebuf[AIRPCAP_ERRBUF_SIZE];
/* Retrieve object data */
GtkWidget *main_w;
@ -706,8 +710,10 @@ airpcap_if_destroy_cb(GtkWidget *w _U_, gpointer user_data _U_)
if( g_strcasecmp(airpcap_if_selected->description,airpcap_if_active->description) == 0)
{
gtk_label_set_text(GTK_LABEL(toolbar_if_lb), g_strdup_printf("%s %s\t","Current Wireless Interface: #",airpcap_get_if_string_number(airpcap_if_selected)));
airpcap_channel_combo_set_by_number(toolbar_channel_cm,airpcap_if_selected->channel);
airpcap_validation_type_combo_set_by_type(toolbar_wrong_crc_cm,airpcap_if_selected->CrcValidationOn);
airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cm),airpcap_if_selected);
airpcap_validation_type_combo_set_by_type(toolbar_wrong_crc_cm,airpcap_if_selected->CrcValidationOn);
gtk_signal_handler_block_by_func (GTK_OBJECT(toolbar_decryption_ck),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), toolbar);
if(airpcap_if_active->DecryptionOn == AIRPCAP_DECRYPTION_ON)
@ -791,7 +797,7 @@ airpcap_advanced_apply_cb(GtkWidget *button, gpointer data _U_)
if( g_strcasecmp(airpcap_if_selected->description,airpcap_if_active->description) == 0)
{
gtk_label_set_text(GTK_LABEL(toolbar_if_lb), g_strdup_printf("%s %s\t","Current Wireless Interface: #",airpcap_get_if_string_number(airpcap_if_selected)));
airpcap_channel_combo_set_by_number(toolbar_channel_cm,airpcap_if_selected->channel);
airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cm),airpcap_if_selected);
airpcap_validation_type_combo_set_by_type(toolbar_wrong_crc_cm,airpcap_if_selected->CrcValidationOn);
gtk_signal_handler_block_by_func (GTK_OBJECT(toolbar_decryption_ck),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), toolbar);
@ -844,7 +850,7 @@ airpcap_advanced_ok_cb(GtkWidget *w, gpointer data _U_)
if( g_strcasecmp(airpcap_if_selected->description,airpcap_if_active->description) == 0)
{
gtk_label_set_text(GTK_LABEL(toolbar_if_lb), g_strdup_printf("%s %s\t","Current Wireless Interface: #",airpcap_get_if_string_number(airpcap_if_selected)));
airpcap_channel_combo_set_by_number(toolbar_channel_cm,airpcap_if_selected->channel);
airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cm),airpcap_if_selected);
airpcap_validation_type_combo_set_by_type(toolbar_wrong_crc_cm,airpcap_if_selected->CrcValidationOn);
gtk_signal_handler_block_by_func (GTK_OBJECT(toolbar_decryption_ck),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), toolbar);
@ -911,9 +917,15 @@ new_key = g_string_new(text_entered);
g_strchug(new_key->str);
g_strchomp(new_key->str);
if((new_key->len) > WEP_KEY_MAX_CHAR_SIZE)
{
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"WEP key size out of range!\nValid key size range is 2-%d characters (8-%d bits).",WEP_KEY_MAX_CHAR_SIZE,WEP_KEY_MAX_SIZE*8);
return;
}
if((new_key->len % 2) != 0)
{
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"%s","1) A Wep key must is an arbitrary length hexadecimal number.\nThe valid characters are: 0123456789ABCDEF.\nThe number of characters must be even.");
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"Wrong WEP key!\nThe number of characters must be even.");
return;
}
@ -921,7 +933,7 @@ for(i = 0; i < new_key->len; i++)
{
if(!g_ascii_isxdigit(new_key->str[i]))
{
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"%s","2) A Wep key must is an arbitrary length hexadecimal number.\nThe valid characters are: 0123456789ABCDEF.\nThe number of characters must be even.");
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"Wrong WEP key!\nA WEP key must be an hexadecimal number.\nThe valid characters are: 0123456789ABCDEF.");
return;
}
}
@ -935,6 +947,7 @@ g_string_free(new_key,TRUE);
g_free(text_entered);
window_destroy(GTK_WIDGET(data));
return;
}
@ -972,9 +985,15 @@ new_key = g_string_new(text_entered);
g_strchug(new_key->str);
g_strchomp(new_key->str);
if((new_key->len) > WEP_KEY_MAX_CHAR_SIZE)
{
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"WEP key size out of range!\nValid key size range is 2-%d characters (8-%d bits).",WEP_KEY_MAX_CHAR_SIZE,WEP_KEY_MAX_SIZE*8);
return;
}
if((new_key->len % 2) != 0)
{
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"%s","1) A Wep key must is an arbitrary length hexadecimal number.\nThe valid characters are: 0123456789ABCDEF.\nThe number of characters must be even.");
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"Wrong WEP key!\nThe number of characters must be even.");
return;
}
@ -982,7 +1001,7 @@ for(i = 0; i < new_key->len; i++)
{
if(!g_ascii_isxdigit(new_key->str[i]))
{
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"%s","2) A Wep key must is an arbitrary length hexadecimal number.\nThe valid characters are: 0123456789ABCDEF.\nThe number of characters must be even.");
simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"Wrong WEP key!\nA WEP key must be an hexadecimal number.\nThe valid characters are: 0123456789ABCDEF.");
return;
}
}
@ -1403,7 +1422,7 @@ airpcap_if_selected->saved = FALSE;
/* Turns the decryption on or off */
static void
encryption_check_cb(GtkWidget *w, gpointer data)
wep_encryption_check_cb(GtkWidget *w, gpointer data)
{
if( !block_advanced_signals && (airpcap_if_selected != NULL))
{
@ -1420,14 +1439,13 @@ if( !block_advanced_signals && (airpcap_if_selected != NULL))
}
}
/* Called to create the airpcap settings' window */
void
display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
{
/* Main window */
GtkWidget *airpcap_advanced_w;
/* Blink button */
GtkWidget *blink_bt,
*channel_combo;
@ -1497,7 +1515,7 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
/* other stuff */
GList *channel_list,*capture_list;
GList *linktype_list = NULL;
gchar *channel_s,*capture_s;
gchar *capture_s;
/* user data - RETRIEVE pointers of toolbar widgets */
@ -1659,8 +1677,7 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
/* Select the first entry */
if(airpcap_if_selected != NULL)
{
channel_s = g_strdup_printf("%d",airpcap_if_selected->channel);
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_combo)->entry), channel_s);
airpcap_update_channel_combo(GTK_WIDGET(channel_combo), airpcap_if_selected);
}
channel_te = GTK_COMBO(channel_combo)->entry;
@ -1755,7 +1772,7 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
/* encryption enabled box */
encryption_check = gtk_check_button_new_with_label("Enable WEP Decryption");
OBJECT_SET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_DECRYPTION_KEY,encryption_check);
OBJECT_SET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_WEP_DECRYPTION_KEY,encryption_check);
/* Fcs Presence check box */
if(airpcap_if_selected != NULL)
@ -1766,7 +1783,7 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(encryption_check),FALSE);
}
SIGNAL_CONNECT(encryption_check,"toggled",encryption_check_cb,NULL);
SIGNAL_CONNECT(encryption_check,"toggled",wep_encryption_check_cb,NULL);
gtk_box_pack_start (GTK_BOX (encryption_box), encryption_check, FALSE, FALSE, 0);
gtk_widget_show(encryption_check);

View File

@ -82,7 +82,7 @@ if(if_info != NULL)
gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE);
gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE);
airpcap_validation_type_combo_set_by_type(GTK_WIDGET(airpcap_toolbar_crc_filter_combo),if_info->CrcValidationOn);
airpcap_channel_combo_set_by_number(GTK_WIDGET(airpcap_toolbar_channel),if_info->channel);
airpcap_update_channel_combo(GTK_WIDGET(airpcap_toolbar_channel),if_info);
/*decription check box*/
gtk_signal_handler_block_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb);
@ -145,7 +145,7 @@ if(if_info != NULL)
gtk_widget_set_sensitive(airpcap_toolbar_button,TRUE);
gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE);
airpcap_validation_type_combo_set_by_type(GTK_WIDGET(airpcap_toolbar_crc_filter_combo),if_info->CrcValidationOn);
airpcap_channel_combo_set_by_number(GTK_WIDGET(airpcap_toolbar_channel),if_info->channel);
airpcap_update_channel_combo(GTK_WIDGET(airpcap_toolbar_channel),if_info);
/*decription check box*/
gtk_signal_handler_block_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb);
@ -205,14 +205,20 @@ airpcap_fill_key_list(GtkWidget *keylist,airpcap_if_info_t* if_info)
{
GtkWidget *nl_item,*nl_lb;
gchar* s;
unsigned int i;
unsigned int i,n;
n = 0;
if( (if_info != NULL) && (if_info->keysCollection != NULL))
{
n = if_info->keysCollection->nKeys;
for(i = 0; i < if_info->keysCollection->nKeys; i++)
{
s = airpcap_get_key_string(if_info->keysCollection->Keys[i]);
s = airpcap_get_key_string(if_info->keysCollection->Keys[i]); /* g_strdup_printf("1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\0"); */
nl_lb = gtk_label_new(s);
g_free(s);
nl_item = gtk_list_item_new();
gtk_misc_set_alignment (GTK_MISC (nl_lb), 0.0, 0.5);
gtk_container_add(GTK_CONTAINER(nl_item), nl_lb);
@ -398,4 +404,34 @@ airpcap_channel_combo_set_by_number(GtkWidget* w,UINT channel)
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),airpcap_get_channel_name(channel));
}
/*
* Returns '1' if this is the "Any" adapter, '0' otherwise
*/
int
airpcap_if_is_any(airpcap_if_info_t* if_info)
{
if(g_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)==0)
return 1;
else
return 0;
}
/*
* Update channel combo box. If the airpcap interface is "Any", the combo box will be disabled.
*/
void
airpcap_update_channel_combo(GtkWidget* w, airpcap_if_info_t* if_info)
{
if(airpcap_if_is_any(if_info))
{
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry)," ");
gtk_widget_set_sensitive(GTK_WIDGET(w),FALSE);
}
else
{
airpcap_channel_combo_set_by_number(w,if_info->channel);
gtk_widget_set_sensitive(GTK_WIDGET(w),TRUE);
}
}
#endif /* HAVE_AIRPCAP */

View File

@ -127,4 +127,16 @@ airpcap_get_channel_name(UINT n);
void
airpcap_channel_combo_set_by_number(GtkWidget* w,UINT channel);
/*
* Returns '1' if this is the "Any" adapter, '0' otherwise
*/
int
airpcap_if_is_any(airpcap_if_info_t* if_info);
/*
* Update channel combo box. If the airpcap interface is "Any", the combo box will be disabled.
*/
void
airpcap_update_channel_combo(GtkWidget* w, airpcap_if_info_t* if_info);
#endif

View File

@ -850,11 +850,11 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
advanced_hb = gtk_hbox_new(FALSE,5);
gtk_box_pack_start(GTK_BOX(capture_vb), advanced_hb, FALSE, FALSE, 0);
advanced_bt = gtk_button_new();
advanced_bt = gtk_button_new_with_label("Wireless Settings");
/* set the text */
#if GTK_MAJOR_VERSION >= 2
/* XXX - find a way to set the GtkButton label in GTK 1.x */
/* XXX - find a way to set the GtkButton label in GTK 2.x */
gtk_button_set_label(GTK_BUTTON(advanced_bt), "Wireless Settings");
#else
/* Set the GtkButton label in GTK 1.x */

View File

@ -72,7 +72,9 @@
#define AIRPCAP_ADVANCED_EDIT_KEY_TEXT_KEY "airpcap_advanced_edit_key_text_key"
#define AIRPCAP_ADVANCED_EDIT_KEY_OK_KEY "airpcap_advanced_edit_key_ok_key"
#define AIRPCAP_ADVANCED_EDIT_KEY_LABEL_KEY "airpcap_advanced_edit_key_label_key"
#define AIRPCAP_ADVANCED_DECRYPTION_KEY "airpcap_advanced_decryption_key"
#define AIRPCAP_ADVANCED_WEP_DECRYPTION_KEY "airpcap_advanced_wep_decryption_key"
#define AIRPCAP_ADVANCED_WPA_DECRYPTION_KEY "airpcap_advanced_wpa_decryption_key"
#define AIRPCAP_ADVANCED_NOTEBOOK_KEY "airpcap_advanced_notebook_key"
#define AIRPCAP_OPTIONS_ADVANCED_KEY "airpcap_options_advanced_key"