mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-25 09:39:25 +01:00
unit: Add a WSC-R test with a raw PSK
The wsc credentials can contain the passphrase or the raw PSK bytes, now test both scenarios.
This commit is contained in:
parent
3cf8af2431
commit
3aafb80b54
@ -2375,6 +2375,7 @@ struct wsc_r_test_success_data {
|
||||
bool ap_eap_failed;
|
||||
bool sta_eap_failed;
|
||||
struct test_ap_sta_data *s;
|
||||
struct wsc_credential expected_creds;
|
||||
};
|
||||
|
||||
static void test_ap_sta_hs_event_ap(struct handshake_state *hs,
|
||||
@ -2425,14 +2426,7 @@ static void test_ap_sta_hs_event_sta(struct handshake_state *hs,
|
||||
|
||||
assert(eap_event == EAP_WSC_EVENT_CREDENTIAL_OBTAINED);
|
||||
cred = va_arg(args, const struct wsc_credential *);
|
||||
assert(cred->ssid_len == 7 &&
|
||||
!memcmp(cred->ssid, "thessid", 7));
|
||||
assert(cred->auth_type ==
|
||||
WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL);
|
||||
assert(cred->encryption_type == WSC_ENCRYPTION_TYPE_AES_TKIP);
|
||||
assert(cred->network_key_len == 12 &&
|
||||
!memcmp(cred->network_key, "secretsecret", 12));
|
||||
assert(!memcmp(cred->addr, data->s->sta_address, 6));
|
||||
assert(!memcmp(cred, &data->expected_creds, sizeof(*cred)));
|
||||
assert(!data->credentials_obtained);
|
||||
assert(!data->sta_eap_failed);
|
||||
data->credentials_obtained = true;
|
||||
@ -2452,7 +2446,7 @@ static void test_ap_sta_hs_event_sta(struct handshake_state *hs,
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void wsc_r_test_pbc_handshake_wpa2(const void *data)
|
||||
static void wsc_r_test_pbc_handshake(const void *data)
|
||||
{
|
||||
static const unsigned char ap_rsne[] = {
|
||||
0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
|
||||
@ -2463,8 +2457,6 @@ static void wsc_r_test_pbc_handshake_wpa2(const void *data)
|
||||
"EAP-Method=WSC-R\n"
|
||||
"[WSC]\n"
|
||||
"UUID-R=00112233445566778899aabbccddeeff\n"
|
||||
"WPA2-SSID=thessid\n"
|
||||
"WPA2-Passphrase=secretsecret\n"
|
||||
"RFBand=1\n"
|
||||
"ConfigurationMethods=0x680\n";
|
||||
static const char *sta_8021x_str = "[Security]\n"
|
||||
@ -2481,15 +2473,60 @@ static void wsc_r_test_pbc_handshake_wpa2(const void *data)
|
||||
.ap_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
|
||||
.sta_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x08 },
|
||||
};
|
||||
const struct wsc_credential *expected_creds = data;
|
||||
struct wsc_r_test_success_data wsc_data = {
|
||||
.s = &s,
|
||||
.expected_creds = *expected_creds,
|
||||
};
|
||||
uint8_t uuid_e[16];
|
||||
L_AUTO_FREE_VAR(char *, uuid_e_str) = NULL;
|
||||
char ssid_str[33];
|
||||
|
||||
wsc_uuid_from_addr(s.sta_address, uuid_e);
|
||||
uuid_e_str = l_util_hexstring(uuid_e, 16);
|
||||
|
||||
memcpy(wsc_data.expected_creds.addr, s.sta_address, 6);
|
||||
memset(wsc_data.expected_creds.ssid + expected_creds->ssid_len, 0,
|
||||
sizeof(expected_creds->ssid) - expected_creds->ssid_len);
|
||||
memset(wsc_data.expected_creds.network_key +
|
||||
expected_creds->network_key_len, 0,
|
||||
sizeof(expected_creds->network_key) -
|
||||
expected_creds->network_key_len);
|
||||
|
||||
memcpy(ssid_str, expected_creds->ssid, expected_creds->ssid_len);
|
||||
ssid_str[expected_creds->ssid_len] = '\0';
|
||||
|
||||
l_settings_load_from_data(ap_8021x_settings, ap_8021x_str,
|
||||
strlen(ap_8021x_str));
|
||||
l_settings_set_string(ap_8021x_settings, "WSC", "EnrolleeMAC",
|
||||
util_address_to_string(s.sta_address));
|
||||
l_settings_set_string(ap_8021x_settings, "WSC", "UUID-E", uuid_e_str);
|
||||
|
||||
if (expected_creds->auth_type == WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL) {
|
||||
l_settings_set_string(ap_8021x_settings, "WSC",
|
||||
"WPA2-SSID", ssid_str);
|
||||
|
||||
if (expected_creds->network_key_len < 64)
|
||||
l_settings_set_string(ap_8021x_settings, "WSC",
|
||||
"WPA2-Passphrase", (char *)
|
||||
wsc_data.expected_creds.network_key);
|
||||
else {
|
||||
char psk_str[65];
|
||||
|
||||
/*
|
||||
* The PSK is 32-byte long but the setting value is
|
||||
* a hexstring, same as what we expect to receive in
|
||||
* the raw wsc_credential.network_key data.
|
||||
*/
|
||||
memcpy(psk_str, expected_creds->network_key, 64);
|
||||
psk_str[64] = '\0';
|
||||
l_settings_set_string(ap_8021x_settings, "WSC",
|
||||
"WPA2-PSK", psk_str);
|
||||
}
|
||||
} else
|
||||
l_settings_set_string(ap_8021x_settings, "WSC",
|
||||
"Open-SSID", ssid_str);
|
||||
|
||||
__handshake_set_get_nonce_func(random_nonce);
|
||||
__handshake_set_install_tk_func(test_ap_sta_install_tk);
|
||||
__handshake_set_install_gtk_func(NULL);
|
||||
@ -2501,11 +2538,6 @@ static void wsc_r_test_pbc_handshake_wpa2(const void *data)
|
||||
handshake_state_set_supplicant_address(s.ap_hs, s.sta_address);
|
||||
handshake_state_set_authenticator_ie(s.ap_hs, ap_rsne);
|
||||
handshake_state_set_ssid(s.ap_hs, (void *) ssid, strlen(ssid));
|
||||
l_settings_load_from_data(ap_8021x_settings, ap_8021x_str,
|
||||
strlen(ap_8021x_str));
|
||||
l_settings_set_string(ap_8021x_settings, "WSC", "EnrolleeMAC",
|
||||
util_address_to_string(s.sta_address));
|
||||
l_settings_set_string(ap_8021x_settings, "WSC", "UUID-E", uuid_e_str);
|
||||
handshake_state_set_8021x_config(s.ap_hs, ap_8021x_settings);
|
||||
|
||||
handshake_state_set_authenticator(s.sta_hs, false);
|
||||
@ -2533,6 +2565,25 @@ static void wsc_r_test_pbc_handshake_wpa2(const void *data)
|
||||
assert(wsc_data.ap_eap_failed && wsc_data.credentials_sent);
|
||||
}
|
||||
|
||||
struct wsc_credential wsc_r_test_wpa2_cred_passphrase = {
|
||||
.ssid_len = 7,
|
||||
.ssid = "thessid",
|
||||
.auth_type = WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL,
|
||||
.network_key_len = 12,
|
||||
.network_key = "secretsecret",
|
||||
.encryption_type = WSC_ENCRYPTION_TYPE_AES_TKIP,
|
||||
};
|
||||
|
||||
struct wsc_credential wsc_r_test_wpa2_cred_psk = {
|
||||
.ssid_len = 7,
|
||||
.ssid = "thessid",
|
||||
.auth_type = WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL,
|
||||
.network_key_len = 64,
|
||||
.network_key = "2aacd631143bbc2d83fabf3febed3c45"
|
||||
"6ea9f7539a1692ffb416c41cfee0c96f",
|
||||
.encryption_type = WSC_ENCRYPTION_TYPE_AES_TKIP,
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
l_test_init(&argc, &argv);
|
||||
@ -2646,8 +2697,12 @@ int main(int argc, char *argv[])
|
||||
l_test_add("/wsc/retransmission/no fragmentation",
|
||||
wsc_test_retransmission_no_fragmentation, NULL);
|
||||
|
||||
l_test_add("/wsc-r/handshake/PBC Handshake WPA2 Test",
|
||||
wsc_r_test_pbc_handshake_wpa2, NULL);
|
||||
l_test_add("/wsc-r/handshake/PBC Handshake WPA2 passphrase test",
|
||||
wsc_r_test_pbc_handshake,
|
||||
&wsc_r_test_wpa2_cred_passphrase);
|
||||
l_test_add("/wsc-r/handshake/PBC Handshake WPA2 PSK test",
|
||||
wsc_r_test_pbc_handshake,
|
||||
&wsc_r_test_wpa2_cred_psk);
|
||||
|
||||
done:
|
||||
return l_test_run();
|
||||
|
Loading…
Reference in New Issue
Block a user