3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-17 09:29:22 +01:00

unit: Add M2 parser unit test

This commit is contained in:
Denis Kenzior 2016-08-17 21:58:18 -05:00
parent 966f0a974f
commit ed6e5665d4

View File

@ -642,6 +642,150 @@ static void wsc_test_build_m1(const void *data)
l_free(out);
}
static const unsigned char eap_wsc_m2[] = {
0x01, 0x00, 0x01, 0xd6, 0x01, 0x02, 0x01, 0xd6, 0xfe, 0x00, 0x37, 0x2a,
0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10,
0x22, 0x00, 0x01, 0x05, 0x10, 0x1a, 0x00, 0x10, 0xab, 0x84, 0x41, 0x2f,
0xe7, 0xc3, 0xc9, 0xc9, 0xd7, 0xf4, 0xe8, 0xc1, 0x4f, 0x49, 0x2b, 0x79,
0x10, 0x39, 0x00, 0x10, 0x1a, 0xe1, 0xa2, 0xc1, 0x5a, 0xff, 0xa8, 0xb4,
0x3a, 0x4a, 0xe1, 0xea, 0x71, 0x3f, 0xfb, 0x49, 0x10, 0x48, 0x00, 0x10,
0xc4, 0x4a, 0xad, 0x8d, 0x25, 0x2f, 0x52, 0xc6, 0xf9, 0x6b, 0x38, 0x5d,
0xcb, 0x23, 0x31, 0xae, 0x10, 0x32, 0x00, 0xc0, 0xe8, 0x23, 0x5b, 0x62,
0x65, 0x41, 0x83, 0xfa, 0xc3, 0x23, 0x6f, 0x30, 0xc9, 0x4e, 0x32, 0x34,
0x8c, 0xfa, 0xf0, 0xfb, 0xff, 0x09, 0xc1, 0x93, 0x13, 0x7a, 0x80, 0xe2,
0xce, 0x5a, 0x5e, 0xed, 0x55, 0xcd, 0xdb, 0x87, 0x05, 0xbf, 0x06, 0x47,
0xf9, 0x96, 0xdd, 0x96, 0x41, 0xdf, 0x56, 0x6e, 0xb1, 0x20, 0xee, 0xf7,
0x97, 0xf7, 0x59, 0x9f, 0x94, 0x78, 0xe5, 0xff, 0xd7, 0xa0, 0x99, 0xcf,
0x34, 0x00, 0xb4, 0xbd, 0xaf, 0xaf, 0x8f, 0xd9, 0x7d, 0x10, 0x2e, 0x4d,
0x8c, 0xac, 0x0e, 0x8f, 0x19, 0xcf, 0x07, 0xc7, 0x24, 0x6c, 0xa8, 0xf4,
0x18, 0x56, 0x04, 0xbf, 0x80, 0x34, 0x72, 0x18, 0x65, 0x09, 0x7a, 0x85,
0x7b, 0xe2, 0xe0, 0xeb, 0x19, 0x15, 0x69, 0x7f, 0xef, 0x60, 0x78, 0x01,
0x73, 0xb8, 0xd0, 0x33, 0x76, 0x18, 0xf2, 0xf8, 0x29, 0x39, 0x11, 0x1a,
0xcd, 0x6c, 0x5c, 0x10, 0xf5, 0xbf, 0x4e, 0xf3, 0xda, 0x9a, 0x48, 0x46,
0x5c, 0x93, 0x8e, 0x18, 0x03, 0xd0, 0x42, 0x8f, 0xef, 0x5a, 0xc7, 0x9c,
0x1a, 0x10, 0x3a, 0xd3, 0x74, 0x6a, 0x3b, 0x23, 0x37, 0x7b, 0xcd, 0x4a,
0x52, 0xfd, 0x11, 0x4d, 0x62, 0xf8, 0x2e, 0xac, 0xae, 0x2e, 0xcf, 0x25,
0x5c, 0xce, 0xd4, 0xd9, 0x8b, 0x30, 0x06, 0x74, 0x87, 0xd1, 0xb8, 0x64,
0x1a, 0xf5, 0xc6, 0x28, 0x89, 0x1f, 0x68, 0xd7, 0x10, 0x04, 0x00, 0x02,
0x00, 0x23, 0x10, 0x10, 0x00, 0x02, 0x00, 0x0d, 0x10, 0x0d, 0x00, 0x01,
0x01, 0x10, 0x08, 0x00, 0x02, 0x26, 0x88, 0x10, 0x21, 0x00, 0x15, 0x41,
0x53, 0x55, 0x53, 0x54, 0x65, 0x4b, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x75,
0x74, 0x65, 0x72, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x10, 0x23, 0x00, 0x1c,
0x57, 0x69, 0x2d, 0x46, 0x69, 0x20, 0x50, 0x72, 0x6f, 0x74, 0x65, 0x63,
0x74, 0x65, 0x64, 0x20, 0x53, 0x65, 0x74, 0x75, 0x70, 0x20, 0x52, 0x6f,
0x75, 0x74, 0x65, 0x72, 0x10, 0x24, 0x00, 0x08, 0x52, 0x54, 0x2d, 0x41,
0x43, 0x36, 0x38, 0x55, 0x10, 0x42, 0x00, 0x11, 0x31, 0x30, 0x3a, 0x63,
0x33, 0x3a, 0x37, 0x62, 0x3a, 0x35, 0x34, 0x3a, 0x37, 0x34, 0x3a, 0x64,
0x30, 0x10, 0x54, 0x00, 0x08, 0x00, 0x06, 0x00, 0x50, 0xf2, 0x04, 0x00,
0x01, 0x10, 0x11, 0x00, 0x08, 0x52, 0x54, 0x2d, 0x41, 0x43, 0x36, 0x38,
0x55, 0x10, 0x3c, 0x00, 0x01, 0x02, 0x10, 0x02, 0x00, 0x02, 0x00, 0x00,
0x10, 0x09, 0x00, 0x02, 0x00, 0x00, 0x10, 0x12, 0x00, 0x02, 0x00, 0x04,
0x10, 0x2d, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00, 0x10, 0x49, 0x00, 0x06,
0x00, 0x37, 0x2a, 0x00, 0x01, 0x20, 0x10, 0x05, 0x00, 0x08, 0xec, 0xb1,
0x17, 0xac, 0xd9, 0x33, 0x84, 0x5f,
};
struct m2_data {
struct wsc_m2 expected;
const void *pdu;
unsigned int len;
const uint8_t *public_key;
uint32_t public_key_size;
};
static const struct m2_data m2_data_1 = {
.pdu = eap_wsc_m2 + 18,
.len = sizeof(eap_wsc_m2) - 18,
.expected = {
.version2 = true,
.enrollee_nonce = { 0xab, 0x84, 0x41, 0x2f, 0xe7, 0xc3, 0xc9,
0xc9, 0xd7, 0xf4, 0xe8, 0xc1, 0x4f,
0x49, 0x2b, 0x79 },
.registrar_nonce = { 0x1a, 0xe1, 0xa2, 0xc1, 0x5a, 0xff, 0xa8,
0xb4, 0x3a, 0x4a, 0xe1, 0xea, 0x71,
0x3f, 0xfb, 0x49 },
.uuid_r = { 0xc4, 0x4a, 0xad, 0x8d, 0x25, 0x2f, 0x52, 0xc6,
0xf9, 0x6b, 0x38, 0x5d, 0xcb, 0x23, 0x31, 0xae },
.public_key = { }, /* Tested elsewhere */
.auth_type_flags =
WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL |
WSC_AUTHENTICATION_TYPE_WPA_PERSONAL |
WSC_AUTHENTICATION_TYPE_OPEN,
.encryption_type_flags = WSC_ENCRYPTION_TYPE_AES_TKIP |
WSC_ENCRYPTION_TYPE_NONE,
.connection_type_flags = WSC_CONNECTION_TYPE_ESS,
.config_methods = WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON |
WSC_CONFIGURATION_METHOD_PHYSICAL_PUSH_BUTTON |
WSC_CONFIGURATION_METHOD_VIRTUAL_DISPLAY_PIN,
.manufacturer = "ASUSTeK Computer Inc.",
.model_name = "Wi-Fi Protected Setup Router",
.model_number = "RT-AC68U",
.serial_number = "10:c3:7b:54:74:d0",
.primary_device_type = {
.category = 6,
.oui = { 0x00, 0x50, 0xf2 },
.oui_type = 0x04,
.subcategory = 1, },
.device_name = "RT-AC68U",
.rf_bands = WSC_RF_BAND_5_0_GHZ,
.association_state = WSC_ASSOCIATION_STATE_NOT_ASSOCIATED,
.device_password_id = WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON,
.configuration_error = WSC_CONFIGURATION_ERROR_NO_ERROR,
.os_version = 0,
.authenticator = { 0xec, 0xb1, 0x17, 0xac, 0xd9, 0x33, 0x84,
0x5f },
},
.public_key = eap_wsc_m2 + 92,
.public_key_size = 192,
};
static void wsc_test_parse_m2(const void *data)
{
const struct m2_data *test = data;
struct wsc_m2 m2;
const struct wsc_m2 *expected = &test->expected;
int r;
r = wsc_parse_m2(test->pdu, test->len, &m2);
assert(r == 0);
assert(expected->version2 == m2.version2);
assert(!memcmp(expected->uuid_r, m2.uuid_r, 16));
assert(!memcmp(expected->enrollee_nonce, m2.enrollee_nonce, 16));
assert(!memcmp(expected->registrar_nonce, m2.registrar_nonce, 16));
/* Skip public_key testing */
assert(expected->auth_type_flags == m2.auth_type_flags);
assert(expected->encryption_type_flags == m2.encryption_type_flags);
assert(expected->connection_type_flags == m2.connection_type_flags);
assert(expected->config_methods == m2.config_methods);
assert(!strcmp(expected->manufacturer, m2.manufacturer));
assert(!strcmp(expected->model_name, m2.model_name));
assert(!strcmp(expected->model_number, m2.model_number));
assert(!strcmp(expected->serial_number, m2.serial_number));
assert(expected->primary_device_type.category ==
m2.primary_device_type.category);
assert(!memcmp(expected->primary_device_type.oui,
m2.primary_device_type.oui, 3));
assert(expected->primary_device_type.oui_type ==
m2.primary_device_type.oui_type);
assert(expected->primary_device_type.subcategory ==
m2.primary_device_type.subcategory);
assert(!strcmp(expected->device_name, m2.device_name));
assert(expected->rf_bands == m2.rf_bands);
assert(expected->association_state == m2.association_state);
assert(expected->device_password_id == m2.device_password_id);
assert(expected->configuration_error == m2.configuration_error);
assert(expected->os_version == m2.os_version);
assert(!memcmp(expected->authenticator, m2.authenticator, 8));
assert(!memcmp(test->public_key, m2.public_key, 192));
}
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@ -670,5 +814,7 @@ int main(int argc, char *argv[])
l_test_add("/wsc/parse/m1 1", wsc_test_parse_m1, &m1_data_1);
l_test_add("/wsc/build/m1 1", wsc_test_build_m1, &m1_data_1);
l_test_add("/wsc/parse/m2 1", wsc_test_parse_m2, &m2_data_1);
return l_test_run();
}