diff --git a/unit/test-wsc.c b/unit/test-wsc.c index 60e3d88e..76e01fd5 100644 --- a/unit/test-wsc.c +++ b/unit/test-wsc.c @@ -1426,6 +1426,63 @@ static void wsc_test_build_m5(const void *data) l_free(out); } +static const unsigned char eap_wsc_m6[] = { + 0x01, 0x00, 0x00, 0x7c, 0x01, 0xaa, 0x00, 0x7c, 0xfe, 0x00, 0x37, 0x2a, + 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, + 0x22, 0x00, 0x01, 0x0a, 0x10, 0x1a, 0x00, 0x10, 0x19, 0x8d, 0x0d, 0x25, + 0x91, 0x2c, 0x37, 0x1c, 0xeb, 0x07, 0x89, 0x33, 0xe1, 0x25, 0xd7, 0x43, + 0x10, 0x18, 0x00, 0x40, 0x62, 0xfe, 0xc7, 0xf5, 0x1d, 0xa1, 0x0e, 0x5b, + 0xe9, 0x2f, 0xcb, 0x4f, 0x30, 0x7b, 0x15, 0x17, 0x9c, 0xa1, 0x92, 0x1d, + 0xd4, 0x7f, 0x06, 0x2f, 0x14, 0xcd, 0x4b, 0x8f, 0xe6, 0x76, 0xe7, 0x6c, + 0x9a, 0xc1, 0xd0, 0x1f, 0xab, 0x5e, 0x0f, 0xf5, 0xa7, 0xa9, 0x9a, 0xca, + 0xf3, 0xcc, 0xbd, 0x5f, 0xfc, 0xfb, 0x6f, 0x5b, 0x01, 0xb7, 0x05, 0x39, + 0x11, 0xc3, 0xaa, 0x92, 0x5c, 0x06, 0xdb, 0x21, 0x10, 0x05, 0x00, 0x08, + 0xc4, 0x40, 0xd2, 0x39, 0xf1, 0x07, 0x72, 0xcb, +}; + +struct m6_data { + struct wsc_m6 expected; + const uint8_t *expected_encrypted; + size_t expected_encrypted_size; + const void *pdu; + unsigned int len; +}; + +static const struct m6_data m6_data_1 = { + .pdu = eap_wsc_m6 + 18, + .len = sizeof(eap_wsc_m6) - 18, + .expected = { + .version2 = false, + .enrollee_nonce = { 0x19, 0x8d, 0x0d, 0x25, 0x91, 0x2c, 0x37, + 0x1c, 0xeb, 0x07, 0x89, 0x33, 0xe1, + 0x25, 0xd7, 0x43 }, + .authenticator = { 0xc4, 0x40, 0xd2, 0x39, 0xf1, 0x07, + 0x72, 0xcb }, + }, + .expected_encrypted = eap_wsc_m6 + 52, + .expected_encrypted_size = 64, +}; + +static void wsc_test_parse_m6(const void *data) +{ + const struct m6_data *test = data; + struct wsc_m6 m6; + const struct wsc_m6 *expected = &test->expected; + struct iovec encrypted; + int r; + + r = wsc_parse_m6(test->pdu, test->len, &m6, &encrypted); + assert(r == 0); + + assert(expected->version2 == m6.version2); + assert(!memcmp(expected->enrollee_nonce, m6.enrollee_nonce, 16)); + assert(!memcmp(expected->authenticator, m6.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 }; @@ -1652,6 +1709,8 @@ int main(int argc, char *argv[]) l_test_add("/wsc/parse/m5 1", wsc_test_parse_m5, &m5_data_1); l_test_add("/wsc/build/m5 1", wsc_test_build_m5, &m5_data_1); + l_test_add("/wsc/parse/m6 1", wsc_test_parse_m6, &m6_data_1); + l_test_add("/wsc/handshake/PBC Handshake Test", wsc_test_pbc_handshake, NULL);