static void fill_connection (WirelessSecurity *parent, NMConnection *connection) { WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent; NMSettingWirelessSecurity *s_wsec; NMSettingSecretFlags secret_flags; GtkWidget *widget, *passwd_entry; gint auth_alg; const char *key; int i; widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "auth_method_combo")); auth_alg = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wep_key_entry")); passwd_entry = widget; key = gtk_entry_get_text (GTK_ENTRY (widget)); g_strlcpy (sec->keys[sec->cur_index], key, sizeof (sec->keys[sec->cur_index])); /* Blow away the old security setting by adding a clear one */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, (NMSetting *) s_wsec); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, sec->cur_index, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, (auth_alg == 1) ? "shared" : "open", NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, sec->type, NULL); for (i = 0; i < 4; i++) { if (strlen (sec->keys[i])) nm_setting_wireless_security_set_wep_key (s_wsec, i, sec->keys[i]); } /* Save WEP_KEY_FLAGS to the connection */ secret_flags = nma_utils_menu_to_secret_flags (passwd_entry); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, secret_flags, NULL); /* Update secret flags and popup when editing the connection */ if (sec->editing_connection) nma_utils_update_password_storage (passwd_entry, secret_flags, NM_SETTING (s_wsec), sec->password_flags_name); }
static void fill_connection (WirelessSecurity *parent, NMConnection *connection) { WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; GtkWidget *widget; gint auth_alg; const char *key; int i; widget = glade_xml_get_widget (parent->xml, "auth_method_combo"); auth_alg = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); widget = glade_xml_get_widget (parent->xml, "wep_key_entry"); key = gtk_entry_get_text (GTK_ENTRY (widget)); strcpy (sec->keys[sec->cur_index], key); s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS)); g_assert (s_wireless); g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); /* Blow away the old security setting by adding a clear one */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, (NMSetting *) s_wsec); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, sec->cur_index, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, (auth_alg == 1) ? "shared" : "open", NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, sec->type, NULL); for (i = 0; i < 4; i++) { if (strlen (sec->keys[i])) nm_setting_wireless_security_set_wep_key (s_wsec, i, sec->keys[i]); } }
void WifiStatusNM::setConnectedAccessPoint(WifiAccessPoint *ap, String psk) { ScopedPointer<StringArray> cmd; for (const auto& listener : listeners) listener->handleWifiBusy(); // disconnect if no ap provided if (ap == nullptr) { NMActiveConnection *conn = nm_device_get_active_connection(nmdevice); removeNMConnection(nmdevice, conn); return; } // try to connect to ap, dispatch events on success and failure else { NMConnection *connection = NULL; NMSettingWireless *s_wifi = NULL; NMSettingWirelessSecurity *s_wsec = NULL; const char *nm_ap_path = NULL; const GPtrArray *ap_list; NMAccessPoint *candidate_ap; //FIXME: expand WifiAccessPoint struct to know which NMAccessPoint it is ap_list = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(nmdevice)); if (ap_list == NULL) return; for (int i = 0; i < ap_list->len; i++) { const char *candidate_hash; candidate_ap = (NMAccessPoint *) g_ptr_array_index(ap_list, i); candidate_hash = utils_hash_ap(nm_access_point_get_ssid(candidate_ap), nm_access_point_get_mode(candidate_ap), nm_access_point_get_flags(candidate_ap), nm_access_point_get_wpa_flags(candidate_ap), nm_access_point_get_rsn_flags(candidate_ap)); if (ap->hash == candidate_hash) { nm_ap_path = nm_object_get_path(NM_OBJECT(candidate_ap)); break; } } if (!nm_ap_path) return; connecting = true; connection = nm_connection_new(); s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); nm_connection_add_setting(connection, NM_SETTING(s_wifi)); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, nm_access_point_get_ssid(candidate_ap), NM_SETTING_WIRELESS_HIDDEN, false, NULL); if (!psk.isEmpty()) { s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); nm_connection_add_setting(connection, NM_SETTING(s_wsec)); if (nm_access_point_get_wpa_flags(candidate_ap) == NM_802_11_AP_SEC_NONE && nm_access_point_get_rsn_flags(candidate_ap) == NM_802_11_AP_SEC_NONE) { /* WEP */ nm_setting_wireless_security_set_wep_key(s_wsec, 0, psk.toRawUTF8()); if (isValidWEPKeyFormat(psk)) g_object_set(G_OBJECT(s_wsec), NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_KEY, NULL); else if (isValidWEPPassphraseFormat(psk)) g_object_set(G_OBJECT(s_wsec), NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_PASSPHRASE, NULL); else DBG("User input invalid WEP Key type, psk.length() = " << psk.length() << ", not in [5,10,13,26]"); } else { g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK, psk.toRawUTF8(), NULL); } } nm_client_add_and_activate_connection(nmclient, connection, nmdevice, nm_ap_path, handle_add_and_activate_finish, this); } }
static void test_wifi_wep_key (const char *detail, NMWepKeyType wep_type, const char *key_data, const unsigned char *expected, size_t expected_size) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIP4Config *s_ip4; NMSupplicantConfig *config; GHashTable *hash; char *uuid; gboolean success; GError *error = NULL; GByteArray *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; GByteArray *bssid; const unsigned char bssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; const char *bssid_str = "11:22:33:44:55:66"; connection = nm_connection_new (); ASSERT (connection != NULL, detail, "failed to allocate new connection"); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); ASSERT (s_con != NULL, detail, "failed to allocate new %s setting", NM_SETTING_CONNECTION_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Wifi WEP Key", NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); ASSERT (s_wifi != NULL, detail, "failed to allocate new %s setting", NM_SETTING_WIRELESS_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_byte_array_sized_new (sizeof (ssid_data)); g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); bssid = g_byte_array_sized_new (sizeof (bssid_data)); g_byte_array_append (bssid, bssid_data, sizeof (bssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_BSSID, bssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NM_SETTING_WIRELESS_BAND, "bg", NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); g_byte_array_free (ssid, TRUE); g_byte_array_free (bssid, TRUE); /* Wifi Security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); ASSERT (s_wsec != NULL, detail, "failed to allocate new %s setting", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, wep_type, NULL); nm_setting_wireless_security_set_wep_key (s_wsec, 0, key_data); /* IP4 setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); ASSERT (s_ip4 != NULL, detail, "failed to allocate new %s setting", NM_SETTING_IP4_CONFIG_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, detail, "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); config = nm_supplicant_config_new (); ASSERT (config != NULL, detail, "failed to create new supplicant config"); success = nm_supplicant_config_add_setting_wireless (config, s_wifi, TRUE, 0, TRUE); ASSERT (success == TRUE, detail, "failed to add wireless setting to supplicant config."); success = nm_supplicant_config_add_setting_wireless_security (config, s_wsec, NULL, "376aced7-b28c-46be-9a62-fcdf072571da"); ASSERT (success == TRUE, detail, "failed to add wireless security to supplicant config."); hash = nm_supplicant_config_get_hash (config); ASSERT (hash != NULL, detail, "failed to hash supplicant config options."); validate_opt (detail, hash, "scan_ssid", TYPE_INT, GINT_TO_POINTER (1), -1); validate_opt (detail, hash, "ssid", TYPE_BYTES, ssid_data, sizeof (ssid_data)); validate_opt (detail, hash, "bssid", TYPE_KEYWORD, bssid_str, -1); validate_opt (detail, hash, "key_mgmt", TYPE_KEYWORD, "NONE", -1); validate_opt (detail, hash, "wep_tx_keyidx", TYPE_INT, GINT_TO_POINTER (0), -1); validate_opt (detail, hash, "wep_key0", TYPE_BYTES, expected, expected_size); g_object_unref (connection); }