Exemplo n.º 1
0
/*
 * Fill the list with the keys. BEWARE! At this point, Wireshark and Drivers
 * keys should be EQUALS! But is better to load keys from Wireshark, because
 * the driver is not always present, and maybe that cannot support some keys
 * (i.e. the WPA problem)
 */
void
airpcap_fill_key_list(GtkListStore *key_list_store)
{
    gchar*         s = NULL;
    unsigned int i,n;
    airpcap_if_info_t* fake_if_info;
    GList*         wireshark_key_list=NULL;
    decryption_key_t* curr_key = NULL;
    GtkTreeIter    iter;

    fake_if_info = airpcap_driver_fake_if_info_new();

    /* We can retrieve the driver's key list (i.e. we have the right .dll)*/
    wireshark_key_list = get_wireshark_keys();
    n = g_list_length(wireshark_key_list);

    for(i = 0; i < n; i++)
    {
        curr_key = (decryption_key_t*)g_list_nth_data(wireshark_key_list,i);

        if(curr_key->type == AIRPDCAP_KEY_TYPE_WEP)
        {
            gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
                KL_COL_TYPE, AIRPCAP_WEP_KEY_STRING,
                KL_COL_KEY, curr_key->key->str,
                KL_COL_SSID, "",
                -1);
        }
        else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
        {
            if(curr_key->ssid != NULL)
                s = format_uri(curr_key->ssid, ":");
            else
                s = "";

            gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
                KL_COL_TYPE, AIRPCAP_WPA_PWD_KEY_STRING,
                KL_COL_KEY, curr_key->key->str,
                KL_COL_SSID, s,
                -1);

        }
        else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
        {
            gtk_list_store_insert_with_values(key_list_store , &iter, G_MAXINT,
                KL_COL_TYPE, AIRPCAP_WPA_BIN_KEY_STRING,
                KL_COL_KEY, curr_key->key->str,
                KL_COL_SSID, "",
                -1);

        }
    }

    airpcap_if_info_free(fake_if_info);
    return;
}
Exemplo n.º 2
0
/*
 * Fill the list with the keys. BEWARE! At this point, Wireshark and Drivers
 * keys should be EQUALS! But is better to load keys from Wireshark, because
 * the driver is not always present, and maybe that cannot support some keys
 * (i.e. the WPA problem)
 */
void
airpcap_fill_key_list(GtkWidget *keylist)
{
    gchar*		 s = NULL;
    gchar*		 s2 = NULL;
    unsigned int i,n;
    gchar*       new_row[3];
    airpcap_if_info_t* fake_if_info;
    GList*		 wireshark_key_list=NULL;
    decryption_key_t* curr_key = NULL;

    n = 0;

    fake_if_info = airpcap_driver_fake_if_info_new();

    /* We can retrieve the driver's key list (i.e. we have the right .dll)*/
    wireshark_key_list = get_wireshark_keys();
    n = g_list_length(wireshark_key_list);

    for(i = 0; i < n; i++)
    {
	curr_key = (decryption_key_t*)g_list_nth_data(wireshark_key_list,i);

	if(curr_key->type == AIRPDCAP_KEY_TYPE_WEP)
	{
	    s = g_strdup(curr_key->key->str);

	    new_row[0] = g_strdup(AIRPCAP_WEP_KEY_STRING);
	    new_row[1] = g_strdup(s);
	    new_row[2] = g_strdup("");

	    gtk_clist_append(GTK_CLIST(keylist),new_row);

	    g_free(new_row[0]);
	    g_free(new_row[1]);
	    g_free(new_row[2]);

	    g_free(s);
	}
	else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
	{
	    s = g_strdup(curr_key->key->str);
	    if(curr_key->ssid != NULL)
		s2= g_strdup(format_uri(curr_key->ssid, ":"));
	    else
		s2 = NULL;

	    new_row[0] = g_strdup(AIRPCAP_WPA_PWD_KEY_STRING);
	    new_row[1] = g_strdup(s);

	    if(curr_key->ssid != NULL)
		new_row[2] = g_strdup(s2);
	    else
		new_row[2] = g_strdup("");

	    gtk_clist_append(GTK_CLIST(keylist),new_row);

	    g_free(new_row[0]);
	    g_free(new_row[1]);
	    g_free(new_row[2]);

	    g_free(s);
	    if(s2 != NULL)
		g_free(s2);
	}
	else if(curr_key->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
	{
	    s = g_strdup(curr_key->key->str);

	    new_row[0] = g_strdup(AIRPCAP_WPA_BIN_KEY_STRING);
	    new_row[1] = g_strdup(s);
	    new_row[2] = g_strdup("");

	    gtk_clist_append(GTK_CLIST(keylist),new_row);

	    g_free(new_row[0]);
	    g_free(new_row[1]);
	    g_free(new_row[2]);

	    g_free(s);
	}
    }

    airpcap_if_info_free(fake_if_info);
    return;
}
Exemplo n.º 3
0
/*
 * This function will take the current keys (widget list), specified for the
 * current adapter, and save them as default for ALL the others.
 */
void
airpcap_read_and_save_decryption_keys_from_list_store(GtkListStore* key_list_store, airpcap_if_info_t* info_if, GList* if_list)
{
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL(key_list_store);
    gboolean items_left;
    gint if_n = 0;
    gint i = 0;
    airpcap_if_info_t* curr_if = NULL;
    airpcap_if_info_t* fake_info_if = NULL;
    GList* key_list=NULL;

    char* tmp_type = NULL;
    char* tmp_key = NULL;
    char* tmp_ssid = "";

    decryption_key_t* tmp_dk=NULL;

    /*
     * Save the keys for Wireshark...
     */

    /* Create a list of keys from the list store */
    for (items_left = gtk_tree_model_get_iter_first (model, &iter);
         items_left;
         items_left = gtk_tree_model_iter_next (model, &iter)) {

        gtk_tree_model_get(model, &iter,
                           KL_COL_TYPE, &tmp_type,
                           KL_COL_KEY, &tmp_key,
                           KL_COL_SSID, &tmp_ssid,
                           -1);

        if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WEP_KEY_STRING) == 0)
        {
            tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
            tmp_dk->key = g_string_new(tmp_key);
            tmp_dk->ssid = NULL;
            tmp_dk->type = AIRPDCAP_KEY_TYPE_WEP;
            tmp_dk->bits = (guint) tmp_dk->key->len * 4;
            key_list = g_list_append(key_list,tmp_dk);
        }
        else if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WPA_PWD_KEY_STRING) == 0)
        {
            tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
            tmp_dk->key = g_string_new(tmp_key);
            tmp_dk->ssid = g_byte_array_new();
            uri_str_to_bytes(tmp_ssid, tmp_dk->ssid);
            tmp_dk->type = AIRPDCAP_KEY_TYPE_WPA_PWD;
            tmp_dk->bits = 256;
            key_list = g_list_append(key_list,tmp_dk);
        }
        else if(g_ascii_strcasecmp(tmp_type, AIRPCAP_WPA_BIN_KEY_STRING) == 0)
        {
            tmp_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
            tmp_dk->key = g_string_new(tmp_key);
            tmp_dk->ssid = NULL; /* No SSID in this case */
            tmp_dk->type = AIRPDCAP_KEY_TYPE_WPA_PMK;
            tmp_dk->bits = 256;
            key_list = g_list_append(key_list,tmp_dk);
        }
        g_free(tmp_type);
        g_free(tmp_ssid);
    }

    save_wlan_wireshark_wep_keys(key_list);
    /* The key_list has been freed!!! */

    /*
     * Save the key list for driver.
     */
    if( (if_list == NULL) || (info_if == NULL) ) return;

    fake_info_if = airpcap_driver_fake_if_info_new();

    airpcap_add_keys_to_driver_from_list(key_list_store,fake_info_if);
    airpcap_save_driver_if_configuration(fake_info_if);
    airpcap_if_info_free(fake_info_if);

    if_n = g_list_length(if_list);

    /* For all the adapters in the list, empty the key list */
    for(i = 0; i < if_n; i++)
    {
        curr_if = (airpcap_if_info_t*)g_list_nth_data(if_list,i);

        if(curr_if != NULL)
        {
            /* XXX - Set an empty collection */
            airpcap_if_clear_decryption_settings(curr_if);

            /* Save to registry */
            airpcap_save_selected_if_configuration(curr_if);
        }
    }
}