summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2007-06-21 17:49:03 +0000
committerGerald Combs <gerald@wireshark.org>2007-06-21 17:49:03 +0000
commit249a747c51efab55250ab6b57f1d8bad1584522c (patch)
tree9315d25ee4e7c5a3e64b516a88b984d90e270b06 /epan
parent1b8fccbc9df66a8d51ace0251bd00ab1463d4fe2 (diff)
downloadwireshark-249a747c51efab55250ab6b57f1d8bad1584522c.tar.gz
Be less restrictive about WEP key preferences. Use hex_str_to_bytes to
process WEP keys. Allow the "wep:" prefix for WEP keys even when HAVE_AIRPDCAP isn't defined. Add a NULL pointer check to hex_str_to_bytes(). Fixes bug 1584. Fixup indentation. svn path=/trunk/; revision=22151
Diffstat (limited to 'epan')
-rw-r--r--epan/crypt/airpdcap.c378
-rw-r--r--epan/crypt/airpdcap_user.h24
-rw-r--r--epan/dissectors/packet-ieee80211.c75
-rw-r--r--epan/strutil.c8
4 files changed, 199 insertions, 286 deletions
diff --git a/epan/crypt/airpdcap.c b/epan/crypt/airpdcap.c
index df3b0116dd..43fe4c458f 100644
--- a/epan/crypt/airpdcap.c
+++ b/epan/crypt/airpdcap.c
@@ -1325,16 +1325,13 @@ parse_key_string(gchar* input_string)
gchar *ssid;
GString *key_string = NULL;
- GByteArray *ssid_ba = NULL;
+ GByteArray *ssid_ba = NULL, *key_ba;
+ gboolean res;
gchar **tokens;
guint n = 0;
-#if GLIB_MAJOR_VERSION < 2
- gint i;
-#else
- gsize i;
-#endif
decryption_key_t *dk;
+ gchar *first_nibble = input_string;
if(input_string == NULL)
return NULL;
@@ -1346,276 +1343,168 @@ parse_key_string(gchar* input_string)
* of hexadecimal characters (if WEP key is wrong, null will be
* returned...).
*/
- tokens = g_strsplit(input_string,":",0);
-
- /* Tokens is a null termiated array of strings ... */
- while(tokens[n] != NULL)
- n++;
- if(n == 0)
- {
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
+ /* First, check for a WEP string */
+ /* XXX - This duplicates code in packet-ieee80211.c */
+ if (g_strncasecmp(input_string, STRING_KEY_TYPE_WEP ":", 4) == 0) {
+ first_nibble += 4;
}
- /*
- * 'n' contains the number of tokens. If the key string is correct,
- * we should have 2 or 3 tokens... If we have 1 token, it can be an
- * 'old style' WEP key. Check for it.
- */
- if(n == 1)
- {
- /* Maybe it is an 'old style' WEP key */
- key = g_strdup(tokens[0]);
+ key_ba = g_byte_array_new();
+ res = hex_str_to_bytes(first_nibble, key_ba, FALSE);
- /* Create a new string */
- key_string = g_string_new(key);
+ if (res) {
+ /* Key is correct! It was probably an 'old style' WEP key */
+ /* Create the decryption_key_t structure, fill it and return it*/
+ dk = g_malloc(sizeof(decryption_key_t));
- /* Check if it is a correct WEP key */
- if( ((key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((key_string->len) < WEP_KEY_MIN_CHAR_SIZE))
- {
- g_string_free(key_string, TRUE);
- g_free(key);
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
- }
+ dk->type = AIRPDCAP_KEY_TYPE_WEP;
+ dk->key = g_string_new(input_string);
+ dk->bits = key_ba->len * 8;
+ dk->ssid = NULL;
- if((key_string->len % 2) != 0)
- {
- g_string_free(key_string, TRUE);
- g_free(key);
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
+ g_byte_array_free(key_ba, TRUE);
+ return dk;
}
+ g_byte_array_free(key_ba, TRUE);
+
+
+ tokens = g_strsplit(input_string,":",0);
- for(i = 0; i < key_string->len; i++)
+ /* Tokens is a null termiated array of strings ... */
+ while(tokens[n] != NULL)
+ n++;
+
+ if(n < 2)
{
- if(!g_ascii_isxdigit(key_string->str[i]))
- {
- g_string_free(key_string, TRUE);
- g_free(key);
/* Free the array of strings */
g_strfreev(tokens);
return NULL;
- }
}
- /* Key is correct! It was probably an 'old style' WEP key */
- /* Create the decryption_key_t structure, fill it and return it*/
- dk = g_malloc(sizeof(decryption_key_t));
-
- dk->type = AIRPDCAP_KEY_TYPE_WEP;
- dk->key = g_string_new(key);
- dk->bits = dk->key->len * 4;
- dk->ssid = NULL;
-
- g_string_free(key_string, TRUE);
- g_free(key);
-
- /* Free the array of strings */
- g_strfreev(tokens);
-
- return dk;
- }
-
- /* There were at least 2 tokens... copy the type value */
type = g_strdup(tokens[0]);
/*
* The second token is the key (right now it doesn't matter
- * if it is a passphrase or an hexadecimal one)
+ * if it is a passphrase[+ssid] or an hexadecimal one)
*/
key = g_strdup(tokens[1]);
- /* Lower case the type */
- g_strdown(type);
-
+ ssid = NULL;
/* Maybe there is a third token (an ssid, if everything else is ok) */
if(n >= 3)
{
- ssid = g_strdup(tokens[2]);
- }
- else
- {
- ssid = NULL;
+ ssid = g_strdup(tokens[2]);
}
- /*
- * Now the initial key string has been divided in two/three tokens.
- * Let's see which kind of key it is, and if it is the correct form
- */
- if(g_strcasecmp(type,STRING_KEY_TYPE_WEP) == 0) /* WEP key */
+ if (g_strcasecmp(type,STRING_KEY_TYPE_WPA_PSK) == 0) /* WPA key */
{
- /* Create a new string */
- key_string = g_string_new(key);
+ /* Create a new string */
+ key_string = g_string_new(key);
- /* Check if it is a correct WEP key */
- if( ((key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((key_string->len) < WEP_KEY_MIN_CHAR_SIZE))
- {
- g_string_free(key_string, TRUE);
- g_free(key);
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
- }
-
- if((key_string->len % 2) != 0)
- {
- g_string_free(key_string, TRUE);
- g_free(key);
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
- }
+ key_ba = g_byte_array_new();
+ res = hex_str_to_bytes(key, key_ba, FALSE);
- for(i = 0; i < key_string->len; i++)
- {
- if(!g_ascii_isxdigit(key_string->str[i]))
+ /* Two tokens means that the user should have entered a WPA-BIN key ... */
+ if( ((key_ba->len) != WPA_PSK_KEY_CHAR_SIZE))
{
- g_string_free(key_string, TRUE);
- g_free(key);
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
+ g_string_free(key_string, TRUE);
+ g_byte_array_free(key_ba, TRUE);
+
+ g_free(type);
+ g_free(key);
+ /* No ssid has been created ... */
+ /* Free the array of strings */
+ g_strfreev(tokens);
+ return NULL;
}
- }
- dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
+ /* Key was correct!!! Create the new decryption_key_t ... */
+ dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
- dk->type = AIRPDCAP_KEY_TYPE_WEP;
- dk->key = g_string_new(key);
- dk->bits = dk->key->len * 4;
- dk->ssid = NULL;
+ dk->type = AIRPDCAP_KEY_TYPE_WPA_PMK;
+ dk->key = g_string_new(key);
+ dk->bits = key_ba->len * 4;
+ dk->ssid = NULL;
- g_string_free(key_string, TRUE);
- g_free(key);
-
- /* Free the array of strings */
- g_strfreev(tokens);
- return dk;
- }
- else if(g_strcasecmp(type,STRING_KEY_TYPE_WPA_PSK) == 0) /* WPA key */
- {
- /* Create a new string */
- key_string = g_string_new(key);
-
- /* Two tokens means that the user should have entered a WPA-BIN key ... */
- if( ((key_string->len) != WPA_PSK_KEY_CHAR_SIZE))
- {
g_string_free(key_string, TRUE);
-
- g_free(type);
+ g_byte_array_free(key_ba, TRUE);
g_free(key);
- /* No ssid has been created ... */
+ g_free(type);
+
/* Free the array of strings */
g_strfreev(tokens);
- return NULL;
+ return dk;
}
-
- for(i = 0; i < key_string->len; i++)
+ else if(g_strcasecmp(type,STRING_KEY_TYPE_WPA_PWD) == 0) /* WPA key *//* If the number of tokens is more than three, we accept the string... if the first three tokens are correct... */
{
- if(!g_ascii_isxdigit(key_string->str[i]))
+ /* Create a new string */
+ key_string = g_string_new(key);
+ ssid_ba = NULL;
+
+ /* Three (or more) tokens mean that the user entered a WPA-PWD key ... */
+ if( ((key_string->len) > WPA_KEY_MAX_CHAR_SIZE) || ((key_string->len) < WPA_KEY_MIN_CHAR_SIZE))
{
- g_string_free(key_string, TRUE);
- /* No ssid_string has been created ... */
+ g_string_free(key_string, TRUE);
- g_free(type);
- g_free(key);
- /* No ssid has been created ... */
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
+ g_free(type);
+ g_free(key);
+ g_free(ssid);
+
+ /* Free the array of strings */
+ g_strfreev(tokens);
+ return NULL;
}
- }
- /* Key was correct!!! Create the new decryption_key_t ... */
- dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
+ if(ssid != NULL) /* more than three tokens found, means that the user specified the ssid */
+ {
+ ssid_ba = g_byte_array_new();
+ if (! uri_str_to_bytes(ssid, ssid_ba)) {
+ g_string_free(key_string, TRUE);
+ g_byte_array_free(ssid_ba, TRUE);
+ g_free(type);
+ g_free(key);
+ g_free(ssid);
+ /* Free the array of strings */
+ g_strfreev(tokens);
+ return NULL;
+ }
- dk->type = AIRPDCAP_KEY_TYPE_WPA_PMK;
- dk->key = g_string_new(key);
- dk->bits = dk->key->len * 4;
- dk->ssid = NULL;
+ if(ssid_ba->len > WPA_SSID_MAX_CHAR_SIZE)
+ {
+ g_string_free(key_string, TRUE);
+ g_byte_array_free(ssid_ba, TRUE);
- g_string_free(key_string, TRUE);
- g_free(key);
- g_free(type);
+ g_free(type);
+ g_free(key);
+ g_free(ssid);
- /* Free the array of strings */
- g_strfreev(tokens);
- return dk;
- }
- else if(g_strcasecmp(type,STRING_KEY_TYPE_WPA_PWD) == 0) /* WPA key *//* If the number of tokens is more than three, we accept the string... if the first three tokens are correct... */
- {
- /* Create a new string */
- key_string = g_string_new(key);
- ssid_ba = NULL;
+ /* Free the array of strings */
+ g_strfreev(tokens);
+ return NULL;
+ }
+ }
+ /* Key was correct!!! Create the new decryption_key_t ... */
+ dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
- /* Three (or more) tokens mean that the user entered a WPA-PWD key ... */
- if( ((key_string->len) > WPA_KEY_MAX_CHAR_SIZE) || ((key_string->len) < WPA_KEY_MIN_CHAR_SIZE))
- {
- g_string_free(key_string, TRUE);
+ dk->type = AIRPDCAP_KEY_TYPE_WPA_PWD;
+ dk->key = g_string_new(key);
+ dk->bits = 256; /* This is the length of the array pf bytes that will be generated using key+ssid ...*/
+ dk->ssid = byte_array_dup(ssid_ba); /* NULL if ssid_ba is NULL */
- g_free(type);
- g_free(key);
- g_free(ssid);
-
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
- }
-
- if(ssid != NULL) /* more than three tokens found, means that the user specified the ssid */
- {
- ssid_ba = g_byte_array_new();
- if (! uri_str_to_bytes(ssid, ssid_ba)) {
g_string_free(key_string, TRUE);
- g_byte_array_free(ssid_ba, TRUE);
- g_free(type);
- g_free(key);
- g_free(ssid);
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
- }
-
- if(ssid_ba->len > WPA_SSID_MAX_CHAR_SIZE)
- {
- g_string_free(key_string, TRUE);
- g_byte_array_free(ssid_ba, TRUE);
+ if (ssid_ba != NULL)
+ g_byte_array_free(ssid_ba, TRUE);
g_free(type);
g_free(key);
- g_free(ssid);
+ if(ssid != NULL)
+ g_free(ssid);
/* Free the array of strings */
g_strfreev(tokens);
- return NULL;
- }
- }
-
- /* Key was correct!!! Create the new decryption_key_t ... */
- dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
-
- dk->type = AIRPDCAP_KEY_TYPE_WPA_PWD;
- dk->key = g_string_new(key);
- dk->bits = 256; /* This is the length of the array pf bytes that will be generated using key+ssid ...*/
- dk->ssid = byte_array_dup(ssid_ba); /* NULL if ssid_ba is NULL */
-
- g_string_free(key_string, TRUE);
- if (ssid_ba != NULL)
- g_byte_array_free(ssid_ba, TRUE);
-
- g_free(type);
- g_free(key);
- if(ssid != NULL) g_free(ssid);
-
- /* Free the array of strings */
- g_strfreev(tokens);
- return dk;
+ return dk;
}
/* Something was wrong ... free everything */
@@ -1623,9 +1512,9 @@ parse_key_string(gchar* input_string)
g_free(type);
g_free(key);
if(ssid != NULL)
- g_free(ssid); /* It is not always present */
+ g_free(ssid); /* It is not always present */
if (ssid_ba != NULL)
- g_byte_array_free(ssid_ba, TRUE);
+ g_byte_array_free(ssid_ba, TRUE);
/* Free the array of strings */
g_strfreev(tokens);
@@ -1642,38 +1531,27 @@ get_key_string(decryption_key_t* dk)
{
gchar* output_string = NULL;
- if(dk == NULL)
+ if(dk == NULL || dk->key == NULL)
return NULL;
- if(dk->type == AIRPDCAP_KEY_TYPE_WEP)
- {
- if(dk->key == NULL) /* Should NOT happen at all... */
- return NULL;
-
- output_string = g_strdup_printf("%s:%s",STRING_KEY_TYPE_WEP,dk->key->str);
- }
- else if(dk->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
- {
- if(dk->key == NULL) /* Should NOT happen at all... */
- return NULL;
-
- if(dk->ssid == NULL)
- output_string = g_strdup_printf("%s:%s",STRING_KEY_TYPE_WPA_PWD,dk->key->str);
- else
- output_string = g_strdup_printf("%s:%s:%s",
- STRING_KEY_TYPE_WPA_PWD,dk->key->str,
- format_text((guchar *)dk->ssid->data, dk->ssid->len));
- }
- else if(dk->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
- {
- if(dk->key == NULL) /* Should NOT happen at all... */
+ switch(dk->type) {
+ case AIRPDCAP_KEY_TYPE_WEP:
+ output_string = g_strdup_printf("%s:%s",STRING_KEY_TYPE_WEP,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);
+ else
+ output_string = g_strdup_printf("%s:%s:%s",
+ STRING_KEY_TYPE_WPA_PWD, 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);
+ break;
+ default:
return NULL;
-
- output_string = g_strdup_printf("%s:%s",STRING_KEY_TYPE_WPA_PSK,dk->key->str);
- }
- else
- {
- return NULL;
+ break;
}
return output_string;
diff --git a/epan/crypt/airpdcap_user.h b/epan/crypt/airpdcap_user.h
index 0dccb8c975..04d90a4003 100644
--- a/epan/crypt/airpdcap_user.h
+++ b/epan/crypt/airpdcap_user.h
@@ -193,15 +193,31 @@ typedef struct _AIRPDCAP_KEYS_COLLECTION {
/******************************************************************************/
/* Function prototype declarations */
-/*
+/**
* Returns the decryption_key_t struct given a string describing the key.
- * Returns NULL if the key_string cannot be parsed.
+ * @param key_string [IN] Key string in one of the following formats:
+ * - 0102030405 (40/64-bit WEP)
+ * - 01:02:03:04:05 (40/64-bit WEP)
+ * - 0102030405060708090a0b0c0d (104/128-bit WEP)
+ * - 01:02:03:04:05:06:07:08:09:0a:0b:0c:0d (104/128-bit WEP)
+ * - wep:01020304... (WEP)
+ * - wep:01:02:03:04... (WEP)
+ * - wpa-pwd:MyPassword (WPA + plaintext password + "wildcard" SSID)
+ * - wpa-pwd:MyPassword:MySSID (WPA + plaintext password + specific SSID)
+ * - wpa-psk:01020304... (WPA + 256-bit raw key)
+ * @return A pointer to a freshly-g_malloc()ed decryption_key_t struct on
+ * success, or NULL on failure.
+ * @see get_key_string()
*/
decryption_key_t*
parse_key_string(gchar* key_string);
-/*
- * Returns a newly allocated string representing the given decryption_key_t struct
+/**
+ * Returns a newly allocated string representing the given decryption_key_t
+ * struct.
+ * @param dk [IN] Pointer to the key to be converted
+ * @return A g_malloc()ed string representation of the key
+ * @see parse_key_string()
*/
gchar*
get_key_string(decryption_key_t* dk);
diff --git a/epan/dissectors/packet-ieee80211.c b/epan/dissectors/packet-ieee80211.c
index 844f80d637..a4bd66952e 100644
--- a/epan/dissectors/packet-ieee80211.c
+++ b/epan/dissectors/packet-ieee80211.c
@@ -111,19 +111,20 @@ static GHashTable *wlan_fragment_table = NULL;
static GHashTable *wlan_reassembled_table = NULL;
/* Stuff for the WEP decoder */
+static gboolean enable_decryption = FALSE;
+static void init_wepkeys(void);
+#ifndef HAVE_AIRPDCAP
static gint num_wepkeys = 0;
-static gboolean enable_decryption = FALSE;
static guint8 **wep_keys = NULL;
static int *wep_keylens = NULL;
-static void init_wepkeys(void);
-#ifndef HAVE_AIRPDCAP
static tvbuff_t *try_decrypt_wep(tvbuff_t *tvb, guint32 offset, guint32 len);
static int wep_decrypt(guint8 *buf, guint32 len, int key_override);
#else
/* Davide Schiera (2006-11-26): created function to decrypt WEP and WPA/WPA2 */
static tvbuff_t *try_decrypt(tvbuff_t *tvb, guint32 offset, guint32 len, guint8 *algorithm, guint32 *sec_header, guint32 *sec_trailer);
#endif
+
static int weak_iv(guchar *iv);
#define SSWAP(a,b) {guint8 tmp = s[a]; s[a] = s[b]; s[b] = tmp;}
@@ -6085,13 +6086,13 @@ dissect_ieee80211_common (tvbuff_t * tvb, packet_info * pinfo,
fcs_item = proto_tree_add_boolean(fcs_tree,
hf_fcs_good, tvb,
- hdr_len + len, 2,
+ hdr_len + len, 4,
fcs_good);
PROTO_ITEM_SET_GENERATED(fcs_item);
fcs_item = proto_tree_add_boolean(fcs_tree,
hf_fcs_bad, tvb,
- hdr_len + len, 2,
+ hdr_len + len, 4,
fcs_bad);
PROTO_ITEM_SET_GENERATED(fcs_item);
}
@@ -10091,17 +10092,17 @@ proto_register_ieee80211 (void)
g_string_sprintf(key_title, "Key #%d", i + 1);
/* Davide Schiera (2006-11-26): modified keys input tooltip */
g_string_sprintf(key_desc,
- "Key #%d string can be:"
- " <wep hexadecimal key>;"
- " wep:<wep hexadecimal key>;"
- " wpa-pwd:<passphrase>[:<ssid>];"
+ "Key #%d string can be:\n"
+ " <wep hexadecimal key>;\n"
+ " wep:<wep hexadecimal key>;\n"
+ " wpa-pwd:<passphrase>[:<ssid>];\n"
" wpa-psk:<wpa hexadecimal key>", i + 1);
#else
g_string_sprintf(key_name, "wep_key%d", i + 1);
g_string_sprintf(key_title, "WEP key #%d", i + 1);
- g_string_sprintf(key_desc, "WEP key #%d bytes in hexadecimal (A:B:C:D:E) "
- "[40bit], (A:B:C:D:E:F:G:H:I:J:K:L:M) [104bit], or whatever key "
- "length you're using", i + 1);
+ g_string_sprintf(key_desc, "WEP key #%d can be:\n"
+ " <wep hexadecimal key>;\n"
+ " wep:<wep hexadecimal key>\n", i + 1);
#endif
prefs_register_string_preference(wlan_module, key_name->str,
@@ -10239,6 +10240,23 @@ static tvbuff_t *try_decrypt_wep(tvbuff_t *tvb, guint32 offset, guint32 len) {
}
#endif
+/*
+ * Convert a raw WEP key or one prefixed with "wep:" to a byte array.
+ * Separators are allowed.
+ */
+/* XXX This is duplicated in epan/airpdcap.c:parse_key_string() */
+static gboolean
+wep_str_to_bytes(const char *hex_str, GByteArray *bytes) {
+ char *first_nibble = (char *) hex_str;
+
+ if (g_strncasecmp(hex_str, STRING_KEY_TYPE_WEP ":", 4) == 0) {
+ first_nibble += 4;
+ }
+
+ return hex_str_to_bytes(first_nibble, bytes, FALSE);
+}
+
+/* Collect our WEP and WPA keys */
#ifdef HAVE_AIRPDCAP
static
void set_airpdcap_keys(void)
@@ -10267,7 +10285,7 @@ void set_airpdcap_keys(void)
key.KeyType = AIRPDCAP_KEY_TYPE_WEP;
bytes = g_byte_array_new();
- res = hex_str_to_bytes(dk->key->str, bytes, FALSE);
+ res = wep_str_to_bytes(dk->key->str, bytes);
if (dk->key->str && res && bytes->len > 0 && bytes->len <= AIRPDCAP_WEP_KEY_MAXLEN)
{
@@ -10305,7 +10323,7 @@ void set_airpdcap_keys(void)
key.KeyType = AIRPDCAP_KEY_TYPE_WPA_PMK;
bytes = g_byte_array_new();
- res = hex_str_to_bytes(dk->key->str, bytes, FALSE);
+ res = wep_str_to_bytes(dk->key->str, bytes);
/* XXX - Pass the correct array of bytes... */
if (bytes-> len <= AIRPDCAP_WPA_PMK_LEN) {
@@ -10414,6 +10432,7 @@ static int wep_decrypt(guint8 *buf, guint32 len, int keyidx) {
#endif
static void init_wepkeys(void) {
+#ifndef HAVE_AIRPDCAP
const char *tmp;
int i, keyidx;
GByteArray *bytes;
@@ -10446,24 +10465,13 @@ static void init_wepkeys(void) {
bytes = g_byte_array_new();
num_wepkeys = 0;
for ( i = 0; i < MAX_ENCRYPTION_KEYS; i++) {
- res = hex_str_to_bytes(wep_keystr[i], bytes, FALSE);
+ g_strstrip(wep_keystr[i]);
+ res = wep_str_to_bytes(wep_keystr[i], bytes);
if (wep_keystr[i] && res && bytes-> len > 0) {
num_wepkeys++;
}
}
-#ifdef HAVE_AIRPDCAP
- /*
- * XXX - AirPDcap - That God sends it to us beautiful (che dio ce la mandi bona)
- * The next lines will add a key to the AirPDcap context. The keystring will be added
- * to the old WEP array too, but we don't care, because the packets will come here
- * already decrypted... One of these days we will fix this too
- */
- set_airpdcap_keys();
-
- /* END AirPDcap */
-#endif
-
wep_keys = g_malloc0(num_wepkeys * sizeof(guint8*));
wep_keylens = g_malloc(num_wepkeys * sizeof(int));
@@ -10492,7 +10500,7 @@ static void init_wepkeys(void) {
g_free(wep_keys[keyidx]);
}
- res = hex_str_to_bytes(tmp, bytes, FALSE);
+ res = wep_str_to_bytes(tmp, bytes);
if (tmp && res && bytes->len > 0) {
if (bytes->len > 32) {
bytes->len = 32;
@@ -10515,6 +10523,17 @@ static void init_wepkeys(void) {
}
}
g_byte_array_free(bytes, TRUE);
+
+#else /* HAVE_AIRPDCAP defined */
+
+ /*
+ * XXX - AirPDcap - That God sends it to us beautiful (che dio ce la mandi bona)
+ * The next lines will add a key to the AirPDcap context. The keystring will be added
+ * to the old WEP array too, but we don't care, because the packets will come here
+ * already decrypted... One of these days we will fix this too
+ */
+ set_airpdcap_keys();
+#endif /* HAVE_AIRPDCAP */
}
/*
* This code had been taken from AirSnort crack.c function classify()
diff --git a/epan/strutil.c b/epan/strutil.c
index d9ff52d033..b7ab4d1d13 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -433,17 +433,17 @@ hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separato
char two_digits[3];
char one_digit[2];
- g_byte_array_set_size(bytes, 0);
- if (! hex_str) {
+ if (! hex_str || ! bytes) {
return FALSE;
}
+ g_byte_array_set_size(bytes, 0);
p = (const guchar *)hex_str;
while (*p) {
q = p+1;
r = p+2;
s = p+3;
- if (*q && *r && *s
+ if (*q && *r && *s
&& isxdigit(*p) && isxdigit(*q) &&
isxdigit(*r) && isxdigit(*s)) {
four_digits_first_half[0] = *p;
@@ -460,7 +460,7 @@ hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separato
g_byte_array_append(bytes, &val, 1);
val = (guint8) strtoul(four_digits_second_half, NULL, 16);
g_byte_array_append(bytes, &val, 1);
-
+
punct = s + 1;
if (*punct) {
/*