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

unit: Add M5 parser unit test

This commit is contained in:
Denis Kenzior 2016-08-30 09:46:20 -05:00
parent a8580c7ed0
commit 5c88de6e65

View File

@ -1300,6 +1300,64 @@ static void wsc_test_build_m4(const void *data)
l_free(out);
}
static const unsigned char eap_wsc_m5[] = {
0x01, 0x00, 0x00, 0x86, 0x02, 0xa9, 0x00, 0x86, 0xfe, 0x00, 0x37, 0x2a,
0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10,
0x22, 0x00, 0x01, 0x09, 0x10, 0x39, 0x00, 0x10, 0x67, 0xa5, 0x53, 0x61,
0xee, 0x72, 0xc2, 0x21, 0x48, 0x78, 0xc5, 0x70, 0x89, 0x9f, 0xf2, 0xa0,
0x10, 0x18, 0x00, 0x40, 0x9a, 0x31, 0xf8, 0x4b, 0x46, 0x72, 0xf2, 0xcc,
0xf6, 0x3c, 0x84, 0x5e, 0xed, 0x34, 0x64, 0xec, 0xe6, 0x04, 0xe5, 0xb1,
0xac, 0xac, 0xa5, 0x5d, 0x50, 0x5f, 0xcc, 0x5c, 0x99, 0x13, 0x3f, 0xe7,
0x24, 0xb8, 0x10, 0x41, 0x04, 0x94, 0x2a, 0x3c, 0x56, 0xe5, 0x14, 0xee,
0x57, 0xda, 0xdf, 0x25, 0x57, 0xbe, 0x3e, 0x71, 0x8a, 0x10, 0x3a, 0x88,
0xd9, 0x74, 0x42, 0x2d, 0x53, 0x6a, 0xa6, 0xe5, 0x10, 0x49, 0x00, 0x06,
0x00, 0x37, 0x2a, 0x00, 0x01, 0x20, 0x10, 0x05, 0x00, 0x08, 0x6c, 0x80,
0x5a, 0x2f, 0xac, 0x19, 0x7c, 0x35,
};
struct m5_data {
struct wsc_m5 expected;
const uint8_t *expected_encrypted;
size_t expected_encrypted_size;
const void *pdu;
unsigned int len;
};
static const struct m5_data m5_data_1 = {
.pdu = eap_wsc_m5 + 18,
.len = sizeof(eap_wsc_m5) - 18,
.expected = {
.version2 = true,
.registrar_nonce = { 0x67, 0xa5, 0x53, 0x61, 0xee, 0x72, 0xc2,
0x21, 0x48, 0x78, 0xc5, 0x70, 0x89,
0x9f, 0xf2, 0xa0 },
.authenticator = { 0x6c, 0x80, 0x5a, 0x2f, 0xac, 0x19,
0x7c, 0x35 },
},
.expected_encrypted = eap_wsc_m5 + 52,
.expected_encrypted_size = 64,
};
static void wsc_test_parse_m5(const void *data)
{
const struct m5_data *test = data;
struct wsc_m5 m5;
const struct wsc_m5 *expected = &test->expected;
struct iovec encrypted;
int r;
r = wsc_parse_m5(test->pdu, test->len, &m5, &encrypted);
assert(r == 0);
assert(expected->version2 == m5.version2);
assert(!memcmp(expected->registrar_nonce, m5.registrar_nonce, 16));
assert(!memcmp(expected->authenticator, m5.authenticator, 8));
assert(test->expected_encrypted_size == encrypted.iov_len);
assert(!memcmp(test->expected_encrypted,
encrypted.iov_base, encrypted.iov_len));
}
static const uint8_t eap_identity_req[] = {
0x01, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x05, 0x01
};
@ -1492,6 +1550,8 @@ int main(int argc, char *argv[])
l_test_add("/wsc/parse/m4 1", wsc_test_parse_m4, &m4_data_1);
l_test_add("/wsc/build/m4 1", wsc_test_build_m4, &m4_data_1);
l_test_add("/wsc/parse/m5 1", wsc_test_parse_m5, &m5_data_1);
l_test_add("/wsc/handshake/PBC Handshake Test",
wsc_test_pbc_handshake, NULL);