2 * @file configuration.c
4 * @brief Configuration class used to store IKE_SA-configurations.
6 * Object of this type represents a configuration for an IKE_SA and its child_sa's.
11 * Copyright (C) 2005 Jan Hutter, Martin Willi
12 * Hochschule fuer Technik Rapperswil
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 #include "configuration_manager.h"
30 #include "utils/allocator.h"
31 #include "payloads/nonce_payload.h"
32 #include "payloads/proposal_substructure.h"
33 #include "payloads/ke_payload.h"
34 #include "payloads/transform_attribute.h"
37 * Private data of an configuration_t object
39 typedef struct private_configuration_manager_s private_configuration_manager_t
;
41 struct private_configuration_manager_s
{
46 configuration_manager_t
public;
50 static status_t
get_remote_host(private_configuration_manager_t
*this, char *name
, host_t
**host
)
52 /* some hard coded users for testing */
54 if (strcmp(name
, "pinflb30") == 0) {
55 remote
= host_create(AF_INET
, "152.96.193.130", 500);
62 else if (strcmp(name
, "pinflb31") == 0) {
63 remote
= host_create(AF_INET
, "152.96.193.131", 500);
73 static status_t
get_local_host(private_configuration_manager_t
*this, char *name
, host_t
**host
)
75 /* use default route for now */
77 local
= host_create(AF_INET
, "0.0.0.0", 0);
86 static status_t
get_dh_group_number(private_configuration_manager_t
*this,char *name
, u_int16_t
*dh_group_number
, u_int16_t priority
)
88 *dh_group_number
= MODP_1024_BIT
;
92 static status_t
get_proposals_for_host(private_configuration_manager_t
*this, host_t
*host
, linked_list_iterator_t
*iterator
)
94 /* use a default proposal:
95 * - ENCR_AES_CBC 128Bit
96 * - PRF_HMAC_SHA1 128Bit
97 * - AUTH_HMAC_SHA1_96 96Bit
100 proposal_substructure_t
*proposal
;
101 transform_substructure_t
*transform
;
102 transform_attribute_t
*attribute
;
105 proposal
= proposal_substructure_create();
106 if (proposal
== NULL
)
111 proposal
->set_proposal_number(proposal
, 1);
112 proposal
->set_protocol_id(proposal
, 1);
115 * Encryption Algorithm
117 transform
= transform_substructure_create();
118 if (transform
== NULL
)
120 proposal
->destroy(proposal
);
123 status
= proposal
->add_transform_substructure(proposal
, transform
);
124 if (status
!= SUCCESS
)
126 proposal
->destroy(proposal
);
129 transform
->set_transform_type(transform
, ENCRYPTION_ALGORITHM
);
130 transform
->set_transform_id(transform
, ENCR_AES_CBC
);
132 attribute
= transform_attribute_create();
133 if (attribute
== NULL
)
135 proposal
->destroy(proposal
);
138 status
= transform
->add_transform_attribute(transform
, attribute
);
139 if (status
!= SUCCESS
)
141 proposal
->destroy(proposal
);
144 attribute
->set_attribute_type(attribute
, KEY_LENGTH
);
145 attribute
->set_value(attribute
, 16);
148 * Pseudo-random Function
150 transform
= transform_substructure_create();
151 if (transform
== NULL
)
153 proposal
->destroy(proposal
);
156 status
= proposal
->add_transform_substructure(proposal
, transform
);
157 if (status
!= SUCCESS
)
159 proposal
->destroy(proposal
);
162 transform
->set_transform_type(transform
, PSEUDO_RANDOM_FUNCTION
);
163 transform
->set_transform_id(transform
, PRF_HMAC_MD5
);
165 attribute
= transform_attribute_create();
166 if (attribute
== NULL
)
168 proposal
->destroy(proposal
);
171 status
= transform
->add_transform_attribute(transform
, attribute
);
172 if (status
!= SUCCESS
)
174 proposal
->destroy(proposal
);
177 attribute
->set_attribute_type(attribute
, KEY_LENGTH
);
178 attribute
->set_value(attribute
, 16);
182 * Integrity Algorithm
184 transform
= transform_substructure_create();
185 if (transform
== NULL
)
187 proposal
->destroy(proposal
);
190 status
= proposal
->add_transform_substructure(proposal
, transform
);
191 if (status
!= SUCCESS
)
193 proposal
->destroy(proposal
);
196 transform
->set_transform_type(transform
, INTEGRITIY_ALGORITHM
);
197 transform
->set_transform_id(transform
, AUTH_HMAC_MD5_96
);
199 attribute
= transform_attribute_create();
200 if (attribute
== NULL
)
202 proposal
->destroy(proposal
);
205 status
= transform
->add_transform_attribute(transform
, attribute
);
206 if (status
!= SUCCESS
)
208 proposal
->destroy(proposal
);
211 attribute
->set_attribute_type(attribute
, KEY_LENGTH
);
212 attribute
->set_value(attribute
, 16);
216 * Diffie-Hellman Group
218 transform
= transform_substructure_create();
219 if (transform
== NULL
)
221 proposal
->destroy(proposal
);
224 status
= proposal
->add_transform_substructure(proposal
, transform
);
225 if (status
!= SUCCESS
)
227 proposal
->destroy(proposal
);
230 transform
->set_transform_type(transform
, DIFFIE_HELLMAN_GROUP
);
231 transform
->set_transform_id(transform
, MODP_1024_BIT
);
233 iterator
->insert_after(iterator
, (void*)proposal
);
238 static status_t
select_proposals_for_host(private_configuration_manager_t
*this, host_t
*host
, linked_list_iterator_t
*in
, linked_list_iterator_t
*out
)
240 /* use a default proposal:
241 * - ENCR_AES_CBC 128Bit
242 * - PRF_HMAC_SHA1 128Bit
243 * - AUTH_HMAC_SHA1_96 96Bit
246 proposal_substructure_t
*proposal
;
247 transform_substructure_t
*transform
;
248 transform_attribute_t
*attribute
;
251 proposal
= proposal_substructure_create();
252 if (proposal
== NULL
)
257 proposal
->set_proposal_number(proposal
, 1);
258 proposal
->set_protocol_id(proposal
, 1);
261 * Encryption Algorithm
263 transform
= transform_substructure_create();
264 if (transform
== NULL
)
266 proposal
->destroy(proposal
);
269 status
= proposal
->add_transform_substructure(proposal
, transform
);
270 if (status
!= SUCCESS
)
272 proposal
->destroy(proposal
);
275 transform
->set_transform_type(transform
, ENCRYPTION_ALGORITHM
);
276 transform
->set_transform_id(transform
, ENCR_AES_CBC
);
278 attribute
= transform_attribute_create();
279 if (attribute
== NULL
)
281 proposal
->destroy(proposal
);
284 status
= transform
->add_transform_attribute(transform
, attribute
);
285 if (status
!= SUCCESS
)
287 proposal
->destroy(proposal
);
290 attribute
->set_attribute_type(attribute
, KEY_LENGTH
);
291 attribute
->set_value(attribute
, 16);
294 * Pseudo-random Function
296 transform
= transform_substructure_create();
297 if (transform
== NULL
)
299 proposal
->destroy(proposal
);
302 status
= proposal
->add_transform_substructure(proposal
, transform
);
303 if (status
!= SUCCESS
)
305 proposal
->destroy(proposal
);
308 transform
->set_transform_type(transform
, PSEUDO_RANDOM_FUNCTION
);
309 transform
->set_transform_id(transform
, PRF_HMAC_MD5
);
311 attribute
= transform_attribute_create();
312 if (attribute
== NULL
)
314 proposal
->destroy(proposal
);
317 status
= transform
->add_transform_attribute(transform
, attribute
);
318 if (status
!= SUCCESS
)
320 proposal
->destroy(proposal
);
323 attribute
->set_attribute_type(attribute
, KEY_LENGTH
);
324 attribute
->set_value(attribute
, 16);
328 * Integrity Algorithm
330 transform
= transform_substructure_create();
331 if (transform
== NULL
)
333 proposal
->destroy(proposal
);
336 status
= proposal
->add_transform_substructure(proposal
, transform
);
337 if (status
!= SUCCESS
)
339 proposal
->destroy(proposal
);
342 transform
->set_transform_type(transform
, INTEGRITIY_ALGORITHM
);
343 transform
->set_transform_id(transform
, AUTH_HMAC_MD5_96
);
345 attribute
= transform_attribute_create();
346 if (attribute
== NULL
)
348 proposal
->destroy(proposal
);
351 status
= transform
->add_transform_attribute(transform
, attribute
);
352 if (status
!= SUCCESS
)
354 proposal
->destroy(proposal
);
357 attribute
->set_attribute_type(attribute
, KEY_LENGTH
);
358 attribute
->set_value(attribute
, 16);
362 * Diffie-Hellman Group
364 transform
= transform_substructure_create();
365 if (transform
== NULL
)
367 proposal
->destroy(proposal
);
370 status
= proposal
->add_transform_substructure(proposal
, transform
);
371 if (status
!= SUCCESS
)
373 proposal
->destroy(proposal
);
376 transform
->set_transform_type(transform
, DIFFIE_HELLMAN_GROUP
);
377 transform
->set_transform_id(transform
, MODP_1024_BIT
);
379 out
->insert_after(out
, (void*)proposal
);
384 static status_t
is_dh_group_allowed_for_host(private_configuration_manager_t
*this, host_t
*host
, diffie_hellman_group_t group
, bool *allowed
)
386 if (group
== MODP_768_BIT
||
387 group
== MODP_1024_BIT
)
397 * Implements function destroy of configuration_t.
398 * See #configuration_s.destroy for description.
400 static status_t
destroy(private_configuration_manager_t
*this)
402 allocator_free(this);
407 * Described in header-file
409 configuration_manager_t
*configuration_manager_create()
411 private_configuration_manager_t
*this = allocator_alloc_thing(private_configuration_manager_t
);
417 /* public functions */
418 this->public.destroy
= (status_t(*)(configuration_manager_t
*))destroy
;
419 this->public.get_remote_host
= (status_t(*)(configuration_manager_t
*,char*,host_t
**))get_remote_host
;
420 this->public.get_local_host
= (status_t(*)(configuration_manager_t
*,char*,host_t
**))get_local_host
;
421 this->public.get_dh_group_number
= (status_t(*)(configuration_manager_t
*,char*,u_int16_t
*, u_int16_t
))get_dh_group_number
;
422 this->public.get_proposals_for_host
= (status_t(*)(configuration_manager_t
*,host_t
*,linked_list_iterator_t
*))get_proposals_for_host
;
423 this->public.select_proposals_for_host
= (status_t(*)(configuration_manager_t
*,host_t
*,linked_list_iterator_t
*,linked_list_iterator_t
*))select_proposals_for_host
;
424 this->public.is_dh_group_allowed_for_host
= (status_t(*)(configuration_manager_t
*,host_t
*,diffie_hellman_group_t
,bool*)) is_dh_group_allowed_for_host
;
426 return (&this->public);