]>
Commit | Line | Data |
---|---|---|
aae95101 TB |
1 | /* |
2 | * Copyright (C) 2016 Tobias Brunner | |
3 | * HSR Hochschule fuer Technik Rapperswil | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2 of the License, or (at your | |
8 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 | * for more details. | |
14 | */ | |
15 | ||
16 | #include "test_suite.h" | |
17 | ||
18 | #include <config/proposal.h> | |
19 | ||
9e5065d8 TB |
20 | static struct { |
21 | protocol_id_t proto; | |
22 | char *proposal; | |
23 | char *expected; | |
24 | } create_data[] = { | |
25 | { PROTO_IKE, "", NULL }, | |
26 | { PROTO_IKE, "sha256", NULL }, | |
27 | { PROTO_IKE, "sha256-modp3072", NULL }, | |
28 | { PROTO_IKE, "null-sha256-modp3072", "IKE:NULL/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_3072" }, | |
29 | { PROTO_IKE, "aes128", NULL }, | |
30 | { PROTO_IKE, "aes128-sha256", NULL }, | |
31 | { PROTO_IKE, "aes128-sha256-modpnone", NULL }, | |
32 | { PROTO_IKE, "aes128-sha256-modp3072", "IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_3072" }, | |
33 | { PROTO_IKE, "aes128-sha256-prfsha384-modp3072", "IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_384/MODP_3072" }, | |
34 | { PROTO_IKE, "aes128gcm16-modp3072", NULL }, | |
35 | { PROTO_IKE, "aes128gcm16-prfsha256-modp3072", "IKE:AES_GCM_16_128/PRF_HMAC_SHA2_256/MODP_3072" }, | |
36 | { PROTO_IKE, "aes128gcm16-sha256-modp3072", "IKE:AES_GCM_16_128/PRF_HMAC_SHA2_256/MODP_3072" }, | |
37 | { PROTO_IKE, "aes128gcm16-aes128-modp3072", NULL }, | |
38 | { PROTO_IKE, "aes128gcm16-aes128-sha256-modp3072", NULL }, | |
39 | { PROTO_ESP, "", NULL }, | |
40 | { PROTO_ESP, "sha256", NULL }, | |
41 | { PROTO_ESP, "aes128-sha256", "ESP:AES_CBC_128/HMAC_SHA2_256_128/NO_EXT_SEQ" }, | |
42 | { PROTO_ESP, "aes128-sha256-esn", "ESP:AES_CBC_128/HMAC_SHA2_256_128/EXT_SEQ" }, | |
43 | { PROTO_ESP, "aes128-sha256-noesn", "ESP:AES_CBC_128/HMAC_SHA2_256_128/NO_EXT_SEQ" }, | |
44 | { PROTO_ESP, "aes128-sha256-esn-noesn", "ESP:AES_CBC_128/HMAC_SHA2_256_128/EXT_SEQ/NO_EXT_SEQ" }, | |
45 | { PROTO_ESP, "aes128-sha256-prfsha256-modp3072", "ESP:AES_CBC_128/HMAC_SHA2_256_128/MODP_3072/NO_EXT_SEQ" }, | |
46 | { PROTO_ESP, "aes128gcm16-aes128-sha256-modp3072", NULL }, | |
47 | { PROTO_ESP, "aes128gmac", "ESP:NULL_AES_GMAC_128/NO_EXT_SEQ" }, | |
48 | { PROTO_AH, "", NULL }, | |
49 | { PROTO_AH, "aes128", NULL }, | |
50 | { PROTO_AH, "aes128-sha256", "AH:HMAC_SHA2_256_128/NO_EXT_SEQ" }, | |
51 | { PROTO_AH, "sha256-sha1", "AH:HMAC_SHA2_256_128/HMAC_SHA1_96/NO_EXT_SEQ" }, | |
52 | { PROTO_AH, "aes128gmac-sha256", "AH:AES_128_GMAC/HMAC_SHA2_256_128/NO_EXT_SEQ" }, | |
53 | { PROTO_AH, "aes128gmac-sha256-prfsha256", "AH:AES_128_GMAC/HMAC_SHA2_256_128/NO_EXT_SEQ" }, | |
54 | { PROTO_AH, "aes128gmac-aes256gmac-aes128-sha256", "AH:AES_128_GMAC/AES_256_GMAC/HMAC_SHA2_256_128/NO_EXT_SEQ" }, | |
55 | { PROTO_AH, "sha256-esn", "AH:HMAC_SHA2_256_128/EXT_SEQ" }, | |
56 | { PROTO_AH, "sha256-noesn", "AH:HMAC_SHA2_256_128/NO_EXT_SEQ" }, | |
57 | { PROTO_AH, "sha256-esn-noesn", "AH:HMAC_SHA2_256_128/EXT_SEQ/NO_EXT_SEQ" }, | |
58 | }; | |
59 | ||
60 | START_TEST(test_create_from_string) | |
61 | { | |
62 | proposal_t *proposal; | |
63 | char str[BUF_LEN]; | |
64 | ||
65 | proposal = proposal_create_from_string(create_data[_i].proto, | |
66 | create_data[_i].proposal); | |
67 | if (!create_data[_i].expected) | |
68 | { | |
69 | ck_assert(!proposal); | |
70 | return; | |
71 | } | |
72 | snprintf(str, sizeof(str), "%P", proposal); | |
73 | ck_assert_str_eq(create_data[_i].expected, str); | |
74 | proposal->destroy(proposal); | |
75 | } | |
76 | END_TEST | |
77 | ||
aae95101 | 78 | static struct { |
9b191d59 | 79 | protocol_id_t proto; |
aae95101 TB |
80 | char *self; |
81 | char *other; | |
82 | char *expected; | |
83 | } select_data[] = { | |
9b191d59 TB |
84 | { PROTO_ESP, "aes128", "aes128", "aes128" }, |
85 | { PROTO_ESP, "aes128", "aes256", NULL }, | |
86 | { PROTO_ESP, "aes128-aes256", "aes256-aes128", "aes128" }, | |
87 | { PROTO_ESP, "aes256-aes128", "aes128-aes256", "aes256" }, | |
88 | { PROTO_ESP, "aes128-aes256-sha1-sha256", "aes256-aes128-sha256-sha1", "aes128-sha1" }, | |
89 | { PROTO_ESP, "aes256-aes128-sha256-sha1", "aes128-aes256-sha1-sha256", "aes256-sha256" }, | |
90 | { PROTO_ESP, "aes128-sha256-modp3072", "aes128-sha256", NULL }, | |
91 | { PROTO_ESP, "aes128-sha256", "aes128-sha256-modp3072", NULL }, | |
92 | { PROTO_ESP, "aes128-sha256-modp3072", "aes128-sha256-modpnone", NULL }, | |
93 | { PROTO_ESP, "aes128-sha256-modpnone", "aes128-sha256-modp3072", NULL }, | |
94 | { PROTO_ESP, "aes128-sha256-modp3072-modpnone", "aes128-sha256", "aes128-sha256" }, | |
95 | { PROTO_ESP, "aes128-sha256", "aes128-sha256-modp3072-modpnone", "aes128-sha256" }, | |
96 | { PROTO_ESP, "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072" }, | |
97 | { PROTO_ESP, "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone" }, | |
9b191d59 TB |
98 | { PROTO_IKE, "aes128-sha256-modp3072", "aes128-sha256-modp3072", "aes128-sha256-modp3072" }, |
99 | { PROTO_IKE, "aes128-sha256-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modp3072" }, | |
100 | { PROTO_IKE, "aes128-sha256-modp3072-modpnone", "aes128-sha256-modp3072", "aes128-sha256-modp3072" }, | |
aae95101 TB |
101 | }; |
102 | ||
103 | START_TEST(test_select) | |
104 | { | |
105 | proposal_t *self, *other, *selected, *expected; | |
106 | ||
9b191d59 | 107 | self = proposal_create_from_string(select_data[_i].proto, |
aae95101 | 108 | select_data[_i].self); |
9b191d59 | 109 | other = proposal_create_from_string(select_data[_i].proto, |
aae95101 TB |
110 | select_data[_i].other); |
111 | selected = self->select(self, other, FALSE); | |
112 | if (select_data[_i].expected) | |
113 | { | |
9b191d59 | 114 | expected = proposal_create_from_string(select_data[_i].proto, |
aae95101 TB |
115 | select_data[_i].expected); |
116 | ck_assert(selected); | |
117 | ck_assert_msg(expected->equals(expected, selected), "proposal %P does " | |
118 | "not match expected %P", selected, expected); | |
119 | expected->destroy(expected); | |
120 | } | |
121 | else | |
122 | { | |
123 | ck_assert(!selected); | |
124 | } | |
125 | DESTROY_IF(selected); | |
126 | other->destroy(other); | |
127 | self->destroy(self); | |
128 | } | |
129 | END_TEST | |
130 | ||
131 | Suite *proposal_suite_create() | |
132 | { | |
133 | Suite *s; | |
134 | TCase *tc; | |
135 | ||
136 | s = suite_create("proposal"); | |
137 | ||
9e5065d8 TB |
138 | tc = tcase_create("create_from_string"); |
139 | tcase_add_loop_test(tc, test_create_from_string, 0, countof(create_data)); | |
140 | suite_add_tcase(s, tc); | |
141 | ||
aae95101 TB |
142 | tc = tcase_create("select"); |
143 | tcase_add_loop_test(tc, test_select, 0, countof(select_data)); | |
144 | suite_add_tcase(s, tc); | |
145 | ||
146 | return s; | |
147 | } |