From ba951ed2055d346bff0c6924580da5aa463cf4f7 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 4 Nov 2019 16:17:30 +0100 Subject: [PATCH] wip: unit-tests: Tests for additional key exchanges --- src/libcharon/tests/suites/test_ike_rekey.c | 38 +++++++++++++++++++ .../tests/utils/exchange_test_helper.c | 12 ++++++ 2 files changed, 50 insertions(+) diff --git a/src/libcharon/tests/suites/test_ike_rekey.c b/src/libcharon/tests/suites/test_ike_rekey.c index 5960e989df..9b6924a053 100644 --- a/src/libcharon/tests/suites/test_ike_rekey.c +++ b/src/libcharon/tests/suites/test_ike_rekey.c @@ -102,6 +102,43 @@ START_TEST(test_regular) } END_TEST +/** + * Config for multiple KE exchange tests + */ +static exchange_test_sa_conf_t add_ke_conf = { + .initiator = { + .ike = "aes256-sha256-modp3072-ke1_ecp256", + }, + .responder = { + .ike = "aes256-sha256-modp3072-ke1_ecp256", + }, +}; + +/** + * FIXME: rekeying is not yet supported + */ +START_TEST(test_regular_additional_ke) +{ + ike_sa_t *a, *b; + + if (_i) + { /* responder rekeys the IKE_SA */ + exchange_test_helper->establish_sa(exchange_test_helper, + &b, &a, &add_ke_conf); + } + else + { /* initiator rekeys the IKE_SA */ + exchange_test_helper->establish_sa(exchange_test_helper, + &a, &b, &add_ke_conf); + } + + call_ikesa(b, destroy); + call_ikesa(a, destroy); + + charon->ike_sa_manager->flush(charon->ike_sa_manager); +} +END_TEST + /** * IKE_SA rekeying where the responder does not agree with the DH group selected * by the initiator, either initiated by the original initiator or responder of @@ -1464,6 +1501,7 @@ Suite *ike_rekey_suite_create() tc = tcase_create("regular"); tcase_add_loop_test(tc, test_regular, 0, 2); + tcase_add_loop_test(tc, test_regular_additional_ke, 0, 2); tcase_add_loop_test(tc, test_regular_ke_invalid, 0, 2); suite_add_tcase(s, tc); diff --git a/src/libcharon/tests/utils/exchange_test_helper.c b/src/libcharon/tests/utils/exchange_test_helper.c index 5faaf1dc6d..24394603de 100644 --- a/src/libcharon/tests/utils/exchange_test_helper.c +++ b/src/libcharon/tests/utils/exchange_test_helper.c @@ -264,6 +264,7 @@ METHOD(exchange_test_helper_t, establish_sa, void, ike_sa_id_t *id_i, *id_r; ike_sa_t *sa_i, *sa_r; child_cfg_t *child_i; + proposal_t *proposal; child_i = create_sa(this, init, resp, conf); @@ -281,6 +282,17 @@ METHOD(exchange_test_helper_t, establish_sa, void, /* <-- IKE_SA_INIT */ id_i->set_responder_spi(id_i, id_r->get_responder_spi(id_r)); process_message(this, sa_i, NULL); + + proposal = sa_i->get_proposal(sa_i); + if (proposal->get_algorithm(proposal, ADDITIONAL_KEY_EXCHANGE_1, NULL, + NULL)) + { + /* IKE_INTERMEDIATE --> */ + process_message(this, sa_r, NULL); + /* <-- IKE_INTERMEDIATE */ + process_message(this, sa_i, NULL); + } + /* IKE_AUTH --> */ process_message(this, sa_r, NULL); /* <-- IKE_AUTH */ -- 2.47.2