- encryptino payload
[strongswan.git] / Source / charon / encoding / message.c
1 /**
2 * @file message.c
3 *
4 * @brief Class message_t. Object of this type represents an IKEv2-Message.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <stdlib.h>
24
25 #include "message.h"
26
27 #include <types.h>
28 #include <globals.h>
29 #include <sa/ike_sa_id.h>
30 #include <encoding/generator.h>
31 #include <encoding/parser.h>
32 #include <utils/linked_list.h>
33 #include <utils/allocator.h>
34 #include <utils/logger_manager.h>
35 #include <encoding/payloads/encodings.h>
36 #include <encoding/payloads/payload.h>
37 #include <encoding/payloads/encryption_payload.h>
38
39
40 typedef struct supported_payload_entry_t supported_payload_entry_t;
41
42 /**
43 * Supported payload entry used in message_rule_t
44 *
45 */
46 struct supported_payload_entry_t {
47 /**
48 * Payload type
49 */
50 payload_type_t payload_type;
51
52 /**
53 * Minimal occurence of this payload
54 */
55 size_t min_occurence;
56
57 /**
58 * Max occurence of this payload
59 */
60 size_t max_occurence;
61 };
62
63 typedef struct message_rule_t message_rule_t;
64
65 /**
66 * Message Rule used to find out which payloads are supported by each message type
67 *
68 */
69 struct message_rule_t {
70 /**
71 * Type of message
72 */
73 exchange_type_t exchange_type;
74
75 /**
76 * Is message a request or response
77 */
78 bool is_request;
79 /**
80 * Number of supported payloads
81 */
82 size_t supported_payloads_count;
83 /**
84 * Pointer to first supported payload entry
85 */
86 supported_payload_entry_t *supported_payloads;
87 };
88
89 /**
90 * message rule for ike_sa_init from initiator
91 */
92 static supported_payload_entry_t supported_ike_sa_init_i_payloads[] =
93 {
94 {SECURITY_ASSOCIATION,1,1},
95 {KEY_EXCHANGE,1,1},
96 {NONCE,1,1},
97 };
98
99 /**
100 * message rule for ike_sa_init from responder
101 */
102 static supported_payload_entry_t supported_ike_sa_init_r_payloads[] =
103 {
104 {SECURITY_ASSOCIATION,1,1},
105 {KEY_EXCHANGE,1,1},
106 {NONCE,1,1},
107 };
108
109
110 /**
111 * message rules, defines allowed payloads
112 */
113 static message_rule_t message_rules[] = {
114 {IKE_SA_INIT,TRUE,(sizeof(supported_ike_sa_init_i_payloads)/sizeof(supported_payload_entry_t)),supported_ike_sa_init_i_payloads},
115 {IKE_SA_INIT,FALSE,(sizeof(supported_ike_sa_init_r_payloads)/sizeof(supported_payload_entry_t)),supported_ike_sa_init_r_payloads}
116 };
117
118 typedef struct payload_entry_t payload_entry_t;
119
120 /**
121 * Entry for a payload in the internal used linked list
122 *
123 */
124 struct payload_entry_t {
125 /**
126 * Type of payload
127 */
128 payload_type_t payload_type;
129 /**
130 * Data struct holding the data of given payload
131 */
132 void *data_struct;
133 };
134
135
136 typedef struct private_message_t private_message_t;
137
138 /**
139 * Private data of an message_t object
140 */
141 struct private_message_t {
142
143 /**
144 * Public part of a message_t object
145 */
146 message_t public;
147
148
149 /**
150 * Minor version of message
151 */
152 u_int8_t major_version;
153
154 /**
155 * Major version of message
156 */
157 u_int8_t minor_version;
158
159 /**
160 * First Payload in message
161 */
162 payload_type_t first_payload;
163
164 /**
165 * Assigned exchange type
166 */
167 exchange_type_t exchange_type;
168
169
170 /**
171 * TRUE if message is request.
172 * FALSE if message is reply.
173 */
174 bool is_request;
175
176 /**
177 * Message ID of this message
178 */
179 u_int32_t message_id;
180
181 /**
182 * ID of assigned IKE_SA
183 */
184 ike_sa_id_t *ike_sa_id;
185
186 /**
187 * Assigned UDP packet.
188 *
189 * Stores incoming packet or last generated one.
190 */
191 packet_t *packet;
192
193 /**
194 * Linked List where payload data are stored in
195 */
196 linked_list_t *payloads;
197
198 /**
199 * Assigned parser to parse Header and Body of this message
200 */
201 parser_t *parser;
202
203 /**
204 * logger for this message
205 */
206 logger_t *logger;
207
208 /**
209 * Gets a list of supported payloads of this message type
210 *
211 * @param this calling object
212 * @param[out] supported_payloads first entry of supported payloads
213 * @param[out] supported_payloads_count number of supported payload entries
214 *
215 * @return SUCCESS
216 * NOT_FOUND if no supported payload definition could be found
217 */
218 status_t (*get_supported_payloads) (private_message_t *this, supported_payload_entry_t **supported_payloads,size_t *supported_payloads_count);
219
220 };
221
222 /**
223 * Implements private_message_t's get_supported_payloads function.
224 * See #private_message_t.get_supported_payloads.
225 */
226 status_t get_supported_payloads (private_message_t *this, supported_payload_entry_t **supported_payloads,size_t *supported_payloads_count)
227 {
228 int i;
229 exchange_type_t exchange_type = this->public.get_exchange_type(&(this->public));
230 bool is_request = this->public.get_request(&(this->public));
231
232
233 for (i = 0; i < (sizeof(message_rules) / sizeof(message_rule_t)); i++)
234 {
235 if ((exchange_type == message_rules[i].exchange_type) &&
236 (is_request == message_rules[i].is_request))
237 {
238 /* found rule for given exchange_type*/
239 *supported_payloads = message_rules[i].supported_payloads;
240 *supported_payloads_count = message_rules[i].supported_payloads_count;
241
242 return SUCCESS;
243 }
244
245
246 }
247 *supported_payloads = NULL;
248 *supported_payloads_count = 0;
249 return NOT_FOUND;
250 }
251
252 /**
253 * Implements message_t's set_ike_sa_id function.
254 * See #message_s.set_ike_sa_id.
255 */
256 static status_t set_ike_sa_id (private_message_t *this,ike_sa_id_t *ike_sa_id)
257 {
258 status_t status;
259 status = ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id));
260 return status;
261 }
262
263 /**
264 * Implements message_t's get_ike_sa_id function.
265 * See #message_s.get_ike_sa_id.
266 */
267 static status_t get_ike_sa_id (private_message_t *this,ike_sa_id_t **ike_sa_id)
268 {
269 status_t status;
270 if (this->ike_sa_id == NULL)
271 {
272 return FAILED;
273 }
274 status = this->ike_sa_id->clone(this->ike_sa_id,ike_sa_id);
275 return status;
276 }
277
278
279 /**
280 * Implements message_t's set_message_id function.
281 * See #message_s.set_message_id.
282 */
283 static status_t set_message_id (private_message_t *this,u_int32_t message_id)
284 {
285 this->message_id = message_id;
286 return SUCCESS;
287 }
288
289
290 /**
291 * Implements message_t's set_message_id function.
292 * See #message_s.set_message_id.
293 */
294 static u_int32_t get_message_id (private_message_t *this)
295 {
296 return this->message_id;
297 }
298
299 /**
300 * Implements message_t's get_responder_spi function.
301 * See #message_s.get_responder_spi.
302 */
303 static u_int64_t get_responder_spi (private_message_t *this)
304 {
305 return (this->ike_sa_id->get_responder_spi(this->ike_sa_id));
306 }
307
308 /**
309 * Implements message_t's set_major_version function.
310 * See #message_s.set_major_version.
311 */
312 static status_t set_major_version (private_message_t *this,u_int8_t major_version)
313 {
314 this->major_version = major_version;
315 return SUCCESS;
316 }
317
318
319 /**
320 * Implements message_t's get_major_version function.
321 * See #message_s.get_major_version.
322 */
323 static u_int8_t get_major_version (private_message_t *this)
324 {
325 return this->major_version;
326 }
327
328 /**
329 * Implements message_t's set_minor_version function.
330 * See #message_s.set_minor_version.
331 */
332 static status_t set_minor_version (private_message_t *this,u_int8_t minor_version)
333 {
334 this->minor_version = minor_version;
335 return SUCCESS;
336 }
337
338
339 /**
340 * Implements message_t's get_minor_version function.
341 * See #message_s.get_minor_version.
342 */
343 static u_int8_t get_minor_version (private_message_t *this)
344 {
345 return this->minor_version;
346 }
347
348 /**
349 * Implements message_t's set_exchange_type function.
350 * See #message_s.set_exchange_type.
351 */
352 static status_t set_exchange_type (private_message_t *this,exchange_type_t exchange_type)
353 {
354 this->exchange_type = exchange_type;
355 return SUCCESS;
356 }
357
358
359 /**
360 * Implements message_t's get_exchange_type function.
361 * See #message_s.get_exchange_type.
362 */
363 static exchange_type_t get_exchange_type (private_message_t *this)
364 {
365 return this->exchange_type;
366 }
367
368
369 /**
370 * Implements message_t's set_request function.
371 * See #message_s.set_request.
372 */
373 static status_t set_request (private_message_t *this,bool request)
374 {
375 this->is_request = request;
376 return SUCCESS;
377 }
378
379 /**
380 * Implements message_t's get_request function.
381 * See #message_s.get_request.
382 */
383 static exchange_type_t get_request (private_message_t *this)
384 {
385 return this->is_request;
386 }
387
388 static status_t add_payload(private_message_t *this, payload_t *payload)
389 {
390 payload_t *last_payload;
391 if ((this->payloads->get_count(this->payloads) > 0) &&
392 (this->payloads->get_last(this->payloads,(void **) &last_payload) != SUCCESS))
393 {
394 return OUT_OF_RES;
395 }
396
397 if (this->payloads->insert_last(this->payloads, payload) != SUCCESS)
398 {
399 return OUT_OF_RES;
400 }
401 if (this->payloads->get_count(this->payloads) == 1)
402 {
403 this->first_payload = payload->get_type(payload);
404 }
405 else
406 {
407 last_payload->set_next_type(last_payload,payload->get_type(payload));
408 }
409
410 this->logger->log(this->logger, CONTROL|MORE, "added payload of type %s to message",
411 mapping_find(payload_type_m, payload->get_type(payload)));
412
413 return SUCCESS;
414 }
415
416 static status_t set_source(private_message_t *this, host_t *host)
417 {
418 if (this->packet->source != NULL)
419 {
420 this->packet->source->destroy(this->packet->source);
421 }
422 this->packet->source = host;
423 return SUCCESS;
424 }
425
426 static status_t set_destination(private_message_t *this, host_t *host)
427 {
428 if (this->packet->destination != NULL)
429 {
430 this->packet->destination->destroy(this->packet->destination);
431 }
432 this->packet->destination = host;
433 return SUCCESS;
434 }
435
436 static status_t get_source(private_message_t *this, host_t **host)
437 {
438 *host = this->packet->source;
439 return SUCCESS;
440 }
441
442 static status_t get_destination(private_message_t *this, host_t **host)
443 {
444 *host = this->packet->destination;
445 return SUCCESS;
446 }
447
448
449 static status_t get_payload_iterator(private_message_t *this, iterator_t **iterator)
450 {
451 return this->payloads->create_iterator(this->payloads, iterator, TRUE);
452 }
453
454
455 /**
456 * Implements message_t's generate function.
457 * See #message_s.generate.
458 */
459 static status_t generate(private_message_t *this, crypter_t *crypter, signer_t* signer, packet_t **packet)
460 {
461 generator_t *generator;
462 ike_header_t *ike_header;
463 payload_t *payload, *next_payload;
464 iterator_t *iterator;
465 status_t status;
466
467
468 this->logger->log(this->logger, CONTROL, "generating message, contains %d payloads",
469 this->payloads->get_count(this->payloads));
470
471 if (this->exchange_type == EXCHANGE_TYPE_UNDEFINED)
472 {
473 this->logger->log(this->logger, ERROR, "exchange type is not defined");
474 return INVALID_STATE;
475 }
476
477 if (this->packet->source == NULL ||
478 this->packet->destination == NULL)
479 {
480 this->logger->log(this->logger, ERROR, "source/destination not defined");
481 return INVALID_STATE;
482 }
483
484 /* build ike header */
485 ike_header = ike_header_create();
486 if (ike_header == NULL)
487 {
488 return OUT_OF_RES;
489 }
490
491 ike_header->set_exchange_type(ike_header, this->exchange_type);
492 ike_header->set_message_id(ike_header, this->message_id);
493 ike_header->set_response_flag(ike_header, !this->is_request);
494 ike_header->set_initiator_flag(ike_header, this->ike_sa_id->is_initiator(this->ike_sa_id));
495 ike_header->set_initiator_spi(ike_header, this->ike_sa_id->get_initiator_spi(this->ike_sa_id));
496 ike_header->set_responder_spi(ike_header, this->ike_sa_id->get_responder_spi(this->ike_sa_id));
497
498 generator = generator_create();
499 if (generator == NULL)
500 {
501 return OUT_OF_RES;
502 }
503
504 payload = (payload_t*)ike_header;
505
506 if (this->payloads->create_iterator(this->payloads, &iterator, TRUE) != SUCCESS)
507 {
508 generator->destroy(generator);
509 ike_header->destroy(ike_header);
510 return OUT_OF_RES;
511 }
512 /* generate every payload, except last one */
513 while(iterator->has_next(iterator))
514 {
515 iterator->current(iterator, (void**)&next_payload);
516 payload->set_next_type(payload, next_payload->get_type(next_payload));
517 status = generator->generate_payload(generator, payload);
518 if (status != SUCCESS)
519 {
520 generator->destroy(generator);
521 ike_header->destroy(ike_header);
522 return status;
523 }
524 payload = next_payload;
525 }
526 iterator->destroy(iterator);
527
528 /* build last payload */
529 payload->set_next_type(payload, NO_PAYLOAD);
530 /* if it's an encryption payload, build it first */
531 if (payload->get_type(payload) == ENCRYPTED)
532 {
533 encryption_payload_t *encryption_payload = (encryption_payload_t*)payload;
534 encryption_payload->set_signer(encryption_payload, signer);
535 status = encryption_payload->encrypt(encryption_payload, crypter);
536 if (status != SUCCESS)
537 {
538 generator->destroy(generator);
539 ike_header->destroy(ike_header);
540 return status;
541 }
542 }
543 status = generator->generate_payload(generator, payload);
544 if (status != SUCCESS)
545 {
546 generator->destroy(generator);
547 ike_header->destroy(ike_header);
548 return status;
549 }
550 ike_header->destroy(ike_header);
551
552 /* build packet */
553 if (this->packet->data.ptr != NULL)
554 {
555 allocator_free(this->packet->data.ptr);
556 }
557 status = generator->write_to_chunk(generator, &(this->packet->data));
558 generator->destroy(generator);
559 if (status != SUCCESS)
560 {
561 return status;
562 }
563
564 /* append integrity checksum if necessary */
565 if (payload->get_type(payload) == ENCRYPTED)
566 {
567 encryption_payload_t *encryption_payload = (encryption_payload_t*)payload;
568 status = encryption_payload->build_signature(encryption_payload, this->packet->data);
569 if (status != SUCCESS)
570 {
571 return status;
572 }
573 }
574
575 /* colen packet for caller */
576 this->packet->clone(this->packet, packet);
577
578 this->logger->log(this->logger, CONTROL, "message generated successfully");
579 return SUCCESS;
580 }
581
582 /**
583 * Implements message_t's parse_header function.
584 * See #message_s.parse_header.
585 */
586 static status_t parse_header(private_message_t *this)
587 {
588 ike_header_t *ike_header;
589 status_t status;
590
591
592 this->logger->log(this->logger, CONTROL, "parsing header of message");
593
594 this->parser->reset_context(this->parser);
595 status = this->parser->parse_payload(this->parser,HEADER,(payload_t **) &ike_header);
596 if (status != SUCCESS)
597 {
598 this->logger->log(this->logger, ERROR, "Header could not be parsed");
599 return status;
600
601 }
602
603 /* verify payload */
604 status = ike_header->payload_interface.verify(&(ike_header->payload_interface));
605 if (status != SUCCESS)
606 {
607 this->logger->log(this->logger, ERROR, "Header verification failed");
608 ike_header->destroy(ike_header);
609 return status;
610 }
611
612 if (this->ike_sa_id != NULL)
613 {
614 this->ike_sa_id->destroy(this->ike_sa_id);
615 }
616
617 this->ike_sa_id = ike_sa_id_create(ike_header->get_initiator_spi(ike_header),
618 ike_header->get_responder_spi(ike_header),
619 ike_header->get_initiator_flag(ike_header));
620 if (this->ike_sa_id == NULL)
621 {
622 this->logger->log(this->logger, ERROR, "could not create ike_sa_id object");
623 ike_header->destroy(ike_header);
624 return OUT_OF_RES;
625 }
626 this->exchange_type = ike_header->get_exchange_type(ike_header);
627 this->message_id = ike_header->get_message_id(ike_header);
628 this->is_request = (!(ike_header->get_response_flag(ike_header)));
629 this->major_version = ike_header->get_maj_version(ike_header);
630 this->minor_version = ike_header->get_min_version(ike_header);
631 this->first_payload = ike_header->payload_interface.get_next_type(&(ike_header->payload_interface));
632
633
634 this->logger->log(this->logger, CONTROL, "parsing header successfully");
635
636 ike_header->destroy(ike_header);
637 return SUCCESS;
638 }
639
640 /**
641 * Implements message_t.parse_body.
642 */
643 static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t *signer)
644 {
645 status_t status = SUCCESS;
646 payload_type_t current_payload_type = this->first_payload;
647
648 this->logger->log(this->logger, CONTROL, "parsing body of message");
649
650 while (current_payload_type != NO_PAYLOAD)
651 {
652 payload_t *current_payload;
653
654 this->logger->log(this->logger, CONTROL|MORE, "start parsing payload of type %s",
655 mapping_find(payload_type_m, current_payload_type));
656
657 status = this->parser->parse_payload(this->parser,current_payload_type,(payload_t **) &current_payload);
658 if (status != SUCCESS)
659 {
660 this->logger->log(this->logger, ERROR, "payload type %s could not be parsed",mapping_find(payload_type_m,current_payload_type));
661 return status;
662 }
663
664 status = current_payload->verify(current_payload);
665 if (status != SUCCESS)
666 {
667 this->logger->log(this->logger, ERROR, "payload type %s could not be verified",mapping_find(payload_type_m,current_payload_type));
668 status = VERIFY_ERROR;
669 return status;
670 }
671
672 /* encrypted payload must be decrypted */
673 if (current_payload->get_type(current_payload) == ENCRYPTED)
674 {
675 encryption_payload_t *encryption_payload = (encryption_payload_t*)current_payload;
676 encryption_payload->set_signer(encryption_payload, signer);
677 status = encryption_payload->verify_signature(encryption_payload, this->packet->data);
678 if (status != SUCCESS)
679 {
680 this->logger->log(this->logger, ERROR, "encryption payload signature invaild");
681 return status;
682 }
683 status = encryption_payload->decrypt(encryption_payload, crypter);
684 if (status != SUCCESS)
685 {
686 this->logger->log(this->logger, ERROR, "parsing decrypted encryption payload failed");
687 return status;
688 }
689 }
690
691 /* get next payload type */
692 current_payload_type = current_payload->get_next_type(current_payload);
693
694 status = this->payloads->insert_last(this->payloads,current_payload);
695 if (status != SUCCESS)
696 {
697 this->logger->log(this->logger, ERROR, "%s on adding payload", mapping_find(status_m, status));
698 return status;;
699 }
700
701 }
702 return this->public.verify(&(this->public));
703
704 }
705
706 /**
707 * implements message_t.verify
708 */
709 static status_t verify(private_message_t *this)
710 {
711 iterator_t *iterator;
712 status_t status;
713 int i;
714 supported_payload_entry_t *supported_payloads;
715 size_t supported_payloads_count;
716
717 this->logger->log(this->logger, CONTROL|MORE, "verifying message");
718
719 status = this->get_supported_payloads(this, &supported_payloads, &supported_payloads_count);
720 if (status != SUCCESS)
721 {
722 this->logger->log(this->logger, ERROR, "could not get supported payloads: %s");
723 return status;
724 }
725
726 status = this->payloads->create_iterator(this->payloads,&iterator,TRUE);
727 if (status != SUCCESS)
728 {
729 this->logger->log(this->logger, ERROR, "Could not create iterator to check supported payloads");
730 return status;
731 }
732
733 /* check for payloads with wrong count*/
734 for (i = 0; i < supported_payloads_count;i++)
735 {
736 size_t min_occurence = supported_payloads[i].min_occurence;
737 size_t max_occurence = supported_payloads[i].max_occurence;
738 payload_type_t payload_type = supported_payloads[i].payload_type;
739 size_t found_payloads = 0;
740
741 iterator->reset(iterator);
742
743 while(iterator->has_next(iterator))
744 {
745 payload_t *current_payload;
746 status = iterator->current(iterator,(void **)&current_payload);
747 if (status != SUCCESS)
748 {
749 this->logger->log(this->logger, ERROR, "Could not get payload from internal list");
750 iterator->destroy(iterator);
751 return OUT_OF_RES;
752 }
753 if (current_payload->get_type(current_payload) == payload_type)
754 {
755 found_payloads++;
756 if (found_payloads > max_occurence)
757 {
758 this->logger->log(this->logger, ERROR, "Payload of type %s more than %d times (%d) occured in current message",
759 mapping_find(payload_type_m,current_payload->get_type(current_payload)),max_occurence,found_payloads);
760 iterator->destroy(iterator);
761 return NOT_SUPPORTED;
762 }
763 }
764 }
765 if (found_payloads < min_occurence)
766 {
767 this->logger->log(this->logger, ERROR, "Payload of type %s not occured %d times",
768 mapping_find(payload_type_m,payload_type),min_occurence);
769 iterator->destroy(iterator);
770 return NOT_SUPPORTED;
771 }
772 }
773 iterator->destroy(iterator);
774
775 return SUCCESS;
776 }
777
778
779 /**
780 * Implements message_t's destroy function.
781 * See #message_s.destroy.
782 */
783 static status_t destroy (private_message_t *this)
784 {
785 iterator_t *iterator;
786
787 this->packet->destroy(this->packet);
788
789 if (this->ike_sa_id != NULL)
790 {
791 this->ike_sa_id->destroy(this->ike_sa_id);
792 }
793
794 this->payloads->create_iterator(this->payloads, &iterator, TRUE);
795 while (iterator->has_next(iterator))
796 {
797 payload_t *payload;
798 iterator->current(iterator, (void**)&payload);
799 this->logger->log(this->logger, CONTROL|MOST, "Destroying payload of type %s",
800 mapping_find(payload_type_m, payload->get_type(payload)));
801 payload->destroy(payload);
802 }
803 iterator->destroy(iterator);
804 this->payloads->destroy(this->payloads);
805 this->parser->destroy(this->parser);
806 global_logger_manager->destroy_logger(global_logger_manager, this->logger);
807
808 allocator_free(this);
809 return SUCCESS;
810 }
811
812 /*
813 * Described in Header-File
814 */
815 message_t *message_create_from_packet(packet_t *packet)
816 {
817 private_message_t *this = allocator_alloc_thing(private_message_t);
818 if (this == NULL)
819 {
820 return NULL;
821 }
822
823 /* public functions */
824 this->public.set_major_version = (status_t(*)(message_t*, u_int8_t))set_major_version;
825 this->public.get_major_version = (u_int8_t(*)(message_t*))get_major_version;
826 this->public.set_minor_version = (status_t(*)(message_t*, u_int8_t))set_minor_version;
827 this->public.get_minor_version = (u_int8_t(*)(message_t*))get_minor_version;
828 this->public.set_message_id = (status_t(*)(message_t*, u_int32_t))set_message_id;
829 this->public.get_message_id = (u_int32_t(*)(message_t*))get_message_id;
830 this->public.get_responder_spi = (u_int64_t(*)(message_t*))get_responder_spi;
831 this->public.set_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t *))set_ike_sa_id;
832 this->public.get_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t **))get_ike_sa_id;
833 this->public.set_exchange_type = (status_t(*)(message_t*, exchange_type_t))set_exchange_type;
834 this->public.get_exchange_type = (exchange_type_t(*)(message_t*))get_exchange_type;
835 this->public.set_request = (status_t(*)(message_t*, bool))set_request;
836 this->public.get_request = (bool(*)(message_t*))get_request;
837 this->public.add_payload = (status_t(*)(message_t*,payload_t*))add_payload;
838 this->public.generate = (status_t (*) (message_t *,crypter_t*,signer_t*,packet_t**)) generate;
839 this->public.set_source = (status_t (*) (message_t*,host_t*)) set_source;
840 this->public.get_source = (status_t (*) (message_t*,host_t**)) get_source;
841 this->public.set_destination = (status_t (*) (message_t*,host_t*)) set_destination;
842 this->public.get_destination = (status_t (*) (message_t*,host_t**)) get_destination;
843 this->public.get_payload_iterator = (status_t (*) (message_t *, iterator_t **)) get_payload_iterator;
844 this->public.parse_header = (status_t (*) (message_t *)) parse_header;
845 this->public.parse_body = (status_t (*) (message_t *,crypter_t*,signer_t*)) parse_body;
846 this->public.verify = (status_t (*) (message_t*)) verify;
847 this->public.destroy = (status_t(*)(message_t*))destroy;
848
849 /* public values */
850 this->exchange_type = EXCHANGE_TYPE_UNDEFINED;
851 this->is_request = TRUE;
852 this->ike_sa_id = NULL;
853 this->first_payload = NO_PAYLOAD;
854 this->message_id = 0;
855
856 /* private functions */
857 this->get_supported_payloads = get_supported_payloads;
858
859 /* private values */
860 if (packet == NULL)
861 {
862 packet = packet_create();
863 }
864 if (packet == NULL)
865 {
866 allocator_free(this);
867 return NULL;
868 }
869 this->packet = packet;
870 this->payloads = linked_list_create();
871 if (this->payloads == NULL)
872 {
873 allocator_free(this);
874 return NULL;
875 }
876
877 /* parser is created from data of packet */
878 this->parser = parser_create(this->packet->data);
879 if (this->parser == NULL)
880 {
881 this->payloads->destroy(this->payloads);
882 allocator_free(this);
883 return NULL;
884 }
885
886 this->logger = global_logger_manager->create_logger(global_logger_manager, MESSAGE, NULL);
887 if (this->logger == NULL)
888 {
889 this->parser->destroy(this->parser);
890 this->payloads->destroy(this->payloads);
891 allocator_free(this);
892 return NULL;
893 }
894
895 return (&this->public);
896 }
897
898 /*
899 * Described in Header-File
900 */
901 message_t *message_create()
902 {
903 return message_create_from_packet(NULL);
904 }