- added and tested auth_payload_t class
[strongswan.git] / Source / charon / testcases / generator_test.c
1 /**
2 * @file generator_test.c
3 *
4 * @brief Tests for the generator_t class.
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 <string.h>
24
25 #include "generator_test.h"
26
27 #include <daemon.h>
28 #include <encoding/generator.h>
29 #include <utils/allocator.h>
30 #include <utils/logger_manager.h>
31 #include <utils/logger.h>
32 #include <encoding/payloads/encodings.h>
33 #include <encoding/payloads/ike_header.h>
34 #include <encoding/payloads/transform_attribute.h>
35 #include <encoding/payloads/transform_substructure.h>
36 #include <encoding/payloads/proposal_substructure.h>
37 #include <encoding/payloads/sa_payload.h>
38 #include <encoding/payloads/ke_payload.h>
39 #include <encoding/payloads/notify_payload.h>
40 #include <encoding/payloads/nonce_payload.h>
41 #include <encoding/payloads/id_payload.h>
42 #include <encoding/payloads/auth_payload.h>
43
44 /*
45 * Described in Header
46 */
47 void test_generator_with_header_payload(tester_t *tester)
48 {
49 generator_t *generator;
50 ike_header_t *header_data;
51 chunk_t generated_data;
52 logger_t *logger;
53
54 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"header payload");
55
56 header_data = ike_header_create();
57 header_data->set_initiator_spi(header_data,1);
58 header_data->set_responder_spi(header_data,2);
59 ((payload_t *) header_data)->set_next_type((payload_t *) header_data, 3);
60 header_data->set_exchange_type(header_data, 6);
61 header_data->set_initiator_flag(header_data, TRUE);
62 header_data->set_response_flag(header_data, TRUE);
63 header_data->set_message_id(header_data,7);
64
65 generator = generator_create();
66 tester->assert_true(tester,(generator != NULL), "generator create check");
67
68 generator->generate_payload(generator,(payload_t *) header_data);
69
70 generator->write_to_chunk(generator,&generated_data);
71
72 u_int8_t expected_generation[] = {
73 0x01,0x00,0x00,0x00,
74 0x00,0x00,0x00,0x00,
75 0x02,0x00,0x00,0x00,
76 0x00,0x00,0x00,0x00,
77 0x03,0x20,0x06,0x28,
78 0x00,0x00,0x00,0x07,
79 0x00,0x00,0x00,0x1C,
80 };
81
82 logger->log_bytes(logger,RAW,"expected header",expected_generation,sizeof(expected_generation));
83 tester->assert_true(tester,(generated_data.len == sizeof(expected_generation)), "compare generated data length");
84 logger->log_chunk(logger,RAW,"generated header",&generated_data);
85 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data 1");
86 allocator_free_chunk(&generated_data);
87
88 generator->destroy(generator);
89
90 header_data->set_initiator_spi(header_data,0x22000054231234LL);
91 header_data->set_responder_spi(header_data,0x122398);
92 ((payload_t *) header_data)->set_next_type((payload_t *) header_data,0xF3);
93 header_data->set_exchange_type(header_data, 0x12);
94 header_data->set_initiator_flag(header_data, TRUE);
95 header_data->set_response_flag(header_data, TRUE);
96 header_data->set_message_id(header_data,0x33AFF3);
97
98 generator = generator_create();
99 tester->assert_true(tester,(generator != NULL), "generator create check");
100
101 generator->generate_payload(generator,(payload_t *)header_data);
102
103 generator->write_to_chunk(generator,&generated_data);
104
105 u_int8_t expected_generation2[] = {
106 0x34,0x12,0x23,0x54,
107 0x00,0x00,0x22,0x00,
108 0x98,0x23,0x12,0x00,
109 0x00,0x00,0x00,0x00,
110 0xF3,0x20,0x12,0x28,
111 0x00,0x33,0xAF,0xF3,
112 0x00,0x00,0x00,0x1C,
113 };
114
115
116 logger->log_bytes(logger,RAW,"expected header",expected_generation2,sizeof(expected_generation2));
117
118 logger->log_chunk(logger,RAW,"generated header",&generated_data);
119
120 tester->assert_true(tester,(memcmp(expected_generation2,generated_data.ptr,sizeof(expected_generation2)) == 0), "compare generated data 2");
121 allocator_free_chunk(&generated_data);
122
123 header_data->destroy(header_data);
124
125 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
126 generator->destroy(generator);
127 }
128
129 /*
130 * Described in header
131 */
132 void test_generator_with_transform_attribute(tester_t *tester)
133 {
134 generator_t *generator;
135 transform_attribute_t *attribute;
136 chunk_t generated_data;
137 logger_t *logger;
138
139 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"transform_attribute payload");
140
141
142 /* test empty attribute */
143 generator = generator_create();
144 tester->assert_true(tester,(generator != NULL), "generator create check");
145 attribute = transform_attribute_create();
146 generator->generate_payload(generator,(payload_t *)attribute);
147 generator->write_to_chunk(generator,&generated_data);
148 logger->log_chunk(logger,RAW,"generated attribute",&generated_data);
149
150 u_int8_t expected_generation[] = {
151 0x80,0x00,0x00,0x00,
152 };
153 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
154 allocator_free_chunk(&generated_data);
155 attribute->destroy(attribute);
156 generator->destroy(generator);
157
158 /* test attribute with 2 byte data */
159 generator = generator_create();
160 tester->assert_true(tester,(generator != NULL), "generator create check");
161
162 attribute = transform_attribute_create();
163 u_int16_t dataval = 5768;
164 chunk_t data;
165 data.ptr = (void *) &dataval;
166 data.len = 2;
167
168 attribute->set_value_chunk(attribute,data);
169
170 generator->generate_payload(generator,(payload_t *)attribute);
171 generator->write_to_chunk(generator,&generated_data);
172 logger->log_chunk(logger,RAW,"generated attribute",&generated_data);
173
174 u_int8_t expected_generation2[] = {
175 0x80,0x00,0x16,0x88,
176 };
177 tester->assert_true(tester,(memcmp(expected_generation2,generated_data.ptr,sizeof(expected_generation2)) == 0), "compare generated data");
178
179 allocator_free_chunk(&generated_data);
180 attribute->destroy(attribute);
181 generator->destroy(generator);
182
183
184
185 /* test attribute with 25 byte data */
186 generator = generator_create();
187 tester->assert_true(tester,(generator != NULL), "generator create check");
188
189 attribute = transform_attribute_create();
190 char *stringval = "ddddddddddeeeeeeeeeefffff";
191 data.ptr = (void *) stringval;
192 data.len = 25;
193
194 attribute->set_value_chunk(attribute,data);
195
196 attribute->set_attribute_type(attribute,456);
197
198
199 generator->generate_payload(generator,(payload_t *)attribute);
200 generator->write_to_chunk(generator,&generated_data);
201 logger->log_chunk(logger,RAW,"generated attribute",&generated_data);
202
203 u_int8_t expected_generation3[] = {
204 0x01,0xC8,0x00,0x19,
205 0x64,0x64,0x64,0x64,
206 0x64,0x64,0x64,0x64,
207 0x64,0x64,0x65,0x65,
208 0x65,0x65,0x65,0x65,
209 0x65,0x65,0x65,0x65,
210 0x66,0x66,0x66,0x66,
211 0x66
212 };
213 tester->assert_true(tester,(memcmp(expected_generation3,generated_data.ptr,sizeof(expected_generation3)) == 0), "compare generated data");
214
215 allocator_free_chunk(&generated_data);
216 attribute->destroy(attribute);
217 generator->destroy(generator);
218
219
220 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
221 }
222
223
224
225 /*
226 * Described in header
227 */
228 void test_generator_with_transform_substructure(tester_t *tester)
229 {
230 generator_t *generator;
231 transform_attribute_t *attribute1, *attribute2;
232 transform_substructure_t *transform;
233 chunk_t data;
234 chunk_t generated_data;
235 logger_t *logger;
236
237 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"transform substr.");
238
239 /* create generator */
240 generator = generator_create();
241 tester->assert_true(tester,(generator != NULL), "generator create check");
242
243 /* create attribute 1 */
244 attribute1 = transform_attribute_create();
245 char *stringval = "abcd";
246 data.ptr = (void *) stringval;
247 data.len = 4;
248 attribute1->set_value_chunk(attribute1,data);
249 attribute1->set_attribute_type(attribute1,0);
250 logger->log(logger,CONTROL,"attribute1 created");
251
252 /* create attribute 2 */
253 attribute2 = transform_attribute_create();
254 stringval = "efgh";
255 data.ptr = (void *) stringval;
256 data.len = 4;
257 attribute2->set_value_chunk(attribute2,data);
258 attribute2->set_attribute_type(attribute2,0);
259 logger->log(logger,CONTROL,"attribute2 created");
260
261 /* create transform */
262 transform = transform_substructure_create();
263 tester->assert_true(tester,(transform != NULL), "transform create check");
264 transform->add_transform_attribute(transform,attribute1);
265 transform->add_transform_attribute(transform,attribute2);
266 transform->set_transform_type(transform,5); /* hex 5 */
267 transform->set_transform_id(transform,65000); /* hex FDE8 */
268
269
270 logger->log(logger,CONTROL,"transform created");
271
272 generator->generate_payload(generator,(payload_t *)transform);
273 generator->write_to_chunk(generator,&generated_data);
274 logger->log_chunk(logger,RAW,"generated transform",&generated_data);
275
276 u_int8_t expected_generation3[] = {
277 0x00,0x00,0x00,0x18,
278 0x05,0x00,0xFD,0xE8,
279 0x00,0x00,0x00,0x04,
280 0x61,0x62,0x63,0x64,
281 0x00,0x00,0x00,0x04,
282 0x65,0x66,0x67,0x68,
283 };
284 tester->assert_true(tester,(memcmp(expected_generation3,generated_data.ptr,sizeof(expected_generation3)) == 0), "compare generated data");
285
286 allocator_free_chunk(&generated_data);
287 transform->destroy(transform);
288 generator->destroy(generator);
289
290
291 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
292 }
293
294
295 /*
296 * Described in header
297 */
298 void test_generator_with_proposal_substructure(tester_t *tester)
299 {
300 generator_t *generator;
301 transform_attribute_t *attribute1, *attribute2, *attribute3;
302 transform_substructure_t *transform1, *transform2;
303 proposal_substructure_t *proposal;
304 chunk_t data;
305 chunk_t generated_data;
306 logger_t *logger;
307
308 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"transform substr.");
309
310 /* create generator */
311 generator = generator_create();
312 tester->assert_true(tester,(generator != NULL), "generator create check");
313
314 /* create attribute 1 */
315 attribute1 = transform_attribute_create();
316 char *stringval = "abcd";
317 data.ptr = (void *) stringval;
318 data.len = 4;
319 attribute1->set_value_chunk(attribute1,data);
320 attribute1->set_attribute_type(attribute1,0);
321
322 logger->log(logger,CONTROL,"attribute1 created");
323
324 /* create attribute 2 */
325 attribute2 = transform_attribute_create();
326 stringval = "efgh";
327 data.ptr = (void *) stringval;
328 data.len = 4;
329 attribute2->set_value_chunk(attribute2,data);
330 attribute2->set_attribute_type(attribute2,0);
331 logger->log(logger,CONTROL,"attribute2 created");
332
333 /* create attribute 3 */
334 attribute3 = transform_attribute_create();
335 stringval = "ijkl";
336 data.ptr = (void *) stringval;
337 data.len = 4;
338 attribute3->set_value_chunk(attribute3,data);
339 attribute3->set_attribute_type(attribute3,0);
340 logger->log(logger,CONTROL,"attribute3 created");
341
342 /* create transform 1*/
343 transform1 = transform_substructure_create();
344 tester->assert_true(tester,(transform1 != NULL), "transform create check");
345 transform1->add_transform_attribute(transform1,attribute1);
346 transform1->add_transform_attribute(transform1,attribute2);
347 transform1->set_transform_type(transform1,5); /* hex 5 */
348 transform1->set_transform_id(transform1,65000); /* hex FDE8 */
349
350 /* create transform 2*/
351 transform2 = transform_substructure_create();
352 tester->assert_true(tester,(transform2 != NULL), "transform create check");
353 transform2->add_transform_attribute(transform2,attribute3);
354 transform2->set_transform_type(transform2,3); /* hex 3 */
355 transform2->set_transform_id(transform2,4); /* hex 4 */
356
357 logger->log(logger,CONTROL,"transforms created");
358
359 proposal = proposal_substructure_create();
360 tester->assert_true(tester,(proposal != NULL), "proposal create check");
361
362 stringval = "ABCDEFGH";
363 data.ptr = (void *) stringval;
364 data.len = 8;
365
366 proposal->add_transform_substructure(proposal,transform1);
367 proposal->add_transform_substructure(proposal,transform2);
368 proposal->set_spi(proposal,data);
369 proposal->set_proposal_number(proposal,7);
370 proposal->set_protocol_id(proposal,4);
371
372 generator->generate_payload(generator,(payload_t *)proposal);
373 generator->write_to_chunk(generator,&generated_data);
374 logger->log_chunk(logger,RAW,"generated transform",&generated_data);
375
376 u_int8_t expected_generation[] = {
377 /* proposal header */
378 0x00,0x00,0x00,0x38,
379 0x07,0x04,0x08,0x02,
380 /* SPI */
381 0x41,0x42,0x43,0x44,
382 0x45,0x46,0x47,0x48,
383 /* first transform */
384 0x03,0x00,0x00,0x18,
385 0x05,0x00,0xFD,0xE8,
386 /* first transform attributes */
387 0x00,0x00,0x00,0x04,
388 0x61,0x62,0x63,0x64,
389 0x00,0x00,0x00,0x04,
390 0x65,0x66,0x67,0x68,
391 /* second transform */
392 0x00,0x00,0x00,0x10,
393 0x03,0x00,0x00,0x04,
394 /* second transform attributes */
395 0x00,0x00,0x00,0x04,
396 0x69,0x6A,0x6B,0x6C
397 };
398 logger->log_bytes(logger,RAW,"expected transform",expected_generation,sizeof(expected_generation));
399
400 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
401
402 allocator_free_chunk(&generated_data);
403 proposal->destroy(proposal);
404 generator->destroy(generator);
405
406
407 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
408 }
409
410 /*
411 * Described in header
412 */
413 void test_generator_with_sa_payload(tester_t *tester)
414 {
415 generator_t *generator;
416 transform_attribute_t *attribute1, *attribute2, *attribute3;
417 transform_substructure_t *transform1, *transform2;
418 proposal_substructure_t *proposal1, *proposal2;
419 sa_payload_t *sa_payload;
420 ike_header_t *ike_header;
421
422 chunk_t data;
423 chunk_t generated_data;
424 logger_t *logger;
425
426 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with SA Payload");
427
428 /* create generator */
429 generator = generator_create();
430 tester->assert_true(tester,(generator != NULL), "generator create check");
431
432 /* create attribute 1 */
433 attribute1 = transform_attribute_create();
434 char *stringval = "abcd";
435 data.ptr = (void *) stringval;
436 data.len = 4;
437 attribute1->set_value_chunk(attribute1,data);
438 attribute1->set_attribute_type(attribute1,0);
439 logger->log(logger,CONTROL,"attribute1 created");
440
441 /* create attribute 2 */
442 attribute2 = transform_attribute_create();
443 stringval = "efgh";
444 data.ptr = (void *) stringval;
445 data.len = 4;
446 attribute2->set_value_chunk(attribute2,data);
447 attribute2->set_attribute_type(attribute2,0);
448 logger->log(logger,CONTROL,"attribute2 created");
449
450 /* create attribute 3 */
451 attribute3 = transform_attribute_create();
452 stringval = "ijkl";
453 data.ptr = (void *) stringval;
454 data.len = 4;
455 attribute3->set_value_chunk(attribute3,data);
456 attribute3->set_attribute_type(attribute3,0);
457 logger->log(logger,CONTROL,"attribute3 created");
458
459 /* create transform 1*/
460 transform1 = transform_substructure_create();
461 tester->assert_true(tester,(transform1 != NULL), "transform create check");
462 transform1->add_transform_attribute(transform1,attribute1);
463 transform1->add_transform_attribute(transform1,attribute2);
464 transform1->set_transform_type(transform1,5); /* hex 5 */
465 transform1->set_transform_id(transform1,65000); /* hex FDE8 */
466
467 /* create transform 2*/
468 transform2 = transform_substructure_create();
469 tester->assert_true(tester,(transform2 != NULL), "transform create check");
470 transform2->add_transform_attribute(transform2,attribute3);
471 transform2->set_transform_type(transform2,3); /* hex 3 */
472 transform2->set_transform_id(transform2,4); /* hex 4 */
473
474 logger->log(logger,CONTROL,"transforms created");
475
476 /* create proposal 1 */
477 proposal1 = proposal_substructure_create();
478 tester->assert_true(tester,(proposal1 != NULL), "proposal create check");
479
480 stringval = "ABCDEFGH";
481 data.ptr = (void *) stringval;
482 data.len = 8;
483
484 proposal1->add_transform_substructure(proposal1,transform1);
485 proposal1->add_transform_substructure(proposal1,transform2);
486 proposal1->set_spi(proposal1,data);
487 proposal1->set_proposal_number(proposal1,7);
488 proposal1->set_protocol_id(proposal1,4);
489
490 /* create proposal 2 */
491 proposal2 = proposal_substructure_create();
492 tester->assert_true(tester,(proposal2 != NULL), "proposal create check");
493 proposal2->set_proposal_number(proposal2,7);
494 proposal2->set_protocol_id(proposal2,5);
495
496 /* create sa_payload */
497 sa_payload = sa_payload_create();
498
499 sa_payload->add_proposal_substructure(sa_payload,proposal1);
500 sa_payload->add_proposal_substructure(sa_payload,proposal2);
501
502 ike_header = ike_header_create();
503 ike_header->set_initiator_spi(ike_header,0x22000054231234LL);
504 ike_header->set_responder_spi(ike_header,0x122398);
505 ((payload_t *) ike_header)->set_next_type((payload_t *) ike_header,SECURITY_ASSOCIATION);
506 ike_header->set_exchange_type(ike_header, 0x12);
507 ike_header->set_initiator_flag(ike_header, TRUE);
508 ike_header->set_response_flag(ike_header, TRUE);
509 ike_header->set_message_id(ike_header,0x33AFF3);
510
511 generator->generate_payload(generator,(payload_t *)ike_header);
512 generator->generate_payload(generator,(payload_t *)sa_payload);
513 generator->write_to_chunk(generator,&generated_data);
514 logger->log_chunk(logger,RAW,"generated transform",&generated_data);
515
516 u_int8_t expected_generation[] = {
517 /* sa payload header */
518 0x34,0x12,0x23,0x54,
519 0x00,0x00,0x22,0x00,
520 0x98,0x23,0x12,0x00,
521 0x00,0x00,0x00,0x00,
522 0x21,0x20,0x12,0x28,
523 0x00,0x33,0xAF,0xF3,
524 0x00,0x00,0x00,0x60,
525
526 /* sa payload header */
527 0x00,0x00,0x00,0x44,
528 /* proposal header */
529 0x00,0x00,0x00,0x38,
530 0x07,0x04,0x08,0x02,
531 /* SPI */
532 0x41,0x42,0x43,0x44,
533 0x45,0x46,0x47,0x48,
534 /* first transform */
535 0x03,0x00,0x00,0x18,
536 0x05,0x00,0xFD,0xE8,
537 /* first transform attributes */
538 0x00,0x00,0x00,0x04,
539 0x61,0x62,0x63,0x64,
540 0x00,0x00,0x00,0x04,
541 0x65,0x66,0x67,0x68,
542 /* second transform */
543 0x00,0x00,0x00,0x10,
544 0x03,0x00,0x00,0x04,
545 /* second transform attributes */
546 0x00,0x00,0x00,0x04,
547 0x69,0x6A,0x6B,0x6C,
548 /* proposal header 2*/
549 0x00,0x00,0x00,0x08,
550 0x07,0x05,0x00,0x00,
551
552 };
553
554 logger->log_bytes(logger,RAW,"expected transform",expected_generation,sizeof(expected_generation));
555
556 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
557
558 allocator_free_chunk(&generated_data);
559 ike_header->destroy(ike_header);
560 sa_payload->destroy(sa_payload);
561 generator->destroy(generator);
562
563 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
564
565 }
566
567 /*
568 * Described in header
569 */
570 void test_generator_with_ke_payload(tester_t *tester)
571 {
572 generator_t *generator;
573 ke_payload_t *ke_payload;
574 logger_t *logger;
575 chunk_t generated_data;
576 chunk_t key_exchange_data;
577
578 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with KE Payload");
579
580 /* create generator */
581 generator = generator_create();
582 tester->assert_true(tester,(generator != NULL), "generator create check");
583
584 ke_payload = ke_payload_create();
585
586
587 key_exchange_data.ptr = "test-text";
588 key_exchange_data.len = strlen(key_exchange_data.ptr);
589
590 ke_payload->set_key_exchange_data(ke_payload,key_exchange_data);
591
592 ke_payload->set_dh_group_number(ke_payload,7777);
593
594 generator->generate_payload(generator,(payload_t *)ke_payload);
595 generator->write_to_chunk(generator,&generated_data);
596 logger->log_chunk(logger,RAW,"generated payload",&generated_data);
597
598 u_int8_t expected_generation[] = {
599 /* payload header */
600 0x00,0x00,0x00,0x11,
601 0x1E,0x61,0x00,0x00,
602 /* key exchange data */
603 0x74,0x65,0x73,0x74,
604 0x2D,0x74,0x65,0x78,
605 0x74
606 };
607
608
609 logger->log_bytes(logger,RAW,"expected payload",expected_generation,sizeof(expected_generation));
610
611 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
612
613 allocator_free_chunk(&generated_data);
614
615 ke_payload->destroy(ke_payload);
616 generator->destroy(generator);
617
618 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
619
620 }
621
622 /*
623 * Described in header
624 */
625 void test_generator_with_notify_payload(tester_t *tester)
626 {
627 generator_t *generator;
628 notify_payload_t *notify_payload;
629 logger_t *logger;
630 chunk_t generated_data;
631 chunk_t spi,notification_data;
632
633 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with Notify Payload");
634
635 /* create generator */
636 generator = generator_create();
637 tester->assert_true(tester,(generator != NULL), "generator create check");
638
639 notify_payload = notify_payload_create();
640
641
642 spi.ptr = "12345";
643 spi.len = strlen(spi.ptr);
644
645 notification_data.ptr = "67890";
646 notification_data.len = strlen(notification_data.ptr);
647
648 notify_payload->set_protocol_id(notify_payload,255);
649 notify_payload->set_notify_message_type(notify_payload,63333); /* Hex F765 */
650 notify_payload->set_spi(notify_payload,spi);
651 notify_payload->set_notification_data(notify_payload,notification_data);
652
653 generator->generate_payload(generator,(payload_t *)notify_payload);
654 generator->write_to_chunk(generator,&generated_data);
655 logger->log_chunk(logger,RAW,"generated payload",&generated_data);
656
657 u_int8_t expected_generation[] = {
658 /* payload header */
659 0x00,0x00,0x00,0x12,
660 0xFF,0x05,0xF7,0x65,
661 /* spi */
662 0x31,0x32,0x33,0x34,
663 0x35,
664 /* notification data */
665 0x36,0x37,0x38,0x39,
666 0x30,
667 };
668
669 logger->log_bytes(logger,RAW,"expected payload",expected_generation,sizeof(expected_generation));
670
671 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
672
673 allocator_free_chunk(&generated_data);
674
675 notify_payload->destroy(notify_payload);
676 generator->destroy(generator);
677
678 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
679
680 }
681
682 /*
683 * Described in header
684 */
685 void test_generator_with_nonce_payload(tester_t *tester)
686 {
687 generator_t *generator;
688 nonce_payload_t *nonce_payload;
689 logger_t *logger;
690 chunk_t generated_data;
691 chunk_t nonce;
692
693 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with Nonce Payload");
694
695 /* create generator */
696 generator = generator_create();
697 tester->assert_true(tester,(generator != NULL), "generator create check");
698
699 nonce_payload = nonce_payload_create();
700
701
702 nonce.ptr = "1234567890123456";
703 nonce.len = strlen("1234567890123456");
704
705 nonce_payload->set_nonce(nonce_payload,nonce);
706
707 generator->generate_payload(generator,(payload_t *)nonce_payload);
708 generator->write_to_chunk(generator,&generated_data);
709 logger->log_chunk(logger,RAW,"generated payload",&generated_data);
710
711
712 u_int8_t expected_generation[] = {
713 /* payload header */
714 0x00,0x00,0x00,0x14,
715 /* nonce data */
716 0x31,0x32,0x33,0x34,
717 0x35,0x36,0x37,0x38,
718 0x39,0x30,0x31,0x32,
719 0x33,0x34,0x35,0x36
720 };
721
722 logger->log_bytes(logger,RAW,"expected payload",expected_generation,sizeof(expected_generation));
723
724 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
725
726 allocator_free_chunk(&generated_data);
727
728
729 nonce_payload->destroy(nonce_payload);
730 generator->destroy(generator);
731
732 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
733
734 }
735
736 /*
737 * Described in header.
738 */
739 void test_generator_with_id_payload(tester_t *tester)
740 {
741 generator_t *generator;
742 id_payload_t *id_payload;
743 logger_t *logger;
744 chunk_t generated_data;
745 chunk_t id;
746
747 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with ID Payload");
748
749 /* create generator */
750 generator = generator_create();
751 tester->assert_true(tester,(generator != NULL), "generator create check");
752
753 id_payload = id_payload_create(FALSE);
754
755
756 id.ptr = "123456789012";
757 id.len = strlen(id.ptr);
758
759 id_payload->set_id_type(id_payload,ID_IPV4_ADDR);
760 id_payload->set_data(id_payload,id);
761
762 generator->generate_payload(generator,(payload_t *)id_payload);
763 generator->write_to_chunk(generator,&generated_data);
764 logger->log_chunk(logger,RAW,"generated payload",&generated_data);
765
766
767 u_int8_t expected_generation[] = {
768 /* payload header */
769 0x00,0x00,0x00,0x14,
770 0x01,0x00,0x00,0x00,
771 /* id data */
772 0x31,0x32,0x33,0x34,
773 0x35,0x36,0x37,0x38,
774 0x39,0x30,0x31,0x32,
775 };
776
777 logger->log_bytes(logger,RAW,"expected payload",expected_generation,sizeof(expected_generation));
778
779 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
780
781 allocator_free_chunk(&generated_data);
782
783 id_payload->destroy(id_payload);
784 generator->destroy(generator);
785
786 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
787 }
788
789 /*
790 * Described in header.
791 */
792 void test_generator_with_auth_payload(tester_t *tester)
793 {
794 generator_t *generator;
795 auth_payload_t *auth_payload;
796 logger_t *logger;
797 chunk_t generated_data;
798 chunk_t auth;
799
800 logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with AUTH Payload");
801
802 /* create generator */
803 generator = generator_create();
804 tester->assert_true(tester,(generator != NULL), "generator create check");
805
806 auth_payload = auth_payload_create(FALSE);
807
808
809 auth.ptr = "123456789012";
810 auth.len = strlen(auth.ptr);
811
812 auth_payload->set_auth_method(auth_payload,SHARED_KEY_MESSAGE_INTEGRITY_CODE);
813 auth_payload->set_data(auth_payload,auth);
814
815 generator->generate_payload(generator,(payload_t *)auth_payload);
816 generator->write_to_chunk(generator,&generated_data);
817 logger->log_chunk(logger,RAW,"generated payload",&generated_data);
818
819
820 u_int8_t expected_generation[] = {
821 /* payload header */
822 0x00,0x00,0x00,0x14,
823 0x02,0x00,0x00,0x00,
824 /* auth data */
825 0x31,0x32,0x33,0x34,
826 0x35,0x36,0x37,0x38,
827 0x39,0x30,0x31,0x32,
828 };
829
830 logger->log_bytes(logger,RAW,"expected payload",expected_generation,sizeof(expected_generation));
831
832 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
833
834 allocator_free_chunk(&generated_data);
835
836 auth_payload->destroy(auth_payload);
837 generator->destroy(generator);
838
839 charon->logger_manager->destroy_logger(charon->logger_manager,logger);
840 }