]>
git.ipfire.org Git - people/ms/strongswan.git/blob - programs/charon/testing/proposal_test.c
2 * @file proposal_test.c
4 * @brief Tests for the proposal_t class.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
23 #include "proposal_test.h"
26 #include <config/proposal.h>
27 #include <utils/logger.h>
31 * Described in header.
33 void test_proposal(protected_tester_t
*tester
)
35 proposal_t
*proposal1
, *proposal2
, *proposal3
;
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);
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);
57 proposal3
= proposal1
->select(proposal1
, proposal2
);
58 tester
->assert_false(tester
, proposal3
== NULL
, "proposal select");
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");
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");
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
))
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");
80 iterator
->destroy(iterator
);
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
))
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");
90 iterator
->destroy(iterator
);
92 proposal3
->destroy(proposal3
);
95 proposal1
->destroy(proposal1
);
96 proposal2
->destroy(proposal2
);