- added ts for both initator and responder
[strongswan.git] / Source / charon / config / sa_config.h
1 /**
2 * @file sa_config.h
3 *
4 * @brief Interface of sa_config_t.
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 #ifndef _SA_CONFIG_H_
24 #define _SA_CONFIG_H_
25
26 #include <types.h>
27 #include <utils/identification.h>
28 #include <encoding/payloads/auth_payload.h>
29 #include <encoding/payloads/transform_substructure.h>
30 #include <network/host.h>
31 #include <transforms/crypters/crypter.h>
32 #include <transforms/signers/signer.h>
33 #include <transforms/diffie_hellman.h>
34 #include <config/traffic_selector.h>
35
36
37 typedef struct child_proposal_t child_proposal_t;
38
39 /**
40 * @brief Storage structure for a proposal for a child sa.
41 *
42 * A proposal for a child sa contains data for
43 * AH, ESP, or both.
44 *
45 * @ingroup config
46 */
47 struct child_proposal_t {
48
49 /**
50 * Data for AH, if set
51 */
52 struct {
53 bool is_set;
54 integrity_algorithm_t integrity_algorithm;
55 size_t integrity_algorithm_key_size;
56 diffie_hellman_group_t diffie_hellman_group;
57 extended_sequence_numbers_t extended_sequence_numbers;
58 u_int8_t spi[4];
59 } ah;
60
61 /**
62 * data for ESP, if set
63 */
64 struct {
65 bool is_set;
66 encryption_algorithm_t encryption_algorithm;
67 size_t encryption_algorithm_key_size;
68 integrity_algorithm_t integrity_algorithm;
69 size_t integrity_algorithm_key_size;
70 diffie_hellman_group_t diffie_hellman_group;
71 extended_sequence_numbers_t extended_sequence_numbers;
72 u_int8_t spi[4];
73 } esp;
74 };
75
76
77 typedef struct sa_config_t sa_config_t;
78
79 /**
80 * @brief Stores configuration of an initialized connection.
81 *
82 * During the IKE_AUTH phase, we have enought data to specify a
83 * configuration.
84 *
85 * @warning This config is not thread save.
86 *
87 * @ingroup config
88 */
89 struct sa_config_t {
90
91 /**
92 * @brief Get own id to use for identification.
93 *
94 * @param this calling object
95 * @return own id
96 */
97 identification_t *(*get_my_id) (sa_config_t *this);
98
99 /**
100 * @brief Get id of communication partner..
101 *
102 * @param this calling object
103 * @return other id
104 */
105 identification_t *(*get_other_id) (sa_config_t *this);
106
107 /**
108 * @brief Get authentication method to use for IKE_AUTH.
109 *
110 * @param this calling object
111 * @return authentication methood
112 */
113 auth_method_t (*get_auth_method) (sa_config_t *this);
114
115 /**
116 * @brief Get configured traffic selectors for initiator site.
117 *
118 * Returns a pointer to an allocated array, in which
119 * pointers to traffic selectors are stored.
120 *
121 * @warning Resulting pointer array must be freed!
122 * @warning Traffic selectors in array must be destroyed!
123 *
124 * @param this calling object
125 * @param[out]traffic_selectors pointer where traffic selectors will be allocated
126 * @return number of returned traffic selectors
127 */
128 size_t (*get_traffic_selectors_initiator) (sa_config_t *this, traffic_selector_t **traffic_selectors[]);
129
130
131 /**
132 * @brief Get configured traffic selectors for responder site.
133 *
134 * Returns a pointer to an allocated array, in which
135 * pointers to traffic selectors are stored.
136 *
137 * @warning Resulting pointer array must be freed!
138 * @warning Traffic selectors in array must be destroyed!
139 *
140 * @param this calling object
141 * @param[out]traffic_selectors pointer where traffic selectors will be allocated
142 * @return number of returned traffic selectors
143 */
144 size_t (*get_traffic_selectors_responder) (sa_config_t *this, traffic_selector_t **traffic_selectors[]);
145
146 /**
147 * @brief Select traffic selectors from a supplied list for initiator.
148 *
149 * Returns a pointer to an allocated array, in which
150 * pointers to traffic selectors are stored.
151 *
152 * @warning Resulting pointer array must be freed!
153 * @warning Traffic selectors in array must be destroyed!
154 *
155 * @param this calling object
156 * @param supplied pointer to an array of ts to select from.
157 * @param count number of ts stored at supplied
158 * @param[out]traffic_selectors pointer where selected traffic selectors will be allocated
159 * @return number of selected traffic selectors
160 */
161 size_t (*select_traffic_selectors_initiator) (sa_config_t *this, traffic_selector_t *supplied[], size_t count, traffic_selector_t **selected[]);
162
163 /**
164 * @brief Select traffic selectors from a supplied list for responder.
165 *
166 * Returns a pointer to an allocated array, in which
167 * pointers to traffic selectors are stored.
168 *
169 * @warning Resulting pointer array must be freed!
170 * @warning Traffic selectors in array must be destroyed!
171 *
172 * @param this calling object
173 * @param supplied pointer to an array of ts to select from.
174 * @param count number of ts stored at supplied
175 * @param[out]traffic_selectors pointer where selected traffic selectors will be allocated
176 * @return number of selected traffic selectors
177 */
178 size_t (*select_traffic_selectors_responder) (sa_config_t *this, traffic_selector_t *supplied[], size_t count, traffic_selector_t **selected[]);
179
180 /**
181 * @brief Get the list of proposals for this config.
182 *
183 * @warning Resulting array must be freed!
184 *
185 * @param this calling object
186 * @param[out]traffic_selectors pointer where proposals will be allocated
187 * @return number of allocated proposals
188 */
189 size_t (*get_proposals) (sa_config_t *this, u_int8_t ah_spi[4], u_int8_t esp_spi[4], child_proposal_t *proposals[]);
190
191 /**
192 * @brief Select a proposal from a supplied list
193 *
194 * @warning Resulting array must be freed!
195 *
196 * @param this calling object
197 * @param supplied pointer to an array of proposals to select from.
198 * @param count number of proposals stored at supplied
199 * @return the selected proposal
200 */
201 child_proposal_t* (*select_proposal) (sa_config_t *this, u_int8_t ah_spi[4], u_int8_t esp_spi[4], child_proposal_t *supplied, size_t count);
202
203 /**
204 * @brief Add a traffic selector to the list for initiator.
205 *
206 * Added proposal will be cloned.
207 *
208 * @warning Do not add while other threads are reading.
209 *
210 * @param this calling object
211 * @param traffic_selector traffic_selector to add
212 */
213 void (*add_traffic_selector_initiator) (sa_config_t *this, traffic_selector_t *traffic_selector);
214
215 /**
216 * @brief Add a traffic selector to the list for responder.
217 *
218 * Added proposal will be cloned.
219 *
220 * @warning Do not add while other threads are reading.
221 *
222 * @param this calling object
223 * @param traffic_selector traffic_selector to add
224 */
225 void (*add_traffic_selector_responder) (sa_config_t *this, traffic_selector_t *traffic_selector);
226
227 /**
228 * @brief Add a proposal to the list.
229 *
230 * The proposals are stored by priority, first added
231 * is the most prefered.
232 * Added proposal will be cloned.
233 *
234 * @warning Do not add while other threads are reading.
235 *
236 * @param this calling object
237 * @param proposal proposal to add
238 */
239 void (*add_proposal) (sa_config_t *this, child_proposal_t *proposal);
240
241 /**
242 * @brief Destroys the config object
243 *
244 *
245 * @param this calling object
246 */
247 void (*destroy) (sa_config_t *this);
248 };
249
250 /**
251 * @brief Create a configuration object for IKE_AUTH and later.
252 *
253 * @return created sa_config_t
254 *
255 * @ingroup config
256 */
257 sa_config_t *sa_config_create();
258
259 #endif //_SA_CONFIG_H_