3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-19 18:22:32 +01:00

unit: Update to the new API

This commit is contained in:
Denis Kenzior 2018-06-21 17:32:56 -07:00
parent 3df790e3c5
commit 7c0bc22b7c
2 changed files with 76 additions and 22 deletions

View File

@ -32,6 +32,7 @@
#include <ell/tls-private.h> #include <ell/tls-private.h>
#include <ell/key-private.h> #include <ell/key-private.h>
#include "src/util.h"
#include "src/eapol.h" #include "src/eapol.h"
#include "src/crypto.h" #include "src/crypto.h"
#include "src/ie.h" #include "src/ie.h"
@ -68,6 +69,31 @@ static const uint8_t *aa;
/* Supplicant Address */ /* Supplicant Address */
static const uint8_t *spa; static const uint8_t *spa;
struct test_handshake_state {
struct handshake_state super;
const uint8_t *tk;
};
static void test_handshake_state_free(struct handshake_state *hs)
{
struct test_handshake_state *ths =
container_of(hs, struct test_handshake_state, super);
l_free(ths);
}
static struct handshake_state *test_handshake_state_new(uint32_t ifindex)
{
struct test_handshake_state *ths;
ths = l_new(struct test_handshake_state, 1);
ths->super.ifindex = ifindex;
ths->super.free = test_handshake_state_free;
return &ths->super;
}
struct eapol_key_data { struct eapol_key_data {
const unsigned char *frame; const unsigned char *frame;
size_t frame_len; size_t frame_len;
@ -2129,7 +2155,7 @@ static void eapol_sm_test_ptk(const void *data)
expected_step4_frame = eapol_key_data_6; expected_step4_frame = eapol_key_data_6;
expected_step4_frame_size = sizeof(eapol_key_data_6); expected_step4_frame_size = sizeof(eapol_key_data_6);
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -2193,7 +2219,7 @@ static void eapol_sm_test_igtk(const void *data)
expected_step4_frame = eapol_key_data_32; expected_step4_frame = eapol_key_data_32;
expected_step4_frame_size = sizeof(eapol_key_data_32); expected_step4_frame_size = sizeof(eapol_key_data_32);
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -2260,7 +2286,7 @@ static void eapol_sm_test_wpa2_ptk_gtk(const void *data)
expected_gtk_step2_frame = eapol_key_data_12; expected_gtk_step2_frame = eapol_key_data_12;
expected_gtk_step2_frame_size = sizeof(eapol_key_data_12); expected_gtk_step2_frame_size = sizeof(eapol_key_data_12);
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -2328,7 +2354,7 @@ static void eapol_sm_test_wpa_ptk_gtk(const void *data)
expected_gtk_step2_frame = eapol_key_data_18; expected_gtk_step2_frame = eapol_key_data_18;
expected_gtk_step2_frame_size = sizeof(eapol_key_data_18); expected_gtk_step2_frame_size = sizeof(eapol_key_data_18);
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -2395,7 +2421,7 @@ static void eapol_sm_test_wpa_ptk_gtk_2(const void *data)
expected_gtk_step2_frame = eapol_key_data_24; expected_gtk_step2_frame = eapol_key_data_24;
expected_gtk_step2_frame_size = sizeof(eapol_key_data_24); expected_gtk_step2_frame_size = sizeof(eapol_key_data_24);
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -2430,27 +2456,29 @@ static void eapol_sm_test_wpa_ptk_gtk_2(const void *data)
eapol_exit(); eapol_exit();
} }
static void verify_install_tk(uint32_t ifindex, const uint8_t *aa_addr, static void verify_install_tk(struct handshake_state *hs,
const uint8_t *tk, uint32_t cipher, const uint8_t *tk, uint32_t cipher)
void *user_data)
{ {
assert(ifindex == 1); struct test_handshake_state *ths =
assert(!memcmp(aa_addr, aa, 6)); container_of(hs, struct test_handshake_state, super);
if (user_data) { assert(hs->ifindex == 1);
assert(!memcmp(tk, user_data, 32)); assert(!memcmp(hs->aa, aa, 6));
if (ths->tk) {
assert(!memcmp(tk, ths->tk, 32));
assert(cipher == CRYPTO_CIPHER_TKIP); assert(cipher == CRYPTO_CIPHER_TKIP);
} }
verify_install_tk_called = true; verify_install_tk_called = true;
} }
static void verify_install_gtk(uint32_t ifindex, uint8_t key_index, static void verify_install_gtk(struct handshake_state *hs, uint8_t key_index,
const uint8_t *gtk, uint8_t gtk_len, const uint8_t *gtk, uint8_t gtk_len,
const uint8_t *rsc, uint8_t rsc_len, const uint8_t *rsc, uint8_t rsc_len,
uint32_t cipher, void *user_data) uint32_t cipher)
{ {
assert(ifindex == 1); assert(hs->ifindex == 1);
verify_install_gtk_called = true; verify_install_gtk_called = true;
} }
@ -2508,7 +2536,7 @@ static void eapol_sm_wpa2_retransmit_test(const void *data)
strlen(ssid), psk); strlen(ssid), psk);
eapol_init(); eapol_init();
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -2847,6 +2875,7 @@ static void eapol_sm_test_tls(struct eapol_8021x_tls_test_state *s,
static uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 }; static uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
bool r; bool r;
struct handshake_state *hs; struct handshake_state *hs;
struct test_handshake_state *ths;
struct eapol_sm *sm; struct eapol_sm *sm;
struct l_settings *settings; struct l_settings *settings;
uint8_t tx_buf[2000]; uint8_t tx_buf[2000];
@ -2865,7 +2894,7 @@ static void eapol_sm_test_tls(struct eapol_8021x_tls_test_state *s,
__handshake_set_get_nonce_func(test_nonce); __handshake_set_get_nonce_func(test_nonce);
__eapol_set_deauthenticate_func(verify_deauthenticate); __eapol_set_deauthenticate_func(verify_deauthenticate);
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -3043,7 +3072,8 @@ static void eapol_sm_test_tls(struct eapol_8021x_tls_test_state *s,
__eapol_set_tx_packet_func(verify_step4); __eapol_set_tx_packet_func(verify_step4);
__handshake_set_install_tk_func(verify_install_tk); __handshake_set_install_tk_func(verify_install_tk);
handshake_state_set_user_data(hs, ptk->tk); ths = container_of(hs, struct test_handshake_state, super);
ths->tk = ptk->tk;
__eapol_rx_packet(1, ap_address, ETH_P_PAE, __eapol_rx_packet(1, ap_address, ETH_P_PAE,
step3_buf, sizeof(eapol_key_data_15), false); step3_buf, sizeof(eapol_key_data_15), false);
assert(verify_step4_called); assert(verify_step4_called);
@ -3230,7 +3260,7 @@ static void eapol_sm_test_eap_nak(const void *data)
__handshake_set_get_nonce_func(test_nonce); __handshake_set_get_nonce_func(test_nonce);
__eapol_set_deauthenticate_func(verify_deauthenticate); __eapol_set_deauthenticate_func(verify_deauthenticate);
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -3327,7 +3357,7 @@ static void eapol_ft_handshake_test(const void *data)
expected_step4_frame = eapol_key_data_28; expected_step4_frame = eapol_key_data_28;
expected_step4_frame_size = sizeof(eapol_key_data_28); expected_step4_frame_size = sizeof(eapol_key_data_28);
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);

View File

@ -42,6 +42,30 @@
#include "src/ie.h" #include "src/ie.h"
#include "src/handshake.h" #include "src/handshake.h"
struct test_handshake_state {
struct handshake_state super;
};
static void test_handshake_state_free(struct handshake_state *hs)
{
struct test_handshake_state *ths =
container_of(hs, struct test_handshake_state, super);
l_free(ths);
}
static struct handshake_state *test_handshake_state_new(uint32_t ifindex)
{
struct test_handshake_state *ths;
ths = l_new(struct test_handshake_state, 1);
ths->super.ifindex = ifindex;
ths->super.free = test_handshake_state_free;
return &ths->super;
}
static const unsigned char wsc_attrs1[] = { static const unsigned char wsc_attrs1[] = {
0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, 0x44, 0x00, 0x01, 0x02, 0x10, 0x41, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, 0x44, 0x00, 0x01, 0x02, 0x10, 0x41,
0x00, 0x01, 0x01, 0x10, 0x12, 0x00, 0x02, 0x00, 0x04, 0x10, 0x53, 0x00, 0x00, 0x01, 0x01, 0x10, 0x12, 0x00, 0x02, 0x00, 0x04, 0x10, 0x53, 0x00,
@ -1963,7 +1987,7 @@ static void wsc_test_pbc_handshake(const void *data)
eap_init(1400); eap_init(1400);
eapol_init(); eapol_init();
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);
@ -2071,7 +2095,7 @@ static void wsc_test_retransmission_no_fragmentation(const void *data)
eap_init(1400); eap_init(1400);
eapol_init(); eapol_init();
hs = handshake_state_new(1); hs = test_handshake_state_new(1);
sm = eapol_sm_new(hs); sm = eapol_sm_new(hs);
eapol_register(sm); eapol_register(sm);