diff --git a/unit/test-eapol.c b/unit/test-eapol.c index 43bb6322..17bdc13c 100644 --- a/unit/test-eapol.c +++ b/unit/test-eapol.c @@ -59,9 +59,9 @@ static const uint8_t *expected_gtk_step2_frame; static size_t expected_gtk_step2_frame_size; /* Authenticator Address */ -static uint8_t *aa; +static const uint8_t *aa; /* Supplicant Address */ -static uint8_t *spa; +static const uint8_t *spa; struct eapol_key_data { const unsigned char *frame; @@ -1172,6 +1172,206 @@ static struct eapol_key_data eapol_key_test_24 = { .key_data_len = 0, }; +/* FT frame, 1 of 4. For parameters see eapol_ft_handshake_test */ +static const unsigned char eapol_key_data_25[] = { + 0x02, 0x03, 0x00, 0x5f, 0x02, 0x00, 0x8b, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x33, 0xb2, 0x74, 0xa0, 0xae, 0xc9, 0xe8, + 0x5d, 0x61, 0x11, 0x8f, 0x1b, 0x6b, 0x97, 0x77, 0x4e, 0x5b, 0x75, 0x08, + 0x37, 0x45, 0x77, 0xdc, 0x14, 0x08, 0xa5, 0xf1, 0x80, 0xc5, 0xd2, 0xe9, + 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, +}; + +static struct eapol_key_data eapol_key_test_25 = { + .frame = eapol_key_data_25, + .frame_len = sizeof(eapol_key_data_25), + .protocol_version = EAPOL_PROTOCOL_VERSION_2004, + .packet_len = 95, + .descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211, + .key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES, + .key_type = true, + .install = false, + .key_ack = true, + .key_mic = false, + .secure = false, + .error = false, + .request = false, + .encrypted_key_data = false, + .smk_message = false, + .key_length = 16, + .key_replay_counter = 1, + .key_nonce = { 0x33, 0xb2, 0x74, 0xa0, 0xae, 0xc9, 0xe8, 0x5d, 0x61, + 0x11, 0x8f, 0x1b, 0x6b, 0x97, 0x77, 0x4e, 0x5b, 0x75, + 0x08, 0x37, 0x45, 0x77, 0xdc, 0x14, 0x08, 0xa5, 0xf1, + 0x80, 0xc5, 0xd2, 0xe9, 0xfd }, + .eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_data_len = 0, +}; + +/* FT frame, 2 of 4. For parameters see eapol_ft_handshake_test */ +static const unsigned char eapol_key_data_26[] = { + 0x02, 0x03, 0x00, 0xf0, 0x02, 0x01, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0xac, 0x1e, 0xb2, 0xc7, 0x0b, 0x20, 0x8c, + 0xe6, 0x0a, 0xe2, 0x07, 0xb2, 0x38, 0x9e, 0x44, 0x1f, 0xff, 0x39, 0x86, + 0x3d, 0x44, 0x9f, 0x81, 0x24, 0x6f, 0xe3, 0x6e, 0xde, 0x0f, 0x1f, 0x56, + 0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0xa1, 0x95, + 0x19, 0xe8, 0x5f, 0xcf, 0x2e, 0x60, 0x7d, 0x6f, 0xfb, 0xd9, 0xe8, 0x04, + 0xb0, 0x00, 0x91, 0x30, 0x26, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, + 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x00, + 0x00, 0x01, 0x00, 0xde, 0xce, 0x50, 0xa0, 0x9e, 0xf0, 0x8c, 0x4e, 0xbe, + 0xf2, 0xf1, 0xdb, 0xe9, 0x67, 0xb4, 0xd4, 0x36, 0x03, 0x12, 0x34, 0x01, + 0x37, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x64, 0x75, + 0x6d, 0x6d, 0x79, 0x30, +}; + +static struct eapol_key_data eapol_key_test_26 = { + .frame = eapol_key_data_26, + .frame_len = sizeof(eapol_key_data_26), + .protocol_version = EAPOL_PROTOCOL_VERSION_2004, + .packet_len = 240, + .descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211, + .key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES, + .key_type = true, + .install = false, + .key_ack = false, + .key_mic = true, + .secure = false, + .error = false, + .request = false, + .encrypted_key_data = false, + .smk_message = false, + .key_length = 0, + .key_replay_counter = 1, + .key_nonce = { 0xac, 0x1e, 0xb2, 0xc7, 0x0b, 0x20, 0x8c, 0xe6, 0x0a, + 0xe2, 0x07, 0xb2, 0x38, 0x9e, 0x44, 0x1f, 0xff, 0x39, + 0x86, 0x3d, 0x44, 0x9f, 0x81, 0x24, 0x6f, 0xe3, 0x6e, + 0xde, 0x0f, 0x1f, 0x56, 0xce }, + .eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_mic_data = { 0x79, 0xa1, 0x95, 0x19, 0xe8, 0x5f, 0xcf, 0x2e, 0x60, + 0x7d, 0x6f, 0xfb, 0xd9, 0xe8, 0x04, 0xb0 }, + .key_data_len = 145, +}; + +/* FT frame, 3 of 4. For parameters see eapol_ft_handshake_test */ +static const unsigned char eapol_key_data_27[] = { + 0x02, 0x03, 0x01, 0x1f, 0x02, 0x13, 0xcb, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x33, 0xb2, 0x74, 0xa0, 0xae, 0xc9, 0xe8, + 0x5d, 0x61, 0x11, 0x8f, 0x1b, 0x6b, 0x97, 0x77, 0x4e, 0x5b, 0x75, 0x08, + 0x37, 0x45, 0x77, 0xdc, 0x14, 0x08, 0xa5, 0xf1, 0x80, 0xc5, 0xd2, 0xe9, + 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xe3, 0x6d, + 0xef, 0x96, 0x5b, 0x07, 0xaa, 0x58, 0xce, 0xed, 0xb1, 0x57, 0x83, 0x51, + 0x7e, 0x00, 0xc0, 0x1d, 0x41, 0x1c, 0xf6, 0x35, 0x4e, 0x5c, 0x0f, 0x4d, + 0x03, 0x08, 0xe7, 0x3b, 0x33, 0x04, 0xde, 0x5e, 0x01, 0x77, 0x1c, 0xb8, + 0x91, 0xef, 0x4f, 0x24, 0x64, 0x84, 0xaa, 0x94, 0x42, 0xc3, 0xcb, 0x63, + 0x2d, 0xed, 0x5e, 0x5f, 0xcb, 0x1a, 0xff, 0x53, 0x58, 0x45, 0xd5, 0xc2, + 0x11, 0x52, 0x40, 0x06, 0x08, 0x70, 0xd8, 0xd1, 0xf7, 0x79, 0xfe, 0x37, + 0xb8, 0x6d, 0xd6, 0x27, 0x45, 0xbc, 0x11, 0x2a, 0x69, 0x05, 0x2c, 0x40, + 0x3a, 0x06, 0x24, 0x5a, 0x7a, 0xa6, 0x79, 0x4b, 0x18, 0xc8, 0xbf, 0x21, + 0x10, 0xa0, 0x7d, 0x80, 0x89, 0x77, 0x85, 0x27, 0x88, 0x74, 0x07, 0x00, + 0x14, 0xe0, 0x91, 0xa2, 0xe0, 0xa2, 0x25, 0x3c, 0x26, 0xce, 0xd6, 0x9f, + 0x33, 0x20, 0x99, 0xc6, 0xc0, 0x46, 0x91, 0x8a, 0x68, 0x5b, 0xa0, 0xa1, + 0x30, 0xcd, 0x76, 0x58, 0x26, 0x81, 0x03, 0xe6, 0x79, 0x3b, 0xf6, 0x4b, + 0x2f, 0x1d, 0x73, 0x8f, 0x62, 0xda, 0x22, 0xa9, 0xb4, 0xac, 0x77, 0xcc, + 0xd4, 0xd4, 0x6f, 0x80, 0x31, 0xfb, 0x3d, 0x21, 0xde, 0x41, 0x09, 0x70, + 0xcc, 0x18, 0xa6, 0xa5, 0x3e, 0xda, 0x1b, 0x6b, 0x30, 0xce, 0xd4, 0xde, + 0xd4, 0x86, 0x7e, 0x71, 0xd0, 0x97, 0x85, 0xcc, 0xa2, 0xd3, 0x4c, 0x56, + 0xcf, 0x1a, 0xd3, 0xff, 0xf8, 0x18, 0xfd, 0x52, 0x77, 0x21, 0xe9, 0x87, + 0x3f, 0x14, 0x30, +}; + +static struct eapol_key_data eapol_key_test_27 = { + .frame = eapol_key_data_27, + .frame_len = sizeof(eapol_key_data_27), + .protocol_version = EAPOL_PROTOCOL_VERSION_2004, + .packet_len = 287, + .descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211, + .key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES, + .key_type = true, + .install = true, + .key_ack = true, + .key_mic = true, + .secure = true, + .error = false, + .request = false, + .encrypted_key_data = true, + .smk_message = false, + .key_length = 16, + .key_replay_counter = 2, + .key_nonce = { 0x33, 0xb2, 0x74, 0xa0, 0xae, 0xc9, 0xe8, 0x5d, 0x61, + 0x11, 0x8f, 0x1b, 0x6b, 0x97, 0x77, 0x4e, 0x5b, 0x75, + 0x08, 0x37, 0x45, 0x77, 0xdc, 0x14, 0x08, 0xa5, 0xf1, + 0x80, 0xc5, 0xd2, 0xe9, 0xfd }, + .eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_mic_data = { 0x12, 0xe3, 0x6d, 0xef, 0x96, 0x5b, 0x07, 0xaa, 0x58, + 0xce, 0xed, 0xb1, 0x57, 0x83, 0x51, 0x7e }, + .key_data_len = 192, +}; + +/* FT frame, 4 of 4. For parameters see eapol_ft_handshake_test */ +static const unsigned char eapol_key_data_28[] = { + 0x02, 0x03, 0x00, 0x5f, 0x02, 0x03, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x85, 0x3a, + 0x3c, 0x83, 0x71, 0x4a, 0x94, 0xe4, 0x30, 0xdf, 0xb2, 0x06, 0x65, 0xa1, + 0xd4, 0x00, 0x00, +}; + +static struct eapol_key_data eapol_key_test_28 = { + .frame = eapol_key_data_28, + .frame_len = sizeof(eapol_key_data_28), + .protocol_version = EAPOL_PROTOCOL_VERSION_2004, + .packet_len = 95, + .descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211, + .key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES, + .key_type = true, + .install = false, + .key_ack = false, + .key_mic = true, + .secure = true, + .error = false, + .request = false, + .encrypted_key_data = false, + .smk_message = false, + .key_length = 0, + .key_replay_counter = 2, + .key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .key_mic_data = { 0x3e, 0x85, 0x3a, 0x3c, 0x83, 0x71, 0x4a, 0x94, 0xe4, + 0x30, 0xdf, 0xb2, 0x06, 0x65, 0xa1, 0xd4 }, + .key_data_len = 0, +}; + static void eapol_key_test(const void *data) { const struct eapol_key_data *test = data; @@ -2543,6 +2743,83 @@ static void eapol_sm_test_eap_nak(const void *data) eapol_exit(); } +static void eapol_ft_handshake_test(const void *data) +{ + const unsigned char psk[] = { + 0xbc, 0xcd, 0x17, 0x98, 0xef, 0x6c, 0xb8, 0x7f, + 0x2b, 0x54, 0x75, 0xfb, 0x98, 0x06, 0x57, 0xd2, + 0xea, 0x02, 0x6c, 0xe3, 0x68, 0xef, 0x3f, 0xca, + 0xda, 0x31, 0x48, 0x54, 0x3f, 0xee, 0x94, 0xf0 }; + const unsigned char ap_rsne[] = { + 0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, + 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, + 0x00, 0x0f, 0xac, 0x04, 0x81, 0x00 }; + const unsigned char own_rsne[] = { + 0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, + 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, + 0x00, 0x0f, 0xac, 0x04 }; + const uint8_t mde[] = { 0x36, 0x03, 0x12, 0x34, 0x01 }; + const uint8_t fte[] = { + 0x37, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x64, 0x75, + 0x6d, 0x6d, 0x79, 0x30 }; + const uint8_t r0khid[] = "dummy0"; + const uint8_t r1khid[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 }; + const uint8_t ap_address[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 }; + const uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x00 }; + const char *ssid = "TestFT"; + struct eapol_sm *sm; + + eapol_init(); + + snonce = eapol_key_test_26.key_nonce; + __eapol_set_get_nonce_func(test_nonce); + + aa = ap_address; + spa = sta_address; + verify_step2_called = false; + expected_step2_frame = eapol_key_data_26; + expected_step2_frame_size = sizeof(eapol_key_data_26); + verify_step4_called = false; + expected_step4_frame = eapol_key_data_28; + expected_step4_frame_size = sizeof(eapol_key_data_28); + + sm = eapol_sm_new(); + eapol_register(1, sm); + eapol_sm_set_pmk(sm, psk); + eapol_sm_set_authenticator_address(sm, aa); + eapol_sm_set_supplicant_address(sm, spa); + eapol_sm_set_ssid(sm, (void *) ssid, strlen(ssid)); + + eapol_sm_set_own_rsn(sm, own_rsne); + eapol_sm_set_ap_rsn(sm, ap_rsne); + eapol_sm_set_mde(sm, mde); + eapol_sm_set_fte(sm, fte); + eapol_sm_set_kh_ids(sm, r0khid, strlen((void *) r0khid), r1khid); + eapol_start(sm); + + __eapol_set_tx_packet_func(verify_step2); + __eapol_rx_packet(1, aa, eapol_key_data_25, sizeof(eapol_key_data_25)); + assert(verify_step2_called); + + __eapol_set_tx_packet_func(verify_step4); + __eapol_rx_packet(1, aa, eapol_key_data_27, sizeof(eapol_key_data_27)); + assert(verify_step4_called); + + eapol_cancel(1); + eapol_exit(); +} + int main(int argc, char *argv[]) { l_test_init(&argc, &argv); @@ -2595,6 +2872,14 @@ int main(int argc, char *argv[]) eapol_key_test, &eapol_key_test_23); l_test_add("/EAPoL Key/Key Frame 24", eapol_key_test, &eapol_key_test_24); + l_test_add("/EAPoL Key/Key Frame 25", + eapol_key_test, &eapol_key_test_25); + l_test_add("/EAPoL Key/Key Frame 26", + eapol_key_test, &eapol_key_test_26); + l_test_add("/EAPoL Key/Key Frame 27", + eapol_key_test, &eapol_key_test_27); + l_test_add("/EAPoL Key/Key Frame 28", + eapol_key_test, &eapol_key_test_28); l_test_add("/EAPoL Key/MIC Test 1", eapol_key_mic_test, &eapol_key_mic_test_1); @@ -2633,5 +2918,8 @@ int main(int argc, char *argv[]) l_test_add("EAPoL/8021x EAP NAK", &eapol_sm_test_eap_nak, NULL); + l_test_add("EAPoL/FT-Using-PSK 4-Way Handshake", + &eapol_ft_handshake_test, NULL); + return l_test_run(); }