- creation of ts payloads using ts
[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.
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) (sa_config_t *this, traffic_selector_t **traffic_selectors[]);
129
130 /**
131 * @brief Select traffic selectors from a supplied list.
132 *
133 * Returns a pointer to an allocated array, in which
134 * pointers to traffic selectors are stored.
135 *
136 * @warning Resulting pointer array must be freed!
137 * @warning Traffic selectors in array must be destroyed!
138 *
139 * @param this calling object
140 * @param supplied pointer to an array of ts to select from.
141 * @param count number of ts stored at supplied
142 * @param[out]traffic_selectors pointer where selected traffic selectors will be allocated
143 * @return number of selected traffic selectors
144 */
145 size_t (*select_traffic_selectors) (sa_config_t *this, traffic_selector_t *supplied[], size_t count, traffic_selector_t **selected[]);
146
147 /**
148 * @brief Get the list of proposals for this config.
149 *
150 * @warning Resulting array must be freed!
151 *
152 * @param this calling object
153 * @param[out]traffic_selectors pointer where proposals will be allocated
154 * @return number of allocated proposals
155 */
156 size_t (*get_proposals) (sa_config_t *this, u_int8_t ah_spi[4], u_int8_t esp_spi[4], child_proposal_t *proposals[]);
157
158 /**
159 * @brief Select a proposal from a supplied list
160 *
161 * @warning Resulting array must be freed!
162 *
163 * @param this calling object
164 * @param supplied pointer to an array of proposals to select from.
165 * @param count number of proposals stored at supplied
166 * @return the selected proposal
167 */
168 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);
169
170 /**
171 * @brief Add a traffic selector to the list.
172 *
173 * Added proposal will be cloned.
174 *
175 * @warning Do not add while other threads are reading.
176 *
177 * @param this calling object
178 * @param traffic_selector traffic_selector to add
179 */
180 void (*add_traffic_selector) (sa_config_t *this, traffic_selector_t *traffic_selector);
181
182 /**
183 * @brief Add a proposal to the list.
184 *
185 * The proposals are stored by priority, first added
186 * is the most prefered.
187 * Added proposal will be cloned.
188 *
189 * @warning Do not add while other threads are reading.
190 *
191 * @param this calling object
192 * @param proposal proposal to add
193 */
194 void (*add_proposal) (sa_config_t *this, child_proposal_t *proposal);
195
196 /**
197 * @brief Destroys the config object
198 *
199 *
200 * @param this calling object
201 */
202 void (*destroy) (sa_config_t *this);
203 };
204
205 /**
206 * @brief Create a configuration object for IKE_AUTH and later.
207 *
208 * @return created sa_config_t
209 *
210 * @ingroup config
211 */
212 sa_config_t *sa_config_create();
213
214 #endif //_SA_CONFIG_H_