4 * @brief Tests for the parser_t class.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
25 #include "parser_test.h"
27 #include <utils/allocator.h>
28 #include <utils/logger_manager.h>
29 #include <encoding/generator.h>
30 #include <encoding/parser.h>
31 #include <encoding/payloads/encodings.h>
32 #include <encoding/payloads/ike_header.h>
33 #include <encoding/payloads/sa_payload.h>
34 #include <encoding/payloads/nonce_payload.h>
35 #include <encoding/payloads/id_payload.h>
36 #include <encoding/payloads/ke_payload.h>
37 #include <encoding/payloads/notify_payload.h>
38 #include <encoding/payloads/auth_payload.h>
39 #include <encoding/payloads/ts_payload.h>
45 void test_parser_with_header_payload(tester_t
*tester
)
48 ike_header_t
*ike_header
;
52 u_int8_t header_bytes
[] = {
61 header_chunk
.ptr
= header_bytes
;
62 header_chunk
.len
= sizeof(header_bytes
);
65 parser
= parser_create(header_chunk
);
66 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
67 status
= parser
->parse_payload(parser
, HEADER
, (payload_t
**)&ike_header
);
68 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
69 parser
->destroy(parser
);
71 if (status
!= SUCCESS
)
76 tester
->assert_true(tester
,(ike_header
->get_initiator_spi(ike_header
) == 1),"parsed initiator_spi value");
77 tester
->assert_true(tester
,(ike_header
->get_responder_spi(ike_header
) == 2),"parsed responder_spi value");
78 tester
->assert_true(tester
,(ike_header
->payload_interface
.get_next_type((payload_t
*)ike_header
) == 3),"parsed next_payload value");
79 tester
->assert_true(tester
,(ike_header
->get_maj_version(ike_header
) == 4),"parsed maj_version value");
80 tester
->assert_true(tester
,(ike_header
->get_min_version(ike_header
) == 5),"parsed min_version value");
81 tester
->assert_true(tester
,(ike_header
->get_exchange_type(ike_header
) == 6),"parsed exchange_type value");
82 tester
->assert_true(tester
,(ike_header
->get_initiator_flag(ike_header
) == TRUE
),"parsed flags.initiator value");
83 tester
->assert_true(tester
,(ike_header
->get_version_flag(ike_header
) == FALSE
),"parsed flags.version value");
84 tester
->assert_true(tester
,(ike_header
->get_response_flag(ike_header
) == TRUE
),"parsed flags.response value");
85 tester
->assert_true(tester
,(ike_header
->get_message_id(ike_header
) == 7),"parsed message_id value");
86 tester
->assert_true(tester
,(ike_header
->payload_interface
.get_length((payload_t
*)ike_header
) == 0x1C),"parsed length value");
88 ike_header
->destroy(ike_header
);
94 void test_parser_with_sa_payload(tester_t
*tester
)
97 sa_payload_t
*sa_payload
;
99 chunk_t sa_chunk
, sa_chunk2
, sa_chunk3
;
100 iterator_t
*proposals
, *transforms
, *attributes
;
101 ike_proposal_t
*ike_proposals
;
102 size_t ike_proposal_count
;
103 child_proposal_t
*child_proposals
;
104 size_t child_proposal_count
;
106 /* first test generic parsing functionality */
108 u_int8_t sa_bytes
[] = {
109 0x00,0x80,0x00,0x24, /* payload header*/
110 0x00,0x00,0x00,0x20, /* a proposal */
112 0x01,0x02,0x03,0x04, /* spi */
113 0x00,0x00,0x00,0x14, /* transform */
115 0x80,0x01,0x00,0x05, /* attribute without length */
116 0x00,0x03,0x00,0x04, /* attribute with length */
122 sa_chunk
.ptr
= sa_bytes
;
123 sa_chunk
.len
= sizeof(sa_bytes
);
126 parser
= parser_create(sa_chunk
);
127 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
128 status
= parser
->parse_payload(parser
, SECURITY_ASSOCIATION
, (payload_t
**)&sa_payload
);
129 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
130 parser
->destroy(parser
);
132 if (status
!= SUCCESS
)
138 proposals
= sa_payload
->create_proposal_substructure_iterator(sa_payload
, TRUE
);
139 while (proposals
->has_next(proposals
))
141 proposal_substructure_t
*proposal
;
142 proposals
->current(proposals
, (void**)&proposal
);
144 u_int8_t spi_should
[] = {0x01, 0x02, 0x03, 0x04};
146 tester
->assert_true(tester
,(proposal
->get_proposal_number(proposal
) == 1),"proposal number");
147 tester
->assert_true(tester
,(proposal
->get_protocol_id(proposal
) == 2),"proposal id");
148 spi
= proposal
->get_spi(proposal
);
149 tester
->assert_false(tester
,(memcmp(&spi_should
, spi
.ptr
, spi
.len
)),"proposal spi");
151 transforms
= proposal
->create_transform_substructure_iterator(proposal
, TRUE
);
152 while(transforms
->has_next(transforms
))
154 transform_substructure_t
*transform
;
156 transforms
->current(transforms
, (void**)&transform
);
157 tester
->assert_true(tester
,(transform
->get_transform_type(transform
) == 7),"transform type");
158 tester
->assert_true(tester
,(transform
->get_transform_id(transform
) == 3),"transform id");
159 attributes
= transform
->create_transform_attribute_iterator(transform
, TRUE
);
161 while (attributes
->has_next(attributes
))
163 transform_attribute_t
*attribute
;
164 attributes
->current(attributes
, (void**)&attribute
);
167 u_int8_t value
[] = {0x05, 0x00};
168 chunk_t attribute_value
;
169 tester
->assert_true(tester
,(attribute
->get_attribute_type(attribute
) == 1),"attribute 1 type");
170 attribute_value
= attribute
->get_value_chunk(attribute
);
171 tester
->assert_false(tester
,(memcmp(&value
, attribute_value
.ptr
, attribute_value
.len
)),"attribute 1 value");
175 u_int8_t value
[] = {0x01, 0x02, 0x03, 0x04};
176 chunk_t attribute_value
;
177 tester
->assert_true(tester
,(attribute
->get_attribute_type(attribute
) == 3),"attribute 2 type");
178 attribute_value
= attribute
->get_value_chunk(attribute
);
179 tester
->assert_false(tester
,(memcmp(&value
, attribute_value
.ptr
, attribute_value
.len
)),"attribute 2 value");
183 attributes
->destroy(attributes
);
185 transforms
->destroy(transforms
);
187 proposals
->destroy(proposals
);
189 sa_payload
->destroy(sa_payload
);
193 /* now test SA functionality after parsing an SA payload*/
195 u_int8_t sa_bytes2
[] = {
196 0x00,0x00,0x00,0x6C, /* payload header*/
197 0x02,0x00,0x00,0x34, /* a proposal */
199 0x03,0x00,0x00,0x0C, /* transform 1 */
201 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
202 0x03,0x00,0x00,0x0C, /* transform 2 */
204 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
205 0x03,0x00,0x00,0x0C, /* transform 3 */
207 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
208 0x00,0x00,0x00,0x08, /* transform 4 */
210 0x00,0x00,0x00,0x34, /* a proposal */
212 0x03,0x00,0x00,0x0C, /* transform 1 */
214 0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
215 0x03,0x00,0x00,0x0C, /* transform 2 */
217 0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
218 0x03,0x00,0x00,0x0C, /* transform 3 */
220 0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
221 0x00,0x00,0x00,0x08, /* transform 4 */
225 sa_chunk2
.ptr
= sa_bytes2
;
226 sa_chunk2
.len
= sizeof(sa_bytes2
);
228 parser
= parser_create(sa_chunk2
);
229 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
230 status
= parser
->parse_payload(parser
, SECURITY_ASSOCIATION
, (payload_t
**)&sa_payload
);
231 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
232 parser
->destroy(parser
);
234 if (status
!= SUCCESS
)
239 status
= sa_payload
->payload_interface
.verify(&(sa_payload
->payload_interface
));
240 tester
->assert_true(tester
,(status
== SUCCESS
),"verify call check");
242 status
= sa_payload
->get_ike_proposals (sa_payload
, &ike_proposals
, &ike_proposal_count
);
243 tester
->assert_true(tester
,(status
== SUCCESS
),"get ike proposals call check");
245 tester
->assert_true(tester
,(ike_proposal_count
== 2),"ike proposal count check");
246 tester
->assert_true(tester
,(ike_proposals
[0].encryption_algorithm
== 1),"ike proposal content check");
247 tester
->assert_true(tester
,(ike_proposals
[0].encryption_algorithm_key_length
== 20),"ike proposal content check");
248 tester
->assert_true(tester
,(ike_proposals
[0].integrity_algorithm
== 1),"ike proposal content check");
249 tester
->assert_true(tester
,(ike_proposals
[0].integrity_algorithm_key_length
== 20),"ike proposal content check");
250 tester
->assert_true(tester
,(ike_proposals
[0].pseudo_random_function
== 1),"ike proposal content check");
251 tester
->assert_true(tester
,(ike_proposals
[0].pseudo_random_function_key_length
== 20),"ike proposal content check");
252 tester
->assert_true(tester
,(ike_proposals
[0].diffie_hellman_group
== 1),"ike proposal content check");
254 tester
->assert_true(tester
,(ike_proposals
[1].encryption_algorithm
== 2),"ike proposal content check");
255 tester
->assert_true(tester
,(ike_proposals
[1].encryption_algorithm_key_length
== 16),"ike proposal content check");
256 tester
->assert_true(tester
,(ike_proposals
[1].integrity_algorithm
== 2),"ike proposal content check");
257 tester
->assert_true(tester
,(ike_proposals
[1].integrity_algorithm_key_length
== 16),"ike proposal content check");
258 tester
->assert_true(tester
,(ike_proposals
[1].pseudo_random_function
== 2),"ike proposal content check");
259 tester
->assert_true(tester
,(ike_proposals
[1].pseudo_random_function_key_length
== 16),"ike proposal content check");
260 tester
->assert_true(tester
,(ike_proposals
[1].diffie_hellman_group
== 2),"ike proposal content check");
263 if (status
== SUCCESS
)
265 allocator_free(ike_proposals
);
267 sa_payload
->destroy(sa_payload
);
269 /* now test SA functionality after parsing an SA payload with child sa proposals*/
270 u_int8_t sa_bytes3
[] = {
271 0x00,0x00,0x00,0xA0, /* payload header*/
274 0x02,0x00,0x00,0x28, /* a proposal */
277 0x03,0x00,0x00,0x0C, /* transform 1 */
279 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
281 0x03,0x00,0x00,0x08, /* transform 2 */
284 0x00,0x00,0x00,0x08, /* transform 3 */
288 0x02,0x00,0x00,0x20, /* a proposal */
292 0x03,0x00,0x00,0x0C, /* transform 1 */
294 0x80,0x0E,0x00,0x20, /* keylength attribute with 32 bytes length */
296 0x00,0x00,0x00,0x08, /* transform 2 */
300 0x02,0x00,0x00,0x28, /* a proposal */
303 0x03,0x00,0x00,0x0C, /* transform 1 */
305 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
307 0x03,0x00,0x00,0x08, /* transform 2 */
310 0x00,0x00,0x00,0x08, /* transform 3 */
314 0x00,0x00,0x00,0x2C, /* a proposal */
318 0x03,0x00,0x00,0x0C, /* transform 1 */
320 0x80,0x0E,0x00,0x20, /* keylength attribute with 32 bytes length */
322 0x03,0x00,0x00,0x0C, /* transform 2 */
324 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
326 0x00,0x00,0x00,0x08, /* transform 3 */
330 sa_chunk3
.ptr
= sa_bytes3
;
331 sa_chunk3
.len
= sizeof(sa_bytes3
);
333 parser
= parser_create(sa_chunk3
);
334 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
335 status
= parser
->parse_payload(parser
, SECURITY_ASSOCIATION
, (payload_t
**)&sa_payload
);
336 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
337 parser
->destroy(parser
);
339 if (status
!= SUCCESS
)
344 status
= sa_payload
->payload_interface
.verify(&(sa_payload
->payload_interface
));
345 tester
->assert_true(tester
,(status
== SUCCESS
),"verify call check");
347 status
= sa_payload
->get_ike_proposals (sa_payload
, &ike_proposals
, &ike_proposal_count
);
348 tester
->assert_false(tester
,(status
== SUCCESS
),"get ike proposals call check");
350 status
= sa_payload
->get_child_proposals (sa_payload
, &child_proposals
, &child_proposal_count
);
351 tester
->assert_true(tester
,(status
== SUCCESS
),"get child proposals call check");
354 tester
->assert_true(tester
,(child_proposal_count
== 2),"child proposal count check");
355 tester
->assert_true(tester
,(child_proposals
[0].ah
.is_set
== TRUE
),"is ah set check");
356 tester
->assert_true(tester
,(child_proposals
[0].ah
.integrity_algorithm
== AUTH_HMAC_MD5_96
),"integrity_algorithm check");
357 tester
->assert_true(tester
,(child_proposals
[0].ah
.integrity_algorithm_key_size
== 20),"integrity_algorithm_key_size check");
358 tester
->assert_true(tester
,(child_proposals
[0].ah
.diffie_hellman_group
== MODP_2048_BIT
),"diffie_hellman_group check");
359 tester
->assert_true(tester
,(child_proposals
[0].ah
.extended_sequence_numbers
== EXT_SEQ_NUMBERS
),"extended_sequence_numbers check");
360 tester
->assert_true(tester
,(child_proposals
[0].ah
.spi
[0] == 1),"spi check");
361 tester
->assert_true(tester
,(child_proposals
[0].ah
.spi
[1] == 1),"spi check");
362 tester
->assert_true(tester
,(child_proposals
[0].ah
.spi
[2] == 1),"spi check");
363 tester
->assert_true(tester
,(child_proposals
[0].ah
.spi
[3] == 1),"spi check");
365 tester
->assert_true(tester
,(child_proposals
[0].esp
.is_set
== TRUE
),"is ah set check");
366 tester
->assert_true(tester
,(child_proposals
[0].esp
.encryption_algorithm
== ENCR_AES_CBC
),"integrity_algorithm check");
367 tester
->assert_true(tester
,(child_proposals
[0].esp
.encryption_algorithm_key_size
== 32),"integrity_algorithm_key_size check");
368 tester
->assert_true(tester
,(child_proposals
[0].esp
.diffie_hellman_group
== MODP_1024_BIT
),"diffie_hellman_group check");
369 tester
->assert_true(tester
,(child_proposals
[0].esp
.integrity_algorithm
== AUTH_UNDEFINED
),"integrity_algorithm check");
370 tester
->assert_true(tester
,(child_proposals
[0].esp
.spi
[0] == 2),"spi check");
371 tester
->assert_true(tester
,(child_proposals
[0].esp
.spi
[1] == 2),"spi check");
372 tester
->assert_true(tester
,(child_proposals
[0].esp
.spi
[2] == 2),"spi check");
373 tester
->assert_true(tester
,(child_proposals
[0].esp
.spi
[3] == 2),"spi check");
375 tester
->assert_true(tester
,(child_proposals
[1].ah
.is_set
== TRUE
),"is ah set check");
376 tester
->assert_true(tester
,(child_proposals
[1].ah
.integrity_algorithm
== AUTH_HMAC_MD5_96
),"integrity_algorithm check");
377 tester
->assert_true(tester
,(child_proposals
[1].ah
.integrity_algorithm_key_size
== 20),"integrity_algorithm_key_size check");
378 tester
->assert_true(tester
,(child_proposals
[1].ah
.diffie_hellman_group
== MODP_2048_BIT
),"diffie_hellman_group check");
379 tester
->assert_true(tester
,(child_proposals
[1].ah
.extended_sequence_numbers
== EXT_SEQ_NUMBERS
),"extended_sequence_numbers check");
380 tester
->assert_true(tester
,(child_proposals
[1].ah
.spi
[0] == 1),"spi check");
381 tester
->assert_true(tester
,(child_proposals
[1].ah
.spi
[1] == 1),"spi check");
382 tester
->assert_true(tester
,(child_proposals
[1].ah
.spi
[2] == 1),"spi check");
383 tester
->assert_true(tester
,(child_proposals
[1].ah
.spi
[3] == 1),"spi check");
385 tester
->assert_true(tester
,(child_proposals
[1].esp
.is_set
== TRUE
),"is ah set check");
386 tester
->assert_true(tester
,(child_proposals
[1].esp
.encryption_algorithm
== ENCR_AES_CBC
),"integrity_algorithm check");
387 tester
->assert_true(tester
,(child_proposals
[1].esp
.encryption_algorithm_key_size
== 32),"integrity_algorithm_key_size check");
388 tester
->assert_true(tester
,(child_proposals
[1].esp
.diffie_hellman_group
== MODP_1024_BIT
),"diffie_hellman_group check");
389 tester
->assert_true(tester
,(child_proposals
[1].esp
.integrity_algorithm
== AUTH_HMAC_MD5_96
),"integrity_algorithm check");
390 tester
->assert_true(tester
,(child_proposals
[1].esp
.integrity_algorithm_key_size
== 20),"integrity_algorithm check");
391 tester
->assert_true(tester
,(child_proposals
[1].esp
.spi
[0] == 2),"spi check");
392 tester
->assert_true(tester
,(child_proposals
[1].esp
.spi
[1] == 2),"spi check");
393 tester
->assert_true(tester
,(child_proposals
[1].esp
.spi
[2] == 2),"spi check");
394 tester
->assert_true(tester
,(child_proposals
[1].esp
.spi
[3] == 2),"spi check");
396 if (status
== SUCCESS
)
398 allocator_free(child_proposals
);
402 sa_payload
->destroy(sa_payload
);
406 * Described in Header
408 void test_parser_with_nonce_payload(tester_t
*tester
)
411 nonce_payload_t
*nonce_payload
;
413 chunk_t nonce_chunk
, result
;
415 u_int8_t nonce_bytes
[] = {
416 0x00,0x00,0x00,0x14, /* payload header */
417 0x00,0x01,0x02,0x03, /* 16 Byte nonce */
423 nonce_chunk
.ptr
= nonce_bytes
;
424 nonce_chunk
.len
= sizeof(nonce_bytes
);
426 parser
= parser_create(nonce_chunk
);
427 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
428 status
= parser
->parse_payload(parser
, NONCE
, (payload_t
**)&nonce_payload
);
429 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
430 parser
->destroy(parser
);
432 if (status
!= SUCCESS
)
436 nonce_payload
->get_nonce(nonce_payload
, &result
);
437 tester
->assert_true(tester
,(result
.len
== 16), "parsed nonce lenght");
438 tester
->assert_false(tester
,(memcmp(nonce_bytes
+ 4, result
.ptr
, result
.len
)), "parsed nonce data");
439 nonce_payload
->destroy(nonce_payload
);
440 allocator_free_chunk(&result
);
444 * Described in Header
446 void test_parser_with_id_payload(tester_t
*tester
)
449 id_payload_t
*id_payload
;
451 chunk_t id_chunk
, result
;
453 u_int8_t id_bytes
[] = {
454 0x00,0x00,0x00,0x14, /* payload header */
456 0x04,0x05,0x06,0x07,/* 12 Byte nonce */
461 id_chunk
.ptr
= id_bytes
;
462 id_chunk
.len
= sizeof(id_bytes
);
464 parser
= parser_create(id_chunk
);
465 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
466 status
= parser
->parse_payload(parser
, ID_INITIATOR
, (payload_t
**)&id_payload
);
467 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
468 parser
->destroy(parser
);
470 if (status
!= SUCCESS
)
474 result
= id_payload
->get_data(id_payload
);
475 tester
->assert_true(tester
,(id_payload
->get_initiator(id_payload
) == TRUE
), "is IDi payload");
476 tester
->assert_true(tester
,(id_payload
->get_id_type(id_payload
) == ID_IPV6_ADDR
), "is ID_IPV6_ADDR ID type");
477 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
478 tester
->assert_false(tester
,(memcmp(id_bytes
+ 8, result
.ptr
, result
.len
)), "parsed nonce data");
479 id_payload
->destroy(id_payload
);
480 allocator_free_chunk(&result
);
485 * Described in Header
487 void test_parser_with_ke_payload(tester_t
*tester
)
490 ke_payload_t
*ke_payload
;
492 chunk_t ke_chunk
, result
;
494 u_int8_t ke_bytes
[] = {
495 0x00,0x00,0x00,0x18, /* payload header */
496 0x00,0x03,0x00,0x00, /* dh group 3 */
497 0x01,0x02,0x03,0x03, /* 16 Byte dh data */
503 ke_chunk
.ptr
= ke_bytes
;
504 ke_chunk
.len
= sizeof(ke_bytes
);
506 parser
= parser_create(ke_chunk
);
507 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
508 status
= parser
->parse_payload(parser
, KEY_EXCHANGE
, (payload_t
**)&ke_payload
);
509 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
510 parser
->destroy(parser
);
512 if (status
!= SUCCESS
)
516 tester
->assert_true(tester
,(ke_payload
->get_dh_group_number(ke_payload
) == 3), "DH group");
517 result
= ke_payload
->get_key_exchange_data(ke_payload
);
518 tester
->assert_true(tester
,(result
.len
== 16), "parsed key lenght");
519 tester
->assert_false(tester
,(memcmp(ke_bytes
+ 8, result
.ptr
, result
.len
)), "parsed key data");
520 ke_payload
->destroy(ke_payload
);
525 * Described in Header
527 void test_parser_with_notify_payload(tester_t
*tester
)
530 notify_payload_t
*notify_payload
;
532 chunk_t notify_chunk
, result
;
534 u_int8_t notify_bytes
[] = {
535 0x00,0x00,0x00,0x1C, /* payload header */
537 0x01,0x02,0x03,0x03, /* spi */
538 0x04,0x05,0x06,0x07, /* noti dati */
544 notify_chunk
.ptr
= notify_bytes
;
545 notify_chunk
.len
= sizeof(notify_bytes
);
547 parser
= parser_create(notify_chunk
);
548 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
549 status
= parser
->parse_payload(parser
, NOTIFY
, (payload_t
**)¬ify_payload
);
550 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
551 parser
->destroy(parser
);
553 if (status
!= SUCCESS
)
557 tester
->assert_true(tester
,(notify_payload
->get_protocol_id(notify_payload
) == 3), "Protocol id");
558 tester
->assert_true(tester
,(notify_payload
->get_notify_message_type(notify_payload
) == 1), "notify message type");
560 result
= notify_payload
->get_spi(notify_payload
);
561 tester
->assert_false(tester
,(memcmp(notify_bytes
+ 8, result
.ptr
, result
.len
)), "parsed spi");
563 result
= notify_payload
->get_notification_data(notify_payload
);
564 tester
->assert_false(tester
,(memcmp(notify_bytes
+ 12, result
.ptr
, result
.len
)), "parsed notification data");
566 notify_payload
->destroy(notify_payload
);
570 * Described in Header
572 void test_parser_with_auth_payload(tester_t
*tester
)
575 auth_payload_t
*auth_payload
;
577 chunk_t auth_chunk
, result
;
579 u_int8_t auth_bytes
[] = {
580 0x00,0x00,0x00,0x14, /* payload header */
582 0x04,0x05,0x06,0x07,/* 12 Byte nonce */
587 auth_chunk
.ptr
= auth_bytes
;
588 auth_chunk
.len
= sizeof(auth_bytes
);
590 parser
= parser_create(auth_chunk
);
591 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
592 status
= parser
->parse_payload(parser
, AUTHENTICATION
, (payload_t
**)&auth_payload
);
593 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
594 parser
->destroy(parser
);
596 if (status
!= SUCCESS
)
600 result
= auth_payload
->get_data(auth_payload
);
601 tester
->assert_true(tester
,(auth_payload
->get_auth_method(auth_payload
) == DSS_DIGITAL_SIGNATURE
), "is DSS_DIGITAL_SIGNATURE method");
602 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
603 tester
->assert_false(tester
,(memcmp(auth_bytes
+ 8, result
.ptr
, result
.len
)), "parsed nonce data");
604 auth_payload
->destroy(auth_payload
);
605 allocator_free_chunk(&result
);
609 * Described in Header
611 void test_parser_with_ts_payload(tester_t
*tester
)
614 ts_payload_t
*ts_payload
;
617 traffic_selector_substructure_t
*ts1
, *ts2
;
618 host_t
*start_host1
, *start_host2
, *end_host1
, *end_host2
;
619 iterator_t
*iterator
;
621 u_int8_t ts_bytes
[] = {
626 /* traffic selector 1 */
632 /* traffic selector 2 */
639 ts_chunk
.ptr
= ts_bytes
;
640 ts_chunk
.len
= sizeof(ts_bytes
);
642 parser
= parser_create(ts_chunk
);
643 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
644 status
= parser
->parse_payload(parser
, TRAFFIC_SELECTOR_RESPONDER
, (payload_t
**)&ts_payload
);
645 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
646 parser
->destroy(parser
);
648 if (status
!= SUCCESS
)
653 iterator
= ts_payload
->create_traffic_selector_substructure_iterator(ts_payload
,TRUE
);
655 tester
->assert_true(tester
,(iterator
->has_next(iterator
)), "has next check");
658 iterator
->current(iterator
,(void **)&ts1
);
659 tester
->assert_true(tester
,(ts1
->get_protocol_id(ts1
) == 0), "ip protocol id check");
660 start_host1
= ts1
->get_start_host(ts1
);
661 end_host1
= ts1
->get_end_host(ts1
);
662 tester
->assert_true(tester
,(start_host1
->get_port(start_host1
) == 500), "start port check");
663 tester
->assert_true(tester
,(end_host1
->get_port(end_host1
) == 500), "start port check");
664 tester
->assert_true(tester
,(memcmp(start_host1
->get_address(start_host1
),"192.168.1.0",strlen("192.168.1.0")) == 0), "start address check");
665 tester
->assert_true(tester
,(memcmp(end_host1
->get_address(end_host1
),"192.168.1.255",strlen("192.168.1.255")) == 0), "end address check");
667 start_host1
->destroy(start_host1
);
668 end_host1
->destroy(end_host1
);
670 tester
->assert_true(tester
,(iterator
->has_next(iterator
)), "has next check");
672 /* check second ts */
674 iterator
->current(iterator
,(void **)&ts2
);
676 tester
->assert_true(tester
,(ts2
->get_protocol_id(ts2
) == 3), "ip protocol id check");
677 start_host2
= ts2
->get_start_host(ts2
);
678 end_host2
= ts2
->get_end_host(ts2
);
679 tester
->assert_true(tester
,(start_host2
->get_port(start_host2
) == 0), "start port check");
680 tester
->assert_true(tester
,(end_host2
->get_port(end_host2
) == 65535), "start port check");
681 tester
->assert_true(tester
,(memcmp(start_host2
->get_address(start_host2
),"0.0.0.0",strlen("0.0.0.0")) == 0), "start address check");
682 tester
->assert_true(tester
,(memcmp(end_host2
->get_address(end_host2
),"255.255.255.255",strlen("255.255.255.255")) == 0), "end address check");
683 start_host2
->destroy(start_host2
);
684 end_host2
->destroy(end_host2
);
688 tester
->assert_false(tester
,(iterator
->has_next(iterator
)), "has next check");
690 iterator
->destroy(iterator
);
692 ts_payload
->destroy(ts_payload
);