From 997358a6c475c8886cce388ab325184a1ff733c9 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Fri, 28 Apr 2006 07:14:48 +0000 Subject: - import of strongswan-2.7.0 - applied patch for charon --- programs/charon/testing/proposal_test.c | 98 +++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 programs/charon/testing/proposal_test.c (limited to 'programs/charon/testing/proposal_test.c') diff --git a/programs/charon/testing/proposal_test.c b/programs/charon/testing/proposal_test.c new file mode 100644 index 000000000..1b16390d3 --- /dev/null +++ b/programs/charon/testing/proposal_test.c @@ -0,0 +1,98 @@ +/** + * @file proposal_test.c + * + * @brief Tests for the proposal_t class. + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "proposal_test.h" + +#include +#include +#include + + +/** + * Described in header. + */ +void test_proposal(protected_tester_t *tester) +{ + proposal_t *proposal1, *proposal2, *proposal3; + iterator_t *iterator; + algorithm_t *algo; + bool result; + + proposal1 = proposal_create(1); + proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_3DES, 0); + proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 32); + proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16); + proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 0); + proposal1->add_algorithm(proposal1, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20); + proposal1->add_algorithm(proposal1, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20); + proposal1->add_algorithm(proposal1, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0); + proposal1->add_algorithm(proposal1, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0); + + proposal2 = proposal_create(2); + proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_3IDEA, 0); + proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16); + proposal2->add_algorithm(proposal2, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20); + proposal1->add_algorithm(proposal2, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0); + + /* ah and esp prop */ + proposal3 = proposal1->select(proposal1, proposal2); + tester->assert_false(tester, proposal3 == NULL, "proposal select"); + if (proposal3) + { + result = proposal3->get_algorithm(proposal3, PROTO_ESP, ENCRYPTION_ALGORITHM, &algo); + tester->assert_true(tester, result, "encryption algo select"); + tester->assert_true(tester, algo->algorithm == ENCR_AES_CBC, "encryption algo"); + tester->assert_true(tester, algo->key_size == 16, "encryption keylen"); + + + result = proposal3->get_algorithm(proposal3, PROTO_ESP, INTEGRITY_ALGORITHM, &algo); + tester->assert_true(tester, result, "integrity algo select"); + tester->assert_true(tester, algo->algorithm == AUTH_HMAC_MD5_96, "integrity algo"); + tester->assert_true(tester, algo->key_size == 20, "integrity keylen"); + + iterator = proposal3->create_algorithm_iterator(proposal3, PROTO_ESP, INTEGRITY_ALGORITHM); + tester->assert_false(tester, iterator == NULL, "integrity algo select"); + while(iterator->has_next(iterator)) + { + iterator->current(iterator, (void**)&algo); + tester->assert_true(tester, algo->algorithm == AUTH_HMAC_MD5_96, "integrity algo"); + tester->assert_true(tester, algo->key_size == 20, "integrity keylen"); + } + iterator->destroy(iterator); + + iterator = proposal3->create_algorithm_iterator(proposal3, PROTO_AH, DIFFIE_HELLMAN_GROUP ); + tester->assert_false(tester, iterator == NULL, "dh group algo select"); + while(iterator->has_next(iterator)) + { + iterator->current(iterator, (void**)&algo); + tester->assert_true(tester, algo->algorithm == MODP_1024_BIT, "dh group algo"); + tester->assert_true(tester, algo->key_size == 0, "dh gorup keylen"); + } + iterator->destroy(iterator); + + proposal3->destroy(proposal3); + } + + proposal1->destroy(proposal1); + proposal2->destroy(proposal2); + return; +} -- cgit v1.2.3