aboutsummaryrefslogtreecommitdiffstats
path: root/epan/crypt
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2011-07-04 14:07:20 +0000
committerAnders Broman <anders.broman@ericsson.com>2011-07-04 14:07:20 +0000
commit639e59a9f90f1f0dc4f673f8b1f37c9d64b84834 (patch)
treeb72a5b7d6be3d8e4e5edc594582ce11cd2bcd512 /epan/crypt
parent509c6a7fc070c271ce520739464e22e18e320bb1 (diff)
From Michael Mann:
Removed "key prefix" need within GUI so it's a little more intuitive (because that's what this bug is complaining about). Slight backwards compatibility issue with UAT (because key prefix was in previous keys), but all development (including fix for BUG 1123 that created UAT) has just been on SVN and not released. Also adjusted AirPCap (airpcap_loader.c) to account for the lack of "key prefix". Addressed some memory leaks/excess string creation. https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5985 svn path=/trunk/; revision=37888
Diffstat (limited to 'epan/crypt')
-rw-r--r--epan/crypt/airpdcap.c182
-rw-r--r--epan/crypt/airpdcap_user.h15
2 files changed, 84 insertions, 113 deletions
diff --git a/epan/crypt/airpdcap.c b/epan/crypt/airpdcap.c
index e520882cc3..c96a2a2a29 100644
--- a/epan/crypt/airpdcap.c
+++ b/epan/crypt/airpdcap.c
@@ -1779,12 +1779,11 @@ AirPDcapRsnaPwd2Psk(
/*
* Returns the decryption_key_t struct given a string describing the key.
- * Returns NULL if the key_string cannot be parsed.
+ * Returns NULL if the input_string cannot be parsed.
*/
decryption_key_t*
-parse_key_string(gchar* input_string)
+parse_key_string(gchar* input_string, guint8 key_type)
{
- gchar *type;
gchar *key;
gchar *ssid;
@@ -1795,126 +1794,84 @@ parse_key_string(gchar* input_string)
gchar **tokens;
guint n = 0;
decryption_key_t *dk;
- gchar *first_nibble = input_string;
if(input_string == NULL)
return NULL;
/*
- * Parse the input_string. It should be in the form
- * <key type>:<key data>[:<ssid>]
- * XXX - For backward compatibility, the a WEP key can be just a string
- * of hexadecimal characters (if WEP key is wrong, null will be
+ * Parse the input_string. WEP and WPA will be just a string
+ * of hexadecimal characters (if key is wrong, null will be
* returned...).
+ * WPA-PWD should be in the form
+ * <key data>[:<ssid>]
*/
- /* First, check for a WEP string */
- /* XXX - This duplicates code in packet-ieee80211.c */
- if (g_ascii_strncasecmp(input_string, STRING_KEY_TYPE_WEP ":", 4) == 0) {
- first_nibble += 4;
- }
-
- key_ba = g_byte_array_new();
- res = hex_str_to_bytes(first_nibble, key_ba, FALSE);
-
- if (res && key_ba->len > 0) {
- /* Key is correct! It was probably an 'old style' WEP key */
- /* Create the decryption_key_t structure, fill it and return it*/
- dk = (decryption_key_t *)g_malloc(sizeof(decryption_key_t));
-
- dk->type = AIRPDCAP_KEY_TYPE_WEP;
- /* XXX - The current key handling code in the GUI requires
- * no separators and lower case */
- dk->key = g_string_new(bytes_to_str(key_ba->data, key_ba->len));
- g_string_down(dk->key);
- dk->bits = key_ba->len * 8;
- dk->ssid = NULL;
-
- g_byte_array_free(key_ba, TRUE);
- return dk;
- }
- g_byte_array_free(key_ba, TRUE);
-
-
- tokens = g_strsplit(input_string,":",0);
-
- /* Tokens is a null termiated array of strings ... */
- while(tokens[n] != NULL)
- n++;
-
- if(n < 2)
+ switch(key_type)
{
- /* Free the array of strings */
- g_strfreev(tokens);
- return NULL;
- }
-
- type = g_strdup(tokens[0]);
+ case AIRPDCAP_KEY_TYPE_WEP:
+ case AIRPDCAP_KEY_TYPE_WEP_40:
+ case AIRPDCAP_KEY_TYPE_WEP_104:
+
+ key_ba = g_byte_array_new();
+ res = hex_str_to_bytes(input_string, key_ba, FALSE);
+
+ if (res && key_ba->len > 0) {
+ /* Key is correct! It was probably an 'old style' WEP key */
+ /* Create the decryption_key_t structure, fill it and return it*/
+ dk = (decryption_key_t *)g_malloc(sizeof(decryption_key_t));
+
+ dk->type = AIRPDCAP_KEY_TYPE_WEP;
+ /* XXX - The current key handling code in the GUI requires
+ * no separators and lower case */
+ dk->key = g_string_new(bytes_to_str(key_ba->data, key_ba->len));
+ g_string_down(dk->key);
+ dk->bits = key_ba->len * 8;
+ dk->ssid = NULL;
+
+ g_byte_array_free(key_ba, TRUE);
+ return dk;
+ }
- /*
- * The second token is the key (right now it doesn't matter
- * if it is a passphrase[+ssid] or an hexadecimal one)
- */
- key = g_strdup(tokens[1]);
+ /* Key doesn't work */
+ g_byte_array_free(key_ba, TRUE);
+ return NULL;
- ssid = NULL;
- /* Maybe there is a third token (an ssid, if everything else is ok) */
- if(n >= 3)
- {
- ssid = g_strdup(tokens[2]);
- }
+ case AIRPDCAP_KEY_TYPE_WPA_PWD:
- if (g_ascii_strcasecmp(type,STRING_KEY_TYPE_WPA_PSK) == 0) /* WPA key */
- {
- /* Create a new string */
- key_string = g_string_new(key);
+ tokens = g_strsplit(input_string,":",0);
- key_ba = g_byte_array_new();
- res = hex_str_to_bytes(key, key_ba, FALSE);
+ /* Tokens is a null termiated array of strings ... */
+ while(tokens[n] != NULL)
+ n++;
- /* Two tokens means that the user should have entered a WPA-BIN key ... */
- if(!res || ((key_string->len) != WPA_PSK_KEY_CHAR_SIZE))
+ if(n < 1)
{
- 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;
}
- /* 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_PMK;
- dk->key = g_string_new(key);
- dk->bits = (guint) dk->key->len * 4;
- dk->ssid = NULL;
+ /*
+ * The first token is the key
+ */
+ key = g_strdup(tokens[0]);
- g_string_free(key_string, TRUE);
- g_byte_array_free(key_ba, TRUE);
- g_free(key);
- g_free(type);
+ ssid = NULL;
+ /* Maybe there is a second token (an ssid, if everything else is ok) */
+ if(n >= 2)
+ {
+ ssid = g_strdup(tokens[1]);
+ }
- /* Free the array of strings */
- g_strfreev(tokens);
- return dk;
- }
- else if(g_ascii_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;
- /* Three (or more) tokens mean that the user entered a WPA-PWD key ... */
+ /* Two (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);
- g_free(type);
g_free(key);
g_free(ssid);
@@ -1923,13 +1880,12 @@ parse_key_string(gchar* input_string)
return NULL;
}
- if(ssid != NULL) /* more than three tokens found, means that the user specified the ssid */
+ if(ssid != NULL) /* more than two 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 */
@@ -1942,7 +1898,6 @@ parse_key_string(gchar* input_string)
g_string_free(key_string, TRUE);
g_byte_array_free(ssid_ba, TRUE);
- g_free(type);
g_free(key);
g_free(ssid);
@@ -1964,7 +1919,6 @@ parse_key_string(gchar* input_string)
if (ssid_ba != NULL)
g_byte_array_free(ssid_ba, TRUE);
- g_free(type);
g_free(key);
if(ssid != NULL)
g_free(ssid);
@@ -1972,20 +1926,34 @@ parse_key_string(gchar* input_string)
/* Free the array of strings */
g_strfreev(tokens);
return dk;
- }
- /* Something was wrong ... free everything */
+ case AIRPDCAP_KEY_TYPE_WPA_PSK:
- g_free(type);
- g_free(key);
- if(ssid != NULL)
- g_free(ssid); /* It is not always present */
- if (ssid_ba != NULL)
- g_byte_array_free(ssid_ba, TRUE);
+ key_ba = g_byte_array_new();
+ res = hex_str_to_bytes(input_string, key_ba, FALSE);
- /* Free the array of strings */
- g_strfreev(tokens);
+ /* Two tokens means that the user should have entered a WPA-BIN key ... */
+ if(!res || ((key_ba->len) != WPA_PSK_KEY_CHAR_SIZE))
+ {
+ g_byte_array_free(key_ba, TRUE);
+
+ /* No ssid has been created ... */
+ 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_PMK;
+ dk->key = g_string_new(input_string);
+ dk->bits = (guint) dk->key->len * 4;
+ dk->ssid = NULL;
+
+ g_byte_array_free(key_ba, TRUE);
+ return dk;
+ }
+ /* Type not supported */
return NULL;
}
diff --git a/epan/crypt/airpdcap_user.h b/epan/crypt/airpdcap_user.h
index 1d5e2663c9..1b4836ea80 100644
--- a/epan/crypt/airpdcap_user.h
+++ b/epan/crypt/airpdcap_user.h
@@ -204,17 +204,20 @@ typedef struct _AIRPDCAP_KEYS_COLLECTION {
* - 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)
+ * - MyPassword (WPA + plaintext password + "wildcard" SSID)
+ * - MyPassword:MySSID (WPA + plaintext password + specific SSID)
+ * - 01020304... (WPA + 256-bit raw key)
+ * @param key_type [IN] Type of key used for string. Possibilities include:
+ * - AIRPDCAP_KEY_TYPE_WEP (40/64-bit and 104/128-bit WEP)
+ * - AIRPDCAP_KEY_TYPE_WPA_PWD (WPA + plaintext password + "wildcard" SSID or
+ * WPA + plaintext password + specific SSID)
+ * - AIRPDCAP_KEY_TYPE_WPA_PSK (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);
+parse_key_string(gchar* key_string, guint8 key_type);
/**
* Returns a newly allocated string representing the given decryption_key_t