aboutsummaryrefslogtreecommitdiffstats
path: root/programs/charon/testing/proposal_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'programs/charon/testing/proposal_test.c')
-rw-r--r--programs/charon/testing/proposal_test.c98
1 files changed, 98 insertions, 0 deletions
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 <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 "proposal_test.h"
+
+#include <daemon.h>
+#include <config/proposal.h>
+#include <utils/logger.h>
+
+
+/**
+ * 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;
+}