[network-manager-applet] core: use GChecksum (bgo #502494)
- From: Dan Williams <dcbw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [network-manager-applet] core: use GChecksum (bgo #502494)
- Date: Fri, 4 Dec 2009 18:41:54 +0000 (UTC)
commit df4fbd925c04db450d8811242ee28e56d0ebfee2
Author: Dan Williams <dcbw redhat com>
Date: Fri Dec 4 10:40:45 2009 -0800
core: use GChecksum (bgo #502494)
It was only used for combining wifi APs in the menu through a simple
hash which might as well be done with GChecksum. Add some testcases
too.
configure.ac | 1 +
src/ap-menu-item.c | 19 +--
src/ap-menu-item.h | 10 +-
src/applet-device-wifi.c | 93 +------
src/utils/Makefile.am | 4 +-
src/utils/gnome-keyring-md5.c | 291 ----------------------
src/utils/gnome-keyring-md5.h | 41 ---
src/utils/tests/Makefile.am | 15 ++
src/utils/tests/test-utils.c | 481 ++++++++++++++++++++++++++++++++++++
src/utils/utils.c | 42 +++
src/utils/utils.h | 7 +
src/wireless-security/ws-wep-key.c | 1 -
12 files changed, 569 insertions(+), 436 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 321b8f3..d5d44aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,6 +119,7 @@ Makefile
src/Makefile
src/marshallers/Makefile
src/utils/Makefile
+src/utils/tests/Makefile
src/gconf-helpers/Makefile
src/wireless-security/Makefile
src/connection-editor/Makefile
diff --git a/src/ap-menu-item.c b/src/ap-menu-item.c
index 06db225..9b1f025 100644
--- a/src/ap-menu-item.c
+++ b/src/ap-menu-item.c
@@ -60,9 +60,7 @@ nm_network_menu_item_init (NMNetworkMenuItem * item)
}
GtkWidget*
-nm_network_menu_item_new (guchar *hash,
- guint32 hash_len,
- gboolean has_connections)
+nm_network_menu_item_new (const char *hash, gboolean has_connections)
{
NMNetworkMenuItem * item;
@@ -71,13 +69,7 @@ nm_network_menu_item_new (guchar *hash,
return NULL;
item->has_connections = has_connections;
-
- if (hash && hash_len) {
- item->hash = g_malloc0 (hash_len);
- memcpy (item->hash, hash, hash_len);
- item->hash_len = hash_len;
- }
-
+ item->hash = g_strdup (hash);
return GTK_WIDGET (item);
}
@@ -185,14 +177,11 @@ nm_network_menu_item_best_strength (NMNetworkMenuItem * item,
g_object_unref (pixbuf);
}
-const guchar *
-nm_network_menu_item_get_hash (NMNetworkMenuItem * item,
- guint32 * length)
+const const char *
+nm_network_menu_item_get_hash (NMNetworkMenuItem * item)
{
g_return_val_if_fail (item != NULL, NULL);
- g_return_val_if_fail (length != NULL, NULL);
- *length = item->hash_len;
return item->hash;
}
diff --git a/src/ap-menu-item.h b/src/ap-menu-item.h
index 7f82e17..d1b478b 100644
--- a/src/ap-menu-item.h
+++ b/src/ap-menu-item.h
@@ -50,8 +50,7 @@ struct _NMNetworkMenuItem
guint32 int_strength;
GtkWidget * detail;
GtkWidget * hbox;
- guchar * hash;
- guint32 hash_len;
+ gchar * hash;
gboolean destroyed;
GSList * dupes;
gboolean has_connections;
@@ -66,9 +65,7 @@ struct _NMNetworkMenuItemClass
GType nm_network_menu_item_get_type (void) G_GNUC_CONST;
-GtkWidget* nm_network_menu_item_new (guchar *hash,
- guint32 hash_len,
- gboolean has_connections);
+GtkWidget* nm_network_menu_item_new (const char *hash, gboolean has_connections);
void nm_network_menu_item_set_ssid (NMNetworkMenuItem *item,
GByteArray *ssid);
@@ -81,8 +78,7 @@ guint32 nm_network_menu_item_get_strength (NMNetworkMenuItem *item);
void nm_network_menu_item_best_strength (NMNetworkMenuItem *item,
guint8 strength,
NMApplet *applet);
-const guchar * nm_network_menu_item_get_hash (NMNetworkMenuItem * item,
- guint32 * length);
+const char *nm_network_menu_item_get_hash (NMNetworkMenuItem * item);
void nm_network_menu_item_set_detail (NMNetworkMenuItem * item,
NMAccessPoint * ap,
GdkPixbuf * adhoc_icon,
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index 724141a..40c7804 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -45,7 +45,6 @@
#include "applet-device-wifi.h"
#include "ap-menu-item.h"
#include "utils.h"
-#include "gnome-keyring-md5.h"
#include "wireless-dialog.h"
#define PREF_SUPPRESS_WIRELESS_NEWORKS_AVAILABLE APPLET_PREFS_PATH "/suppress-wireless-networks-available"
@@ -424,12 +423,10 @@ wireless_menu_item_activate (GtkMenuItem *item, gpointer user_data)
user_data);
}
-#define AP_HASH_LEN 16
-
struct dup_data {
NMDevice *device;
NMNetworkMenuItem *found;
- guchar *hash;
+ char *hash;
};
static void
@@ -437,8 +434,7 @@ find_duplicate (gpointer d, gpointer user_data)
{
struct dup_data * data = (struct dup_data *) user_data;
NMDevice *device;
- const guchar * hash;
- guint32 hash_len = 0;
+ const char *hash;
GtkWidget *widget = GTK_WIDGET (d);
g_assert (d && widget);
@@ -452,11 +448,8 @@ find_duplicate (gpointer d, gpointer user_data)
if (NM_DEVICE (device) != data->device)
return;
- hash = nm_network_menu_item_get_hash (NM_NETWORK_MENU_ITEM (widget), &hash_len);
- if (hash == NULL || hash_len != AP_HASH_LEN)
- return;
-
- if (memcmp (hash, data->hash, AP_HASH_LEN) == 0)
+ hash = nm_network_menu_item_get_hash (NM_NETWORK_MENU_ITEM (widget));
+ if (hash && (strcmp (hash, data->hash) == 0))
data->found = NM_NETWORK_MENU_ITEM (widget);
}
@@ -492,7 +485,6 @@ create_new_ap_item (NMDeviceWifi *device,
ap_connections = filter_connections_for_access_point (connections, device, ap);
item = NM_NETWORK_MENU_ITEM (nm_network_menu_item_new (dup_data->hash,
- AP_HASH_LEN,
!!g_slist_length (ap_connections)));
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
@@ -582,8 +574,8 @@ get_menu_item_for_ap (NMDeviceWifi *device,
*/
dup_data.found = NULL;
dup_data.hash = g_object_get_data (G_OBJECT (ap), "hash");
- if (!dup_data.hash)
- return NULL;
+ g_return_val_if_fail (dup_data.hash != NULL, NULL);
+
dup_data.device = NM_DEVICE (device);
g_slist_foreach (menu_list, find_duplicate, &dup_data);
@@ -891,74 +883,17 @@ notify_active_ap_changed_cb (NMDeviceWifi *device,
applet_schedule_update_icon (applet);
}
-static guchar *
-ap_hash (NMAccessPoint * ap)
-{
- struct GnomeKeyringMD5Context ctx;
- unsigned char * digest = NULL;
- unsigned char md5_data[66];
- unsigned char input[33];
- const GByteArray * ssid;
- NM80211Mode mode;
- guint32 flags, wpa_flags, rsn_flags;
-
- g_return_val_if_fail (ap, NULL);
-
- mode = nm_access_point_get_mode (ap);
- flags = nm_access_point_get_flags (ap);
- wpa_flags = nm_access_point_get_wpa_flags (ap);
- rsn_flags = nm_access_point_get_rsn_flags (ap);
-
- memset (&input[0], 0, sizeof (input));
-
- ssid = nm_access_point_get_ssid (ap);
- if (ssid)
- memcpy (input, ssid->data, ssid->len);
-
- if (mode == NM_802_11_MODE_INFRA)
- input[32] |= (1 << 0);
- else if (mode == NM_802_11_MODE_ADHOC)
- input[32] |= (1 << 1);
- else
- input[32] |= (1 << 2);
-
- /* Separate out no encryption, WEP-only, and WPA-capable */
- if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
- && (wpa_flags == NM_802_11_AP_SEC_NONE)
- && (rsn_flags == NM_802_11_AP_SEC_NONE))
- input[32] |= (1 << 3);
- else if ( (flags & NM_802_11_AP_FLAGS_PRIVACY)
- && (wpa_flags == NM_802_11_AP_SEC_NONE)
- && (rsn_flags == NM_802_11_AP_SEC_NONE))
- input[32] |= (1 << 4);
- else if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
- && (wpa_flags != NM_802_11_AP_SEC_NONE)
- && (rsn_flags != NM_802_11_AP_SEC_NONE))
- input[32] |= (1 << 5);
- else
- input[32] |= (1 << 6);
-
- digest = g_malloc (sizeof (unsigned char) * AP_HASH_LEN);
- if (digest == NULL)
- goto out;
-
- gnome_keyring_md5_init (&ctx);
- memcpy (md5_data, input, sizeof (input));
- memcpy (&md5_data[33], input, sizeof (input));
- gnome_keyring_md5_update (&ctx, md5_data, sizeof (md5_data));
- gnome_keyring_md5_final (digest, &ctx);
-
-out:
- return digest;
-}
-
static void
add_hash_to_ap (NMAccessPoint *ap)
{
- guchar *hash = ap_hash (ap);
- g_object_set_data_full (G_OBJECT (ap),
- "hash", hash,
- (GDestroyNotify) g_free);
+ char *hash;
+
+ hash = utils_hash_ap (nm_access_point_get_ssid (ap),
+ nm_access_point_get_mode (ap),
+ nm_access_point_get_flags (ap),
+ nm_access_point_get_wpa_flags (ap),
+ nm_access_point_get_rsn_flags (ap));
+ g_object_set_data_full (G_OBJECT (ap), "hash", hash, (GDestroyNotify) g_free);
}
static void
diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am
index fafab34..60bb579 100644
--- a/src/utils/Makefile.am
+++ b/src/utils/Makefile.am
@@ -1,8 +1,8 @@
+SUBDIRS=. tests
+
noinst_LTLIBRARIES = libutils.la
libutils_la_SOURCES = \
- gnome-keyring-md5.h \
- gnome-keyring-md5.c \
utils.c \
utils.h \
nmn-mobile-providers.h \
diff --git a/src/utils/tests/Makefile.am b/src/utils/tests/Makefile.am
new file mode 100644
index 0000000..72169d6
--- /dev/null
+++ b/src/utils/tests/Makefile.am
@@ -0,0 +1,15 @@
+INCLUDES = -I$(top_srcdir)/src/utils
+
+noinst_PROGRAMS = test-utils
+
+test_utils_SOURCES = test-utils.c
+
+test_utils_CPPFLAGS = $(NMA_CFLAGS)
+
+test_utils_LDADD = \
+ ${top_builddir}/src/utils/libutils.la \
+ $(NMA_LIBS)
+
+check-local: test-utils
+ $(abs_builddir)/test-utils
+
diff --git a/src/utils/tests/test-utils.c b/src/utils/tests/test-utils.c
new file mode 100644
index 0000000..7eb1ffa
--- /dev/null
+++ b/src/utils/tests/test-utils.c
@@ -0,0 +1,481 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2009 Red Hat, Inc.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "utils.h"
+
+typedef struct {
+ char *foobar_infra_open;
+ char *foobar_infra_wep;
+ char *foobar_infra_wpa;
+ char *foobar_infra_rsn;
+ char *foobar_infra_wpa_rsn;
+ char *foobar_adhoc_open;
+ char *foobar_adhoc_wep;
+ char *foobar_adhoc_wpa;
+ char *foobar_adhoc_rsn;
+ char *foobar_adhoc_wpa_rsn;
+
+ char *asdf11_infra_open;
+ char *asdf11_infra_wep;
+ char *asdf11_infra_wpa;
+ char *asdf11_infra_rsn;
+ char *asdf11_infra_wpa_rsn;
+ char *asdf11_adhoc_open;
+ char *asdf11_adhoc_wep;
+ char *asdf11_adhoc_wpa;
+ char *asdf11_adhoc_rsn;
+ char *asdf11_adhoc_wpa_rsn;
+} TestData;
+
+static GByteArray *
+string_to_ssid (const char *str)
+{
+ GByteArray *ssid;
+
+ g_assert (str != NULL);
+
+ ssid = g_byte_array_sized_new (strlen (str));
+ g_assert (ssid != NULL);
+ g_byte_array_append (ssid, (const guint8 *) str, strlen (str));
+ return ssid;
+}
+
+static char *
+make_hash (const char *str,
+ NM80211Mode mode,
+ guint32 flags,
+ guint32 wpa_flags,
+ guint32 rsn_flags)
+{
+ GByteArray *ssid;
+ char *hash, *hash2;
+
+ ssid = string_to_ssid (str);
+
+ hash = utils_hash_ap (ssid, mode, flags, wpa_flags, rsn_flags);
+ g_assert (hash != NULL);
+
+ hash2 = utils_hash_ap (ssid, mode, flags, wpa_flags, rsn_flags);
+ g_assert (hash2 != NULL);
+
+ /* Make sure they are the same each time */
+ g_assert (!strcmp (hash, hash2));
+
+ g_byte_array_free (ssid, TRUE);
+ return hash;
+}
+
+static void
+make_ssid_hashes (const char *ssid,
+ NM80211Mode mode,
+ char **open,
+ char **wep,
+ char **wpa,
+ char **rsn,
+ char **wpa_rsn)
+{
+ *open = make_hash (ssid, mode,
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE);
+
+ *wep = make_hash (ssid, mode,
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE);
+
+ *wpa = make_hash (ssid, mode,
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_PAIR_TKIP |
+ NM_802_11_AP_SEC_GROUP_TKIP |
+ NM_802_11_AP_SEC_KEY_MGMT_PSK,
+ NM_802_11_AP_SEC_NONE);
+
+ *rsn = make_hash (ssid, mode,
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_PAIR_CCMP |
+ NM_802_11_AP_SEC_GROUP_CCMP |
+ NM_802_11_AP_SEC_KEY_MGMT_PSK);
+
+ *wpa_rsn = make_hash (ssid, mode,
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_PAIR_TKIP |
+ NM_802_11_AP_SEC_GROUP_TKIP |
+ NM_802_11_AP_SEC_KEY_MGMT_PSK,
+ NM_802_11_AP_SEC_PAIR_CCMP |
+ NM_802_11_AP_SEC_GROUP_CCMP |
+ NM_802_11_AP_SEC_KEY_MGMT_PSK);
+}
+
+static TestData *
+test_data_new (void)
+{
+ TestData *d;
+
+ d = g_malloc0 (sizeof (TestData));
+ g_assert (d);
+
+ make_ssid_hashes ("foobar", NM_802_11_MODE_INFRA,
+ &d->foobar_infra_open,
+ &d->foobar_infra_wep,
+ &d->foobar_infra_wpa,
+ &d->foobar_infra_rsn,
+ &d->foobar_infra_wpa_rsn);
+
+ make_ssid_hashes ("foobar", NM_802_11_MODE_ADHOC,
+ &d->foobar_adhoc_open,
+ &d->foobar_adhoc_wep,
+ &d->foobar_adhoc_wpa,
+ &d->foobar_adhoc_rsn,
+ &d->foobar_adhoc_wpa_rsn);
+
+ make_ssid_hashes ("asdf11", NM_802_11_MODE_INFRA,
+ &d->asdf11_infra_open,
+ &d->asdf11_infra_wep,
+ &d->asdf11_infra_wpa,
+ &d->asdf11_infra_rsn,
+ &d->asdf11_infra_wpa_rsn);
+
+ make_ssid_hashes ("asdf11", NM_802_11_MODE_ADHOC,
+ &d->asdf11_adhoc_open,
+ &d->asdf11_adhoc_wep,
+ &d->asdf11_adhoc_wpa,
+ &d->asdf11_adhoc_rsn,
+ &d->asdf11_adhoc_wpa_rsn);
+
+ return d;
+}
+
+static void
+test_data_free (TestData *d)
+{
+ g_free (d->foobar_infra_open);
+ g_free (d->foobar_infra_wep);
+ g_free (d->foobar_infra_wpa);
+ g_free (d->foobar_infra_rsn);
+ g_free (d->foobar_infra_wpa_rsn);
+ g_free (d->foobar_adhoc_open);
+ g_free (d->foobar_adhoc_wep);
+ g_free (d->foobar_adhoc_wpa);
+ g_free (d->foobar_adhoc_rsn);
+ g_free (d->foobar_adhoc_wpa_rsn);
+
+ g_free (d->asdf11_infra_open);
+ g_free (d->asdf11_infra_wep);
+ g_free (d->asdf11_infra_wpa);
+ g_free (d->asdf11_infra_rsn);
+ g_free (d->asdf11_infra_wpa_rsn);
+ g_free (d->asdf11_adhoc_open);
+ g_free (d->asdf11_adhoc_wep);
+ g_free (d->asdf11_adhoc_wpa);
+ g_free (d->asdf11_adhoc_rsn);
+ g_free (d->asdf11_adhoc_wpa_rsn);
+
+ g_free (d);
+}
+
+static void
+test_ap_hash_infra_adhoc_open (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_open, d->foobar_adhoc_open));
+}
+
+static void
+test_ap_hash_infra_adhoc_wep (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wep, d->foobar_adhoc_wep));
+}
+
+static void
+test_ap_hash_infra_adhoc_wpa (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wpa, d->foobar_adhoc_wpa));
+}
+
+static void
+test_ap_hash_infra_adhoc_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_rsn, d->foobar_adhoc_rsn));
+}
+
+static void
+test_ap_hash_infra_adhoc_wpa_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wpa_rsn, d->foobar_adhoc_wpa_rsn));
+}
+
+static void
+test_ap_hash_infra_open_wep (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_open, d->foobar_infra_wep));
+}
+
+static void
+test_ap_hash_infra_open_wpa (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_open, d->foobar_infra_wpa));
+}
+
+static void
+test_ap_hash_infra_open_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_open, d->foobar_infra_rsn));
+}
+
+static void
+test_ap_hash_infra_open_wpa_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_open, d->foobar_infra_wpa_rsn));
+}
+
+static void
+test_ap_hash_infra_wep_wpa (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wep, d->foobar_infra_wpa));
+}
+
+static void
+test_ap_hash_infra_wep_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wep, d->foobar_infra_rsn));
+}
+
+static void
+test_ap_hash_infra_wep_wpa_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wep, d->foobar_infra_wpa_rsn));
+}
+
+static void
+test_ap_hash_infra_wpa_rsn (void *f, TestData *d)
+{
+ /* these should be the same as we group all WPA/RSN APs together */
+ g_assert (!strcmp (d->foobar_infra_wpa, d->foobar_infra_rsn));
+}
+
+static void
+test_ap_hash_infra_wpa_wpa_rsn (void *f, TestData *d)
+{
+ /* these should be the same as we group all WPA/RSN APs together */
+ g_assert (!strcmp (d->foobar_infra_wpa, d->foobar_infra_wpa_rsn));
+}
+
+static void
+test_ap_hash_infra_rsn_wpa_rsn (void *f, TestData *d)
+{
+ /* these should be the same as we group all WPA/RSN APs together */
+ g_assert (!strcmp (d->foobar_infra_rsn, d->foobar_infra_wpa_rsn));
+}
+
+static void
+test_ap_hash_adhoc_open_wep (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_open, d->foobar_adhoc_wep));
+}
+
+static void
+test_ap_hash_adhoc_open_wpa (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_open, d->foobar_adhoc_wpa));
+}
+
+static void
+test_ap_hash_adhoc_open_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_open, d->foobar_adhoc_rsn));
+}
+
+static void
+test_ap_hash_adhoc_open_wpa_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_open, d->foobar_adhoc_wpa_rsn));
+}
+
+static void
+test_ap_hash_adhoc_wep_wpa (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_wep, d->foobar_adhoc_wpa));
+}
+
+static void
+test_ap_hash_adhoc_wep_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_wep, d->foobar_adhoc_rsn));
+}
+
+static void
+test_ap_hash_adhoc_wep_wpa_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_wep, d->foobar_adhoc_wpa_rsn));
+}
+
+static void
+test_ap_hash_adhoc_wpa_rsn (void *f, TestData *d)
+{
+ /* these should be the same as we group all WPA/RSN APs together */
+ g_assert (!strcmp (d->foobar_adhoc_wpa, d->foobar_adhoc_rsn));
+}
+
+static void
+test_ap_hash_adhoc_wpa_wpa_rsn (void *f, TestData *d)
+{
+ /* these should be the same as we group all WPA/RSN APs together */
+ g_assert (!strcmp (d->foobar_adhoc_wpa, d->foobar_adhoc_wpa_rsn));
+}
+
+static void
+test_ap_hash_adhoc_rsn_wpa_rsn (void *f, TestData *d)
+{
+ /* these should be the same as we group all WPA/RSN APs together */
+ g_assert (!strcmp (d->foobar_adhoc_rsn, d->foobar_adhoc_wpa_rsn));
+}
+
+static void
+test_ap_hash_foobar_asdf11_infra_open (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_open, d->asdf11_infra_open));
+}
+
+static void
+test_ap_hash_foobar_asdf11_infra_wep (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wep, d->asdf11_infra_wep));
+}
+
+static void
+test_ap_hash_foobar_asdf11_infra_wpa (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wpa, d->asdf11_infra_wpa));
+}
+
+static void
+test_ap_hash_foobar_asdf11_infra_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_rsn, d->asdf11_infra_rsn));
+}
+
+static void
+test_ap_hash_foobar_asdf11_infra_wpa_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_infra_wpa_rsn, d->asdf11_infra_wpa_rsn));
+}
+
+static void
+test_ap_hash_foobar_asdf11_adhoc_open (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_open, d->asdf11_adhoc_open));
+}
+
+static void
+test_ap_hash_foobar_asdf11_adhoc_wep (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_wep, d->asdf11_adhoc_wep));
+}
+
+static void
+test_ap_hash_foobar_asdf11_adhoc_wpa (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_wpa, d->asdf11_adhoc_wpa));
+}
+
+static void
+test_ap_hash_foobar_asdf11_adhoc_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_rsn, d->asdf11_adhoc_rsn));
+}
+
+static void
+test_ap_hash_foobar_asdf11_adhoc_wpa_rsn (void *f, TestData *d)
+{
+ g_assert (strcmp (d->foobar_adhoc_wpa_rsn, d->asdf11_adhoc_wpa_rsn));
+}
+
+typedef void (*TCFunc)(void);
+
+#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
+
+int main (int argc, char **argv)
+{
+ GTestSuite *suite;
+ gint result;
+ TestData *data;
+
+ g_test_init (&argc, &argv, NULL);
+
+ suite = g_test_get_root ();
+ data = test_data_new ();
+
+ /* Test that hashes are different with the same SSID but different AP flags */
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_adhoc_open, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_adhoc_wep, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_adhoc_wpa, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_adhoc_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_adhoc_wpa_rsn, data));
+
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_open_wep, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_open_wpa, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_open_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_open_wpa_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_wep_wpa, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_wep_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_wep_wpa_rsn, data));
+
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_open_wep, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_open_wpa, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_open_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_open_wpa_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_wep_wpa, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_wep_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_wep_wpa_rsn, data));
+
+ /* Test that wpa, rsn, and wpa_rsn all have the same hash */
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_wpa_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_wpa_wpa_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_infra_rsn_wpa_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_wpa_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_wpa_wpa_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_adhoc_rsn_wpa_rsn, data));
+
+ /* Test that hashes are different with the same AP flags but different SSID */
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_infra_open, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_infra_wep, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_infra_wpa, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_infra_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_infra_wpa_rsn, data));
+
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_adhoc_open, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_adhoc_wep, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_adhoc_wpa, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_adhoc_rsn, data));
+ g_test_suite_add (suite, TESTCASE (test_ap_hash_foobar_asdf11_adhoc_wpa_rsn, data));
+
+ result = g_test_run ();
+
+ test_data_free (data);
+
+ return result;
+}
+
diff --git a/src/utils/utils.c b/src/utils/utils.c
index 6405865..6f21f54 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -796,3 +796,45 @@ utils_next_available_name (GSList *connections, const char *format)
return cname;
}
+char *
+utils_hash_ap (const GByteArray *ssid,
+ NM80211Mode mode,
+ guint32 flags,
+ guint32 wpa_flags,
+ guint32 rsn_flags)
+{
+ unsigned char input[66];
+
+ memset (&input[0], 0, sizeof (input));
+
+ if (ssid)
+ memcpy (input, ssid->data, ssid->len);
+
+ if (mode == NM_802_11_MODE_INFRA)
+ input[32] |= (1 << 0);
+ else if (mode == NM_802_11_MODE_ADHOC)
+ input[32] |= (1 << 1);
+ else
+ input[32] |= (1 << 2);
+
+ /* Separate out no encryption, WEP-only, and WPA-capable */
+ if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
+ && (wpa_flags == NM_802_11_AP_SEC_NONE)
+ && (rsn_flags == NM_802_11_AP_SEC_NONE))
+ input[32] |= (1 << 3);
+ else if ( (flags & NM_802_11_AP_FLAGS_PRIVACY)
+ && (wpa_flags == NM_802_11_AP_SEC_NONE)
+ && (rsn_flags == NM_802_11_AP_SEC_NONE))
+ input[32] |= (1 << 4);
+ else if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
+ && (wpa_flags != NM_802_11_AP_SEC_NONE)
+ && (rsn_flags != NM_802_11_AP_SEC_NONE))
+ input[32] |= (1 << 5);
+ else
+ input[32] |= (1 << 6);
+
+ /* duplicate it */
+ memcpy (&input[33], &input[0], 32);
+ return g_compute_checksum_for_data (G_CHECKSUM_MD5, input, sizeof (input));
+}
+
diff --git a/src/utils/utils.h b/src/utils/utils.h
index 11acb66..64f8b28 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
*
* Dan Williams <dcbw redhat com>
@@ -48,5 +49,11 @@ gboolean utils_mac_valid (const struct ether_addr *addr);
char *utils_next_available_name (GSList *connections, const char *format);
+char *utils_hash_ap (const GByteArray *ssid,
+ NM80211Mode mode,
+ guint32 flags,
+ guint32 wpa_flags,
+ guint32 rsn_flags);
+
#endif /* UTILS_H */
diff --git a/src/wireless-security/ws-wep-key.c b/src/wireless-security/ws-wep-key.c
index 85841b3..60d9bfa 100644
--- a/src/wireless-security/ws-wep-key.c
+++ b/src/wireless-security/ws-wep-key.c
@@ -29,7 +29,6 @@
#include "wireless-security.h"
#include "utils.h"
-#include "gnome-keyring-md5.h"
#include "gconf-helpers.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]