Use different return values in payload decryption to distinguish between integrity...
[strongswan.git] / src / libcharon / encoding / message.c
1 /*
2 * Copyright (C) 2006-2007 Tobias Brunner
3 * Copyright (C) 2005-2010 Martin Willi
4 * Copyright (C) 2010 revosec AG
5 * Copyright (C) 2006 Daniel Roethlisberger
6 * Copyright (C) 2005 Jan Hutter
7 * Hochschule fuer Technik Rapperswil
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
18 */
19
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include "message.h"
24
25 #include <library.h>
26 #include <daemon.h>
27 #include <sa/ike_sa_id.h>
28 #include <encoding/generator.h>
29 #include <encoding/parser.h>
30 #include <utils/linked_list.h>
31 #include <encoding/payloads/encodings.h>
32 #include <encoding/payloads/payload.h>
33 #include <encoding/payloads/encryption_payload.h>
34 #include <encoding/payloads/unknown_payload.h>
35 #include <encoding/payloads/cp_payload.h>
36
37 /**
38 * Max number of notify payloads per IKEv2 Message
39 */
40 #define MAX_NOTIFY_PAYLOADS 20
41
42 /**
43 * Max number of delete payloads per IKEv2 Message
44 */
45 #define MAX_DELETE_PAYLOADS 20
46
47 /**
48 * A payload rule defines the rules for a payload
49 * in a specific message rule. It defines if and how
50 * many times a payload must/can occur in a message
51 * and if it must be encrypted.
52 */
53 typedef struct {
54 /* Payload type */
55 payload_type_t type;
56 /* Minimal occurence of this payload. */
57 size_t min_occurence;
58 /* Max occurence of this payload. */
59 size_t max_occurence;
60 /* TRUE if payload must be encrypted */
61 bool encrypted;
62 /* If payload occurs, the message rule is fullfilled */
63 bool sufficient;
64 } payload_rule_t;
65
66 /**
67 * payload ordering structure allows us to reorder payloads according to RFC.
68 */
69 typedef struct {
70 /** payload type */
71 payload_type_t type;
72 /** notify type, if payload == NOTIFY */
73 notify_type_t notify;
74 } payload_order_t;
75
76 /**
77 * A message rule defines the kind of a message,
78 * if it has encrypted contents and a list
79 * of payload ordering rules and payload parsing rules.
80 */
81 typedef struct {
82 /** Type of message. */
83 exchange_type_t exchange_type;
84 /** Is message a request or response. */
85 bool is_request;
86 /** Message contains encrypted payloads. */
87 bool encrypted;
88 /** Number of payload rules which will follow */
89 int rule_count;
90 /** Pointer to first payload rule */
91 payload_rule_t *rules;
92 /** Number of payload order rules */
93 int order_count;
94 /** payload ordering rules */
95 payload_order_t *order;
96 } message_rule_t;
97
98 /**
99 * Message rule for IKE_SA_INIT from initiator.
100 */
101 static payload_rule_t ike_sa_init_i_rules[] = {
102 /* payload type min max encr suff */
103 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, FALSE, FALSE},
104 {SECURITY_ASSOCIATION, 1, 1, FALSE, FALSE},
105 {KEY_EXCHANGE, 1, 1, FALSE, FALSE},
106 {NONCE, 1, 1, FALSE, FALSE},
107 {VENDOR_ID, 0, 10, FALSE, FALSE},
108 };
109
110 /**
111 * payload order for IKE_SA_INIT initiator
112 */
113 static payload_order_t ike_sa_init_i_order[] = {
114 /* payload type notify type */
115 {NOTIFY, COOKIE},
116 {SECURITY_ASSOCIATION, 0},
117 {KEY_EXCHANGE, 0},
118 {NONCE, 0},
119 {NOTIFY, NAT_DETECTION_SOURCE_IP},
120 {NOTIFY, NAT_DETECTION_DESTINATION_IP},
121 {NOTIFY, 0},
122 {VENDOR_ID, 0},
123 };
124
125 /**
126 * Message rule for IKE_SA_INIT from responder.
127 */
128 static payload_rule_t ike_sa_init_r_rules[] = {
129 /* payload type min max encr suff */
130 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, FALSE, TRUE},
131 {SECURITY_ASSOCIATION, 1, 1, FALSE, FALSE},
132 {KEY_EXCHANGE, 1, 1, FALSE, FALSE},
133 {NONCE, 1, 1, FALSE, FALSE},
134 {VENDOR_ID, 0, 10, FALSE, FALSE},
135 };
136
137 /**
138 * payload order for IKE_SA_INIT responder
139 */
140 static payload_order_t ike_sa_init_r_order[] = {
141 /* payload type notify type */
142 {SECURITY_ASSOCIATION, 0},
143 {KEY_EXCHANGE, 0},
144 {NONCE, 0},
145 {NOTIFY, NAT_DETECTION_SOURCE_IP},
146 {NOTIFY, NAT_DETECTION_DESTINATION_IP},
147 {NOTIFY, HTTP_CERT_LOOKUP_SUPPORTED},
148 {CERTIFICATE_REQUEST, 0},
149 {NOTIFY, 0},
150 {VENDOR_ID, 0},
151 };
152
153 /**
154 * Message rule for IKE_AUTH from initiator.
155 */
156 static payload_rule_t ike_auth_i_rules[] = {
157 /* payload type min max encr suff */
158 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, TRUE, FALSE},
159 {EXTENSIBLE_AUTHENTICATION, 0, 1, TRUE, TRUE},
160 {AUTHENTICATION, 0, 1, TRUE, TRUE},
161 {ID_INITIATOR, 0, 1, TRUE, FALSE},
162 {CERTIFICATE, 0, 4, TRUE, FALSE},
163 {CERTIFICATE_REQUEST, 0, 1, TRUE, FALSE},
164 {ID_RESPONDER, 0, 1, TRUE, FALSE},
165 #ifdef ME
166 {SECURITY_ASSOCIATION, 0, 1, TRUE, FALSE},
167 {TRAFFIC_SELECTOR_INITIATOR, 0, 1, TRUE, FALSE},
168 {TRAFFIC_SELECTOR_RESPONDER, 0, 1, TRUE, FALSE},
169 #else
170 {SECURITY_ASSOCIATION, 0, 1, TRUE, FALSE},
171 {TRAFFIC_SELECTOR_INITIATOR, 0, 1, TRUE, FALSE},
172 {TRAFFIC_SELECTOR_RESPONDER, 0, 1, TRUE, FALSE},
173 #endif /* ME */
174 {CONFIGURATION, 0, 1, TRUE, FALSE},
175 {VENDOR_ID, 0, 10, TRUE, FALSE},
176 };
177
178 /**
179 * payload order for IKE_AUTH initiator
180 */
181 static payload_order_t ike_auth_i_order[] = {
182 /* payload type notify type */
183 {ID_INITIATOR, 0},
184 {CERTIFICATE, 0},
185 {NOTIFY, INITIAL_CONTACT},
186 {NOTIFY, HTTP_CERT_LOOKUP_SUPPORTED},
187 {CERTIFICATE_REQUEST, 0},
188 {ID_RESPONDER, 0},
189 {AUTHENTICATION, 0},
190 {EXTENSIBLE_AUTHENTICATION, 0},
191 {CONFIGURATION, 0},
192 {NOTIFY, IPCOMP_SUPPORTED},
193 {NOTIFY, USE_TRANSPORT_MODE},
194 {NOTIFY, ESP_TFC_PADDING_NOT_SUPPORTED},
195 {NOTIFY, NON_FIRST_FRAGMENTS_ALSO},
196 {SECURITY_ASSOCIATION, 0},
197 {TRAFFIC_SELECTOR_INITIATOR, 0},
198 {TRAFFIC_SELECTOR_RESPONDER, 0},
199 {NOTIFY, MOBIKE_SUPPORTED},
200 {NOTIFY, ADDITIONAL_IP4_ADDRESS},
201 {NOTIFY, ADDITIONAL_IP6_ADDRESS},
202 {NOTIFY, NO_ADDITIONAL_ADDRESSES},
203 {NOTIFY, 0},
204 {VENDOR_ID, 0},
205 };
206
207 /**
208 * Message rule for IKE_AUTH from responder.
209 */
210 static payload_rule_t ike_auth_r_rules[] = {
211 /* payload type min max encr suff */
212 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, TRUE, TRUE},
213 {EXTENSIBLE_AUTHENTICATION, 0, 1, TRUE, TRUE},
214 {AUTHENTICATION, 0, 1, TRUE, TRUE},
215 {CERTIFICATE, 0, 4, TRUE, FALSE},
216 {ID_RESPONDER, 0, 1, TRUE, FALSE},
217 {SECURITY_ASSOCIATION, 0, 1, TRUE, FALSE},
218 {TRAFFIC_SELECTOR_INITIATOR, 0, 1, TRUE, FALSE},
219 {TRAFFIC_SELECTOR_RESPONDER, 0, 1, TRUE, FALSE},
220 {CONFIGURATION, 0, 1, TRUE, FALSE},
221 {VENDOR_ID, 0, 10, TRUE, FALSE},
222 };
223
224 /**
225 * payload order for IKE_AUTH responder
226 */
227 static payload_order_t ike_auth_r_order[] = {
228 /* payload type notify type */
229 {ID_RESPONDER, 0},
230 {CERTIFICATE, 0},
231 {AUTHENTICATION, 0},
232 {EXTENSIBLE_AUTHENTICATION, 0},
233 {CONFIGURATION, 0},
234 {NOTIFY, IPCOMP_SUPPORTED},
235 {NOTIFY, USE_TRANSPORT_MODE},
236 {NOTIFY, ESP_TFC_PADDING_NOT_SUPPORTED},
237 {NOTIFY, NON_FIRST_FRAGMENTS_ALSO},
238 {SECURITY_ASSOCIATION, 0},
239 {TRAFFIC_SELECTOR_INITIATOR, 0},
240 {TRAFFIC_SELECTOR_RESPONDER, 0},
241 {NOTIFY, AUTH_LIFETIME},
242 {NOTIFY, MOBIKE_SUPPORTED},
243 {NOTIFY, ADDITIONAL_IP4_ADDRESS},
244 {NOTIFY, ADDITIONAL_IP6_ADDRESS},
245 {NOTIFY, NO_ADDITIONAL_ADDRESSES},
246 {NOTIFY, 0},
247 {VENDOR_ID, 0},
248 };
249
250 /**
251 * Message rule for INFORMATIONAL from initiator.
252 */
253 static payload_rule_t informational_i_rules[] = {
254 /* payload type min max encr suff */
255 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, TRUE, FALSE},
256 {CONFIGURATION, 0, 1, TRUE, FALSE},
257 {DELETE, 0, MAX_DELETE_PAYLOADS, TRUE, FALSE},
258 {VENDOR_ID, 0, 10, TRUE, FALSE},
259 };
260
261 /**
262 * payload order for INFORMATIONAL initiator
263 */
264 static payload_order_t informational_i_order[] = {
265 /* payload type notify type */
266 {NOTIFY, UPDATE_SA_ADDRESSES},
267 {NOTIFY, NAT_DETECTION_SOURCE_IP},
268 {NOTIFY, NAT_DETECTION_DESTINATION_IP},
269 {NOTIFY, COOKIE2},
270 {NOTIFY, 0},
271 {DELETE, 0},
272 {CONFIGURATION, 0},
273 };
274
275 /**
276 * Message rule for INFORMATIONAL from responder.
277 */
278 static payload_rule_t informational_r_rules[] = {
279 /* payload type min max encr suff */
280 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, TRUE, FALSE},
281 {CONFIGURATION, 0, 1, TRUE, FALSE},
282 {DELETE, 0, MAX_DELETE_PAYLOADS, TRUE, FALSE},
283 {VENDOR_ID, 0, 10, TRUE, FALSE},
284 };
285
286 /**
287 * payload order for INFORMATIONAL responder
288 */
289 static payload_order_t informational_r_order[] = {
290 /* payload type notify type */
291 {NOTIFY, UPDATE_SA_ADDRESSES},
292 {NOTIFY, NAT_DETECTION_SOURCE_IP},
293 {NOTIFY, NAT_DETECTION_DESTINATION_IP},
294 {NOTIFY, COOKIE2},
295 {NOTIFY, 0},
296 {DELETE, 0},
297 {CONFIGURATION, 0},
298 };
299
300 /**
301 * Message rule for CREATE_CHILD_SA from initiator.
302 */
303 static payload_rule_t create_child_sa_i_rules[] = {
304 /* payload type min max encr suff */
305 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, TRUE, FALSE},
306 {SECURITY_ASSOCIATION, 1, 1, TRUE, FALSE},
307 {NONCE, 1, 1, TRUE, FALSE},
308 {KEY_EXCHANGE, 0, 1, TRUE, FALSE},
309 {TRAFFIC_SELECTOR_INITIATOR, 0, 1, TRUE, FALSE},
310 {TRAFFIC_SELECTOR_RESPONDER, 0, 1, TRUE, FALSE},
311 {CONFIGURATION, 0, 1, TRUE, FALSE},
312 {VENDOR_ID, 0, 10, TRUE, FALSE},
313 };
314
315 /**
316 * payload order for CREATE_CHILD_SA from initiator.
317 */
318 static payload_order_t create_child_sa_i_order[] = {
319 /* payload type notify type */
320 {NOTIFY, REKEY_SA},
321 {NOTIFY, IPCOMP_SUPPORTED},
322 {NOTIFY, USE_TRANSPORT_MODE},
323 {NOTIFY, ESP_TFC_PADDING_NOT_SUPPORTED},
324 {NOTIFY, NON_FIRST_FRAGMENTS_ALSO},
325 {SECURITY_ASSOCIATION, 0},
326 {NONCE, 0},
327 {KEY_EXCHANGE, 0},
328 {TRAFFIC_SELECTOR_INITIATOR, 0},
329 {TRAFFIC_SELECTOR_RESPONDER, 0},
330 {NOTIFY, 0},
331 };
332
333 /**
334 * Message rule for CREATE_CHILD_SA from responder.
335 */
336 static payload_rule_t create_child_sa_r_rules[] = {
337 /* payload type min max encr suff */
338 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, TRUE, TRUE},
339 {SECURITY_ASSOCIATION, 1, 1, TRUE, FALSE},
340 {NONCE, 1, 1, TRUE, FALSE},
341 {KEY_EXCHANGE, 0, 1, TRUE, FALSE},
342 {TRAFFIC_SELECTOR_INITIATOR, 0, 1, TRUE, FALSE},
343 {TRAFFIC_SELECTOR_RESPONDER, 0, 1, TRUE, FALSE},
344 {CONFIGURATION, 0, 1, TRUE, FALSE},
345 {VENDOR_ID, 0, 10, TRUE, FALSE},
346 };
347
348 /**
349 * payload order for CREATE_CHILD_SA from responder.
350 */
351 static payload_order_t create_child_sa_r_order[] = {
352 /* payload type notify type */
353 {NOTIFY, IPCOMP_SUPPORTED},
354 {NOTIFY, USE_TRANSPORT_MODE},
355 {NOTIFY, ESP_TFC_PADDING_NOT_SUPPORTED},
356 {NOTIFY, NON_FIRST_FRAGMENTS_ALSO},
357 {SECURITY_ASSOCIATION, 0},
358 {NONCE, 0},
359 {KEY_EXCHANGE, 0},
360 {TRAFFIC_SELECTOR_INITIATOR, 0},
361 {TRAFFIC_SELECTOR_RESPONDER, 0},
362 {NOTIFY, ADDITIONAL_TS_POSSIBLE},
363 {NOTIFY, 0},
364 };
365
366 #ifdef ME
367 /**
368 * Message rule for ME_CONNECT from initiator.
369 */
370 static payload_rule_t me_connect_i_rules[] = {
371 /* payload type min max encr suff */
372 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, TRUE, TRUE},
373 {ID_PEER, 1, 1, TRUE, FALSE},
374 {VENDOR_ID, 0, 10, TRUE, FALSE}
375 };
376
377 /**
378 * payload order for ME_CONNECT from initiator.
379 */
380 static payload_order_t me_connect_i_order[] = {
381 /* payload type notify type */
382 {NOTIFY, 0},
383 {ID_PEER, 0},
384 {VENDOR_ID, 0},
385 };
386
387 /**
388 * Message rule for ME_CONNECT from responder.
389 */
390 static payload_rule_t me_connect_r_rules[] = {
391 /* payload type min max encr suff */
392 {NOTIFY, 0, MAX_NOTIFY_PAYLOADS, TRUE, TRUE},
393 {VENDOR_ID, 0, 10, TRUE, FALSE}
394 };
395
396 /**
397 * payload order for ME_CONNECT from responder.
398 */
399 static payload_order_t me_connect_r_order[] = {
400 /* payload type notify type */
401 {NOTIFY, 0},
402 {VENDOR_ID, 0},
403 };
404 #endif /* ME */
405
406 /**
407 * Message rules, defines allowed payloads.
408 */
409 static message_rule_t message_rules[] = {
410 {IKE_SA_INIT, TRUE, FALSE,
411 countof(ike_sa_init_i_rules), ike_sa_init_i_rules,
412 countof(ike_sa_init_i_order), ike_sa_init_i_order,
413 },
414 {IKE_SA_INIT, FALSE, FALSE,
415 countof(ike_sa_init_r_rules), ike_sa_init_r_rules,
416 countof(ike_sa_init_r_order), ike_sa_init_r_order,
417 },
418 {IKE_AUTH, TRUE, TRUE,
419 countof(ike_auth_i_rules), ike_auth_i_rules,
420 countof(ike_auth_i_order), ike_auth_i_order,
421 },
422 {IKE_AUTH, FALSE, TRUE,
423 countof(ike_auth_r_rules), ike_auth_r_rules,
424 countof(ike_auth_r_order), ike_auth_r_order,
425 },
426 {INFORMATIONAL, TRUE, TRUE,
427 countof(informational_i_rules), informational_i_rules,
428 countof(informational_i_order), informational_i_order,
429 },
430 {INFORMATIONAL, FALSE, TRUE,
431 countof(informational_r_rules), informational_r_rules,
432 countof(informational_r_order), informational_r_order,
433 },
434 {CREATE_CHILD_SA, TRUE, TRUE,
435 countof(create_child_sa_i_rules), create_child_sa_i_rules,
436 countof(create_child_sa_i_order), create_child_sa_i_order,
437 },
438 {CREATE_CHILD_SA, FALSE, TRUE,
439 countof(create_child_sa_r_rules), create_child_sa_r_rules,
440 countof(create_child_sa_r_order), create_child_sa_r_order,
441 },
442 #ifdef ME
443 {ME_CONNECT, TRUE, TRUE,
444 countof(me_connect_i_rules), me_connect_i_rules,
445 countof(me_connect_i_order), me_connect_i_order,
446 },
447 {ME_CONNECT, FALSE, TRUE,
448 countof(me_connect_r_rules), me_connect_r_rules,
449 countof(me_connect_r_order), me_connect_r_order,
450 },
451 #endif /* ME */
452 };
453
454
455 typedef struct private_message_t private_message_t;
456
457 /**
458 * Private data of an message_t object.
459 */
460 struct private_message_t {
461
462 /**
463 * Public part of a message_t object.
464 */
465 message_t public;
466
467 /**
468 * Minor version of message.
469 */
470 u_int8_t major_version;
471
472 /**
473 * Major version of message.
474 */
475 u_int8_t minor_version;
476
477 /**
478 * First Payload in message.
479 */
480 payload_type_t first_payload;
481
482 /**
483 * Assigned exchange type.
484 */
485 exchange_type_t exchange_type;
486
487 /**
488 * TRUE if message is a request, FALSE if a reply.
489 */
490 bool is_request;
491
492 /**
493 * Message ID of this message.
494 */
495 u_int32_t message_id;
496
497 /**
498 * ID of assigned IKE_SA.
499 */
500 ike_sa_id_t *ike_sa_id;
501
502 /**
503 * Assigned UDP packet, stores incoming packet or last generated one.
504 */
505 packet_t *packet;
506
507 /**
508 * Linked List where payload data are stored in.
509 */
510 linked_list_t *payloads;
511
512 /**
513 * Assigned parser to parse Header and Body of this message.
514 */
515 parser_t *parser;
516
517 /**
518 * The message rule for this message instance
519 */
520 message_rule_t *rule;
521 };
522
523 /**
524 * Get the message rule that applies to this message
525 */
526 static message_rule_t* get_message_rule(private_message_t *this)
527 {
528 int i;
529
530 for (i = 0; i < countof(message_rules); i++)
531 {
532 if ((this->exchange_type == message_rules[i].exchange_type) &&
533 (this->is_request == message_rules[i].is_request))
534 {
535 return &message_rules[i];
536 }
537 }
538 return NULL;
539 }
540
541 /**
542 * Look up a payload rule
543 */
544 static payload_rule_t* get_payload_rule(private_message_t *this,
545 payload_type_t type)
546 {
547 int i;
548
549 for (i = 0; i < this->rule->rule_count;i++)
550 {
551 if (this->rule->rules[i].type == type)
552 {
553 return &this->rule->rules[i];
554 }
555 }
556 return NULL;
557 }
558
559 METHOD(message_t, set_ike_sa_id, void,
560 private_message_t *this,ike_sa_id_t *ike_sa_id)
561 {
562 DESTROY_IF(this->ike_sa_id);
563 this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
564 }
565
566 METHOD(message_t, get_ike_sa_id, ike_sa_id_t*,
567 private_message_t *this)
568 {
569 return this->ike_sa_id;
570 }
571
572 METHOD(message_t, set_message_id, void,
573 private_message_t *this,u_int32_t message_id)
574 {
575 this->message_id = message_id;
576 }
577
578 METHOD(message_t, get_message_id, u_int32_t,
579 private_message_t *this)
580 {
581 return this->message_id;
582 }
583
584 METHOD(message_t, get_initiator_spi, u_int64_t,
585 private_message_t *this)
586 {
587 return (this->ike_sa_id->get_initiator_spi(this->ike_sa_id));
588 }
589
590 METHOD(message_t, get_responder_spi, u_int64_t,
591 private_message_t *this)
592 {
593 return (this->ike_sa_id->get_responder_spi(this->ike_sa_id));
594 }
595
596 METHOD(message_t, set_major_version, void,
597 private_message_t *this, u_int8_t major_version)
598 {
599 this->major_version = major_version;
600 }
601
602 METHOD(message_t, get_major_version, u_int8_t,
603 private_message_t *this)
604 {
605 return this->major_version;
606 }
607
608 METHOD(message_t, set_minor_version, void,
609 private_message_t *this,u_int8_t minor_version)
610 {
611 this->minor_version = minor_version;
612 }
613
614 METHOD(message_t, get_minor_version, u_int8_t,
615 private_message_t *this)
616 {
617 return this->minor_version;
618 }
619
620 METHOD(message_t, set_exchange_type, void,
621 private_message_t *this, exchange_type_t exchange_type)
622 {
623 this->exchange_type = exchange_type;
624 }
625
626 METHOD(message_t, get_exchange_type, exchange_type_t,
627 private_message_t *this)
628 {
629 return this->exchange_type;
630 }
631
632 METHOD(message_t, get_first_payload_type, payload_type_t,
633 private_message_t *this)
634 {
635 return this->first_payload;
636 }
637
638 METHOD(message_t, set_request, void,
639 private_message_t *this, bool request)
640 {
641 this->is_request = request;
642 }
643
644 METHOD(message_t, get_request, bool,
645 private_message_t *this)
646 {
647 return this->is_request;
648 }
649
650 /**
651 * Is this message in an encoded form?
652 */
653 static bool is_encoded(private_message_t *this)
654 {
655 chunk_t data = this->packet->get_data(this->packet);
656
657 if (data.ptr == NULL)
658 {
659 return FALSE;
660 }
661 return TRUE;
662 }
663
664 METHOD(message_t, add_payload, void,
665 private_message_t *this, payload_t *payload)
666 {
667 payload_t *last_payload;
668
669 if (this->payloads->get_count(this->payloads) > 0)
670 {
671 this->payloads->get_last(this->payloads, (void **)&last_payload);
672 last_payload->set_next_type(last_payload, payload->get_type(payload));
673 }
674 else
675 {
676 this->first_payload = payload->get_type(payload);
677 }
678 payload->set_next_type(payload, NO_PAYLOAD);
679 this->payloads->insert_last(this->payloads, payload);
680
681 DBG2(DBG_ENC ,"added payload of type %N to message",
682 payload_type_names, payload->get_type(payload));
683 }
684
685 METHOD(message_t, add_notify, void,
686 private_message_t *this, bool flush, notify_type_t type, chunk_t data)
687 {
688 notify_payload_t *notify;
689 payload_t *payload;
690
691 if (flush)
692 {
693 while (this->payloads->remove_last(this->payloads,
694 (void**)&payload) == SUCCESS)
695 {
696 payload->destroy(payload);
697 }
698 }
699 notify = notify_payload_create();
700 notify->set_notify_type(notify, type);
701 notify->set_notification_data(notify, data);
702 add_payload(this, (payload_t*)notify);
703 }
704
705 METHOD(message_t, set_source, void,
706 private_message_t *this, host_t *host)
707 {
708 this->packet->set_source(this->packet, host);
709 }
710
711 METHOD(message_t, set_destination, void,
712 private_message_t *this, host_t *host)
713 {
714 this->packet->set_destination(this->packet, host);
715 }
716
717 METHOD(message_t, get_source, host_t*,
718 private_message_t *this)
719 {
720 return this->packet->get_source(this->packet);
721 }
722
723 METHOD(message_t, get_destination, host_t*,
724 private_message_t *this)
725 {
726 return this->packet->get_destination(this->packet);
727 }
728
729 METHOD(message_t, create_payload_enumerator, enumerator_t*,
730 private_message_t *this)
731 {
732 return this->payloads->create_enumerator(this->payloads);
733 }
734
735 METHOD(message_t, get_payload, payload_t*,
736 private_message_t *this, payload_type_t type)
737 {
738 payload_t *current, *found = NULL;
739 enumerator_t *enumerator;
740
741 enumerator = create_payload_enumerator(this);
742 while (enumerator->enumerate(enumerator, &current))
743 {
744 if (current->get_type(current) == type)
745 {
746 found = current;
747 break;
748 }
749 }
750 enumerator->destroy(enumerator);
751 return found;
752 }
753
754 METHOD(message_t, get_notify, notify_payload_t*,
755 private_message_t *this, notify_type_t type)
756 {
757 enumerator_t *enumerator;
758 notify_payload_t *notify = NULL;
759 payload_t *payload;
760
761 enumerator = create_payload_enumerator(this);
762 while (enumerator->enumerate(enumerator, &payload))
763 {
764 if (payload->get_type(payload) == NOTIFY)
765 {
766 notify = (notify_payload_t*)payload;
767 if (notify->get_notify_type(notify) == type)
768 {
769 break;
770 }
771 notify = NULL;
772 }
773 }
774 enumerator->destroy(enumerator);
775 return notify;
776 }
777
778 /**
779 * get a string representation of the message
780 */
781 static char* get_string(private_message_t *this, char *buf, int len)
782 {
783 enumerator_t *enumerator;
784 payload_t *payload;
785 int written;
786 char *pos = buf;
787
788 memset(buf, 0, len);
789 len--;
790
791 written = snprintf(pos, len, "%N %s %d [",
792 exchange_type_names, this->exchange_type,
793 this->is_request ? "request" : "response",
794 this->message_id);
795 if (written >= len || written < 0)
796 {
797 return "";
798 }
799 pos += written;
800 len -= written;
801
802 enumerator = create_payload_enumerator(this);
803 while (enumerator->enumerate(enumerator, &payload))
804 {
805 written = snprintf(pos, len, " %N", payload_type_short_names,
806 payload->get_type(payload));
807 if (written >= len || written < 0)
808 {
809 return buf;
810 }
811 pos += written;
812 len -= written;
813 if (payload->get_type(payload) == NOTIFY)
814 {
815 notify_payload_t *notify = (notify_payload_t*)payload;
816 written = snprintf(pos, len, "(%N)", notify_type_short_names,
817 notify->get_notify_type(notify));
818 if (written >= len || written < 0)
819 {
820 return buf;
821 }
822 pos += written;
823 len -= written;
824 }
825 if (payload->get_type(payload) == EXTENSIBLE_AUTHENTICATION)
826 {
827 eap_payload_t *eap = (eap_payload_t*)payload;
828 u_int32_t vendor;
829 eap_type_t type;
830 char method[64] = "";
831
832 type = eap->get_type(eap, &vendor);
833 if (type)
834 {
835 if (vendor)
836 {
837 snprintf(method, sizeof(method), "/%d-%d", type, vendor);
838 }
839 else
840 {
841 snprintf(method, sizeof(method), "/%N",
842 eap_type_short_names, type);
843 }
844 }
845 written = snprintf(pos, len, "/%N%s", eap_code_short_names,
846 eap->get_code(eap), method);
847 if (written >= len || written < 0)
848 {
849 return buf;
850 }
851 pos += written;
852 len -= written;
853 }
854 if (payload->get_type(payload) == CONFIGURATION)
855 {
856 cp_payload_t *cp = (cp_payload_t*)payload;
857 enumerator_t *attributes;
858 configuration_attribute_t *attribute;
859 bool first = TRUE;
860
861 attributes = cp->create_attribute_enumerator(cp);
862 while (attributes->enumerate(attributes, &attribute))
863 {
864 written = snprintf(pos, len, "%s%N", first ? "(" : " ",
865 configuration_attribute_type_short_names,
866 attribute->get_type(attribute));
867 if (written >= len || written < 0)
868 {
869 return buf;
870 }
871 pos += written;
872 len -= written;
873 first = FALSE;
874 }
875 attributes->destroy(attributes);
876 if (!first)
877 {
878 written = snprintf(pos, len, ")");
879 if (written >= len || written < 0)
880 {
881 return buf;
882 }
883 pos += written;
884 len -= written;
885 }
886 }
887 }
888 enumerator->destroy(enumerator);
889
890 /* remove last space */
891 snprintf(pos, len, " ]");
892 return buf;
893 }
894
895 /**
896 * reorder payloads depending on reordering rules
897 */
898 static void order_payloads(private_message_t *this)
899 {
900 linked_list_t *list;
901 payload_t *payload;
902 int i;
903
904 /* move to temp list */
905 list = linked_list_create();
906 while (this->payloads->remove_last(this->payloads,
907 (void**)&payload) == SUCCESS)
908 {
909 list->insert_first(list, payload);
910 }
911 /* for each rule, ... */
912 for (i = 0; i < this->rule->order_count; i++)
913 {
914 enumerator_t *enumerator;
915 notify_payload_t *notify;
916 payload_order_t order;
917
918 order = this->rule->order[i];
919
920 /* ... find all payload ... */
921 enumerator = list->create_enumerator(list);
922 while (enumerator->enumerate(enumerator, &payload))
923 {
924 /* ... with that type ... */
925 if (payload->get_type(payload) == order.type)
926 {
927 notify = (notify_payload_t*)payload;
928
929 /**... and check notify for type. */
930 if (order.type != NOTIFY || order.notify == 0 ||
931 order.notify == notify->get_notify_type(notify))
932 {
933 list->remove_at(list, enumerator);
934 add_payload(this, payload);
935 }
936 }
937 }
938 enumerator->destroy(enumerator);
939 }
940 /* append all payloads without a rule to the end */
941 while (list->remove_last(list, (void**)&payload) == SUCCESS)
942 {
943 /* do not complain about payloads in private use space */
944 if (payload->get_type(payload) < 128)
945 {
946 DBG1(DBG_ENC, "payload %N has no ordering rule in %N %s",
947 payload_type_names, payload->get_type(payload),
948 exchange_type_names, this->rule->exchange_type,
949 this->rule->is_request ? "request" : "response");
950 }
951 add_payload(this, payload);
952 }
953 list->destroy(list);
954 }
955
956 /**
957 * Wrap payloads in a encryption payload, if required
958 */
959 static encryption_payload_t* wrap_payloads(private_message_t *this)
960 {
961 encryption_payload_t *encryption;
962 linked_list_t *payloads;
963 payload_t *current;
964
965 if (!this->rule->encrypted)
966 {
967 DBG2(DBG_ENC, "not encrypting payloads");
968 return NULL;
969 }
970
971 /* copy all payloads in a temporary list */
972 payloads = linked_list_create();
973 while (this->payloads->remove_first(this->payloads,
974 (void**)&current) == SUCCESS)
975 {
976 payloads->insert_last(payloads, current);
977 }
978
979 encryption = encryption_payload_create();
980 while (payloads->remove_first(payloads, (void**)&current) == SUCCESS)
981 {
982 payload_rule_t *rule;
983 payload_type_t type;
984 bool encrypt = TRUE;
985
986 type = current->get_type(current);
987 rule = get_payload_rule(this, type);
988 if (rule)
989 {
990 encrypt = rule->encrypted;
991 }
992 if (encrypt)
993 {
994 DBG2(DBG_ENC, "insert payload %N to encryption payload",
995 payload_type_names, type);
996 encryption->add_payload(encryption, current);
997 }
998 else
999 {
1000 DBG2(DBG_ENC, "insert payload %N unencrypted",
1001 payload_type_names, type);
1002 add_payload(this, current);
1003 }
1004 }
1005 payloads->destroy(payloads);
1006
1007 return encryption;
1008 }
1009
1010 METHOD(message_t, generate, status_t,
1011 private_message_t *this, aead_t *aead, packet_t **packet)
1012 {
1013 generator_t *generator;
1014 ike_header_t *ike_header;
1015 payload_t *payload, *next;
1016 encryption_payload_t *encryption;
1017 enumerator_t *enumerator;
1018 chunk_t chunk;
1019 char str[256];
1020 u_int32_t *lenpos;
1021
1022 if (is_encoded(this))
1023 { /* already generated, return a new packet clone */
1024 *packet = this->packet->clone(this->packet);
1025 return SUCCESS;
1026 }
1027
1028 if (this->exchange_type == EXCHANGE_TYPE_UNDEFINED)
1029 {
1030 DBG1(DBG_ENC, "exchange type is not defined");
1031 return INVALID_STATE;
1032 }
1033
1034 if (this->packet->get_source(this->packet) == NULL ||
1035 this->packet->get_destination(this->packet) == NULL)
1036 {
1037 DBG1(DBG_ENC, "source/destination not defined");
1038 return INVALID_STATE;
1039 }
1040
1041 this->rule = get_message_rule(this);
1042 if (!this->rule)
1043 {
1044 DBG1(DBG_ENC, "no message rules specified for this message type");
1045 return NOT_SUPPORTED;
1046 }
1047
1048 order_payloads(this);
1049
1050 DBG1(DBG_ENC, "generating %s", get_string(this, str, sizeof(str)));
1051
1052 encryption = wrap_payloads(this);
1053
1054 ike_header = ike_header_create();
1055 ike_header->set_exchange_type(ike_header, this->exchange_type);
1056 ike_header->set_message_id(ike_header, this->message_id);
1057 ike_header->set_response_flag(ike_header, !this->is_request);
1058 ike_header->set_initiator_flag(ike_header,
1059 this->ike_sa_id->is_initiator(this->ike_sa_id));
1060 ike_header->set_initiator_spi(ike_header,
1061 this->ike_sa_id->get_initiator_spi(this->ike_sa_id));
1062 ike_header->set_responder_spi(ike_header,
1063 this->ike_sa_id->get_responder_spi(this->ike_sa_id));
1064
1065 generator = generator_create();
1066
1067 /* generate all payloads with proper next type */
1068 payload = (payload_t*)ike_header;
1069 enumerator = create_payload_enumerator(this);
1070 while (enumerator->enumerate(enumerator, &next))
1071 {
1072 payload->set_next_type(payload, next->get_type(next));
1073 generator->generate_payload(generator, payload);
1074 payload = next;
1075 }
1076 enumerator->destroy(enumerator);
1077 payload->set_next_type(payload, encryption ? ENCRYPTED : NO_PAYLOAD);
1078 generator->generate_payload(generator, payload);
1079 ike_header->destroy(ike_header);
1080
1081 if (encryption)
1082 {
1083 u_int32_t *lenpos;
1084
1085 /* build associated data (without header of encryption payload) */
1086 chunk = generator->get_chunk(generator, &lenpos);
1087 encryption->set_transform(encryption, aead);
1088 /* fill in length, including encryption payload */
1089 htoun32(lenpos, chunk.len + encryption->get_length(encryption));
1090
1091 this->payloads->insert_last(this->payloads, encryption);
1092 if (!encryption->encrypt(encryption, chunk))
1093 {
1094 generator->destroy(generator);
1095 return INVALID_STATE;
1096 }
1097 generator->generate_payload(generator, &encryption->payload_interface);
1098 }
1099 chunk = generator->get_chunk(generator, &lenpos);
1100 htoun32(lenpos, chunk.len);
1101 this->packet->set_data(this->packet, chunk_clone(chunk));
1102 generator->destroy(generator);
1103
1104 *packet = this->packet->clone(this->packet);
1105 return SUCCESS;
1106 }
1107
1108 METHOD(message_t, get_packet, packet_t*,
1109 private_message_t *this)
1110 {
1111 if (this->packet == NULL)
1112 {
1113 return NULL;
1114 }
1115 return this->packet->clone(this->packet);
1116 }
1117
1118 METHOD(message_t, get_packet_data, chunk_t,
1119 private_message_t *this)
1120 {
1121 if (this->packet == NULL)
1122 {
1123 return chunk_empty;
1124 }
1125 return chunk_clone(this->packet->get_data(this->packet));
1126 }
1127
1128 METHOD(message_t, parse_header, status_t,
1129 private_message_t *this)
1130 {
1131 ike_header_t *ike_header;
1132 status_t status;
1133
1134 DBG2(DBG_ENC, "parsing header of message");
1135
1136 this->parser->reset_context(this->parser);
1137 status = this->parser->parse_payload(this->parser, HEADER,
1138 (payload_t**)&ike_header);
1139 if (status != SUCCESS)
1140 {
1141 DBG1(DBG_ENC, "header could not be parsed");
1142 return status;
1143
1144 }
1145
1146 status = ike_header->payload_interface.verify(
1147 &ike_header->payload_interface);
1148 if (status != SUCCESS)
1149 {
1150 DBG1(DBG_ENC, "header verification failed");
1151 ike_header->destroy(ike_header);
1152 return status;
1153 }
1154
1155 DESTROY_IF(this->ike_sa_id);
1156 this->ike_sa_id = ike_sa_id_create(ike_header->get_initiator_spi(ike_header),
1157 ike_header->get_responder_spi(ike_header),
1158 ike_header->get_initiator_flag(ike_header));
1159
1160 this->exchange_type = ike_header->get_exchange_type(ike_header);
1161 this->message_id = ike_header->get_message_id(ike_header);
1162 this->is_request = !ike_header->get_response_flag(ike_header);
1163 this->major_version = ike_header->get_maj_version(ike_header);
1164 this->minor_version = ike_header->get_min_version(ike_header);
1165 this->first_payload = ike_header->payload_interface.get_next_type(
1166 &ike_header->payload_interface);
1167
1168 DBG2(DBG_ENC, "parsed a %N %s", exchange_type_names, this->exchange_type,
1169 this->is_request ? "request" : "response");
1170
1171 ike_header->destroy(ike_header);
1172
1173 this->rule = get_message_rule(this);
1174 if (!this->rule)
1175 {
1176 DBG1(DBG_ENC, "no message rules specified for a %N %s",
1177 exchange_type_names, this->exchange_type,
1178 this->is_request ? "request" : "response");
1179 }
1180 return status;
1181 }
1182
1183 /**
1184 * Decrypt payload from the encryption payload
1185 */
1186 static status_t decrypt_payloads(private_message_t *this, aead_t *aead)
1187 {
1188 bool was_encrypted = FALSE;
1189 payload_t *payload, *previous = NULL;
1190 enumerator_t *enumerator;
1191 payload_rule_t *rule;
1192 payload_type_t type;
1193 status_t status = SUCCESS;
1194
1195 enumerator = this->payloads->create_enumerator(this->payloads);
1196 while (enumerator->enumerate(enumerator, &payload))
1197 {
1198 type = payload->get_type(payload);
1199
1200 DBG2(DBG_ENC, "process payload of type %N", payload_type_names, type);
1201
1202 if (type == ENCRYPTED)
1203 {
1204 encryption_payload_t *encryption;
1205 payload_t *encrypted;
1206 chunk_t chunk;
1207
1208 encryption = (encryption_payload_t*)payload;
1209
1210 DBG2(DBG_ENC, "found an encryption payload");
1211
1212 if (enumerator->enumerate(enumerator, &payload))
1213 {
1214 DBG1(DBG_ENC, "encrypted payload is not last payload");
1215 status = VERIFY_ERROR;
1216 break;
1217 }
1218 encryption->set_transform(encryption, aead);
1219 chunk = this->packet->get_data(this->packet);
1220 if (chunk.len < encryption->get_length(encryption))
1221 {
1222 DBG1(DBG_ENC, "invalid payload length");
1223 status = VERIFY_ERROR;
1224 break;
1225 }
1226 chunk.len -= encryption->get_length(encryption);
1227 status = encryption->decrypt(encryption, chunk);
1228 if (status != SUCCESS)
1229 {
1230 break;
1231 }
1232
1233 was_encrypted = TRUE;
1234 this->payloads->remove_at(this->payloads, enumerator);
1235
1236 while ((encrypted = encryption->remove_payload(encryption)))
1237 {
1238 type = encrypted->get_type(encrypted);
1239 if (previous)
1240 {
1241 previous->set_next_type(previous, type);
1242 }
1243 else
1244 {
1245 this->first_payload = type;
1246 }
1247 DBG2(DBG_ENC, "insert decrypted payload of type "
1248 "%N at end of list", payload_type_names, type);
1249 this->payloads->insert_last(this->payloads, encrypted);
1250 previous = encrypted;
1251 }
1252 encryption->destroy(encryption);
1253 }
1254 if (type != UNKNOWN_PAYLOAD && !was_encrypted)
1255 {
1256 rule = get_payload_rule(this, type);
1257 if (!rule || rule->encrypted)
1258 {
1259 DBG1(DBG_ENC, "payload type %N was not encrypted",
1260 payload_type_names, type);
1261 status = VERIFY_ERROR;
1262 break;
1263 }
1264 }
1265 previous = payload;
1266 }
1267 enumerator->destroy(enumerator);
1268 return status;
1269 }
1270
1271 /**
1272 * Verify a message and all payload according to message/payload rules
1273 */
1274 static status_t verify(private_message_t *this)
1275 {
1276 int i;
1277
1278 DBG2(DBG_ENC, "verifying message structure");
1279
1280 /* check for payloads with wrong count*/
1281 for (i = 0; i < this->rule->rule_count; i++)
1282 {
1283 enumerator_t *enumerator;
1284 payload_t *payload;
1285 payload_rule_t *rule;
1286 int found = 0;
1287
1288 rule = &this->rule->rules[i];
1289 enumerator = create_payload_enumerator(this);
1290 while (enumerator->enumerate(enumerator, &payload))
1291 {
1292 payload_type_t type;
1293 unknown_payload_t *unknown;
1294
1295 type = payload->get_type(payload);
1296 if (type == UNKNOWN_PAYLOAD)
1297 {
1298 /* unknown payloads are ignored if they are not critical */
1299 unknown = (unknown_payload_t*)payload;
1300 if (unknown->is_critical(unknown))
1301 {
1302 DBG1(DBG_ENC, "%N is not supported, but its critical!",
1303 payload_type_names, type);
1304 enumerator->destroy(enumerator);
1305 return NOT_SUPPORTED;
1306 }
1307 }
1308 else if (type == rule->type)
1309 {
1310 found++;
1311 DBG2(DBG_ENC, "found payload of type %N",
1312 payload_type_names, type);
1313 if (found > rule->max_occurence)
1314 {
1315 DBG1(DBG_ENC, "payload of type %N more than %d times (%d) "
1316 "occured in current message", payload_type_names,
1317 type, rule->max_occurence, found);
1318 enumerator->destroy(enumerator);
1319 return VERIFY_ERROR;
1320 }
1321 }
1322 }
1323 enumerator->destroy(enumerator);
1324
1325 if (found < rule->min_occurence)
1326 {
1327 DBG1(DBG_ENC, "payload of type %N not occured %d times (%d)",
1328 payload_type_names, rule->type, rule->min_occurence, found);
1329 return VERIFY_ERROR;
1330 }
1331 if (rule->sufficient)
1332 {
1333 return SUCCESS;
1334 }
1335 }
1336 return SUCCESS;
1337 }
1338
1339 METHOD(message_t, parse_body, status_t,
1340 private_message_t *this, aead_t *aead)
1341 {
1342 status_t status = SUCCESS;
1343 payload_t *payload;
1344 payload_type_t type;
1345 char str[256];
1346
1347 type = this->first_payload;
1348
1349 DBG2(DBG_ENC, "parsing body of message, first payload is %N",
1350 payload_type_names, type);
1351
1352 while (type != NO_PAYLOAD)
1353 {
1354 DBG2(DBG_ENC, "starting parsing a %N payload",
1355 payload_type_names, type);
1356
1357 status = this->parser->parse_payload(this->parser, type, &payload);
1358 if (status != SUCCESS)
1359 {
1360 DBG1(DBG_ENC, "payload type %N could not be parsed",
1361 payload_type_names, type);
1362 return PARSE_ERROR;
1363 }
1364
1365 DBG2(DBG_ENC, "verifying payload of type %N", payload_type_names, type);
1366 status = payload->verify(payload);
1367 if (status != SUCCESS)
1368 {
1369 DBG1(DBG_ENC, "%N payload verification failed",
1370 payload_type_names, type);
1371 payload->destroy(payload);
1372 return VERIFY_ERROR;
1373 }
1374
1375 DBG2(DBG_ENC, "%N payload verified. Adding to payload list",
1376 payload_type_names, type);
1377 this->payloads->insert_last(this->payloads, payload);
1378
1379 /* an encryption payload is the last one, so STOP here. decryption is
1380 * done later */
1381 if (type == ENCRYPTED)
1382 {
1383 DBG2(DBG_ENC, "%N payload found. Stop parsing",
1384 payload_type_names, type);
1385 break;
1386 }
1387 type = payload->get_next_type(payload);
1388 }
1389
1390 if (type == ENCRYPTED)
1391 {
1392 status = decrypt_payloads(this, aead);
1393 if (status != SUCCESS)
1394 {
1395 DBG1(DBG_ENC, "could not decrypt payloads");
1396 return status;
1397 }
1398 }
1399
1400 status = verify(this);
1401 if (status != SUCCESS)
1402 {
1403 return status;
1404 }
1405
1406 DBG1(DBG_ENC, "parsed %s", get_string(this, str, sizeof(str)));
1407
1408 return SUCCESS;
1409 }
1410
1411 METHOD(message_t, destroy, void,
1412 private_message_t *this)
1413 {
1414 DESTROY_IF(this->ike_sa_id);
1415 this->payloads->destroy_offset(this->payloads, offsetof(payload_t, destroy));
1416 this->packet->destroy(this->packet);
1417 this->parser->destroy(this->parser);
1418 free(this);
1419 }
1420
1421 /*
1422 * Described in Header-File
1423 */
1424 message_t *message_create_from_packet(packet_t *packet)
1425 {
1426 private_message_t *this;
1427
1428 INIT(this,
1429 .public = {
1430 .set_major_version = _set_major_version,
1431 .get_major_version = _get_major_version,
1432 .set_minor_version = _set_minor_version,
1433 .get_minor_version = _get_minor_version,
1434 .set_message_id = _set_message_id,
1435 .get_message_id = _get_message_id,
1436 .get_initiator_spi = _get_initiator_spi,
1437 .get_responder_spi = _get_responder_spi,
1438 .set_ike_sa_id = _set_ike_sa_id,
1439 .get_ike_sa_id = _get_ike_sa_id,
1440 .set_exchange_type = _set_exchange_type,
1441 .get_exchange_type = _get_exchange_type,
1442 .get_first_payload_type = _get_first_payload_type,
1443 .set_request = _set_request,
1444 .get_request = _get_request,
1445 .add_payload = _add_payload,
1446 .add_notify = _add_notify,
1447 .generate = _generate,
1448 .set_source = _set_source,
1449 .get_source = _get_source,
1450 .set_destination = _set_destination,
1451 .get_destination = _get_destination,
1452 .create_payload_enumerator = _create_payload_enumerator,
1453 .get_payload = _get_payload,
1454 .get_notify = _get_notify,
1455 .parse_header = _parse_header,
1456 .parse_body = _parse_body,
1457 .get_packet = _get_packet,
1458 .get_packet_data = _get_packet_data,
1459 .destroy = _destroy,
1460 },
1461 .exchange_type = EXCHANGE_TYPE_UNDEFINED,
1462 .is_request = TRUE,
1463 .first_payload = NO_PAYLOAD,
1464 .packet = packet,
1465 .payloads = linked_list_create(),
1466 .parser = parser_create(packet->get_data(packet)),
1467 );
1468
1469 return (&this->public);
1470 }
1471
1472 /*
1473 * Described in Header.
1474 */
1475 message_t *message_create()
1476 {
1477 return message_create_from_packet(packet_create());
1478 }
1479