unit: Add M4 parser unit test

This commit is contained in:
Denis Kenzior 2016-08-19 15:04:42 -05:00
parent d3ee7c71be
commit 5322daa79a
1 changed files with 75 additions and 0 deletions

View File

@ -1093,6 +1093,79 @@ static void wsc_test_build_m3(const void *data)
l_free(out);
}
static const unsigned char eap_wsc_m4[] = {
0x01, 0x00, 0x00, 0xc4, 0x01, 0xa9, 0x00, 0xc4, 0xfe, 0x00, 0x37, 0x2a,
0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10,
0x22, 0x00, 0x01, 0x08, 0x10, 0x1a, 0x00, 0x10, 0x19, 0x8d, 0x0d, 0x25,
0x91, 0x2c, 0x37, 0x1c, 0xeb, 0x07, 0x89, 0x33, 0xe1, 0x25, 0xd7, 0x43,
0x10, 0x3d, 0x00, 0x20, 0x33, 0x81, 0x27, 0xf0, 0xb6, 0x75, 0x4c, 0x11,
0x83, 0x05, 0x3f, 0xa6, 0x10, 0x4b, 0xb5, 0x55, 0x2d, 0x7e, 0x65, 0x29,
0x48, 0x8c, 0xbd, 0xc4, 0x47, 0x49, 0xbd, 0xc9, 0x80, 0x67, 0x0e, 0x78,
0x10, 0x3e, 0x00, 0x20, 0x3f, 0x7c, 0x94, 0x89, 0xf8, 0x10, 0x4e, 0x9b,
0x37, 0xf6, 0x64, 0x28, 0xe1, 0x63, 0xdb, 0xca, 0x90, 0x42, 0xf4, 0x84,
0x3f, 0x1f, 0x2a, 0x7a, 0x3e, 0x4b, 0x29, 0xc3, 0xd2, 0x93, 0x79, 0x37,
0x10, 0x18, 0x00, 0x40, 0x8e, 0x02, 0xd6, 0x5f, 0xff, 0x43, 0xdf, 0x55,
0x19, 0xe2, 0x48, 0x30, 0xce, 0x02, 0x7c, 0xd6, 0x73, 0x6e, 0x19, 0x61,
0x38, 0x99, 0x5d, 0xb3, 0x63, 0x05, 0xba, 0xf2, 0xcc, 0xa4, 0xcf, 0x24,
0x33, 0x26, 0xb3, 0x93, 0x92, 0xbc, 0xb6, 0x65, 0x9d, 0x94, 0xe3, 0xe4,
0x39, 0xf3, 0xd0, 0xc5, 0x51, 0x79, 0x00, 0x67, 0xa2, 0x4e, 0xd6, 0x56,
0xfa, 0xb3, 0x0e, 0x0d, 0xca, 0x45, 0x76, 0xdf, 0x10, 0x05, 0x00, 0x08,
0x30, 0xf1, 0xf6, 0x4d, 0x5c, 0x55, 0x36, 0x3c,
};
struct m4_data {
struct wsc_m4 expected;
const uint8_t *expected_encrypted;
size_t expected_encrypted_size;
const void *pdu;
unsigned int len;
};
static const struct m4_data m4_data_1 = {
.pdu = eap_wsc_m4 + 18,
.len = sizeof(eap_wsc_m4) - 18,
.expected = {
.version2 = false,
.enrollee_nonce = { 0x19, 0x8d, 0x0d, 0x25, 0x91, 0x2c, 0x37,
0x1c, 0xeb, 0x07, 0x89, 0x33, 0xe1,
0x25, 0xd7, 0x43 },
.r_hash1 = { 0x33, 0x81, 0x27, 0xf0, 0xb6, 0x75, 0x4c, 0x11,
0x83, 0x05, 0x3f, 0xa6, 0x10, 0x4b, 0xb5, 0x55, 0x2d,
0x7e, 0x65, 0x29, 0x48, 0x8c, 0xbd, 0xc4, 0x47, 0x49,
0xbd, 0xc9, 0x80, 0x67, 0x0e, 0x78 },
.r_hash2 = { 0x3f, 0x7c, 0x94, 0x89, 0xf8, 0x10, 0x4e, 0x9b,
0x37, 0xf6, 0x64, 0x28, 0xe1, 0x63, 0xdb, 0xca, 0x90,
0x42, 0xf4, 0x84, 0x3f, 0x1f, 0x2a, 0x7a, 0x3e, 0x4b,
0x29, 0xc3, 0xd2, 0x93, 0x79, 0x37 },
.authenticator = { 0x30, 0xf1, 0xf6, 0x4d, 0x5c, 0x55,
0x36, 0x3c },
},
.expected_encrypted = eap_wsc_m4 + 124,
.expected_encrypted_size = 64,
};
static void wsc_test_parse_m4(const void *data)
{
const struct m4_data *test = data;
struct wsc_m4 m4;
const struct wsc_m4 *expected = &test->expected;
struct iovec encrypted;
int r;
r = wsc_parse_m4(test->pdu, test->len, &m4, &encrypted);
assert(r == 0);
assert(expected->version2 == m4.version2);
assert(!memcmp(expected->enrollee_nonce, m4.enrollee_nonce, 16));
assert(!memcmp(expected->r_hash1, m4.r_hash1, 32));
assert(!memcmp(expected->r_hash2, m4.r_hash2, 32));
assert(!memcmp(expected->authenticator, m4.authenticator, 8));
assert(test->expected_encrypted_size == encrypted.iov_len);
assert(!memcmp(test->expected_encrypted,
encrypted.iov_base, encrypted.iov_len));
}
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@ -1135,5 +1208,7 @@ int main(int argc, char *argv[])
l_test_add("/wsc/parse/m3 1", wsc_test_parse_m3, &m3_data_1);
l_test_add("/wsc/build/m3 1", wsc_test_build_m3, &m3_data_1);
l_test_add("/wsc/parse/m4 1", wsc_test_parse_m4, &m4_data_1);
return l_test_run();
}