2005-12-23 Dan Williams <dcbw@redhat.com>

* gnome/applet/applet-compat.c
		- Fix bugs in GConf entry conversion

	* gnome/applet/applet-dbus-info.c
		- (nmi_dbus_get_network_properties): handle case of the BSSID
			list being zero-length

	* libnm-util/cipher-*
	  libnm-util/dbus-helpers.c
		- All ciphers must now return hashed keys as UTF-8 valid
			hexadecimal strings, ie "8f3dae4023".  They are pushed
			through dbus as strings too.
		- Consolidate various functions that do bin->hex and hex->bin
			conversion into cipher.c

	* src/nm-ap-security-wep.c
	  src/nm-ap-security-wpa-psk.c
		- Handle NULL keys since we may not know keys right away

	* src/nm-dbus-nmi.c
		- (nm_dbus_get_network_data_cb): actually advance to the start
			of the wireless security info before we try to deserialize it

	* libnm-util/test-ciphers.c
		- Update cipher tests for the change to UTF-8 hexadecimal strings


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1230 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2005-12-23 08:20:12 +00:00
parent fef4d7791b
commit 5c35a1372c
16 changed files with 213 additions and 248 deletions

View file

@ -1,3 +1,31 @@
2005-12-23 Dan Williams <dcbw@redhat.com>
* gnome/applet/applet-compat.c
- Fix bugs in GConf entry conversion
* gnome/applet/applet-dbus-info.c
- (nmi_dbus_get_network_properties): handle case of the BSSID
list being zero-length
* libnm-util/cipher-*
libnm-util/dbus-helpers.c
- All ciphers must now return hashed keys as UTF-8 valid
hexadecimal strings, ie "8f3dae4023". They are pushed
through dbus as strings too.
- Consolidate various functions that do bin->hex and hex->bin
conversion into cipher.c
* src/nm-ap-security-wep.c
src/nm-ap-security-wpa-psk.c
- Handle NULL keys since we may not know keys right away
* src/nm-dbus-nmi.c
- (nm_dbus_get_network_data_cb): actually advance to the start
of the wireless security info before we try to deserialize it
* libnm-util/test-ciphers.c
- Update cipher tests for the change to UTF-8 hexadecimal strings
2005-12-22 Dan Williams <dcbw@redhat.com>
* gnome/applet/applet-compat.[ch]

View file

@ -185,7 +185,7 @@ set_key_in_keyring (const char *essid,
&item_id);
if (ret != GNOME_KEYRING_RESULT_OK)
{
nm_warning ("%s:%d (%s): Error saving encryption key in keyring for '%s'. Ret=%d",
nm_warning ("%s:%d (%s): Error converting encryption key for '%s'. Ret=%d",
__FILE__, __LINE__, __func__, essid, ret);
}
@ -289,7 +289,7 @@ convert_one_entry (GConfClient *client,
}
/* Ignore any entry that looks like it doesn't need conversion */
if (!nm_gconf_get_int_helper (client,
if (nm_gconf_get_int_helper (client,
GCONF_PATH_WIRELESS_NETWORKS,
"we_cipher",
escaped_network,
@ -313,7 +313,7 @@ convert_one_entry (GConfClient *client,
key = g_strdup_printf ("%s/%s/addresses", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
if ((addrs_value = gconf_client_get (client, key, NULL)))
{
if ((addrs_value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (addrs_value) != GCONF_VALUE_STRING))
if ((addrs_value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (addrs_value) == GCONF_VALUE_STRING))
{
GSList * list;
char * conv_key;
@ -333,6 +333,7 @@ convert_one_entry (GConfClient *client,
/* Convert security information, if any */
switch (key_type)
{
case NM_ENC_TYPE_UNKNOWN:
case NM_ENC_TYPE_NONE:
convert_no_encryption (client, escaped_network);
break;

View file

@ -462,7 +462,7 @@ nmi_dbus_get_network_properties (DBusConnection *connection,
/* Fourth arg: List of AP BSSIDs (ARRAY, STRING) */
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array_iter);
if (bssids_value)
if (bssids_value && (g_slist_length (gconf_value_get_list (bssids_value)) > 0))
{
g_slist_foreach (gconf_value_get_list (bssids_value),
(GFunc) addr_list_append_helper,
@ -470,8 +470,8 @@ nmi_dbus_get_network_properties (DBusConnection *connection,
}
else
{
const char *fake = " ";
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &fake);
const char *fake = "";
dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &fake);
}
dbus_message_iter_close_container (&iter, &array_iter);
@ -833,7 +833,7 @@ nmi_save_network_info (NMWirelessApplet *applet,
key = g_strdup_printf ("%s/%s", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
gconf_entry = gconf_client_get_entry (applet->gconf_client, key, NULL, TRUE, NULL);
g_free (key);
if (gconf_entry)
if (!gconf_entry)
{
nm_warning ("%s:%d (%s): GConf entry for '%s' doesn't exist.", __FILE__, __LINE__, __func__, essid);
goto out;

View file

@ -51,4 +51,15 @@ struct IEEE_802_11_Cipher
};
int cipher_default_validate_func (IEEE_802_11_Cipher *cipher,
const char *ssid,
const char *input);
char * cipher_bin2hexstr (const char *bytes,
int len,
int final_len);
char * cipher_hexstr2bin (const char *hex,
size_t len);
#endif /* CIPHER_PRIVATE_H */

View file

@ -33,23 +33,14 @@ static char * cipher_wep64_ascii_hash_func (IEEE_802_11_Cipher *cipher, const ch
static char * cipher_wep_ascii_hash_func (IEEE_802_11_Cipher *cipher, const char *input, int req_keylen)
{
int keylen;
char * ret = NULL;
g_return_val_if_fail (cipher != NULL, NULL);
g_return_val_if_fail (input != NULL, NULL);
g_return_val_if_fail (req_keylen > 0, NULL);
keylen = strlen (input);
if (keylen != req_keylen)
if (strlen (input) != req_keylen)
return NULL;
if (keylen > IW_ENCODING_TOKEN_MAX)
keylen = IW_ENCODING_TOKEN_MAX;
ret = g_malloc0 (keylen+1);
memcpy (ret, input, keylen);
return ret;
return cipher_bin2hexstr (input, req_keylen, req_keylen * 2);
}

View file

@ -31,90 +31,6 @@ static char * cipher_wep128_hex_hash_func (IEEE_802_11_Cipher *cipher, const cha
static char * cipher_wep64_hex_hash_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input);
static char * cipher_wep_hex_convert_func (IEEE_802_11_Cipher *cipher, const char *input, int req_keylen)
{
const char * p;
gboolean success = TRUE;
int keylen = 0;
int dlen; /* Digits sequence length */
GString * hashed = NULL;
char * ret = NULL;
g_return_val_if_fail (cipher != NULL, NULL);
g_return_val_if_fail (input != NULL, NULL);
g_return_val_if_fail (req_keylen > 0, NULL);
hashed = g_string_sized_new (32);
/* Code here is mostly ripped from wireless-tools */
/* Third case : as hexadecimal digits */
p = input;
dlen = -1;
/* Loop until we run out of chars in input or overflow the output */
while (*p != '\0')
{
int temph;
int templ;
int count;
/* No more chars in this sequence */
if (dlen <= 0)
{
/* Skip separator */
if (dlen == 0)
p++;
/* Calculate num of char to next separator */
dlen = strcspn (p, "-:;.,");
if (!dlen)
continue;
}
/* Get each char separatly (and not by two) so that we don't
* get confused by 'enc' (=> '0E'+'0C') and similar */
count = sscanf (p, "%1X%1X", &temph, &templ);
if (count < 1)
{
success = FALSE;
break; /* Error -> non-hex char */
}
/* Fixup odd strings such as '123' is '01'+'23' and not '12'+'03'*/
if (dlen % 2)
count = 1;
/* Put back two chars as one byte and output */
if (count == 2)
templ |= temph << 4;
else
templ = temph;
g_string_append_c (hashed, (unsigned char) (templ & 0xFF));
/* Check overflow in output */
if (hashed->len >= IW_ENCODING_TOKEN_MAX)
break;
/* Move on to next chars */
p += count;
keylen += count;
dlen -= count;
}
/* Ensure the actual key data length is what's required */
if (keylen != req_keylen)
success = FALSE;
if (success)
ret = hashed->str;
/* Don't free the string data if conversion was successful */
g_string_free (hashed, (success == TRUE ? FALSE : TRUE));
return ret;
}
#define WEP128_HEX_INPUT_SIZE 26
IEEE_802_11_Cipher * cipher_wep128_hex_new (void)
{
@ -132,10 +48,19 @@ IEEE_802_11_Cipher * cipher_wep128_hex_new (void)
static char * cipher_wep128_hex_hash_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input)
{
char * bin = NULL;
char * hex = NULL;
g_return_val_if_fail (cipher != NULL, NULL);
g_return_val_if_fail (input != NULL, NULL);
return cipher_wep_hex_convert_func (cipher, input, WEP128_HEX_INPUT_SIZE);
/* Convert -> bin and back to -> hexstr for validation */
if (!(bin = cipher_hexstr2bin (input, WEP128_HEX_INPUT_SIZE)))
return NULL;
if (!(hex = cipher_bin2hexstr (bin, WEP128_HEX_INPUT_SIZE / 2, WEP128_HEX_INPUT_SIZE)))
return NULL;
g_free (bin);
return hex;
}
@ -156,8 +81,17 @@ IEEE_802_11_Cipher * cipher_wep64_hex_new (void)
static char * cipher_wep64_hex_hash_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input)
{
char * bin = NULL;
char * hex = NULL;
g_return_val_if_fail (cipher != NULL, NULL);
g_return_val_if_fail (input != NULL, NULL);
return cipher_wep_hex_convert_func (cipher, input, WEP64_HEX_INPUT_SIZE);
/* Convert -> bin and back to -> hexstr for validation */
if (!(bin = cipher_hexstr2bin (input, WEP64_HEX_INPUT_SIZE)))
return NULL;
if (!(hex = cipher_bin2hexstr (bin, WEP64_HEX_INPUT_SIZE / 2, WEP64_HEX_INPUT_SIZE)))
return NULL;
g_free (bin);
return hex;
}

View file

@ -37,37 +37,6 @@ static char * cipher_wep128_passphrase_hash_func (IEEE_802_11_Cipher *cipher, co
static char * cipher_wep64_passphrase_hash_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input);
/*
* cipher_wep_passphrase_ascii_to_hex
*
* Convert an ascii string into a suitable string for use
* as a WEP key.
*
* Code originally by Alex Larsson <alexl@redhat.com> and
* copyright Red Hat, Inc. under terms of the LGPL.
*
*/
static char * cipher_wep_passphrase_ascii_to_hex (const unsigned char *ascii, int req_keylen)
{
static char hex_digits[] = "0123456789abcdef";
char *res;
int i;
g_return_val_if_fail (ascii != NULL, NULL);
g_return_val_if_fail ((req_keylen == 26) || (req_keylen == 10), NULL);
res = g_malloc (33);
for (i = 0; i < 16; i++)
{
res[2*i] = hex_digits[(ascii[i] >> 4) & 0xf];
res[2*i+1] = hex_digits[ascii[i] & 0xf];
}
/* Cut converted key off at the correct length for this cipher type */
res[req_keylen] = 0;
return res;
}
static char * cipher_wep_passphrase_hash_func (IEEE_802_11_Cipher *cipher, const char *input, int req_keylen)
{
char md5_data[65];
@ -94,7 +63,7 @@ static char * cipher_wep_passphrase_hash_func (IEEE_802_11_Cipher *cipher, const
gnome_keyring_md5_string (md5_data, digest);
#endif
return (cipher_wep_passphrase_ascii_to_hex (digest, req_keylen));
return (cipher_bin2hexstr ((const char *) &digest, 16, req_keylen));
}

View file

@ -29,50 +29,7 @@
static char * cipher_wpa_psk_hex_hash_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input);
/* From hostap, Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> */
static int hex2num(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return -1;
}
static int hex2byte(const char *hex)
{
int a, b;
a = hex2num(*hex++);
if (a < 0)
return -1;
b = hex2num(*hex++);
if (b < 0)
return -1;
return (a << 4) | b;
}
static int hexstr2bin(const char *hex, char *buf, size_t len)
{
size_t i;
int a;
const char *ipos = hex;
char *opos = buf;
for (i = 0; i < len; i++) {
a = hex2byte(ipos);
if (a < 0)
return -1;
*opos++ = a;
ipos += 2;
}
return 0;
}
/* End from hostap */
#define HEXSTR_WPA_PMK_LEN WPA_PMK_LEN * 2
IEEE_802_11_Cipher * cipher_wpa_psk_hex_new (void)
{
@ -80,8 +37,8 @@ IEEE_802_11_Cipher * cipher_wpa_psk_hex_new (void)
cipher->refcount = 1;
cipher->we_cipher = IW_AUTH_CIPHER_TKIP;
cipher->input_min = 2;
cipher->input_max = WPA_PMK_LEN * 2;
cipher->input_min = HEXSTR_WPA_PMK_LEN;
cipher->input_max = HEXSTR_WPA_PMK_LEN;
cipher->cipher_hash_func = cipher_wpa_psk_hex_hash_func;
cipher->cipher_input_validate_func = cipher_default_validate_func;
@ -90,19 +47,17 @@ IEEE_802_11_Cipher * cipher_wpa_psk_hex_new (void)
static char * cipher_wpa_psk_hex_hash_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input)
{
char * buf = NULL;
char * ret = NULL;
int err = -1;
char * bin = NULL;
char * hex = NULL;
g_return_val_if_fail (cipher != NULL, NULL);
g_return_val_if_fail (input != NULL, NULL);
buf = g_malloc0 (WPA_PMK_LEN+1);
err = hexstr2bin (input, buf, WPA_PMK_LEN);
if (err != 0)
g_free (buf);
else
ret = buf;
return ret;
/* Convert -> bin and back to -> hexstr for validation */
if (!(bin = cipher_hexstr2bin (input, HEXSTR_WPA_PMK_LEN)))
return NULL;
if (!(hex = cipher_bin2hexstr (bin, WPA_PMK_LEN, HEXSTR_WPA_PMK_LEN)))
return NULL;
g_free (bin);
return hex;
}

View file

@ -121,3 +121,93 @@ int cipher_default_validate_func (IEEE_802_11_Cipher *cipher, const char *ssid,
return ret;
}
/*
* cipher_bin2hexstr
*
* Convert a byte-array into a hexadecimal string.
*
* Code originally by Alex Larsson <alexl@redhat.com> and
* copyright Red Hat, Inc. under terms of the LGPL.
*
*/
char *
cipher_bin2hexstr (const char *bytes,
int len,
int final_len)
{
static char hex_digits[] = "0123456789abcdef";
char * result;
int i;
g_return_val_if_fail (bytes != NULL, NULL);
g_return_val_if_fail (len > 0, NULL);
g_return_val_if_fail (len < 256, NULL); /* Arbitrary limit */
result = g_malloc0 (len * 2);
for (i = 0; i < len; i++)
{
result[2*i] = hex_digits[(bytes[i] >> 4) & 0xf];
result[2*i+1] = hex_digits[bytes[i] & 0xf];
}
/* Cut converted key off at the correct length for this cipher type */
result[final_len] = '\0';
return result;
}
/* From hostap, Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> */
static int hex2num(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return -1;
}
static int hex2byte(const char *hex)
{
int a, b;
a = hex2num(*hex++);
if (a < 0)
return -1;
b = hex2num(*hex++);
if (b < 0)
return -1;
return (a << 4) | b;
}
char *
cipher_hexstr2bin(const char *hex,
size_t len)
{
size_t i;
int a;
const char * ipos = hex;
char * buf = NULL;
char * opos;
/* Length must be a multiple of 2 */
if ((len % 2) != 0)
return NULL;
opos = buf = g_malloc0 ((len / 2) + 1);
for (i = 0; i < len; i += 2)
{
a = hex2byte(ipos);
if (a < 0)
{
g_free (buf);
return NULL;
}
*opos++ = a;
ipos += 2;
}
return buf;
}
/* End from hostap */

View file

@ -35,7 +35,4 @@ int ieee_802_11_cipher_validate (IEEE_802_11_Cipher *cipher, const cha
/* Private API members (not part of the public API) */
int ieee_802_11_cipher_refcount (IEEE_802_11_Cipher *cipher);
/* For use by ciphers themselves */
int cipher_default_validate_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input);
#endif /* CIPHER_H */

View file

@ -28,25 +28,6 @@
#include "cipher.h"
static dbus_bool_t key_append_helper (DBusMessageIter *iter, const char *key)
{
DBusMessageIter subiter;
int key_len;
g_return_val_if_fail (iter != NULL, FALSE);
g_return_val_if_fail (key != NULL, FALSE);
key_len = strlen (key);
g_return_val_if_fail (key_len > 0, FALSE);
if (!dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &subiter))
return FALSE;
dbus_message_iter_append_fixed_array (&subiter, DBUS_TYPE_BYTE, &key, key_len);
dbus_message_iter_close_container (iter, &subiter);
return TRUE;
}
static void we_cipher_append_helper (DBusMessageIter *iter, int we_cipher)
{
dbus_int32_t dbus_we_cipher = (dbus_int32_t) we_cipher;
@ -61,13 +42,13 @@ nmu_security_serialize_wep (DBusMessageIter *iter,
const char *key,
int auth_alg)
{
const char * fake_key = "";
g_return_val_if_fail (iter != NULL, FALSE);
g_return_val_if_fail (key != NULL, FALSE);
g_return_val_if_fail ((auth_alg == IW_AUTH_ALG_OPEN_SYSTEM) || (auth_alg == IW_AUTH_ALG_SHARED_KEY), FALSE);
/* Second arg: hashed key (ARRAY, BYTE) */
if (!key_append_helper (iter, key))
return FALSE;
/* Second arg: hashed key (STRING) */
dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, key ? &key : &fake_key);
/* Third arg: WEP authentication algorithm (INT32) */
dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &auth_alg);
@ -92,13 +73,11 @@ nmu_security_deserialize_wep (DBusMessageIter *iter,
g_return_val_if_fail (key_len != NULL, FALSE);
g_return_val_if_fail (auth_alg != NULL, FALSE);
/* Next arg: key (ARRAY, BYTE) */
g_return_val_if_fail ((dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_ARRAY)
&& (dbus_message_iter_get_element_type (iter) == DBUS_TYPE_BYTE), FALSE);
/* Next arg: key (STRING) */
g_return_val_if_fail (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_STRING, FALSE);
dbus_message_iter_recurse (iter, &subiter);
dbus_message_iter_get_fixed_array (&subiter, &dbus_key, &dbus_key_len);
g_return_val_if_fail (dbus_key_len > 0, FALSE);
dbus_message_iter_get_basic (iter, &dbus_key);
g_return_val_if_fail (dbus_key != NULL, FALSE);
/* Next arg: authentication algorithm (INT32) */
g_return_val_if_fail (dbus_message_iter_next (iter), FALSE);
@ -108,8 +87,8 @@ nmu_security_deserialize_wep (DBusMessageIter *iter,
g_return_val_if_fail ((dbus_auth_alg == IW_AUTH_ALG_OPEN_SYSTEM)
|| (dbus_auth_alg == IW_AUTH_ALG_SHARED_KEY), FALSE);
*key = dbus_key;
*key_len = dbus_key_len;
*key = strlen (dbus_key) > 0 ? dbus_key : NULL;
*key_len = strlen (dbus_key);
*auth_alg = dbus_auth_alg;
return TRUE;
}
@ -154,9 +133,8 @@ nmu_security_serialize_wpa_psk (DBusMessageIter *iter,
g_return_val_if_fail ((wpa_version == IW_AUTH_WPA_VERSION_WPA) || (wpa_version == IW_AUTH_WPA_VERSION_WPA2), FALSE);
g_return_val_if_fail ((key_mgt == IW_AUTH_KEY_MGMT_802_1X) || (key_mgt == IW_AUTH_KEY_MGMT_PSK), FALSE);
/* Second arg: hashed key (ARRAY, BYTE) */
if (!key_append_helper (iter, key))
return FALSE;
/* Second arg: hashed key (STRING) */
dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &key);
/* Third arg: WPA version (INT32) */
dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &wpa_version);
@ -187,13 +165,11 @@ nmu_security_deserialize_wpa_psk (DBusMessageIter *iter,
g_return_val_if_fail (wpa_version != NULL, FALSE);
g_return_val_if_fail (key_mgt != NULL, FALSE);
/* Next arg: key (ARRAY, BYTE) */
g_return_val_if_fail ((dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_ARRAY)
&& (dbus_message_iter_get_element_type (iter) == DBUS_TYPE_BYTE), FALSE);
/* Next arg: key (STRING) */
g_return_val_if_fail (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_STRING, FALSE);
dbus_message_iter_recurse (iter, &subiter);
dbus_message_iter_get_fixed_array (&subiter, &dbus_key, &dbus_key_len);
g_return_val_if_fail (dbus_key_len > 0, FALSE);
dbus_message_iter_get_basic (iter, &dbus_key);
g_return_val_if_fail (dbus_key != NULL, FALSE);
/* Next arg: WPA version (INT32) */
g_return_val_if_fail (dbus_message_iter_next (iter), FALSE);
@ -211,8 +187,8 @@ nmu_security_deserialize_wpa_psk (DBusMessageIter *iter,
g_return_val_if_fail ((dbus_key_mgt == IW_AUTH_KEY_MGMT_802_1X)
|| (dbus_key_mgt == IW_AUTH_KEY_MGMT_PSK), FALSE);
*key = dbus_key;
*key_len = dbus_key_len;
*key = strlen (dbus_key) > 0 ? dbus_key : NULL;
*key_len = strlen (dbus_key);
*wpa_version = dbus_wpa_version;
*key_mgt = dbus_key_mgt;
return TRUE;

View file

@ -66,7 +66,8 @@ nm_ap_security_wep_new_deserialize (DBusMessageIter *iter, int we_cipher)
/* Success, build up our security object */
security = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL);
nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher);
nm_ap_security_set_key (NM_AP_SECURITY (security), key, key_len);
if (key)
nm_ap_security_set_key (NM_AP_SECURITY (security), key, key_len);
security->priv->auth_algorithm = auth_algorithm;
set_description (security);

View file

@ -56,7 +56,8 @@ nm_ap_security_wpa_psk_new_deserialize (DBusMessageIter *iter, int we_cipher)
/* Success, build up our security object */
security = g_object_new (NM_TYPE_AP_SECURITY_WPA_PSK, NULL);
nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher);
nm_ap_security_set_key (NM_AP_SECURITY (security), key, key_len);
if (key)
nm_ap_security_set_key (NM_AP_SECURITY (security), key, key_len);
security->priv->wpa_version = wpa_version;
security->priv->key_mgt = key_mgt;

View file

@ -60,6 +60,7 @@ nm_ap_security_new_deserialize (DBusMessageIter *iter)
int we_cipher;
g_return_val_if_fail (iter != NULL, NULL);
/* We require the WE cipher (an INT32) first */
g_return_val_if_fail (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_INT32, NULL);

View file

@ -423,6 +423,14 @@ static void nm_dbus_get_network_data_cb (DBusPendingCall *pcall, void *user_data
}
/* Unserialize access point security info */
if (!dbus_message_iter_has_next (&iter))
{
nm_warning ("%s:%d (%s): a message argument (security info) was invalid.",
__FILE__, __LINE__, __func__);
goto out;
}
dbus_message_iter_next (&iter);
if (!(security = nm_ap_security_new_deserialize (&iter)))
{
nm_warning ("%s:%d (%s): message arguments were invalid (could not deserialize "

View file

@ -59,7 +59,7 @@ struct Inputs
char * overrun;
char * incorrect_input;
char * correct_input;
char correct_output[100];
char * correct_output;
};
#define WEP128_ASCII_SELECTOR 0
@ -77,7 +77,7 @@ struct Inputs test_input[6] =
"herecomessantaclaus",
NULL,
"1234567891234",
{ 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x31, 0x32, 0x33, 0x34, 0x00 }
"31323334353637383931323334"
},
{
/* WEP64 ASCII */
@ -85,7 +85,7 @@ struct Inputs test_input[6] =
"herecomessantaclaus",
NULL,
"12345",
{ 0x31, 0x32, 0x33, 0x34, 0x35, 0x00 }
"3132333435"
},
{
/* WEP128 Hex */
@ -93,7 +93,7 @@ struct Inputs test_input[6] =
"3235ab39b9b2e32fda8a919b9a021458",
"qwertyuiopjxccjvjpapadfjcd",
"4ec5de9938b606e9d40dff721e",
{ 0x4e, 0xc5, 0xde, 0x99, 0x38, 0xb6, 0x06, 0xe9, 0xd4, 0x0d, 0xff, 0x72, 0x1e, 0x00 }
"4ec5de9938b606e9d40dff721e"
},
{
/* WEP64 Hex */
@ -101,7 +101,7 @@ struct Inputs test_input[6] =
"3235ab39b9b2e",
"qwertyuiop",
"4ec5de9938",
{ 0x4e, 0xc5, 0xde, 0x99, 0x38 }
"4ec5de9938"
},
{
/* WEP128 Passphrse */
@ -109,8 +109,7 @@ struct Inputs test_input[6] =
"3235ab39b9b2e32fda8a919b9a0214583235ab39b9b2e32fda8a919b9a0214583acb",
NULL,
"You don't remember me but I remember you.",
{ 0x30, 0x36, 0x61, 0x39, 0x63, 0x37, 0x30, 0x37, 0x31, 0x35, 0x66, 0x65, 0x30,
0x36, 0x31, 0x32, 0x39, 0x63, 0x36, 0x32, 0x35, 0x61, 0x32, 0x34, 0x38, 0x64 }
"06a9c70715fe06129c625a248d"
},
{
/* WEP64 Passphrse */
@ -118,7 +117,7 @@ struct Inputs test_input[6] =
"3235ab39b9b2e32fda8a919b9a0214583235ab39b9b2e32fda8a919b9a0214583acb",
NULL,
"Have you forgotten all I know?",
{ 0x31, 0x38, 0x30, 0x37, 0x34, 0x66, 0x33, 0x31, 0x37, 0x38 }
"18074f3178"
}
};
@ -153,6 +152,9 @@ static void test_inputs (IEEE_802_11_Cipher *cipher, const char *test, int selec
if (memcmp (output, input->correct_output, strlen (input->correct_output)) != 0)
test_result (progname, test, TEST_FAIL, "Hashed output did not match expected!\n");
if (!g_utf8_validate (output, strlen (output), NULL))
test_result (progname, test, TEST_FAIL, "Hashed output was not valid UTF8!\n");
test_result (progname, test, TEST_SUCCEED, NULL);
}