2005-12-09 23:25:22 +00:00
|
|
|
/* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* (C) Copyright 2005 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <iwlib.h>
|
|
|
|
|
|
|
|
|
|
#include "cipher.h"
|
|
|
|
|
#include "cipher-private.h"
|
2005-12-10 19:33:26 +00:00
|
|
|
#include "cipher-wpa-psk-hex.h"
|
2005-12-09 23:25:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static char * cipher_wpa_psk_hex_hash_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input);
|
|
|
|
|
|
2005-12-23 08:20:12 +00:00
|
|
|
#define HEXSTR_WPA_PMK_LEN WPA_PMK_LEN * 2
|
2005-12-09 23:25:22 +00:00
|
|
|
|
2005-12-10 19:33:26 +00:00
|
|
|
IEEE_802_11_Cipher * cipher_wpa_psk_hex_new (void)
|
2005-12-09 23:25:22 +00:00
|
|
|
{
|
|
|
|
|
IEEE_802_11_Cipher * cipher = g_malloc0 (sizeof (IEEE_802_11_Cipher));
|
|
|
|
|
|
2005-12-21 08:11:57 +00:00
|
|
|
cipher->refcount = 1;
|
2005-12-09 23:25:22 +00:00
|
|
|
cipher->we_cipher = IW_AUTH_CIPHER_TKIP;
|
2005-12-23 08:20:12 +00:00
|
|
|
cipher->input_min = HEXSTR_WPA_PMK_LEN;
|
|
|
|
|
cipher->input_max = HEXSTR_WPA_PMK_LEN;
|
2005-12-09 23:25:22 +00:00
|
|
|
cipher->cipher_hash_func = cipher_wpa_psk_hex_hash_func;
|
|
|
|
|
cipher->cipher_input_validate_func = cipher_default_validate_func;
|
|
|
|
|
|
2005-12-10 19:33:26 +00:00
|
|
|
return cipher;
|
2005-12-09 23:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 20:46:26 +00:00
|
|
|
|
|
|
|
|
void cipher_wpa_psk_hex_set_we_cipher (IEEE_802_11_Cipher *cipher, int we_cipher)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (cipher != NULL);
|
|
|
|
|
g_return_if_fail ((we_cipher == IW_AUTH_CIPHER_TKIP) || (we_cipher == IW_AUTH_CIPHER_CCMP));
|
|
|
|
|
g_return_if_fail ((cipher->we_cipher == IW_AUTH_CIPHER_TKIP) || (cipher->we_cipher == IW_AUTH_CIPHER_CCMP));
|
|
|
|
|
|
|
|
|
|
cipher->we_cipher = we_cipher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-12-09 23:25:22 +00:00
|
|
|
static char * cipher_wpa_psk_hex_hash_func (IEEE_802_11_Cipher *cipher, const char *ssid, const char *input)
|
|
|
|
|
{
|
2005-12-23 08:20:12 +00:00
|
|
|
char * bin = NULL;
|
|
|
|
|
char * hex = NULL;
|
2005-12-09 23:25:22 +00:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (cipher != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (input != NULL, NULL);
|
|
|
|
|
|
2005-12-23 08:20:12 +00:00
|
|
|
/* 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;
|
2005-12-09 23:25:22 +00:00
|
|
|
}
|