04ec28a61e9013c2bcf6512919dc43fc7ec0b9f0
[strongswan.git] / src / charon / config / proposal.c
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * 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 * $Id$
16 */
17
18 #include <string.h>
19
20 #include "proposal.h"
21
22 #include <daemon.h>
23 #include <utils/linked_list.h>
24 #include <utils/identification.h>
25 #include <utils/lexparser.h>
26 #include <crypto/prfs/prf.h>
27 #include <crypto/crypters/crypter.h>
28 #include <crypto/signers/signer.h>
29
30
31 ENUM(protocol_id_names, PROTO_NONE, PROTO_ESP,
32 "PROTO_NONE",
33 "IKE",
34 "AH",
35 "ESP",
36 );
37
38 ENUM_BEGIN(transform_type_names, UNDEFINED_TRANSFORM_TYPE, UNDEFINED_TRANSFORM_TYPE,
39 "UNDEFINED_TRANSFORM_TYPE");
40 ENUM_NEXT(transform_type_names, ENCRYPTION_ALGORITHM, EXTENDED_SEQUENCE_NUMBERS, UNDEFINED_TRANSFORM_TYPE,
41 "ENCRYPTION_ALGORITHM",
42 "PSEUDO_RANDOM_FUNCTION",
43 "INTEGRITY_ALGORITHM",
44 "DIFFIE_HELLMAN_GROUP",
45 "EXTENDED_SEQUENCE_NUMBERS");
46 ENUM_END(transform_type_names, EXTENDED_SEQUENCE_NUMBERS);
47
48 ENUM(extended_sequence_numbers_names, NO_EXT_SEQ_NUMBERS, EXT_SEQ_NUMBERS,
49 "NO_EXT_SEQ_NUMBERS",
50 "EXT_SEQ_NUMBERS",
51 );
52
53 typedef struct private_proposal_t private_proposal_t;
54
55 /**
56 * Private data of an proposal_t object
57 */
58 struct private_proposal_t {
59
60 /**
61 * Public part
62 */
63 proposal_t public;
64
65 /**
66 * protocol (ESP or AH)
67 */
68 protocol_id_t protocol;
69
70 /**
71 * priority ordered list of encryption algorithms
72 */
73 linked_list_t *encryption_algos;
74
75 /**
76 * priority ordered list of integrity algorithms
77 */
78 linked_list_t *integrity_algos;
79
80 /**
81 * priority ordered list of pseudo random functions
82 */
83 linked_list_t *prf_algos;
84
85 /**
86 * priority ordered list of dh groups
87 */
88 linked_list_t *dh_groups;
89
90 /**
91 * priority ordered list of extended sequence number flags
92 */
93 linked_list_t *esns;
94
95 /**
96 * senders SPI
97 */
98 u_int64_t spi;
99 };
100
101 /**
102 * Add algorithm/keysize to a algorithm list
103 */
104 static void add_algo(linked_list_t *list, u_int16_t algo, size_t key_size)
105 {
106 algorithm_t *algo_key;
107
108 algo_key = malloc_thing(algorithm_t);
109 algo_key->algorithm = algo;
110 algo_key->key_size = key_size;
111 list->insert_last(list, (void*)algo_key);
112 }
113
114 /**
115 * Implements proposal_t.add_algorithm
116 */
117 static void add_algorithm(private_proposal_t *this, transform_type_t type, u_int16_t algo, size_t key_size)
118 {
119 switch (type)
120 {
121 case ENCRYPTION_ALGORITHM:
122 add_algo(this->encryption_algos, algo, key_size);
123 break;
124 case INTEGRITY_ALGORITHM:
125 add_algo(this->integrity_algos, algo, key_size);
126 break;
127 case PSEUDO_RANDOM_FUNCTION:
128 add_algo(this->prf_algos, algo, key_size);
129 break;
130 case DIFFIE_HELLMAN_GROUP:
131 add_algo(this->dh_groups, algo, 0);
132 break;
133 case EXTENDED_SEQUENCE_NUMBERS:
134 add_algo(this->esns, algo, 0);
135 break;
136 default:
137 break;
138 }
139 }
140
141 /**
142 * Implements proposal_t.create_algorithm_iterator.
143 */
144 static iterator_t *create_algorithm_iterator(private_proposal_t *this, transform_type_t type)
145 {
146 switch (type)
147 {
148 case ENCRYPTION_ALGORITHM:
149 return this->encryption_algos->create_iterator(this->encryption_algos, TRUE);
150 case INTEGRITY_ALGORITHM:
151 return this->integrity_algos->create_iterator(this->integrity_algos, TRUE);
152 case PSEUDO_RANDOM_FUNCTION:
153 return this->prf_algos->create_iterator(this->prf_algos, TRUE);
154 case DIFFIE_HELLMAN_GROUP:
155 return this->dh_groups->create_iterator(this->dh_groups, TRUE);
156 case EXTENDED_SEQUENCE_NUMBERS:
157 return this->esns->create_iterator(this->esns, TRUE);
158 default:
159 break;
160 }
161 return NULL;
162 }
163
164 /**
165 * Implements proposal_t.get_algorithm.
166 */
167 static bool get_algorithm(private_proposal_t *this, transform_type_t type, algorithm_t** algo)
168 {
169 iterator_t *iterator = create_algorithm_iterator(this, type);
170 if (iterator->iterate(iterator, (void**)algo))
171 {
172 iterator->destroy(iterator);
173 return TRUE;
174 }
175 iterator->destroy(iterator);
176 return FALSE;
177 }
178
179 /**
180 * Implements proposal_t.has_dh_group
181 */
182 static bool has_dh_group(private_proposal_t *this, diffie_hellman_group_t group)
183 {
184 algorithm_t *current;
185 iterator_t *iterator;
186 bool result = FALSE;
187
188 iterator = this->dh_groups->create_iterator(this->dh_groups, TRUE);
189 if (iterator->get_count(iterator))
190 {
191 while (iterator->iterate(iterator, (void**)&current))
192 {
193 if (current->algorithm == group)
194 {
195 result = TRUE;
196 break;
197 }
198 }
199 }
200 else if (group == MODP_NONE)
201 {
202 result = TRUE;
203 }
204 iterator->destroy(iterator);
205 return result;
206 }
207
208 /**
209 * Find a matching alg/keysize in two linked lists
210 */
211 static bool select_algo(linked_list_t *first, linked_list_t *second, bool *add, u_int16_t *alg, size_t *key_size)
212 {
213 iterator_t *first_iter, *second_iter;
214 algorithm_t *first_alg, *second_alg;
215
216 /* if in both are zero algorithms specified, we HAVE a match */
217 if (first->get_count(first) == 0 && second->get_count(second) == 0)
218 {
219 *add = FALSE;
220 return TRUE;
221 }
222
223 first_iter = first->create_iterator(first, TRUE);
224 second_iter = second->create_iterator(second, TRUE);
225 /* compare algs, order of algs in "first" is preferred */
226 while (first_iter->iterate(first_iter, (void**)&first_alg))
227 {
228 second_iter->reset(second_iter);
229 while (second_iter->iterate(second_iter, (void**)&second_alg))
230 {
231 if (first_alg->algorithm == second_alg->algorithm &&
232 first_alg->key_size == second_alg->key_size)
233 {
234 /* ok, we have an algorithm */
235 *alg = first_alg->algorithm;
236 *key_size = first_alg->key_size;
237 *add = TRUE;
238 first_iter->destroy(first_iter);
239 second_iter->destroy(second_iter);
240 return TRUE;
241 }
242 }
243 }
244 /* no match in all comparisons */
245 first_iter->destroy(first_iter);
246 second_iter->destroy(second_iter);
247 return FALSE;
248 }
249
250 /**
251 * Implements proposal_t.select.
252 */
253 static proposal_t *select_proposal(private_proposal_t *this, private_proposal_t *other)
254 {
255 proposal_t *selected;
256 u_int16_t algo;
257 size_t key_size;
258 bool add;
259
260 DBG2(DBG_CFG, "selecting proposal:");
261
262 /* check protocol */
263 if (this->protocol != other->protocol)
264 {
265 DBG2(DBG_CFG, " protocol mismatch, skipping");
266 return NULL;
267 }
268
269 selected = proposal_create(this->protocol);
270
271 /* select encryption algorithm */
272 if (select_algo(this->encryption_algos, other->encryption_algos, &add, &algo, &key_size))
273 {
274 if (add)
275 {
276 selected->add_algorithm(selected, ENCRYPTION_ALGORITHM, algo, key_size);
277 }
278 }
279 else
280 {
281 selected->destroy(selected);
282 DBG2(DBG_CFG, " no acceptable ENCRYPTION_ALGORITHM found, skipping");
283 return NULL;
284 }
285 /* select integrity algorithm */
286 if (select_algo(this->integrity_algos, other->integrity_algos, &add, &algo, &key_size))
287 {
288 if (add)
289 {
290 selected->add_algorithm(selected, INTEGRITY_ALGORITHM, algo, key_size);
291 }
292 }
293 else
294 {
295 selected->destroy(selected);
296 DBG2(DBG_CFG, " no acceptable INTEGRITY_ALGORITHM found, skipping");
297 return NULL;
298 }
299 /* select prf algorithm */
300 if (select_algo(this->prf_algos, other->prf_algos, &add, &algo, &key_size))
301 {
302 if (add)
303 {
304 selected->add_algorithm(selected, PSEUDO_RANDOM_FUNCTION, algo, key_size);
305 }
306 }
307 else
308 {
309 selected->destroy(selected);
310 DBG2(DBG_CFG, " no acceptable PSEUDO_RANDOM_FUNCTION found, skipping");
311 return NULL;
312 }
313 /* select a DH-group */
314 if (select_algo(this->dh_groups, other->dh_groups, &add, &algo, &key_size))
315 {
316 if (add)
317 {
318 selected->add_algorithm(selected, DIFFIE_HELLMAN_GROUP, algo, 0);
319 }
320 }
321 else
322 {
323 selected->destroy(selected);
324 DBG2(DBG_CFG, " no acceptable DIFFIE_HELLMAN_GROUP found, skipping");
325 return NULL;
326 }
327 /* select if we use ESNs */
328 if (select_algo(this->esns, other->esns, &add, &algo, &key_size))
329 {
330 if (add)
331 {
332 selected->add_algorithm(selected, EXTENDED_SEQUENCE_NUMBERS, algo, 0);
333 }
334 }
335 else
336 {
337 selected->destroy(selected);
338 DBG2(DBG_CFG, " no acceptable EXTENDED_SEQUENCE_NUMBERS found, skipping");
339 return NULL;
340 }
341 DBG2(DBG_CFG, " proposal matches");
342
343 /* apply SPI from "other" */
344 selected->set_spi(selected, other->spi);
345
346 /* everything matched, return new proposal */
347 return selected;
348 }
349
350 /**
351 * Implements proposal_t.get_protocols.
352 */
353 static protocol_id_t get_protocol(private_proposal_t *this)
354 {
355 return this->protocol;
356 }
357
358 /**
359 * Implements proposal_t.set_spi.
360 */
361 static void set_spi(private_proposal_t *this, u_int64_t spi)
362 {
363 this->spi = spi;
364 }
365
366 /**
367 * Implements proposal_t.get_spi.
368 */
369 static u_int64_t get_spi(private_proposal_t *this)
370 {
371 return this->spi;
372 }
373
374 /**
375 * Clone a algorithm list
376 */
377 static void clone_algo_list(linked_list_t *list, linked_list_t *clone_list)
378 {
379 algorithm_t *algo, *clone_algo;
380 iterator_t *iterator = list->create_iterator(list, TRUE);
381 while (iterator->iterate(iterator, (void**)&algo))
382 {
383 clone_algo = malloc_thing(algorithm_t);
384 memcpy(clone_algo, algo, sizeof(algorithm_t));
385 clone_list->insert_last(clone_list, (void*)clone_algo);
386 }
387 iterator->destroy(iterator);
388 }
389
390 /**
391 * Implements proposal_t.clone
392 */
393 static proposal_t *clone_(private_proposal_t *this)
394 {
395 private_proposal_t *clone = (private_proposal_t*)proposal_create(this->protocol);
396
397 clone_algo_list(this->encryption_algos, clone->encryption_algos);
398 clone_algo_list(this->integrity_algos, clone->integrity_algos);
399 clone_algo_list(this->prf_algos, clone->prf_algos);
400 clone_algo_list(this->dh_groups, clone->dh_groups);
401 clone_algo_list(this->esns, clone->esns);
402
403 clone->spi = this->spi;
404
405 return &clone->public;
406 }
407
408 /**
409 * add a algorithm identified by a string to the proposal.
410 * TODO: we could use gperf here.
411 */
412 static status_t add_string_algo(private_proposal_t *this, chunk_t alg)
413 {
414 if (strncmp(alg.ptr, "null", alg.len) == 0)
415 {
416 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_NULL, 0);
417 }
418 else if (strncmp(alg.ptr, "aes128", alg.len) == 0)
419 {
420 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 128);
421 }
422 else if (strncmp(alg.ptr, "aes192", alg.len) == 0)
423 {
424 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 192);
425 }
426 else if (strncmp(alg.ptr, "aes256", alg.len) == 0)
427 {
428 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 256);
429 }
430 else if (strncmp(alg.ptr, "3des", alg.len) == 0)
431 {
432 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
433 }
434 /* blowfish only uses some predefined key sizes yet */
435 else if (strncmp(alg.ptr, "blowfish128", alg.len) == 0)
436 {
437 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 128);
438 }
439 else if (strncmp(alg.ptr, "blowfish192", alg.len) == 0)
440 {
441 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 192);
442 }
443 else if (strncmp(alg.ptr, "blowfish256", alg.len) == 0)
444 {
445 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 256);
446 }
447 else if (strncmp(alg.ptr, "sha", alg.len) == 0 ||
448 strncmp(alg.ptr, "sha1", alg.len) == 0)
449 {
450 /* sha means we use SHA for both, PRF and AUTH */
451 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
452 if (this->protocol == PROTO_IKE)
453 {
454 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA1, 0);
455 }
456 }
457 else if (strncmp(alg.ptr, "sha256", alg.len) == 0 ||
458 strncmp(alg.ptr, "sha2_256", alg.len) == 0)
459 {
460 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_256_128, 0);
461 if (this->protocol == PROTO_IKE)
462 {
463 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_256, 0);
464 }
465 }
466 else if (strncmp(alg.ptr, "sha384", alg.len) == 0 ||
467 strncmp(alg.ptr, "sha2_384", alg.len) == 0)
468 {
469 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_384_192, 0);
470 if (this->protocol == PROTO_IKE)
471 {
472 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_384, 0);
473 }
474 }
475 else if (strncmp(alg.ptr, "sha512", alg.len) == 0 ||
476 strncmp(alg.ptr, "sha2_512", alg.len) == 0)
477 {
478 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_512_256, 0);
479 if (this->protocol == PROTO_IKE)
480 {
481 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_512, 0);
482 }
483 }
484 else if (strncmp(alg.ptr, "md5", alg.len) == 0)
485 {
486 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0);
487 if (this->protocol == PROTO_IKE)
488 {
489 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_MD5, 0);
490 }
491 }
492 else if (strncmp(alg.ptr, "aesxcbc", alg.len) == 0)
493 {
494 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_AES_XCBC_96, 0);
495 if (this->protocol == PROTO_IKE)
496 {
497 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, AUTH_AES_XCBC_96, 0);
498 }
499 }
500 else if (strncmp(alg.ptr, "modp768", alg.len) == 0)
501 {
502 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_768_BIT, 0);
503 }
504 else if (strncmp(alg.ptr, "modp1024", alg.len) == 0)
505 {
506 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
507 }
508 else if (strncmp(alg.ptr, "modp1536", alg.len) == 0)
509 {
510 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_1536_BIT, 0);
511 }
512 else if (strncmp(alg.ptr, "modp2048", alg.len) == 0)
513 {
514 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
515 }
516 else if (strncmp(alg.ptr, "modp4096", alg.len) == 0)
517 {
518 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_4096_BIT, 0);
519 }
520 else if (strncmp(alg.ptr, "modp8192", alg.len) == 0)
521 {
522 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_8192_BIT, 0);
523 }
524 else
525 {
526 return FAILED;
527 }
528 return SUCCESS;
529 }
530
531 /**
532 * Implements proposal_t.destroy.
533 */
534 static void destroy(private_proposal_t *this)
535 {
536 this->encryption_algos->destroy_function(this->encryption_algos, free);
537 this->integrity_algos->destroy_function(this->integrity_algos, free);
538 this->prf_algos->destroy_function(this->prf_algos, free);
539 this->dh_groups->destroy_function(this->dh_groups, free);
540 this->esns->destroy_function(this->esns, free);
541 free(this);
542 }
543
544 /*
545 * Describtion in header-file
546 */
547 proposal_t *proposal_create(protocol_id_t protocol)
548 {
549 private_proposal_t *this = malloc_thing(private_proposal_t);
550
551 this->public.add_algorithm = (void (*)(proposal_t*,transform_type_t,u_int16_t,size_t))add_algorithm;
552 this->public.create_algorithm_iterator = (iterator_t* (*)(proposal_t*,transform_type_t))create_algorithm_iterator;
553 this->public.get_algorithm = (bool (*)(proposal_t*,transform_type_t,algorithm_t**))get_algorithm;
554 this->public.has_dh_group = (bool (*)(proposal_t*,diffie_hellman_group_t))has_dh_group;
555 this->public.select = (proposal_t* (*)(proposal_t*,proposal_t*))select_proposal;
556 this->public.get_protocol = (protocol_id_t(*)(proposal_t*))get_protocol;
557 this->public.set_spi = (void(*)(proposal_t*,u_int64_t))set_spi;
558 this->public.get_spi = (u_int64_t(*)(proposal_t*))get_spi;
559 this->public.clone = (proposal_t*(*)(proposal_t*))clone_;
560 this->public.destroy = (void(*)(proposal_t*))destroy;
561
562 this->spi = 0;
563 this->protocol = protocol;
564
565 this->encryption_algos = linked_list_create();
566 this->integrity_algos = linked_list_create();
567 this->prf_algos = linked_list_create();
568 this->dh_groups = linked_list_create();
569 this->esns = linked_list_create();
570
571 return &this->public;
572 }
573
574 /*
575 * Describtion in header-file
576 */
577 proposal_t *proposal_create_default(protocol_id_t protocol)
578 {
579 private_proposal_t *this = (private_proposal_t*)proposal_create(protocol);
580
581 switch (protocol)
582 {
583 case PROTO_IKE:
584 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 128);
585 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 192);
586 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 256);
587 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
588 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_256_128, 0);
589 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
590 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0);
591 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_384_192, 0);
592 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA2_512_256, 0);
593 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_256, 0);
594 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA1, 0);
595 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_MD5, 0);
596 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_384, 0);
597 add_algorithm(this, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA2_512, 0);
598 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
599 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_1536_BIT, 0);
600 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
601 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_4096_BIT, 0);
602 add_algorithm(this, DIFFIE_HELLMAN_GROUP, MODP_8192_BIT, 0);
603 break;
604 case PROTO_ESP:
605 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 128);
606 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 192);
607 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 256);
608 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
609 add_algorithm(this, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 256);
610 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
611 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_AES_XCBC_96, 0);
612 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0);
613 add_algorithm(this, EXTENDED_SEQUENCE_NUMBERS, NO_EXT_SEQ_NUMBERS, 0);
614 break;
615 case PROTO_AH:
616 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
617 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_AES_XCBC_96, 0);
618 add_algorithm(this, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0);
619 add_algorithm(this, EXTENDED_SEQUENCE_NUMBERS, NO_EXT_SEQ_NUMBERS, 0);
620 break;
621 default:
622 break;
623 }
624
625 return &this->public;
626 }
627
628 /*
629 * Describtion in header-file
630 */
631 proposal_t *proposal_create_from_string(protocol_id_t protocol, const char *algs)
632 {
633 private_proposal_t *this = (private_proposal_t*)proposal_create(protocol);
634 chunk_t string = {(void*)algs, strlen(algs)};
635 chunk_t alg;
636 status_t status = SUCCESS;
637
638 eat_whitespace(&string);
639 if (string.len < 1)
640 {
641 destroy(this);
642 return NULL;
643 }
644
645 /* get all tokens, separated by '-' */
646 while (extract_token(&alg, '-', &string))
647 {
648 status |= add_string_algo(this, alg);
649 }
650 if (string.len)
651 {
652 status |= add_string_algo(this, string);
653 }
654 if (status != SUCCESS)
655 {
656 destroy(this);
657 return NULL;
658 }
659
660 if (protocol == PROTO_AH || protocol == PROTO_ESP)
661 {
662 add_algorithm(this, EXTENDED_SEQUENCE_NUMBERS, NO_EXT_SEQ_NUMBERS, 0);
663 }
664 return &this->public;
665 }