2 * Copyright (C) 2006-2007 Tobias Brunner
3 * Copyright (C) 2006 Daniel Roethlisberger
4 * Copyright (C) 2005-2006 Martin Willi
5 * Copyright (C) 2005 Jan Hutter
6 * Hochschule fuer Technik Rapperswil
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 #include <sa/ike_sa_id.h>
29 #include <encoding/generator.h>
30 #include <encoding/parser.h>
31 #include <utils/linked_list.h>
32 #include <encoding/payloads/encodings.h>
33 #include <encoding/payloads/payload.h>
34 #include <encoding/payloads/encryption_payload.h>
35 #include <encoding/payloads/unknown_payload.h>
38 * Max number of notify payloads per IKEv2 Message
40 #define MAX_NOTIFY_PAYLOADS 20
43 typedef struct payload_rule_t payload_rule_t
;
46 * A payload rule defines the rules for a payload
47 * in a specific message rule. It defines if and how
48 * many times a payload must/can occur in a message
49 * and if it must be encrypted.
51 struct payload_rule_t
{
55 payload_type_t payload_type
;
58 * Minimal occurence of this payload.
63 * Max occurence of this payload.
68 * TRUE if payload must be encrypted
73 * If this payload occurs, the message rule is
74 * fullfilled in any case. This applies e.g. to
80 typedef struct payload_order_t payload_order_t
;
83 * payload ordering structure allows us to reorder payloads according to RFC.
85 struct payload_order_t
{
93 * notify type, if payload == NOTIFY
99 typedef struct message_rule_t message_rule_t
;
102 * A message rule defines the kind of a message,
103 * if it has encrypted contents and a list
104 * of payload ordering rules and payload parsing rules.
106 struct message_rule_t
{
110 exchange_type_t exchange_type
;
113 * Is message a request or response.
118 * Message contains encrypted content.
120 bool encrypted_content
;
123 * Number of payload rules which will follow
125 int payload_rule_count
;
128 * Pointer to first payload rule
130 payload_rule_t
*payload_rules
;
133 * Number of payload order rules
135 int payload_order_count
;
138 * payload ordering rules
140 payload_order_t
*payload_order
;
144 * Message rule for IKE_SA_INIT from initiator.
146 static payload_rule_t ike_sa_init_i_payload_rules
[] = {
147 /* payload type min max encr suff */
148 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, FALSE
, FALSE
},
149 {SECURITY_ASSOCIATION
, 1, 1, FALSE
, FALSE
},
150 {KEY_EXCHANGE
, 1, 1, FALSE
, FALSE
},
151 {NONCE
, 1, 1, FALSE
, FALSE
},
152 {VENDOR_ID
, 0, 10, FALSE
, FALSE
},
156 * payload order for IKE_SA_INIT initiator
158 static payload_order_t ike_sa_init_i_payload_order
[] = {
159 /* payload type notify type */
161 {SECURITY_ASSOCIATION
, 0},
164 {NOTIFY
, NAT_DETECTION_SOURCE_IP
},
165 {NOTIFY
, NAT_DETECTION_DESTINATION_IP
},
171 * Message rule for IKE_SA_INIT from responder.
173 static payload_rule_t ike_sa_init_r_payload_rules
[] = {
174 /* payload type min max encr suff */
175 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, FALSE
, TRUE
},
176 {SECURITY_ASSOCIATION
, 1, 1, FALSE
, FALSE
},
177 {KEY_EXCHANGE
, 1, 1, FALSE
, FALSE
},
178 {NONCE
, 1, 1, FALSE
, FALSE
},
179 {VENDOR_ID
, 0, 10, FALSE
, FALSE
},
183 * payload order for IKE_SA_INIT responder
185 static payload_order_t ike_sa_init_r_payload_order
[] = {
186 /* payload type notify type */
187 {SECURITY_ASSOCIATION
, 0},
190 {NOTIFY
, NAT_DETECTION_SOURCE_IP
},
191 {NOTIFY
, NAT_DETECTION_DESTINATION_IP
},
192 {NOTIFY
, HTTP_CERT_LOOKUP_SUPPORTED
},
193 {CERTIFICATE_REQUEST
, 0},
199 * Message rule for IKE_AUTH from initiator.
201 static payload_rule_t ike_auth_i_payload_rules
[] = {
202 /* payload type min max encr suff */
203 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, TRUE
, FALSE
},
204 {EXTENSIBLE_AUTHENTICATION
, 0, 1, TRUE
, TRUE
},
205 {AUTHENTICATION
, 0, 1, TRUE
, TRUE
},
206 {ID_INITIATOR
, 1, 1, TRUE
, FALSE
},
207 {CERTIFICATE
, 0, 4, TRUE
, FALSE
},
208 {CERTIFICATE_REQUEST
, 0, 1, TRUE
, FALSE
},
209 {ID_RESPONDER
, 0, 1, TRUE
, FALSE
},
211 {SECURITY_ASSOCIATION
, 0, 1, TRUE
, FALSE
},
212 {TRAFFIC_SELECTOR_INITIATOR
, 0, 1, TRUE
, FALSE
},
213 {TRAFFIC_SELECTOR_RESPONDER
, 0, 1, TRUE
, FALSE
},
215 {SECURITY_ASSOCIATION
, 1, 1, TRUE
, FALSE
},
216 {TRAFFIC_SELECTOR_INITIATOR
, 1, 1, TRUE
, FALSE
},
217 {TRAFFIC_SELECTOR_RESPONDER
, 1, 1, TRUE
, FALSE
},
219 {CONFIGURATION
, 0, 1, TRUE
, FALSE
},
220 {VENDOR_ID
, 0, 10, TRUE
, FALSE
},
224 * payload order for IKE_AUTH initiator
226 static payload_order_t ike_auth_i_payload_order
[] = {
227 /* payload type notify type */
230 {NOTIFY
, INITIAL_CONTACT
},
231 {NOTIFY
, HTTP_CERT_LOOKUP_SUPPORTED
},
232 {CERTIFICATE_REQUEST
, 0},
235 {EXTENSIBLE_AUTHENTICATION
, 0},
237 {NOTIFY
, IPCOMP_SUPPORTED
},
238 {NOTIFY
, USE_TRANSPORT_MODE
},
239 {NOTIFY
, ESP_TFC_PADDING_NOT_SUPPORTED
},
240 {NOTIFY
, NON_FIRST_FRAGMENTS_ALSO
},
241 {SECURITY_ASSOCIATION
, 0},
242 {TRAFFIC_SELECTOR_INITIATOR
, 0},
243 {TRAFFIC_SELECTOR_RESPONDER
, 0},
244 {NOTIFY
, MOBIKE_SUPPORTED
},
245 {NOTIFY
, ADDITIONAL_IP4_ADDRESS
},
246 {NOTIFY
, ADDITIONAL_IP6_ADDRESS
},
247 {NOTIFY
, NO_ADDITIONAL_ADDRESSES
},
253 * Message rule for IKE_AUTH from responder.
255 static payload_rule_t ike_auth_r_payload_rules
[] = {
256 /* payload type min max encr suff */
257 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, TRUE
, TRUE
},
258 {EXTENSIBLE_AUTHENTICATION
, 0, 1, TRUE
, TRUE
},
259 {CERTIFICATE
, 0, 4, TRUE
, FALSE
},
260 {ID_RESPONDER
, 0, 1, TRUE
, FALSE
},
261 {AUTHENTICATION
, 0, 1, TRUE
, FALSE
},
262 {SECURITY_ASSOCIATION
, 0, 1, TRUE
, FALSE
},
263 {TRAFFIC_SELECTOR_INITIATOR
, 0, 1, TRUE
, FALSE
},
264 {TRAFFIC_SELECTOR_RESPONDER
, 0, 1, TRUE
, FALSE
},
265 {CONFIGURATION
, 0, 1, TRUE
, FALSE
},
266 {VENDOR_ID
, 0, 10, TRUE
, FALSE
},
270 * payload order for IKE_AUTH responder
272 static payload_order_t ike_auth_r_payload_order
[] = {
273 /* payload type notify type */
277 {EXTENSIBLE_AUTHENTICATION
, 0},
279 {NOTIFY
, IPCOMP_SUPPORTED
},
280 {NOTIFY
, USE_TRANSPORT_MODE
},
281 {NOTIFY
, ESP_TFC_PADDING_NOT_SUPPORTED
},
282 {NOTIFY
, NON_FIRST_FRAGMENTS_ALSO
},
283 {SECURITY_ASSOCIATION
, 0},
284 {TRAFFIC_SELECTOR_INITIATOR
, 0},
285 {TRAFFIC_SELECTOR_RESPONDER
, 0},
286 {NOTIFY
, AUTH_LIFETIME
},
287 {NOTIFY
, MOBIKE_SUPPORTED
},
288 {NOTIFY
, ADDITIONAL_IP4_ADDRESS
},
289 {NOTIFY
, ADDITIONAL_IP6_ADDRESS
},
290 {NOTIFY
, NO_ADDITIONAL_ADDRESSES
},
296 * Message rule for INFORMATIONAL from initiator.
298 static payload_rule_t informational_i_payload_rules
[] = {
299 /* payload type min max encr suff */
300 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, TRUE
, FALSE
},
301 {CONFIGURATION
, 0, 1, TRUE
, FALSE
},
302 {DELETE
, 0, 1, TRUE
, FALSE
},
303 {VENDOR_ID
, 0, 10, TRUE
, FALSE
},
307 * payload order for INFORMATIONAL initiator
309 static payload_order_t informational_i_payload_order
[] = {
310 /* payload type notify type */
311 {NOTIFY
, UPDATE_SA_ADDRESSES
},
312 {NOTIFY
, NAT_DETECTION_SOURCE_IP
},
313 {NOTIFY
, NAT_DETECTION_DESTINATION_IP
},
321 * Message rule for INFORMATIONAL from responder.
323 static payload_rule_t informational_r_payload_rules
[] = {
324 /* payload type min max encr suff */
325 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, TRUE
, FALSE
},
326 {CONFIGURATION
, 0, 1, TRUE
, FALSE
},
327 {DELETE
, 0, 1, TRUE
, FALSE
},
328 {VENDOR_ID
, 0, 10, TRUE
, FALSE
},
332 * payload order for INFORMATIONAL responder
334 static payload_order_t informational_r_payload_order
[] = {
335 /* payload type notify type */
336 {NOTIFY
, UPDATE_SA_ADDRESSES
},
337 {NOTIFY
, NAT_DETECTION_SOURCE_IP
},
338 {NOTIFY
, NAT_DETECTION_DESTINATION_IP
},
346 * Message rule for CREATE_CHILD_SA from initiator.
348 static payload_rule_t create_child_sa_i_payload_rules
[] = {
349 /* payload type min max encr suff */
350 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, TRUE
, FALSE
},
351 {SECURITY_ASSOCIATION
, 1, 1, TRUE
, FALSE
},
352 {NONCE
, 1, 1, TRUE
, FALSE
},
353 {KEY_EXCHANGE
, 0, 1, TRUE
, FALSE
},
354 {TRAFFIC_SELECTOR_INITIATOR
, 0, 1, TRUE
, FALSE
},
355 {TRAFFIC_SELECTOR_RESPONDER
, 0, 1, TRUE
, FALSE
},
356 {CONFIGURATION
, 0, 1, TRUE
, FALSE
},
357 {VENDOR_ID
, 0, 10, TRUE
, FALSE
},
361 * payload order for CREATE_CHILD_SA from initiator.
363 static payload_order_t create_child_sa_i_payload_order
[] = {
364 /* payload type notify type */
366 {NOTIFY
, IPCOMP_SUPPORTED
},
367 {NOTIFY
, USE_TRANSPORT_MODE
},
368 {NOTIFY
, ESP_TFC_PADDING_NOT_SUPPORTED
},
369 {NOTIFY
, NON_FIRST_FRAGMENTS_ALSO
},
370 {SECURITY_ASSOCIATION
, 0},
373 {TRAFFIC_SELECTOR_INITIATOR
, 0},
374 {TRAFFIC_SELECTOR_RESPONDER
, 0},
379 * Message rule for CREATE_CHILD_SA from responder.
381 static payload_rule_t create_child_sa_r_payload_rules
[] = {
382 /* payload type min max encr suff */
383 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, TRUE
, TRUE
},
384 {SECURITY_ASSOCIATION
, 1, 1, TRUE
, FALSE
},
385 {NONCE
, 1, 1, TRUE
, FALSE
},
386 {KEY_EXCHANGE
, 0, 1, TRUE
, FALSE
},
387 {TRAFFIC_SELECTOR_INITIATOR
, 0, 1, TRUE
, FALSE
},
388 {TRAFFIC_SELECTOR_RESPONDER
, 0, 1, TRUE
, FALSE
},
389 {CONFIGURATION
, 0, 1, TRUE
, FALSE
},
390 {VENDOR_ID
, 0, 10, TRUE
, FALSE
},
394 * payload order for CREATE_CHILD_SA from responder.
396 static payload_order_t create_child_sa_r_payload_order
[] = {
397 /* payload type notify type */
398 {NOTIFY
, IPCOMP_SUPPORTED
},
399 {NOTIFY
, USE_TRANSPORT_MODE
},
400 {NOTIFY
, ESP_TFC_PADDING_NOT_SUPPORTED
},
401 {NOTIFY
, NON_FIRST_FRAGMENTS_ALSO
},
402 {SECURITY_ASSOCIATION
, 0},
405 {TRAFFIC_SELECTOR_INITIATOR
, 0},
406 {TRAFFIC_SELECTOR_RESPONDER
, 0},
407 {NOTIFY
, ADDITIONAL_TS_POSSIBLE
},
413 * Message rule for ME_CONNECT from initiator.
415 static payload_rule_t me_connect_i_payload_rules
[] = {
416 /* payload type min max encr suff */
417 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, TRUE
, TRUE
},
418 {ID_PEER
, 1, 1, TRUE
, FALSE
},
419 {VENDOR_ID
, 0, 10, TRUE
, FALSE
}
423 * payload order for ME_CONNECT from initiator.
425 static payload_order_t me_connect_i_payload_order
[] = {
426 /* payload type notify type */
433 * Message rule for ME_CONNECT from responder.
435 static payload_rule_t me_connect_r_payload_rules
[] = {
436 /* payload type min max encr suff */
437 {NOTIFY
, 0, MAX_NOTIFY_PAYLOADS
, TRUE
, TRUE
},
438 {VENDOR_ID
, 0, 10, TRUE
, FALSE
}
442 * payload order for ME_CONNECT from responder.
444 static payload_order_t me_connect_r_payload_order
[] = {
445 /* payload type notify type */
452 * Message rules, defines allowed payloads.
454 static message_rule_t message_rules
[] = {
455 {IKE_SA_INIT
, TRUE
, FALSE
,
456 (sizeof(ike_sa_init_i_payload_rules
)/sizeof(payload_rule_t
)),
457 ike_sa_init_i_payload_rules
,
458 (sizeof(ike_sa_init_i_payload_order
)/sizeof(payload_order_t
)),
459 ike_sa_init_i_payload_order
,
461 {IKE_SA_INIT
, FALSE
, FALSE
,
462 (sizeof(ike_sa_init_r_payload_rules
)/sizeof(payload_rule_t
)),
463 ike_sa_init_r_payload_rules
,
464 (sizeof(ike_sa_init_r_payload_order
)/sizeof(payload_order_t
)),
465 ike_sa_init_r_payload_order
,
467 {IKE_AUTH
, TRUE
, TRUE
,
468 (sizeof(ike_auth_i_payload_rules
)/sizeof(payload_rule_t
)),
469 ike_auth_i_payload_rules
,
470 (sizeof(ike_auth_i_payload_order
)/sizeof(payload_order_t
)),
471 ike_auth_i_payload_order
,
473 {IKE_AUTH
, FALSE
, TRUE
,
474 (sizeof(ike_auth_r_payload_rules
)/sizeof(payload_rule_t
)),
475 ike_auth_r_payload_rules
,
476 (sizeof(ike_auth_r_payload_order
)/sizeof(payload_order_t
)),
477 ike_auth_r_payload_order
,
479 {INFORMATIONAL
, TRUE
, TRUE
,
480 (sizeof(informational_i_payload_rules
)/sizeof(payload_rule_t
)),
481 informational_i_payload_rules
,
482 (sizeof(informational_i_payload_order
)/sizeof(payload_order_t
)),
483 informational_i_payload_order
,
485 {INFORMATIONAL
, FALSE
, TRUE
,
486 (sizeof(informational_r_payload_rules
)/sizeof(payload_rule_t
)),
487 informational_r_payload_rules
,
488 (sizeof(informational_r_payload_order
)/sizeof(payload_order_t
)),
489 informational_r_payload_order
,
491 {CREATE_CHILD_SA
, TRUE
, TRUE
,
492 (sizeof(create_child_sa_i_payload_rules
)/sizeof(payload_rule_t
)),
493 create_child_sa_i_payload_rules
,
494 (sizeof(create_child_sa_i_payload_order
)/sizeof(payload_order_t
)),
495 create_child_sa_i_payload_order
,
497 {CREATE_CHILD_SA
, FALSE
, TRUE
,
498 (sizeof(create_child_sa_r_payload_rules
)/sizeof(payload_rule_t
)),
499 create_child_sa_r_payload_rules
,
500 (sizeof(create_child_sa_r_payload_order
)/sizeof(payload_order_t
)),
501 create_child_sa_r_payload_order
,
504 {ME_CONNECT
, TRUE
, TRUE
,
505 (sizeof(me_connect_i_payload_rules
)/sizeof(payload_rule_t
)),
506 me_connect_i_payload_rules
,
507 (sizeof(me_connect_i_payload_order
)/sizeof(payload_order_t
)),
508 me_connect_i_payload_order
,
510 {ME_CONNECT
, FALSE
, TRUE
,
511 (sizeof(me_connect_r_payload_rules
)/sizeof(payload_rule_t
)),
512 me_connect_r_payload_rules
,
513 (sizeof(me_connect_r_payload_order
)/sizeof(payload_order_t
)),
514 me_connect_r_payload_order
,
520 typedef struct private_message_t private_message_t
;
523 * Private data of an message_t object.
525 struct private_message_t
{
528 * Public part of a message_t object.
533 * Minor version of message.
535 u_int8_t major_version
;
538 * Major version of message.
540 u_int8_t minor_version
;
543 * First Payload in message.
545 payload_type_t first_payload
;
548 * Assigned exchange type.
550 exchange_type_t exchange_type
;
553 * TRUE if message is a request, FALSE if a reply.
558 * Message ID of this message.
560 u_int32_t message_id
;
563 * ID of assigned IKE_SA.
565 ike_sa_id_t
*ike_sa_id
;
568 * Assigned UDP packet, stores incoming packet or last generated one.
573 * Linked List where payload data are stored in.
575 linked_list_t
*payloads
;
578 * Assigned parser to parse Header and Body of this message.
583 * The message rule for this message instance
585 message_rule_t
*message_rule
;
589 * Implementation of private_message_t.set_message_rule.
591 static status_t
set_message_rule(private_message_t
*this)
595 for (i
= 0; i
< (sizeof(message_rules
) / sizeof(message_rule_t
)); i
++)
597 if ((this->exchange_type
== message_rules
[i
].exchange_type
) &&
598 (this->is_request
== message_rules
[i
].is_request
))
600 /* found rule for given exchange_type*/
601 this->message_rule
= &(message_rules
[i
]);
605 this->message_rule
= NULL
;
610 * Implementation of private_message_t.get_payload_rule.
612 static status_t
get_payload_rule(private_message_t
*this, payload_type_t payload_type
, payload_rule_t
**payload_rule
)
616 for (i
= 0; i
< this->message_rule
->payload_rule_count
;i
++)
618 if (this->message_rule
->payload_rules
[i
].payload_type
== payload_type
)
620 *payload_rule
= &(this->message_rule
->payload_rules
[i
]);
625 *payload_rule
= NULL
;
630 * Implementation of message_t.set_ike_sa_id.
632 static void set_ike_sa_id (private_message_t
*this,ike_sa_id_t
*ike_sa_id
)
634 DESTROY_IF(this->ike_sa_id
);
635 this->ike_sa_id
= ike_sa_id
->clone(ike_sa_id
);
639 * Implementation of message_t.get_ike_sa_id.
641 static ike_sa_id_t
* get_ike_sa_id (private_message_t
*this)
643 return this->ike_sa_id
;
647 * Implementation of message_t.set_message_id.
649 static void set_message_id (private_message_t
*this,u_int32_t message_id
)
651 this->message_id
= message_id
;
655 * Implementation of message_t.get_message_id.
657 static u_int32_t
get_message_id (private_message_t
*this)
659 return this->message_id
;
663 * Implementation of message_t.get_initiator_spi.
665 static u_int64_t
get_initiator_spi (private_message_t
*this)
667 return (this->ike_sa_id
->get_initiator_spi(this->ike_sa_id
));
671 * Implementation of message_t.get_responder_spi.
673 static u_int64_t
get_responder_spi (private_message_t
*this)
675 return (this->ike_sa_id
->get_responder_spi(this->ike_sa_id
));
679 * Implementation of message_t.set_major_version.
681 static void set_major_version (private_message_t
*this,u_int8_t major_version
)
683 this->major_version
= major_version
;
688 * Implementation of message_t.set_major_version.
690 static u_int8_t
get_major_version (private_message_t
*this)
692 return this->major_version
;
696 * Implementation of message_t.set_minor_version.
698 static void set_minor_version (private_message_t
*this,u_int8_t minor_version
)
700 this->minor_version
= minor_version
;
704 * Implementation of message_t.get_minor_version.
706 static u_int8_t
get_minor_version (private_message_t
*this)
708 return this->minor_version
;
712 * Implementation of message_t.set_exchange_type.
714 static void set_exchange_type (private_message_t
*this,exchange_type_t exchange_type
)
716 this->exchange_type
= exchange_type
;
720 * Implementation of message_t.get_exchange_type.
722 static exchange_type_t
get_exchange_type (private_message_t
*this)
724 return this->exchange_type
;
728 * Implementation of message_t.get_first_payload_type.
730 static payload_type_t
get_first_payload_type (private_message_t
*this)
732 return this->first_payload
;
736 * Implementation of message_t.set_request.
738 static void set_request (private_message_t
*this,bool request
)
740 this->is_request
= request
;
744 * Implementation of message_t.get_request.
746 static exchange_type_t
get_request (private_message_t
*this)
748 return this->is_request
;
752 * Is this message in an encoded form?
754 static bool is_encoded(private_message_t
*this)
756 chunk_t data
= this->packet
->get_data(this->packet
);
758 if (data
.ptr
== NULL
)
766 * Implementation of message_t.add_payload.
768 static void add_payload(private_message_t
*this, payload_t
*payload
)
770 payload_t
*last_payload
;
772 if (this->payloads
->get_count(this->payloads
) > 0)
774 this->payloads
->get_last(this->payloads
, (void **)&last_payload
);
775 last_payload
->set_next_type(last_payload
, payload
->get_type(payload
));
779 this->first_payload
= payload
->get_type(payload
);
781 payload
->set_next_type(payload
, NO_PAYLOAD
);
782 this->payloads
->insert_last(this->payloads
, payload
);
784 DBG2(DBG_ENC
,"added payload of type %N to message",
785 payload_type_names
, payload
->get_type(payload
));
789 * Implementation of message_t.add_notify.
791 static void add_notify(private_message_t
*this, bool flush
, notify_type_t type
,
794 notify_payload_t
*notify
;
799 while (this->payloads
->remove_last(this->payloads
,
800 (void**)&payload
) == SUCCESS
)
802 payload
->destroy(payload
);
805 notify
= notify_payload_create();
806 notify
->set_notify_type(notify
, type
);
807 notify
->set_notification_data(notify
, data
);
808 add_payload(this, (payload_t
*)notify
);
812 * Implementation of message_t.set_source.
814 static void set_source(private_message_t
*this, host_t
*host
)
816 this->packet
->set_source(this->packet
, host
);
820 * Implementation of message_t.set_destination.
822 static void set_destination(private_message_t
*this, host_t
*host
)
824 this->packet
->set_destination(this->packet
, host
);
828 * Implementation of message_t.get_source.
830 static host_t
* get_source(private_message_t
*this)
832 return this->packet
->get_source(this->packet
);
836 * Implementation of message_t.get_destination.
838 static host_t
* get_destination(private_message_t
*this)
840 return this->packet
->get_destination(this->packet
);
844 * Implementation of message_t.get_payload_iterator.
846 static iterator_t
*get_payload_iterator(private_message_t
*this)
848 return this->payloads
->create_iterator(this->payloads
, TRUE
);
852 * Implementation of message_t.get_payload.
854 static payload_t
*get_payload(private_message_t
*this, payload_type_t type
)
856 payload_t
*current
, *found
= NULL
;
857 iterator_t
*iterator
;
859 iterator
= this->payloads
->create_iterator(this->payloads
, TRUE
);
860 while (iterator
->iterate(iterator
, (void**)¤t
))
862 if (current
->get_type(current
) == type
)
868 iterator
->destroy(iterator
);
873 * get a string representation of the message
875 static char* get_string(private_message_t
*this, char *buf
, int len
)
877 iterator_t
*iterator
;
885 written
= snprintf(pos
, len
, "%N %s %d [",
886 exchange_type_names
, this->exchange_type
,
887 this->is_request ?
"request" : "response",
889 if (written
>= len
|| written
< 0)
896 iterator
= this->payloads
->create_iterator(this->payloads
, TRUE
);
897 while (iterator
->iterate(iterator
, (void**)&payload
))
899 written
= snprintf(pos
, len
, " %N", payload_type_short_names
,
900 payload
->get_type(payload
));
901 if (written
>= len
|| written
< 0)
907 if (payload
->get_type(payload
) == NOTIFY
)
909 notify_payload_t
*notify
= (notify_payload_t
*)payload
;
910 written
= snprintf(pos
, len
, "(%N)", notify_type_short_names
,
911 notify
->get_notify_type(notify
));
912 if (written
>= len
|| written
< 0)
920 iterator
->destroy(iterator
);
922 /* remove last space */
923 snprintf(pos
, len
, " ]");
928 * reorder payloads depending on reordering rules
930 static void order_payloads(private_message_t
*this)
936 /* move to temp list */
937 list
= linked_list_create();
938 while (this->payloads
->remove_last(this->payloads
,
939 (void**)&payload
) == SUCCESS
)
941 list
->insert_first(list
, payload
);
943 /* for each rule, ... */
944 for (i
= 0; i
< this->message_rule
->payload_order_count
; i
++)
946 enumerator_t
*enumerator
;
947 notify_payload_t
*notify
;
948 payload_order_t order
= this->message_rule
->payload_order
[i
];
950 /* ... find all payload ... */
951 enumerator
= list
->create_enumerator(list
);
952 while (enumerator
->enumerate(enumerator
, &payload
))
954 /* ... with that type ... */
955 if (payload
->get_type(payload
) == order
.type
)
957 notify
= (notify_payload_t
*)payload
;
959 /**... and check notify for type. */
960 if (order
.type
!= NOTIFY
|| order
.notify
== 0 ||
961 order
.notify
== notify
->get_notify_type(notify
))
963 list
->remove_at(list
, enumerator
);
964 add_payload(this, payload
);
968 enumerator
->destroy(enumerator
);
970 /* append all payloads without a rule to the end */
971 while (list
->remove_last(list
, (void**)&payload
) == SUCCESS
)
973 DBG1(DBG_ENC
, "payload %N has no ordering rule in %N %s",
974 payload_type_names
, payload
->get_type(payload
),
975 exchange_type_names
, this->message_rule
->exchange_type
,
976 this->message_rule
->is_request ?
"request" : "response");
977 add_payload(this, payload
);
983 * Implementation of private_message_t.encrypt_payloads.
985 static status_t
encrypt_payloads(private_message_t
*this,
986 crypter_t
*crypter
, signer_t
* signer
)
988 encryption_payload_t
*encryption_payload
= NULL
;
990 linked_list_t
*all_payloads
;
992 if (!this->message_rule
->encrypted_content
)
994 DBG2(DBG_ENC
, "message doesn't have to be encrypted");
995 /* message contains no content to encrypt */
999 if (!crypter
|| !signer
)
1001 DBG2(DBG_ENC
, "no crypter or signer specified, do not encrypt message");
1002 /* message contains no content to encrypt */
1006 DBG2(DBG_ENC
, "copy all payloads to a temporary list");
1007 all_payloads
= linked_list_create();
1009 /* first copy all payloads in a temporary list */
1010 while (this->payloads
->get_count(this->payloads
) > 0)
1012 void *current_payload
;
1013 this->payloads
->remove_first(this->payloads
,¤t_payload
);
1014 all_payloads
->insert_last(all_payloads
,current_payload
);
1017 encryption_payload
= encryption_payload_create();
1019 DBG2(DBG_ENC
, "check each payloads if they have to get encrypted");
1020 while (all_payloads
->get_count(all_payloads
) > 0)
1022 payload_rule_t
*payload_rule
;
1023 payload_t
*current_payload
;
1024 bool to_encrypt
= FALSE
;
1026 all_payloads
->remove_first(all_payloads
,(void **)¤t_payload
);
1028 status
= get_payload_rule(this,
1029 current_payload
->get_type(current_payload
),&payload_rule
);
1030 /* for payload types which are not found in supported payload list,
1031 * it is presumed that they don't have to be encrypted */
1032 if ((status
== SUCCESS
) && (payload_rule
->encrypted
))
1034 DBG2(DBG_ENC
, "payload %N gets encrypted",
1035 payload_type_names
, current_payload
->get_type(current_payload
));
1041 DBG2(DBG_ENC
, "insert payload %N to encryption payload",
1042 payload_type_names
, current_payload
->get_type(current_payload
));
1043 encryption_payload
->add_payload(encryption_payload
,current_payload
);
1047 DBG2(DBG_ENC
, "insert payload %N unencrypted",
1048 payload_type_names
,current_payload
->get_type(current_payload
));
1049 add_payload(this, (payload_t
*)encryption_payload
);
1054 DBG2(DBG_ENC
, "encrypting encryption payload");
1055 encryption_payload
->set_transforms(encryption_payload
, crypter
,signer
);
1056 status
= encryption_payload
->encrypt(encryption_payload
);
1057 DBG2(DBG_ENC
, "add encrypted payload to payload list");
1058 add_payload(this, (payload_t
*)encryption_payload
);
1060 all_payloads
->destroy(all_payloads
);
1066 * Implementation of message_t.generate.
1068 static status_t
generate(private_message_t
*this, crypter_t
*crypter
,
1069 signer_t
* signer
, packet_t
**packet
)
1071 generator_t
*generator
;
1072 ike_header_t
*ike_header
;
1073 payload_t
*payload
, *next_payload
;
1074 iterator_t
*iterator
;
1076 chunk_t packet_data
;
1079 if (is_encoded(this))
1081 /* already generated, return a new packet clone */
1082 *packet
= this->packet
->clone(this->packet
);
1086 if (this->exchange_type
== EXCHANGE_TYPE_UNDEFINED
)
1088 DBG1(DBG_ENC
, "exchange type is not defined");
1089 return INVALID_STATE
;
1092 if (this->packet
->get_source(this->packet
) == NULL
||
1093 this->packet
->get_destination(this->packet
) == NULL
)
1095 DBG1(DBG_ENC
, "%s not defined",
1096 !this->packet
->get_source(this->packet
) ?
"source" : "destination");
1097 return INVALID_STATE
;
1100 /* set the rules for this messge */
1101 status
= set_message_rule(this);
1102 if (status
!= SUCCESS
)
1104 DBG1(DBG_ENC
, "no message rules specified for this message type");
1105 return NOT_SUPPORTED
;
1108 order_payloads(this);
1110 DBG1(DBG_ENC
, "generating %s", get_string(this, str
, sizeof(str
)));
1112 /* going to encrypt all content which have to be encrypted */
1113 status
= encrypt_payloads(this, crypter
, signer
);
1114 if (status
!= SUCCESS
)
1116 DBG1(DBG_ENC
, "payload encryption failed");
1120 /* build ike header */
1121 ike_header
= ike_header_create();
1123 ike_header
->set_exchange_type(ike_header
, this->exchange_type
);
1124 ike_header
->set_message_id(ike_header
, this->message_id
);
1125 ike_header
->set_response_flag(ike_header
, !this->is_request
);
1126 ike_header
->set_initiator_flag(ike_header
, this->ike_sa_id
->is_initiator(this->ike_sa_id
));
1127 ike_header
->set_initiator_spi(ike_header
, this->ike_sa_id
->get_initiator_spi(this->ike_sa_id
));
1128 ike_header
->set_responder_spi(ike_header
, this->ike_sa_id
->get_responder_spi(this->ike_sa_id
));
1130 generator
= generator_create();
1132 payload
= (payload_t
*)ike_header
;
1135 /* generate every payload expect last one, this is done later*/
1136 iterator
= this->payloads
->create_iterator(this->payloads
, TRUE
);
1137 while(iterator
->iterate(iterator
, (void**)&next_payload
))
1139 payload
->set_next_type(payload
, next_payload
->get_type(next_payload
));
1140 generator
->generate_payload(generator
, payload
);
1141 payload
= next_payload
;
1143 iterator
->destroy(iterator
);
1145 /* last payload has no next payload*/
1146 payload
->set_next_type(payload
, NO_PAYLOAD
);
1148 generator
->generate_payload(generator
, payload
);
1150 ike_header
->destroy(ike_header
);
1153 generator
->write_to_chunk(generator
, &packet_data
);
1154 generator
->destroy(generator
);
1156 /* if last payload is of type encrypted, integrity checksum if necessary */
1157 if (payload
->get_type(payload
) == ENCRYPTED
)
1159 DBG2(DBG_ENC
, "build signature on whole message");
1160 encryption_payload_t
*encryption_payload
= (encryption_payload_t
*)payload
;
1161 status
= encryption_payload
->build_signature(encryption_payload
, packet_data
);
1162 if (status
!= SUCCESS
)
1168 this->packet
->set_data(this->packet
, packet_data
);
1170 /* clone packet for caller */
1171 *packet
= this->packet
->clone(this->packet
);
1173 DBG2(DBG_ENC
, "message generated successfully");
1178 * Implementation of message_t.get_packet.
1180 static packet_t
*get_packet (private_message_t
*this)
1182 if (this->packet
== NULL
)
1186 return this->packet
->clone(this->packet
);
1190 * Implementation of message_t.get_packet_data.
1192 static chunk_t
get_packet_data (private_message_t
*this)
1194 if (this->packet
== NULL
)
1198 return chunk_clone(this->packet
->get_data(this->packet
));
1202 * Implementation of message_t.parse_header.
1204 static status_t
parse_header(private_message_t
*this)
1206 ike_header_t
*ike_header
;
1209 DBG2(DBG_ENC
, "parsing header of message");
1211 this->parser
->reset_context(this->parser
);
1212 status
= this->parser
->parse_payload(this->parser
,HEADER
,(payload_t
**) &ike_header
);
1213 if (status
!= SUCCESS
)
1215 DBG1(DBG_ENC
, "header could not be parsed");
1220 /* verify payload */
1221 status
= ike_header
->payload_interface
.verify(&(ike_header
->payload_interface
));
1222 if (status
!= SUCCESS
)
1224 DBG1(DBG_ENC
, "header verification failed");
1225 ike_header
->destroy(ike_header
);
1229 if (this->ike_sa_id
!= NULL
)
1231 this->ike_sa_id
->destroy(this->ike_sa_id
);
1234 this->ike_sa_id
= ike_sa_id_create(ike_header
->get_initiator_spi(ike_header
),
1235 ike_header
->get_responder_spi(ike_header
),
1236 ike_header
->get_initiator_flag(ike_header
));
1238 this->exchange_type
= ike_header
->get_exchange_type(ike_header
);
1239 this->message_id
= ike_header
->get_message_id(ike_header
);
1240 this->is_request
= (!(ike_header
->get_response_flag(ike_header
)));
1241 this->major_version
= ike_header
->get_maj_version(ike_header
);
1242 this->minor_version
= ike_header
->get_min_version(ike_header
);
1243 this->first_payload
= ike_header
->payload_interface
.get_next_type(&(ike_header
->payload_interface
));
1245 DBG2(DBG_ENC
, "parsed a %N %s", exchange_type_names
, this->exchange_type
,
1246 this->is_request ?
"request" : "response");
1248 ike_header
->destroy(ike_header
);
1250 /* get the rules for this messge */
1251 status
= set_message_rule(this);
1252 if (status
!= SUCCESS
)
1254 DBG1(DBG_ENC
, "no message rules specified for a %N %s",
1255 exchange_type_names
, this->exchange_type
,
1256 this->is_request ?
"request" : "response");
1263 * Implementation of private_message_t.decrypt_and_verify_payloads.
1265 static status_t
decrypt_payloads(private_message_t
*this,crypter_t
*crypter
, signer_t
* signer
)
1267 bool current_payload_was_encrypted
= FALSE
;
1268 payload_t
*previous_payload
= NULL
;
1269 int payload_number
= 1;
1270 iterator_t
*iterator
;
1271 payload_t
*current_payload
;
1274 iterator
= this->payloads
->create_iterator(this->payloads
,TRUE
);
1276 /* process each payload and decrypt a encryption payload */
1277 while(iterator
->iterate(iterator
, (void**)¤t_payload
))
1279 payload_rule_t
*payload_rule
;
1280 payload_type_t current_payload_type
;
1282 /* needed to check */
1283 current_payload_type
= current_payload
->get_type(current_payload
);
1285 DBG2(DBG_ENC
, "process payload of type %N",
1286 payload_type_names
, current_payload_type
);
1288 if (current_payload_type
== ENCRYPTED
)
1290 encryption_payload_t
*encryption_payload
;
1291 payload_t
*current_encrypted_payload
;
1293 encryption_payload
= (encryption_payload_t
*)current_payload
;
1295 DBG2(DBG_ENC
, "found an encryption payload");
1297 if (payload_number
!= this->payloads
->get_count(this->payloads
))
1299 /* encrypted payload is not last one */
1300 DBG1(DBG_ENC
, "encrypted payload is not last payload");
1301 iterator
->destroy(iterator
);
1302 return VERIFY_ERROR
;
1305 encryption_payload
->set_transforms(encryption_payload
, crypter
, signer
);
1306 DBG2(DBG_ENC
, "verify signature of encryption payload");
1307 status
= encryption_payload
->verify_signature(encryption_payload
,
1308 this->packet
->get_data(this->packet
));
1309 if (status
!= SUCCESS
)
1311 DBG1(DBG_ENC
, "encryption payload signature invalid");
1312 iterator
->destroy(iterator
);
1315 DBG2(DBG_ENC
, "decrypting content of encryption payload");
1316 status
= encryption_payload
->decrypt(encryption_payload
);
1317 if (status
!= SUCCESS
)
1319 DBG1(DBG_ENC
, "encrypted payload could not be decrypted and parsed");
1320 iterator
->destroy(iterator
);
1324 /* needed later to find out if a payload was encrypted */
1325 current_payload_was_encrypted
= TRUE
;
1327 /* check if there are payloads contained in the encryption payload */
1328 if (encryption_payload
->get_payload_count(encryption_payload
) == 0)
1330 DBG2(DBG_ENC
, "encrypted payload is empty");
1331 /* remove the encryption payload, is not needed anymore */
1332 iterator
->remove(iterator
);
1333 /* encrypted payload contains no other payload */
1334 current_payload_type
= NO_PAYLOAD
;
1338 /* encryption_payload is replaced with first payload contained in encryption_payload */
1339 encryption_payload
->remove_first_payload(encryption_payload
, ¤t_encrypted_payload
);
1340 iterator
->replace(iterator
,NULL
,(void *) current_encrypted_payload
);
1341 current_payload_type
= current_encrypted_payload
->get_type(current_encrypted_payload
);
1344 /* is the current paylad the first in the message? */
1345 if (previous_payload
== NULL
)
1347 /* yes, set the first payload type of the message to the current type */
1348 this->first_payload
= current_payload_type
;
1352 /* no, set the next_type of the previous payload to the current type */
1353 previous_payload
->set_next_type(previous_payload
, current_payload_type
);
1356 /* all encrypted payloads are added to the payload list */
1357 while (encryption_payload
->get_payload_count(encryption_payload
) > 0)
1359 encryption_payload
->remove_first_payload(encryption_payload
, ¤t_encrypted_payload
);
1360 DBG2(DBG_ENC
, "insert unencrypted payload of type %N at end of list",
1361 payload_type_names
, current_encrypted_payload
->get_type(current_encrypted_payload
));
1362 this->payloads
->insert_last(this->payloads
,current_encrypted_payload
);
1365 /* encryption payload is processed, payloads are moved. Destroy it. */
1366 encryption_payload
->destroy(encryption_payload
);
1369 /* we allow unknown payloads of any type and don't bother if it was encrypted. Not our problem. */
1370 if (current_payload_type
!= UNKNOWN_PAYLOAD
&& current_payload_type
!= NO_PAYLOAD
)
1372 /* get the ruleset for found payload */
1373 status
= get_payload_rule(this, current_payload_type
, &payload_rule
);
1374 if (status
!= SUCCESS
)
1376 /* payload is not allowed */
1377 DBG1(DBG_ENC
, "payload type %N not allowed",
1378 payload_type_names
, current_payload_type
);
1379 iterator
->destroy(iterator
);
1380 return VERIFY_ERROR
;
1383 /* check if the payload was encrypted, and if it should been have encrypted */
1384 if (payload_rule
->encrypted
!= current_payload_was_encrypted
)
1386 /* payload was not encrypted, but should have been. or vice-versa */
1387 DBG1(DBG_ENC
, "payload type %N should be %s!",
1388 payload_type_names
, current_payload_type
,
1389 (payload_rule
->encrypted
) ?
"encrypted" : "not encrypted");
1390 iterator
->destroy(iterator
);
1391 return VERIFY_ERROR
;
1394 /* advance to the next payload */
1396 /* is stored to set next payload in case of found encryption payload */
1397 previous_payload
= current_payload
;
1399 iterator
->destroy(iterator
);
1404 * Implementation of private_message_t.verify.
1406 static status_t
verify(private_message_t
*this)
1409 iterator_t
*iterator
;
1410 payload_t
*current_payload
;
1411 size_t total_found_payloads
= 0;
1413 DBG2(DBG_ENC
, "verifying message structure");
1415 iterator
= this->payloads
->create_iterator(this->payloads
,TRUE
);
1416 /* check for payloads with wrong count*/
1417 for (i
= 0; i
< this->message_rule
->payload_rule_count
;i
++)
1419 size_t found_payloads
= 0;
1421 /* check all payloads for specific rule */
1422 iterator
->reset(iterator
);
1424 while(iterator
->iterate(iterator
,(void **)¤t_payload
))
1426 payload_type_t current_payload_type
;
1428 current_payload_type
= current_payload
->get_type(current_payload
);
1429 if (current_payload_type
== UNKNOWN_PAYLOAD
)
1431 /* unknown payloads are ignored, IF they are not critical */
1432 unknown_payload_t
*unknown_payload
= (unknown_payload_t
*)current_payload
;
1433 if (unknown_payload
->is_critical(unknown_payload
))
1435 DBG1(DBG_ENC
, "%N is not supported, but its critical!",
1436 payload_type_names
, current_payload_type
);
1437 iterator
->destroy(iterator
);
1438 return NOT_SUPPORTED
;
1441 else if (current_payload_type
== this->message_rule
->payload_rules
[i
].payload_type
)
1444 total_found_payloads
++;
1445 DBG2(DBG_ENC
, "found payload of type %N",
1446 payload_type_names
, this->message_rule
->payload_rules
[i
].payload_type
);
1448 /* as soon as ohe payload occures more then specified, the verification fails */
1449 if (found_payloads
> this->message_rule
->payload_rules
[i
].max_occurence
)
1451 DBG1(DBG_ENC
, "payload of type %N more than %d times (%d) occured in current message",
1452 payload_type_names
, current_payload_type
,
1453 this->message_rule
->payload_rules
[i
].max_occurence
, found_payloads
);
1454 iterator
->destroy(iterator
);
1455 return VERIFY_ERROR
;
1460 if (found_payloads
< this->message_rule
->payload_rules
[i
].min_occurence
)
1462 DBG1(DBG_ENC
, "payload of type %N not occured %d times (%d)",
1463 payload_type_names
, this->message_rule
->payload_rules
[i
].payload_type
,
1464 this->message_rule
->payload_rules
[i
].min_occurence
, found_payloads
);
1465 iterator
->destroy(iterator
);
1466 return VERIFY_ERROR
;
1468 if ((this->message_rule
->payload_rules
[i
].sufficient
) && (this->payloads
->get_count(this->payloads
) == total_found_payloads
))
1470 iterator
->destroy(iterator
);
1474 iterator
->destroy(iterator
);
1479 * Implementation of message_t.parse_body.
1481 static status_t
parse_body(private_message_t
*this, crypter_t
*crypter
, signer_t
*signer
)
1483 status_t status
= SUCCESS
;
1484 payload_type_t current_payload_type
;
1487 current_payload_type
= this->first_payload
;
1489 DBG2(DBG_ENC
, "parsing body of message, first payload is %N",
1490 payload_type_names
, current_payload_type
);
1492 /* parse payload for payload, while there are more available */
1493 while ((current_payload_type
!= NO_PAYLOAD
))
1495 payload_t
*current_payload
;
1497 DBG2(DBG_ENC
, "starting parsing a %N payload",
1498 payload_type_names
, current_payload_type
);
1500 /* parse current payload */
1501 status
= this->parser
->parse_payload(this->parser
,current_payload_type
,(payload_t
**) ¤t_payload
);
1503 if (status
!= SUCCESS
)
1505 DBG1(DBG_ENC
, "payload type %N could not be parsed",
1506 payload_type_names
, current_payload_type
);
1510 DBG2(DBG_ENC
, "verifying payload of type %N",
1511 payload_type_names
, current_payload_type
);
1513 /* verify it, stop parsig if its invalid */
1514 status
= current_payload
->verify(current_payload
);
1515 if (status
!= SUCCESS
)
1517 DBG1(DBG_ENC
, "%N payload verification failed",
1518 payload_type_names
, current_payload_type
);
1519 current_payload
->destroy(current_payload
);
1520 return VERIFY_ERROR
;
1523 DBG2(DBG_ENC
, "%N payload verified. Adding to payload list",
1524 payload_type_names
, current_payload_type
);
1525 this->payloads
->insert_last(this->payloads
,current_payload
);
1527 /* an encryption payload is the last one, so STOP here. decryption is done later */
1528 if (current_payload_type
== ENCRYPTED
)
1530 DBG2(DBG_ENC
, "%N payload found. Stop parsing",
1531 payload_type_names
, current_payload_type
);
1535 /* get next payload type */
1536 current_payload_type
= current_payload
->get_next_type(current_payload
);
1539 if (current_payload_type
== ENCRYPTED
)
1541 status
= decrypt_payloads(this,crypter
,signer
);
1542 if (status
!= SUCCESS
)
1544 DBG1(DBG_ENC
, "could not decrypt payloads");
1549 status
= verify(this);
1550 if (status
!= SUCCESS
)
1555 DBG1(DBG_ENC
, "parsed %s", get_string(this, str
, sizeof(str
)));
1561 * Implementation of message_t.destroy.
1563 static void destroy (private_message_t
*this)
1565 DESTROY_IF(this->ike_sa_id
);
1566 this->payloads
->destroy_offset(this->payloads
, offsetof(payload_t
, destroy
));
1567 this->packet
->destroy(this->packet
);
1568 this->parser
->destroy(this->parser
);
1573 * Described in Header-File
1575 message_t
*message_create_from_packet(packet_t
*packet
)
1577 private_message_t
*this = malloc_thing(private_message_t
);
1579 /* public functions */
1580 this->public.set_major_version
= (void(*)(message_t
*, u_int8_t
))set_major_version
;
1581 this->public.get_major_version
= (u_int8_t(*)(message_t
*))get_major_version
;
1582 this->public.set_minor_version
= (void(*)(message_t
*, u_int8_t
))set_minor_version
;
1583 this->public.get_minor_version
= (u_int8_t(*)(message_t
*))get_minor_version
;
1584 this->public.set_message_id
= (void(*)(message_t
*, u_int32_t
))set_message_id
;
1585 this->public.get_message_id
= (u_int32_t(*)(message_t
*))get_message_id
;
1586 this->public.get_initiator_spi
= (u_int64_t(*)(message_t
*))get_initiator_spi
;
1587 this->public.get_responder_spi
= (u_int64_t(*)(message_t
*))get_responder_spi
;
1588 this->public.set_ike_sa_id
= (void(*)(message_t
*, ike_sa_id_t
*))set_ike_sa_id
;
1589 this->public.get_ike_sa_id
= (ike_sa_id_t
*(*)(message_t
*))get_ike_sa_id
;
1590 this->public.set_exchange_type
= (void(*)(message_t
*, exchange_type_t
))set_exchange_type
;
1591 this->public.get_exchange_type
= (exchange_type_t(*)(message_t
*))get_exchange_type
;
1592 this->public.get_first_payload_type
= (payload_type_t(*)(message_t
*))get_first_payload_type
;
1593 this->public.set_request
= (void(*)(message_t
*, bool))set_request
;
1594 this->public.get_request
= (bool(*)(message_t
*))get_request
;
1595 this->public.add_payload
= (void(*)(message_t
*,payload_t
*))add_payload
;
1596 this->public.add_notify
= (void(*)(message_t
*,bool,notify_type_t
,chunk_t
))add_notify
;
1597 this->public.generate
= (status_t (*) (message_t
*,crypter_t
*,signer_t
*,packet_t
**)) generate
;
1598 this->public.set_source
= (void (*) (message_t
*,host_t
*)) set_source
;
1599 this->public.get_source
= (host_t
* (*) (message_t
*)) get_source
;
1600 this->public.set_destination
= (void (*) (message_t
*,host_t
*)) set_destination
;
1601 this->public.get_destination
= (host_t
* (*) (message_t
*)) get_destination
;
1602 this->public.get_payload_iterator
= (iterator_t
* (*) (message_t
*)) get_payload_iterator
;
1603 this->public.get_payload
= (payload_t
* (*) (message_t
*, payload_type_t
)) get_payload
;
1604 this->public.parse_header
= (status_t (*) (message_t
*)) parse_header
;
1605 this->public.parse_body
= (status_t (*) (message_t
*,crypter_t
*,signer_t
*)) parse_body
;
1606 this->public.get_packet
= (packet_t
* (*) (message_t
*)) get_packet
;
1607 this->public.get_packet_data
= (chunk_t (*) (message_t
*this)) get_packet_data
;
1608 this->public.destroy
= (void(*)(message_t
*))destroy
;
1610 /* private values */
1611 this->exchange_type
= EXCHANGE_TYPE_UNDEFINED
;
1612 this->is_request
= TRUE
;
1613 this->ike_sa_id
= NULL
;
1614 this->first_payload
= NO_PAYLOAD
;
1615 this->message_id
= 0;
1617 /* private values */
1620 packet
= packet_create();
1622 this->message_rule
= NULL
;
1623 this->packet
= packet
;
1624 this->payloads
= linked_list_create();
1626 /* parser is created from data of packet */
1627 this->parser
= parser_create(this->packet
->get_data(this->packet
));
1629 return (&this->public);
1633 * Described in Header.
1635 message_t
*message_create()
1637 return message_create_from_packet(NULL
);