9602828cfb050ce986b8689c7ac280358aa7676b
[strongswan.git] / Source / charon / testcases / generator_test.c
1 /**
2 * @file generator.h
3 *
4 * @brief Tests to test the Generator class generator_t
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 "../globals.h"
28 #include "../generator.h"
29 #include "../utils/allocator.h"
30 #include "../utils/logger_manager.h"
31 #include "../utils/logger.h"
32 #include "../payloads/encodings.h"
33 #include "../payloads/ike_header.h"
34 #include "../payloads/transform_attribute.h"
35 #include "../payloads/transform_substructure.h"
36 #include "../payloads/proposal_substructure.h"
37 #include "../payloads/sa_payload.h"
38
39 /*
40 * Described in Header
41 */
42 void test_generator_with_header_payload(tester_t *tester)
43 {
44 generator_t *generator;
45 ike_header_t *header_data;
46 chunk_t generated_data;
47 status_t status;
48 logger_t *logger;
49
50 logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"header payload");
51
52 header_data = ike_header_create();
53 header_data->set_initiator_spi(header_data,1);
54 header_data->set_responder_spi(header_data,2);
55 ((payload_t *) header_data)->set_next_type((payload_t *) header_data, 3);
56 header_data->set_exchange_type(header_data, 6);
57 header_data->set_initiator_flag(header_data, TRUE);
58 header_data->set_response_flag(header_data, TRUE);
59 header_data->set_message_id(header_data,7);
60
61 generator = generator_create();
62 tester->assert_true(tester,(generator != NULL), "generator create check");
63
64 status = generator->generate_payload(generator,(payload_t *) header_data);
65 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
66
67 tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
68
69 u_int8_t expected_generation[] = {
70 0x00,0x00,0x00,0x00,
71 0x00,0x00,0x00,0x01,
72 0x00,0x00,0x00,0x00,
73 0x00,0x00,0x00,0x02,
74 0x03,0x20,0x06,0x28,
75 0x00,0x00,0x00,0x07,
76 0x00,0x00,0x00,0x1C,
77 };
78
79 logger->log_bytes(logger,RAW,"expected header",expected_generation,sizeof(expected_generation));
80 tester->assert_true(tester,(generated_data.len == sizeof(expected_generation)), "compare generated data length");
81 logger->log_chunk(logger,RAW,"generated header",&generated_data);
82 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data 1");
83 allocator_free_chunk(generated_data);
84
85 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
86
87 header_data->set_initiator_spi(header_data,0x22000054231234LL);
88 header_data->set_responder_spi(header_data,0x122398);
89 ((payload_t *) header_data)->set_next_type((payload_t *) header_data,0xF3);
90 header_data->set_exchange_type(header_data, 0x12);
91 header_data->set_initiator_flag(header_data, TRUE);
92 header_data->set_response_flag(header_data, TRUE);
93 header_data->set_message_id(header_data,0x33AFF3);
94
95 generator = generator_create();
96 tester->assert_true(tester,(generator != NULL), "generator create check");
97
98 status = generator->generate_payload(generator,(payload_t *)header_data);
99 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
100
101 tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
102
103 u_int8_t expected_generation2[] = {
104 0x00,0x22,0x00,0x00,
105 0x54,0x23,0x12,0x34,
106 0x00,0x00,0x00,0x00,
107 0x00,0x12,0x23,0x98,
108 0xF3,0x20,0x12,0x28,
109 0x00,0x33,0xAF,0xF3,
110 0x00,0x00,0x00,0x1C,
111 };
112
113 logger->log_bytes(logger,RAW,"expected header",expected_generation2,sizeof(expected_generation2));
114
115 logger->log_chunk(logger,RAW,"generated header",&generated_data);
116
117 tester->assert_true(tester,(memcmp(expected_generation2,generated_data.ptr,sizeof(expected_generation2)) == 0), "compare generated data 2");
118 allocator_free_chunk(generated_data);
119
120 header_data->destroy(header_data);
121
122 global_logger_manager->destroy_logger(global_logger_manager,logger);
123 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
124 }
125
126 /*
127 * Described in header
128 */
129 void test_generator_with_transform_attribute(tester_t *tester)
130 {
131 generator_t *generator;
132 transform_attribute_t *attribute;
133 status_t status;
134 chunk_t generated_data;
135 logger_t *logger;
136
137 logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"transform_attribute payload");
138
139
140 /* test empty attribute */
141 generator = generator_create();
142 tester->assert_true(tester,(generator != NULL), "generator create check");
143 attribute = transform_attribute_create();
144 status = generator->generate_payload(generator,(payload_t *)attribute);
145 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
146 tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
147 logger->log_chunk(logger,RAW,"generated attribute",&generated_data);
148
149 u_int8_t expected_generation[] = {
150 0x80,0x00,0x00,0x00,
151 };
152 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
153 allocator_free_chunk(generated_data);
154 tester->assert_true(tester,(attribute->destroy(attribute) == SUCCESS), "attribute destroy call check");
155 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
156
157 /* test attribute with 2 byte data */
158 generator = generator_create();
159 tester->assert_true(tester,(generator != NULL), "generator create check");
160
161 attribute = transform_attribute_create();
162 u_int16_t dataval = 5768;
163 chunk_t data;
164 data.ptr = (void *) &dataval;
165 data.len = 2;
166
167 attribute->set_value(attribute,data);
168
169 status = generator->generate_payload(generator,(payload_t *)attribute);
170 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
171 tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
172 logger->log_chunk(logger,RAW,"generated attribute",&generated_data);
173
174 u_int8_t expected_generation2[] = {
175 0x80,0x00,0x88,0x16,
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 tester->assert_true(tester,(attribute->destroy(attribute) == SUCCESS), "attribute destroy call check");
181 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
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 status = attribute->set_value(attribute,data);
195 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
196
197 status = attribute->set_attribute_type(attribute,456);
198 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
199
200
201 status = generator->generate_payload(generator,(payload_t *)attribute);
202 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
203 tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
204 logger->log_chunk(logger,RAW,"generated attribute",&generated_data);
205
206 u_int8_t expected_generation3[] = {
207 0x01,0xC8,0x00,0x19,
208 0x64,0x64,0x64,0x64,
209 0x64,0x64,0x64,0x64,
210 0x64,0x64,0x65,0x65,
211 0x65,0x65,0x65,0x65,
212 0x65,0x65,0x65,0x65,
213 0x66,0x66,0x66,0x66,
214 0x66
215 };
216 tester->assert_true(tester,(memcmp(expected_generation3,generated_data.ptr,sizeof(expected_generation3)) == 0), "compare generated data");
217
218 allocator_free_chunk(generated_data);
219 tester->assert_true(tester,(attribute->destroy(attribute) == SUCCESS), "attribute destroy call check");
220 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
221
222
223 global_logger_manager->destroy_logger(global_logger_manager,logger);
224 }
225
226
227
228 /*
229 * Described in header
230 */
231 void test_generator_with_transform_substructure(tester_t *tester)
232 {
233 generator_t *generator;
234 transform_attribute_t *attribute1, *attribute2;
235 transform_substructure_t *transform;
236 chunk_t data;
237 status_t status;
238 chunk_t generated_data;
239 logger_t *logger;
240
241 logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"transform substr.");
242
243 /* create generator */
244 generator = generator_create();
245 tester->assert_true(tester,(generator != NULL), "generator create check");
246
247 /* create attribute 1 */
248 attribute1 = transform_attribute_create();
249 char *stringval = "abcd";
250 data.ptr = (void *) stringval;
251 data.len = 4;
252 status = attribute1->set_value(attribute1,data);
253 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
254 status = attribute1->set_attribute_type(attribute1,0);
255 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
256 logger->log(logger,CONTROL,"attribute1 created");
257
258 /* create attribute 2 */
259 attribute2 = transform_attribute_create();
260 stringval = "efgh";
261 data.ptr = (void *) stringval;
262 data.len = 4;
263 status = attribute2->set_value(attribute2,data);
264 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
265 status = attribute2->set_attribute_type(attribute2,0);
266 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
267 logger->log(logger,CONTROL,"attribute2 created");
268
269 /* create transform */
270 transform = transform_substructure_create();
271 tester->assert_true(tester,(transform != NULL), "transform create check");
272 status = transform->add_transform_attribute(transform,attribute1);
273 tester->assert_true(tester,(status == SUCCESS),"add_transform_attribute call check");
274 status = transform->add_transform_attribute(transform,attribute2);
275 tester->assert_true(tester,(status == SUCCESS),"add_transform_attribute call check");
276 status = transform->set_transform_type(transform,5); /* hex 5 */
277 tester->assert_true(tester,(status == SUCCESS),"set_transform_type call check");
278 status = transform->set_transform_id(transform,65000); /* hex FDE8 */
279 tester->assert_true(tester,(status == SUCCESS),"set_transform_id call check");
280
281
282 logger->log(logger,CONTROL,"transform created");
283
284 status = generator->generate_payload(generator,(payload_t *)transform);
285 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
286 tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
287 logger->log_chunk(logger,RAW,"generated transform",&generated_data);
288
289 u_int8_t expected_generation3[] = {
290 0x00,0x00,0x00,0x18,
291 0x05,0x00,0xFD,0xE8,
292 0x00,0x00,0x00,0x04,
293 0x61,0x62,0x63,0x64,
294 0x00,0x00,0x00,0x04,
295 0x65,0x66,0x67,0x68,
296 };
297 tester->assert_true(tester,(memcmp(expected_generation3,generated_data.ptr,sizeof(expected_generation3)) == 0), "compare generated data");
298
299 allocator_free_chunk(generated_data);
300 tester->assert_true(tester,(transform->destroy(transform) == SUCCESS), "transform destroy call check");
301 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
302
303
304 global_logger_manager->destroy_logger(global_logger_manager,logger);
305 }
306
307
308 /*
309 * Described in header
310 */
311 void test_generator_with_proposal_substructure(tester_t *tester)
312 {
313 generator_t *generator;
314 transform_attribute_t *attribute1, *attribute2, *attribute3;
315 transform_substructure_t *transform1, *transform2;
316 proposal_substructure_t *proposal;
317 chunk_t data;
318 status_t status;
319 chunk_t generated_data;
320 logger_t *logger;
321
322 logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"transform substr.");
323
324 /* create generator */
325 generator = generator_create();
326 tester->assert_true(tester,(generator != NULL), "generator create check");
327
328 /* create attribute 1 */
329 attribute1 = transform_attribute_create();
330 char *stringval = "abcd";
331 data.ptr = (void *) stringval;
332 data.len = 4;
333 status = attribute1->set_value(attribute1,data);
334 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
335 status = attribute1->set_attribute_type(attribute1,0);
336 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
337 logger->log(logger,CONTROL,"attribute1 created");
338
339 /* create attribute 2 */
340 attribute2 = transform_attribute_create();
341 stringval = "efgh";
342 data.ptr = (void *) stringval;
343 data.len = 4;
344 status = attribute2->set_value(attribute2,data);
345 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
346 status = attribute2->set_attribute_type(attribute2,0);
347 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
348 logger->log(logger,CONTROL,"attribute2 created");
349
350 /* create attribute 3 */
351 attribute3 = transform_attribute_create();
352 stringval = "ijkl";
353 data.ptr = (void *) stringval;
354 data.len = 4;
355 status = attribute3->set_value(attribute3,data);
356 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
357 status = attribute3->set_attribute_type(attribute3,0);
358 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
359 logger->log(logger,CONTROL,"attribute3 created");
360
361 /* create transform 1*/
362 transform1 = transform_substructure_create();
363 tester->assert_true(tester,(transform1 != NULL), "transform create check");
364 status = transform1->add_transform_attribute(transform1,attribute1);
365 tester->assert_true(tester,(status == SUCCESS),"add_transform_attribute call check");
366 status = transform1->add_transform_attribute(transform1,attribute2);
367 tester->assert_true(tester,(status == SUCCESS),"add_transform_attribute call check");
368 status = transform1->set_transform_type(transform1,5); /* hex 5 */
369 tester->assert_true(tester,(status == SUCCESS),"set_transform_type call check");
370 status = transform1->set_transform_id(transform1,65000); /* hex FDE8 */
371 tester->assert_true(tester,(status == SUCCESS),"set_transform_id call check");
372
373 /* create transform 2*/
374 transform2 = transform_substructure_create();
375 tester->assert_true(tester,(transform2 != NULL), "transform create check");
376 status = transform2->add_transform_attribute(transform2,attribute3);
377 tester->assert_true(tester,(status == SUCCESS),"add_transform_attribute call check");
378 status = transform2->set_transform_type(transform2,3); /* hex 3 */
379 tester->assert_true(tester,(status == SUCCESS),"set_transform_type call check");
380 status = transform2->set_transform_id(transform2,4); /* hex 4 */
381 tester->assert_true(tester,(status == SUCCESS),"set_transform_id call check");
382
383 logger->log(logger,CONTROL,"transforms created");
384
385 proposal = proposal_substructure_create();
386 tester->assert_true(tester,(proposal != NULL), "proposal create check");
387
388 stringval = "ABCDEFGH";
389 data.ptr = (void *) stringval;
390 data.len = 8;
391
392 status = proposal->add_transform_substructure(proposal,transform1);
393 tester->assert_true(tester,(status == SUCCESS),"add_transform_substructure call check");
394 status = proposal->add_transform_substructure(proposal,transform2);
395 tester->assert_true(tester,(status == SUCCESS),"add_transform_substructure call check");
396 status = proposal->set_spi(proposal,data);
397 tester->assert_true(tester,(status == SUCCESS),"set_spi call check");
398 status = proposal->set_proposal_number(proposal,7);
399 tester->assert_true(tester,(status == SUCCESS),"set_proposal_number call check");
400 status = proposal->set_protocol_id(proposal,4);
401 tester->assert_true(tester,(status == SUCCESS),"set_protocol_id call check");
402
403
404 status = generator->generate_payload(generator,(payload_t *)proposal);
405 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
406 tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
407 logger->log_chunk(logger,RAW,"generated transform",&generated_data);
408
409 u_int8_t expected_generation[] = {
410 /* proposal header */
411 0x00,0x00,0x00,0x38,
412 0x07,0x04,0x08,0x02,
413 /* SPI */
414 0x41,0x42,0x43,0x44,
415 0x45,0x46,0x47,0x48,
416 /* first transform */
417 0x03,0x00,0x00,0x18,
418 0x05,0x00,0xFD,0xE8,
419 /* first transform attributes */
420 0x00,0x00,0x00,0x04,
421 0x61,0x62,0x63,0x64,
422 0x00,0x00,0x00,0x04,
423 0x65,0x66,0x67,0x68,
424 /* second transform */
425 0x00,0x00,0x00,0x10,
426 0x03,0x00,0x00,0x04,
427 /* second transform attributes */
428 0x00,0x00,0x00,0x04,
429 0x69,0x6A,0x6B,0x6C
430 };
431 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
432
433 allocator_free_chunk(generated_data);
434 tester->assert_true(tester,(proposal->destroy(proposal) == SUCCESS), "proposal destroy call check");
435 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
436
437
438 global_logger_manager->destroy_logger(global_logger_manager,logger);
439 }
440
441 void test_generator_with_sa_payload(tester_t *tester)
442 {
443 generator_t *generator;
444 transform_attribute_t *attribute1, *attribute2, *attribute3;
445 transform_substructure_t *transform1, *transform2;
446 proposal_substructure_t *proposal1, *proposal2;
447 sa_payload_t *sa_payload;
448 ike_header_t *ike_header;
449
450 chunk_t data;
451 status_t status;
452 chunk_t generated_data;
453 logger_t *logger;
454
455 logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Message with SA Payload");
456
457 /* create generator */
458 generator = generator_create();
459 tester->assert_true(tester,(generator != NULL), "generator create check");
460
461 /* create attribute 1 */
462 attribute1 = transform_attribute_create();
463 char *stringval = "abcd";
464 data.ptr = (void *) stringval;
465 data.len = 4;
466 status = attribute1->set_value(attribute1,data);
467 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
468 status = attribute1->set_attribute_type(attribute1,0);
469 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
470 logger->log(logger,CONTROL,"attribute1 created");
471
472 /* create attribute 2 */
473 attribute2 = transform_attribute_create();
474 stringval = "efgh";
475 data.ptr = (void *) stringval;
476 data.len = 4;
477 status = attribute2->set_value(attribute2,data);
478 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
479 status = attribute2->set_attribute_type(attribute2,0);
480 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
481 logger->log(logger,CONTROL,"attribute2 created");
482
483 /* create attribute 3 */
484 attribute3 = transform_attribute_create();
485 stringval = "ijkl";
486 data.ptr = (void *) stringval;
487 data.len = 4;
488 status = attribute3->set_value(attribute3,data);
489 tester->assert_true(tester,(status == SUCCESS),"set_value call check");
490 status = attribute3->set_attribute_type(attribute3,0);
491 tester->assert_true(tester,(status == SUCCESS),"set_attribute_type call check");
492 logger->log(logger,CONTROL,"attribute3 created");
493
494 /* create transform 1*/
495 transform1 = transform_substructure_create();
496 tester->assert_true(tester,(transform1 != NULL), "transform create check");
497 status = transform1->add_transform_attribute(transform1,attribute1);
498 tester->assert_true(tester,(status == SUCCESS),"add_transform_attribute call check");
499 status = transform1->add_transform_attribute(transform1,attribute2);
500 tester->assert_true(tester,(status == SUCCESS),"add_transform_attribute call check");
501 status = transform1->set_transform_type(transform1,5); /* hex 5 */
502 tester->assert_true(tester,(status == SUCCESS),"set_transform_type call check");
503 status = transform1->set_transform_id(transform1,65000); /* hex FDE8 */
504 tester->assert_true(tester,(status == SUCCESS),"set_transform_id call check");
505
506 /* create transform 2*/
507 transform2 = transform_substructure_create();
508 tester->assert_true(tester,(transform2 != NULL), "transform create check");
509 status = transform2->add_transform_attribute(transform2,attribute3);
510 tester->assert_true(tester,(status == SUCCESS),"add_transform_attribute call check");
511 status = transform2->set_transform_type(transform2,3); /* hex 3 */
512 tester->assert_true(tester,(status == SUCCESS),"set_transform_type call check");
513 status = transform2->set_transform_id(transform2,4); /* hex 4 */
514 tester->assert_true(tester,(status == SUCCESS),"set_transform_id call check");
515
516 logger->log(logger,CONTROL,"transforms created");
517
518 /* create proposal 1 */
519 proposal1 = proposal_substructure_create();
520 tester->assert_true(tester,(proposal1 != NULL), "proposal create check");
521
522 stringval = "ABCDEFGH";
523 data.ptr = (void *) stringval;
524 data.len = 8;
525
526 status = proposal1->add_transform_substructure(proposal1,transform1);
527 tester->assert_true(tester,(status == SUCCESS),"add_transform_substructure call check");
528 status = proposal1->add_transform_substructure(proposal1,transform2);
529 tester->assert_true(tester,(status == SUCCESS),"add_transform_substructure call check");
530 status = proposal1->set_spi(proposal1,data);
531 tester->assert_true(tester,(status == SUCCESS),"set_spi call check");
532 status = proposal1->set_proposal_number(proposal1,7);
533 tester->assert_true(tester,(status == SUCCESS),"set_proposal_number call check");
534 status = proposal1->set_protocol_id(proposal1,4);
535 tester->assert_true(tester,(status == SUCCESS),"set_protocol_id call check");
536
537 /* create proposal 2 */
538 proposal2 = proposal_substructure_create();
539 tester->assert_true(tester,(proposal2 != NULL), "proposal create check");
540 status = proposal2->set_proposal_number(proposal2,7);
541 tester->assert_true(tester,(status == SUCCESS),"set_proposal_number call check");
542 status = proposal2->set_protocol_id(proposal2,5);
543 tester->assert_true(tester,(status == SUCCESS),"set_protocol_id call check");
544
545 /* create sa_payload */
546 sa_payload = sa_payload_create();
547
548 sa_payload->add_proposal_substructure(sa_payload,proposal1);
549 sa_payload->add_proposal_substructure(sa_payload,proposal2);
550
551 ike_header = ike_header_create();
552 ike_header->set_initiator_spi(ike_header,0x22000054231234LL);
553 ike_header->set_responder_spi(ike_header,0x122398);
554 ((payload_t *) ike_header)->set_next_type((payload_t *) ike_header,SECURITY_ASSOCIATION);
555 ike_header->set_exchange_type(ike_header, 0x12);
556 ike_header->set_initiator_flag(ike_header, TRUE);
557 ike_header->set_response_flag(ike_header, TRUE);
558 ike_header->set_message_id(ike_header,0x33AFF3);
559
560 status = generator->generate_payload(generator,(payload_t *)ike_header);
561 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
562 status = generator->generate_payload(generator,(payload_t *)sa_payload);
563 tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
564 tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
565 logger->log_chunk(logger,RAW,"generated transform",&generated_data);
566
567 u_int8_t expected_generation[] = {
568 /* sa payload header */
569 0x00,0x22,0x00,0x00,
570 0x54,0x23,0x12,0x34,
571 0x00,0x00,0x00,0x00,
572 0x00,0x12,0x23,0x98,
573 0x21,0x20,0x12,0x28,
574 0x00,0x33,0xAF,0xF3,
575 0x00,0x00,0x00,0x60,
576
577 /* sa payload header */
578 0x00,0x00,0x00,0x44,
579 /* proposal header */
580 0x00,0x00,0x00,0x38,
581 0x07,0x04,0x08,0x02,
582 /* SPI */
583 0x41,0x42,0x43,0x44,
584 0x45,0x46,0x47,0x48,
585 /* first transform */
586 0x03,0x00,0x00,0x18,
587 0x05,0x00,0xFD,0xE8,
588 /* first transform attributes */
589 0x00,0x00,0x00,0x04,
590 0x61,0x62,0x63,0x64,
591 0x00,0x00,0x00,0x04,
592 0x65,0x66,0x67,0x68,
593 /* second transform */
594 0x00,0x00,0x00,0x10,
595 0x03,0x00,0x00,0x04,
596 /* second transform attributes */
597 0x00,0x00,0x00,0x04,
598 0x69,0x6A,0x6B,0x6C,
599 /* proposal header 2*/
600 0x00,0x00,0x00,0x08,
601 0x07,0x05,0x00,0x00,
602
603 };
604 tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
605
606 allocator_free_chunk(generated_data);
607 tester->assert_true(tester,(ike_header->destroy(ike_header) == SUCCESS), "ike_header destroy call check");
608 tester->assert_true(tester,(sa_payload->destroy(sa_payload) == SUCCESS), "sa_payload destroy call check");
609 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
610
611 global_logger_manager->destroy_logger(global_logger_manager,logger);
612
613 }