aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/testcases/child_proposal_test.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2006-02-08 15:25:34 +0000
committerMartin Willi <martin@strongswan.org>2006-02-08 15:25:34 +0000
commitc06dbbabd1498d614d4db88bb4205e2afcd6dab8 (patch)
tree694e4df33baf70813367276b6956d9e6a714742e /Source/charon/testcases/child_proposal_test.c
parent384efc76d58eea98648988045de413a6cc027dff (diff)
downloadstrongswan-c06dbbabd1498d614d4db88bb4205e2afcd6dab8.tar.bz2
strongswan-c06dbbabd1498d614d4db88bb4205e2afcd6dab8.tar.xz
- fixed alot of bugs in child_proposal
- near to working state ;-)
Diffstat (limited to 'Source/charon/testcases/child_proposal_test.c')
-rw-r--r--Source/charon/testcases/child_proposal_test.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/Source/charon/testcases/child_proposal_test.c b/Source/charon/testcases/child_proposal_test.c
new file mode 100644
index 000000000..e1ca7de52
--- /dev/null
+++ b/Source/charon/testcases/child_proposal_test.c
@@ -0,0 +1,99 @@
+/**
+ * @file child_proposal_test.c
+ *
+ * @brief Tests for the child_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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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 "child_proposal_test.h"
+
+#include <daemon.h>
+#include <config/child_proposal.h>
+#include <utils/allocator.h>
+#include <utils/logger.h>
+
+
+/**
+ * Described in header.
+ */
+void test_child_proposal(protected_tester_t *tester)
+{
+ child_proposal_t *proposal1, *proposal2, *proposal3;
+ iterator_t *iterator;
+
+ proposal1 = child_proposal_create(1);
+ proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
+ proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 32);
+ proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
+ proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 0);
+ proposal1->add_algorithm(proposal1, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
+ proposal1->add_algorithm(proposal1, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
+ proposal1->add_algorithm(proposal1, AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
+ proposal1->add_algorithm(proposal1, AH, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
+
+ proposal2 = child_proposal_create(2);
+ proposal2->add_algorithm(proposal2, ESP, ENCRYPTION_ALGORITHM, ENCR_3IDEA, 0);
+ proposal2->add_algorithm(proposal2, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
+ proposal2->add_algorithm(proposal2, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
+ //proposal1->add_algorithm(proposal2, 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)
+ {
+ iterator = proposal3->create_algorithm_iterator(proposal3, ESP, ENCRYPTION_ALGORITHM);
+ tester->assert_false(tester, iterator == NULL, "encryption algo select");
+ while(iterator->has_next(iterator))
+ {
+ algorithm_t *algo;
+ iterator->current(iterator, (void**)&algo);
+ tester->assert_true(tester, algo->algorithm == ENCR_AES_CBC, "encryption algo");
+ tester->assert_true(tester, algo->key_size == 16, "encryption keylen");
+ }
+ iterator->destroy(iterator);
+
+ iterator = proposal3->create_algorithm_iterator(proposal3, ESP, INTEGRITY_ALGORITHM);
+ tester->assert_false(tester, iterator == NULL, "integrity algo select");
+ while(iterator->has_next(iterator))
+ {
+ algorithm_t *algo;
+ 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, AH, DIFFIE_HELLMAN_GROUP );
+ tester->assert_false(tester, iterator == NULL, "dh group algo select");
+ while(iterator->has_next(iterator))
+ {
+ algorithm_t *algo;
+ 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;
+}