diff --git a/unit/test-wsc.c b/unit/test-wsc.c index 164f742d..9e1415f9 100644 --- a/unit/test-wsc.c +++ b/unit/test-wsc.c @@ -1706,6 +1706,63 @@ static void wsc_test_build_m8(const void *data) l_free(out); } +static const unsigned char m8_encrypted_settings[] = { + 0x10, 0x0e, 0x00, 0x6f, 0x10, 0x26, 0x00, 0x01, 0x00, 0x10, 0x45, 0x00, + 0x07, 0x54, 0x65, 0x73, 0x74, 0x57, 0x50, 0x41, 0x10, 0x03, 0x00, 0x02, + 0x00, 0x20, 0x10, 0x0f, 0x00, 0x02, 0x00, 0x08, 0x10, 0x28, 0x00, 0x01, + 0x00, 0x10, 0x27, 0x00, 0x40, 0x34, 0x36, 0x30, 0x34, 0x44, 0x30, 0x31, + 0x46, 0x46, 0x44, 0x42, 0x30, 0x42, 0x32, 0x39, 0x32, 0x45, 0x33, 0x37, + 0x37, 0x33, 0x32, 0x44, 0x44, 0x34, 0x45, 0x31, 0x31, 0x43, 0x32, 0x34, + 0x30, 0x31, 0x31, 0x35, 0x34, 0x32, 0x38, 0x39, 0x41, 0x30, 0x39, 0x41, + 0x33, 0x33, 0x41, 0x44, 0x37, 0x30, 0x34, 0x31, 0x37, 0x37, 0x41, 0x42, + 0x30, 0x44, 0x31, 0x42, 0x37, 0x35, 0x38, 0x44, 0x30, 0x10, 0x20, 0x00, + 0x06, 0xa0, 0xa8, 0xcd, 0x1c, 0x7e, 0xc9, 0x10, 0x1e, 0x00, 0x08, 0xe8, + 0x3b, 0x3b, 0xe7, 0x9e, 0x72, 0x06, 0x46, +}; + +struct m8_encrypted_settings_data { + struct wsc_m8_encrypted_settings expected; + unsigned int n_creds; + const void *pdu; + unsigned int len; +}; + +static const struct m8_encrypted_settings_data m8_encrypted_settings_data_1 = { + .pdu = m8_encrypted_settings, + .len = sizeof(m8_encrypted_settings), + .n_creds = 1, + .expected = { + .authenticator = { 0xe8, 0x3b, 0x3b, 0xe7, 0x9e, 0x72, + 0x06, 0x46 }, + }, +}; + +static void wsc_test_parse_m8_encrypted_settings(const void *data) +{ + const struct m8_encrypted_settings_data *test = data; + struct wsc_m8_encrypted_settings m8es; + const struct wsc_m8_encrypted_settings *expected = &test->expected; + struct iovec creds[10]; + size_t n_creds = 10; + int r; + + r = wsc_parse_m8_encrypted_settings(test->pdu, test->len, &m8es, + creds, &n_creds); + assert(r == 0); + + assert(expected->new_password_len == m8es.new_password_len); + + if (m8es.new_password_len > 0) { + assert(!memcmp(expected->new_password, m8es.new_password, + m8es.new_password_len)); + assert(expected->device_password_id == m8es.device_password_id); + } + + assert(n_creds == test->n_creds); + + assert(!memcmp(expected->authenticator, m8es.authenticator, 8)); +} + static const uint8_t eap_identity_req[] = { 0x01, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x05, 0x01 }; @@ -1915,6 +1972,10 @@ int main(int argc, char *argv[]) l_test_add("/wsc/parse/m8 1", wsc_test_parse_m8, &m8_data_1); l_test_add("/wsc/build/m8 1", wsc_test_build_m8, &m8_data_1); + l_test_add("/wsc/parse/m8 encrypted settings 1", + wsc_test_parse_m8_encrypted_settings, + &m8_encrypted_settings_data_1); + l_test_add("/wsc/handshake/PBC Handshake Test", wsc_test_pbc_handshake, NULL);