]> git.ipfire.org Git - people/ms/strongswan.git/blob - programs/charon/testing/proposal_test.c
- import of strongswan-2.7.0
[people/ms/strongswan.git] / programs / charon / testing / proposal_test.c
1 /**
2 * @file proposal_test.c
3 *
4 * @brief Tests for the proposal_t class.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include "proposal_test.h"
24
25 #include <daemon.h>
26 #include <config/proposal.h>
27 #include <utils/logger.h>
28
29
30 /**
31 * Described in header.
32 */
33 void test_proposal(protected_tester_t *tester)
34 {
35 proposal_t *proposal1, *proposal2, *proposal3;
36 iterator_t *iterator;
37 algorithm_t *algo;
38 bool result;
39
40 proposal1 = proposal_create(1);
41 proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
42 proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 32);
43 proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
44 proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 0);
45 proposal1->add_algorithm(proposal1, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
46 proposal1->add_algorithm(proposal1, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
47 proposal1->add_algorithm(proposal1, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
48 proposal1->add_algorithm(proposal1, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
49
50 proposal2 = proposal_create(2);
51 proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_3IDEA, 0);
52 proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
53 proposal2->add_algorithm(proposal2, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
54 proposal1->add_algorithm(proposal2, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
55
56 /* ah and esp prop */
57 proposal3 = proposal1->select(proposal1, proposal2);
58 tester->assert_false(tester, proposal3 == NULL, "proposal select");
59 if (proposal3)
60 {
61 result = proposal3->get_algorithm(proposal3, PROTO_ESP, ENCRYPTION_ALGORITHM, &algo);
62 tester->assert_true(tester, result, "encryption algo select");
63 tester->assert_true(tester, algo->algorithm == ENCR_AES_CBC, "encryption algo");
64 tester->assert_true(tester, algo->key_size == 16, "encryption keylen");
65
66
67 result = proposal3->get_algorithm(proposal3, PROTO_ESP, INTEGRITY_ALGORITHM, &algo);
68 tester->assert_true(tester, result, "integrity algo select");
69 tester->assert_true(tester, algo->algorithm == AUTH_HMAC_MD5_96, "integrity algo");
70 tester->assert_true(tester, algo->key_size == 20, "integrity keylen");
71
72 iterator = proposal3->create_algorithm_iterator(proposal3, PROTO_ESP, INTEGRITY_ALGORITHM);
73 tester->assert_false(tester, iterator == NULL, "integrity algo select");
74 while(iterator->has_next(iterator))
75 {
76 iterator->current(iterator, (void**)&algo);
77 tester->assert_true(tester, algo->algorithm == AUTH_HMAC_MD5_96, "integrity algo");
78 tester->assert_true(tester, algo->key_size == 20, "integrity keylen");
79 }
80 iterator->destroy(iterator);
81
82 iterator = proposal3->create_algorithm_iterator(proposal3, PROTO_AH, DIFFIE_HELLMAN_GROUP );
83 tester->assert_false(tester, iterator == NULL, "dh group algo select");
84 while(iterator->has_next(iterator))
85 {
86 iterator->current(iterator, (void**)&algo);
87 tester->assert_true(tester, algo->algorithm == MODP_1024_BIT, "dh group algo");
88 tester->assert_true(tester, algo->key_size == 0, "dh gorup keylen");
89 }
90 iterator->destroy(iterator);
91
92 proposal3->destroy(proposal3);
93 }
94
95 proposal1->destroy(proposal1);
96 proposal2->destroy(proposal2);
97 return;
98 }