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/cert_payload.h>
40 #include <encoding/payloads/certreq_payload.h>
41 #include <encoding/payloads/ts_payload.h>
42 #include <encoding/payloads/delete_payload.h>
43 #include <encoding/payloads/vendor_id_payload.h>
44 #include <encoding/payloads/cp_payload.h>
45 #include <encoding/payloads/eap_payload.h>
51 void test_parser_with_header_payload(protected_tester_t
*tester
)
54 ike_header_t
*ike_header
;
58 u_int8_t header_bytes
[] = {
67 header_chunk
.ptr
= header_bytes
;
68 header_chunk
.len
= sizeof(header_bytes
);
71 parser
= parser_create(header_chunk
);
72 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
73 status
= parser
->parse_payload(parser
, HEADER
, (payload_t
**)&ike_header
);
74 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
75 parser
->destroy(parser
);
77 if (status
!= SUCCESS
)
82 tester
->assert_true(tester
,(ike_header
->get_initiator_spi(ike_header
) == 1),"parsed initiator_spi value");
83 tester
->assert_true(tester
,(ike_header
->get_responder_spi(ike_header
) == 2),"parsed responder_spi value");
84 tester
->assert_true(tester
,(ike_header
->payload_interface
.get_next_type((payload_t
*)ike_header
) == 3),"parsed next_payload value");
85 tester
->assert_true(tester
,(ike_header
->get_maj_version(ike_header
) == 4),"parsed maj_version value");
86 tester
->assert_true(tester
,(ike_header
->get_min_version(ike_header
) == 5),"parsed min_version value");
87 tester
->assert_true(tester
,(ike_header
->get_exchange_type(ike_header
) == 6),"parsed exchange_type value");
88 tester
->assert_true(tester
,(ike_header
->get_initiator_flag(ike_header
) == TRUE
),"parsed flags.initiator value");
89 tester
->assert_true(tester
,(ike_header
->get_version_flag(ike_header
) == FALSE
),"parsed flags.version value");
90 tester
->assert_true(tester
,(ike_header
->get_response_flag(ike_header
) == TRUE
),"parsed flags.response value");
91 tester
->assert_true(tester
,(ike_header
->get_message_id(ike_header
) == 7),"parsed message_id value");
92 tester
->assert_true(tester
,(ike_header
->payload_interface
.get_length((payload_t
*)ike_header
) == 0x1C),"parsed length value");
94 ike_header
->destroy(ike_header
);
100 void test_parser_with_sa_payload(protected_tester_t
*tester
)
103 sa_payload_t
*sa_payload
;
105 chunk_t sa_chunk
, sa_chunk2
, sa_chunk3
;
106 iterator_t
*proposals
, *transforms
, *attributes
;
108 /* first test generic parsing functionality */
110 u_int8_t sa_bytes
[] = {
111 0x00,0x80,0x00,0x24, /* payload header*/
112 0x00,0x00,0x00,0x20, /* a proposal */
114 0x01,0x02,0x03,0x04, /* spi */
115 0x00,0x00,0x00,0x14, /* transform */
117 0x80,0x01,0x00,0x05, /* attribute without length */
118 0x00,0x03,0x00,0x04, /* attribute with length */
124 sa_chunk
.ptr
= sa_bytes
;
125 sa_chunk
.len
= sizeof(sa_bytes
);
128 parser
= parser_create(sa_chunk
);
129 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
130 status
= parser
->parse_payload(parser
, SECURITY_ASSOCIATION
, (payload_t
**)&sa_payload
);
131 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
132 parser
->destroy(parser
);
134 if (status
!= SUCCESS
)
140 proposals
= sa_payload
->create_proposal_substructure_iterator(sa_payload
, TRUE
);
141 while (proposals
->has_next(proposals
))
143 proposal_substructure_t
*proposal
;
144 proposals
->current(proposals
, (void**)&proposal
);
146 u_int8_t spi_should
[] = {0x01, 0x02, 0x03, 0x04};
148 tester
->assert_true(tester
,(proposal
->get_proposal_number(proposal
) == 1),"proposal number");
149 tester
->assert_true(tester
,(proposal
->get_protocol_id(proposal
) == 2),"proposal id");
150 spi
= proposal
->get_spi(proposal
);
151 tester
->assert_false(tester
,(memcmp(&spi_should
, spi
.ptr
, spi
.len
)),"proposal spi");
153 transforms
= proposal
->create_transform_substructure_iterator(proposal
, TRUE
);
154 while(transforms
->has_next(transforms
))
156 transform_substructure_t
*transform
;
158 transforms
->current(transforms
, (void**)&transform
);
159 tester
->assert_true(tester
,(transform
->get_transform_type(transform
) == 7),"transform type");
160 tester
->assert_true(tester
,(transform
->get_transform_id(transform
) == 3),"transform id");
161 attributes
= transform
->create_transform_attribute_iterator(transform
, TRUE
);
163 while (attributes
->has_next(attributes
))
165 transform_attribute_t
*attribute
;
166 attributes
->current(attributes
, (void**)&attribute
);
169 u_int8_t value
[] = {0x05, 0x00};
170 chunk_t attribute_value
;
171 tester
->assert_true(tester
,(attribute
->get_attribute_type(attribute
) == 1),"attribute 1 type");
172 attribute_value
= attribute
->get_value_chunk(attribute
);
173 tester
->assert_false(tester
,(memcmp(&value
, attribute_value
.ptr
, attribute_value
.len
)),"attribute 1 value");
177 u_int8_t value
[] = {0x01, 0x02, 0x03, 0x04};
178 chunk_t attribute_value
;
179 tester
->assert_true(tester
,(attribute
->get_attribute_type(attribute
) == 3),"attribute 2 type");
180 attribute_value
= attribute
->get_value_chunk(attribute
);
181 tester
->assert_false(tester
,(memcmp(&value
, attribute_value
.ptr
, attribute_value
.len
)),"attribute 2 value");
185 attributes
->destroy(attributes
);
187 transforms
->destroy(transforms
);
189 proposals
->destroy(proposals
);
191 sa_payload
->destroy(sa_payload
);
195 /* now test SA functionality after parsing an SA payload*/
197 u_int8_t sa_bytes2
[] = {
198 0x00,0x00,0x00,0x6C, /* payload header*/
199 0x02,0x00,0x00,0x34, /* a proposal */
201 0x03,0x00,0x00,0x0C, /* transform 1 */
203 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
204 0x03,0x00,0x00,0x0C, /* transform 2 */
206 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
207 0x03,0x00,0x00,0x0C, /* transform 3 */
209 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
210 0x00,0x00,0x00,0x08, /* transform 4 */
212 0x00,0x00,0x00,0x34, /* a proposal */
214 0x03,0x00,0x00,0x0C, /* transform 1 */
216 0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
217 0x03,0x00,0x00,0x0C, /* transform 2 */
219 0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
220 0x03,0x00,0x00,0x0C, /* transform 3 */
222 0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
223 0x00,0x00,0x00,0x08, /* transform 4 */
227 sa_chunk2
.ptr
= sa_bytes2
;
228 sa_chunk2
.len
= sizeof(sa_bytes2
);
230 parser
= parser_create(sa_chunk2
);
231 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
232 status
= parser
->parse_payload(parser
, SECURITY_ASSOCIATION
, (payload_t
**)&sa_payload
);
233 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
234 parser
->destroy(parser
);
236 if (status
!= SUCCESS
)
241 status
= sa_payload
->payload_interface
.verify(&(sa_payload
->payload_interface
));
242 tester
->assert_true(tester
,(status
== SUCCESS
),"verify call check");
244 status = sa_payload->get_ike_proposals (sa_payload, &ike_proposals, &ike_proposal_count);
245 tester->assert_true(tester,(status == SUCCESS),"get ike proposals call check");
247 tester->assert_true(tester,(ike_proposal_count == 2),"ike proposal count check");
248 tester->assert_true(tester,(ike_proposals[0].encryption_algorithm == 1),"ike proposal content check");
249 tester->assert_true(tester,(ike_proposals[0].encryption_algorithm_key_length == 20),"ike proposal content check");
250 tester->assert_true(tester,(ike_proposals[0].integrity_algorithm == 1),"ike proposal content check");
251 tester->assert_true(tester,(ike_proposals[0].integrity_algorithm_key_length == 20),"ike proposal content check");
252 tester->assert_true(tester,(ike_proposals[0].pseudo_random_function == 1),"ike proposal content check");
253 tester->assert_true(tester,(ike_proposals[0].pseudo_random_function_key_length == 20),"ike proposal content check");
254 tester->assert_true(tester,(ike_proposals[0].diffie_hellman_group == 1),"ike proposal content check");
256 tester->assert_true(tester,(ike_proposals[1].encryption_algorithm == 2),"ike proposal content check");
257 tester->assert_true(tester,(ike_proposals[1].encryption_algorithm_key_length == 16),"ike proposal content check");
258 tester->assert_true(tester,(ike_proposals[1].integrity_algorithm == 2),"ike proposal content check");
259 tester->assert_true(tester,(ike_proposals[1].integrity_algorithm_key_length == 16),"ike proposal content check");
260 tester->assert_true(tester,(ike_proposals[1].pseudo_random_function == 2),"ike proposal content check");
261 tester->assert_true(tester,(ike_proposals[1].pseudo_random_function_key_length == 16),"ike proposal content check");
262 tester->assert_true(tester,(ike_proposals[1].diffie_hellman_group == 2),"ike proposal content check");
265 if (status == SUCCESS)
267 allocator_free(ike_proposals);
270 sa_payload
->destroy(sa_payload
);
272 /* now test SA functionality after parsing an SA payload with child sa proposals*/
273 u_int8_t sa_bytes3
[] = {
274 0x00,0x00,0x00,0xA0, /* payload header*/
277 0x02,0x00,0x00,0x28, /* a proposal */
280 0x03,0x00,0x00,0x0C, /* transform 1 */
282 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
284 0x03,0x00,0x00,0x08, /* transform 2 */
287 0x00,0x00,0x00,0x08, /* transform 3 */
291 0x02,0x00,0x00,0x20, /* a proposal */
295 0x03,0x00,0x00,0x0C, /* transform 1 */
297 0x80,0x0E,0x00,0x20, /* keylength attribute with 32 bytes length */
299 0x00,0x00,0x00,0x08, /* transform 2 */
303 0x02,0x00,0x00,0x28, /* a proposal */
306 0x03,0x00,0x00,0x0C, /* transform 1 */
308 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
310 0x03,0x00,0x00,0x08, /* transform 2 */
313 0x00,0x00,0x00,0x08, /* transform 3 */
317 0x00,0x00,0x00,0x2C, /* a proposal */
321 0x03,0x00,0x00,0x0C, /* transform 1 */
323 0x80,0x0E,0x00,0x20, /* keylength attribute with 32 bytes length */
325 0x03,0x00,0x00,0x0C, /* transform 2 */
327 0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
329 0x00,0x00,0x00,0x08, /* transform 3 */
333 sa_chunk3
.ptr
= sa_bytes3
;
334 sa_chunk3
.len
= sizeof(sa_bytes3
);
336 parser
= parser_create(sa_chunk3
);
337 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
338 status
= parser
->parse_payload(parser
, SECURITY_ASSOCIATION
, (payload_t
**)&sa_payload
);
339 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
340 parser
->destroy(parser
);
342 if (status
!= SUCCESS
)
347 status
= sa_payload
->payload_interface
.verify(&(sa_payload
->payload_interface
));
348 tester
->assert_true(tester
,(status
== SUCCESS
),"verify call check");
350 status = sa_payload->get_ike_proposals (sa_payload, &ike_proposals, &ike_proposal_count);
351 tester->assert_false(tester,(status == SUCCESS),"get ike proposals call check");
353 status = sa_payload->get_proposals (sa_payload, &proposals, &proposal_count);
354 tester->assert_true(tester,(status == SUCCESS),"get child proposals call check");
357 tester->assert_true(tester,(proposal_count == 2),"child proposal count check");
358 tester->assert_true(tester,(proposals[0].ah.is_set == TRUE),"is ah set check");
359 tester->assert_true(tester,(proposals[0].ah.integrity_algorithm == AUTH_HMAC_MD5_96),"integrity_algorithm check");
360 tester->assert_true(tester,(proposals[0].ah.integrity_algorithm_key_size == 20),"integrity_algorithm_key_size check");
361 tester->assert_true(tester,(proposals[0].ah.diffie_hellman_group == MODP_2048_BIT),"diffie_hellman_group check");
362 tester->assert_true(tester,(proposals[0].ah.extended_sequence_numbers == EXT_SEQ_NUMBERS),"extended_sequence_numbers check");
363 tester->assert_true(tester,(proposals[0].ah.spi[0] == 1),"spi check");
364 tester->assert_true(tester,(proposals[0].ah.spi[1] == 1),"spi check");
365 tester->assert_true(tester,(proposals[0].ah.spi[2] == 1),"spi check");
366 tester->assert_true(tester,(proposals[0].ah.spi[3] == 1),"spi check");
368 tester->assert_true(tester,(proposals[0].esp.is_set == TRUE),"is ah set check");
369 tester->assert_true(tester,(proposals[0].esp.encryption_algorithm == ENCR_AES_CBC),"integrity_algorithm check");
370 tester->assert_true(tester,(proposals[0].esp.encryption_algorithm_key_size == 32),"integrity_algorithm_key_size check");
371 tester->assert_true(tester,(proposals[0].esp.diffie_hellman_group == MODP_1024_BIT),"diffie_hellman_group check");
372 tester->assert_true(tester,(proposals[0].esp.integrity_algorithm == AUTH_UNDEFINED),"integrity_algorithm check");
373 tester->assert_true(tester,(proposals[0].esp.spi[0] == 2),"spi check");
374 tester->assert_true(tester,(proposals[0].esp.spi[1] == 2),"spi check");
375 tester->assert_true(tester,(proposals[0].esp.spi[2] == 2),"spi check");
376 tester->assert_true(tester,(proposals[0].esp.spi[3] == 2),"spi check");
378 tester->assert_true(tester,(proposals[1].ah.is_set == TRUE),"is ah set check");
379 tester->assert_true(tester,(proposals[1].ah.integrity_algorithm == AUTH_HMAC_MD5_96),"integrity_algorithm check");
380 tester->assert_true(tester,(proposals[1].ah.integrity_algorithm_key_size == 20),"integrity_algorithm_key_size check");
381 tester->assert_true(tester,(proposals[1].ah.diffie_hellman_group == MODP_2048_BIT),"diffie_hellman_group check");
382 tester->assert_true(tester,(proposals[1].ah.extended_sequence_numbers == EXT_SEQ_NUMBERS),"extended_sequence_numbers check");
383 tester->assert_true(tester,(proposals[1].ah.spi[0] == 1),"spi check");
384 tester->assert_true(tester,(proposals[1].ah.spi[1] == 1),"spi check");
385 tester->assert_true(tester,(proposals[1].ah.spi[2] == 1),"spi check");
386 tester->assert_true(tester,(proposals[1].ah.spi[3] == 1),"spi check");
388 tester->assert_true(tester,(proposals[1].esp.is_set == TRUE),"is ah set check");
389 tester->assert_true(tester,(proposals[1].esp.encryption_algorithm == ENCR_AES_CBC),"integrity_algorithm check");
390 tester->assert_true(tester,(proposals[1].esp.encryption_algorithm_key_size == 32),"integrity_algorithm_key_size check");
391 tester->assert_true(tester,(proposals[1].esp.diffie_hellman_group == MODP_1024_BIT),"diffie_hellman_group check");
392 tester->assert_true(tester,(proposals[1].esp.integrity_algorithm == AUTH_HMAC_MD5_96),"integrity_algorithm check");
393 tester->assert_true(tester,(proposals[1].esp.integrity_algorithm_key_size == 20),"integrity_algorithm check");
394 tester->assert_true(tester,(proposals[1].esp.spi[0] == 2),"spi check");
395 tester->assert_true(tester,(proposals[1].esp.spi[1] == 2),"spi check");
396 tester->assert_true(tester,(proposals[1].esp.spi[2] == 2),"spi check");
397 tester->assert_true(tester,(proposals[1].esp.spi[3] == 2),"spi check");
399 if (status == SUCCESS)
401 allocator_free(proposals);
405 sa_payload
->destroy(sa_payload
);
409 * Described in Header
411 void test_parser_with_nonce_payload(protected_tester_t
*tester
)
414 nonce_payload_t
*nonce_payload
;
416 chunk_t nonce_chunk
, result
;
418 u_int8_t nonce_bytes
[] = {
419 0x00,0x00,0x00,0x14, /* payload header */
420 0x00,0x01,0x02,0x03, /* 16 Byte nonce */
426 nonce_chunk
.ptr
= nonce_bytes
;
427 nonce_chunk
.len
= sizeof(nonce_bytes
);
429 parser
= parser_create(nonce_chunk
);
430 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
431 status
= parser
->parse_payload(parser
, NONCE
, (payload_t
**)&nonce_payload
);
432 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
433 parser
->destroy(parser
);
435 if (status
!= SUCCESS
)
439 result
= nonce_payload
->get_nonce(nonce_payload
);
440 tester
->assert_true(tester
,(result
.len
== 16), "parsed nonce lenght");
441 tester
->assert_false(tester
,(memcmp(nonce_bytes
+ 4, result
.ptr
, result
.len
)), "parsed nonce data");
442 nonce_payload
->destroy(nonce_payload
);
443 allocator_free_chunk(&result
);
447 * Described in Header
449 void test_parser_with_id_payload(protected_tester_t
*tester
)
452 id_payload_t
*id_payload
;
454 chunk_t id_chunk
, result
;
456 u_int8_t id_bytes
[] = {
457 0x00,0x00,0x00,0x14, /* payload header */
459 0x04,0x05,0x06,0x07,/* 12 Byte nonce */
464 id_chunk
.ptr
= id_bytes
;
465 id_chunk
.len
= sizeof(id_bytes
);
467 parser
= parser_create(id_chunk
);
468 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
469 status
= parser
->parse_payload(parser
, ID_INITIATOR
, (payload_t
**)&id_payload
);
470 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
471 parser
->destroy(parser
);
473 if (status
!= SUCCESS
)
477 result
= id_payload
->get_data_clone(id_payload
);
478 tester
->assert_true(tester
,(id_payload
->get_initiator(id_payload
) == TRUE
), "is IDi payload");
479 tester
->assert_true(tester
,(id_payload
->get_id_type(id_payload
) == ID_IPV6_ADDR
), "is ID_IPV6_ADDR ID type");
480 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
481 tester
->assert_false(tester
,(memcmp(id_bytes
+ 8, result
.ptr
, result
.len
)), "parsed nonce data");
482 id_payload
->destroy(id_payload
);
483 allocator_free_chunk(&result
);
488 * Described in Header
490 void test_parser_with_ke_payload(protected_tester_t
*tester
)
493 ke_payload_t
*ke_payload
;
495 chunk_t ke_chunk
, result
;
497 u_int8_t ke_bytes
[] = {
498 0x00,0x00,0x00,0x18, /* payload header */
499 0x00,0x03,0x00,0x00, /* dh group 3 */
500 0x01,0x02,0x03,0x03, /* 16 Byte dh data */
506 ke_chunk
.ptr
= ke_bytes
;
507 ke_chunk
.len
= sizeof(ke_bytes
);
509 parser
= parser_create(ke_chunk
);
510 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
511 status
= parser
->parse_payload(parser
, KEY_EXCHANGE
, (payload_t
**)&ke_payload
);
512 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
513 parser
->destroy(parser
);
515 if (status
!= SUCCESS
)
519 tester
->assert_true(tester
,(ke_payload
->get_dh_group_number(ke_payload
) == 3), "DH group");
520 result
= ke_payload
->get_key_exchange_data(ke_payload
);
521 tester
->assert_true(tester
,(result
.len
== 16), "parsed key lenght");
522 tester
->assert_false(tester
,(memcmp(ke_bytes
+ 8, result
.ptr
, result
.len
)), "parsed key data");
523 ke_payload
->destroy(ke_payload
);
528 * Described in Header
530 void test_parser_with_notify_payload(protected_tester_t
*tester
)
533 notify_payload_t
*notify_payload
;
535 chunk_t notify_chunk
, result
;
537 u_int8_t notify_bytes
[] = {
538 0x00,0x00,0x00,0x1C, /* payload header */
540 0x01,0x02,0x03,0x03, /* spi */
541 0x04,0x05,0x06,0x07, /* noti dati */
547 notify_chunk
.ptr
= notify_bytes
;
548 notify_chunk
.len
= sizeof(notify_bytes
);
550 parser
= parser_create(notify_chunk
);
551 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
552 status
= parser
->parse_payload(parser
, NOTIFY
, (payload_t
**)¬ify_payload
);
553 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
554 parser
->destroy(parser
);
556 if (status
!= SUCCESS
)
560 tester
->assert_true(tester
,(notify_payload
->get_protocol_id(notify_payload
) == 3), "Protocol id");
561 tester
->assert_true(tester
,(notify_payload
->get_notify_message_type(notify_payload
) == 1), "notify message type");
563 result
= notify_payload
->get_spi(notify_payload
);
564 tester
->assert_false(tester
,(memcmp(notify_bytes
+ 8, result
.ptr
, result
.len
)), "parsed spi");
566 result
= notify_payload
->get_notification_data(notify_payload
);
567 tester
->assert_false(tester
,(memcmp(notify_bytes
+ 12, result
.ptr
, result
.len
)), "parsed notification data");
569 notify_payload
->destroy(notify_payload
);
573 * Described in Header
575 void test_parser_with_auth_payload(protected_tester_t
*tester
)
578 auth_payload_t
*auth_payload
;
580 chunk_t auth_chunk
, result
;
582 u_int8_t auth_bytes
[] = {
583 0x00,0x00,0x00,0x14, /* payload header */
585 0x04,0x05,0x06,0x07,/* 12 Byte nonce */
590 auth_chunk
.ptr
= auth_bytes
;
591 auth_chunk
.len
= sizeof(auth_bytes
);
593 parser
= parser_create(auth_chunk
);
594 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
595 status
= parser
->parse_payload(parser
, AUTHENTICATION
, (payload_t
**)&auth_payload
);
596 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
597 parser
->destroy(parser
);
599 if (status
!= SUCCESS
)
603 result
= auth_payload
->get_data_clone(auth_payload
);
604 tester
->assert_true(tester
,(auth_payload
->get_auth_method(auth_payload
) == DSS_DIGITAL_SIGNATURE
), "is DSS_DIGITAL_SIGNATURE method");
605 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
606 tester
->assert_false(tester
,(memcmp(auth_bytes
+ 8, result
.ptr
, result
.len
)), "parsed nonce data");
607 auth_payload
->destroy(auth_payload
);
608 allocator_free_chunk(&result
);
612 * Described in Header
614 void test_parser_with_ts_payload(protected_tester_t
*tester
)
617 ts_payload_t
*ts_payload
;
620 traffic_selector_substructure_t
*ts1
, *ts2
;
621 host_t
*start_host1
, *start_host2
, *end_host1
, *end_host2
;
622 iterator_t
*iterator
;
624 u_int8_t ts_bytes
[] = {
629 /* traffic selector 1 */
635 /* traffic selector 2 */
642 ts_chunk
.ptr
= ts_bytes
;
643 ts_chunk
.len
= sizeof(ts_bytes
);
645 parser
= parser_create(ts_chunk
);
646 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
647 status
= parser
->parse_payload(parser
, TRAFFIC_SELECTOR_RESPONDER
, (payload_t
**)&ts_payload
);
648 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
649 parser
->destroy(parser
);
651 if (status
!= SUCCESS
)
656 iterator
= ts_payload
->create_traffic_selector_substructure_iterator(ts_payload
,TRUE
);
658 tester
->assert_true(tester
,(iterator
->has_next(iterator
)), "has next check");
661 iterator
->current(iterator
,(void **)&ts1
);
662 tester
->assert_true(tester
,(ts1
->get_protocol_id(ts1
) == 0), "ip protocol id check");
663 start_host1
= ts1
->get_start_host(ts1
);
664 end_host1
= ts1
->get_end_host(ts1
);
665 tester
->assert_true(tester
,(start_host1
->get_port(start_host1
) == 500), "start port check");
666 tester
->assert_true(tester
,(end_host1
->get_port(end_host1
) == 500), "start port check");
667 tester
->assert_true(tester
,(memcmp(start_host1
->get_address(start_host1
),"192.168.1.0",strlen("192.168.1.0")) == 0), "start address check");
668 tester
->assert_true(tester
,(memcmp(end_host1
->get_address(end_host1
),"192.168.1.255",strlen("192.168.1.255")) == 0), "end address check");
670 start_host1
->destroy(start_host1
);
671 end_host1
->destroy(end_host1
);
673 tester
->assert_true(tester
,(iterator
->has_next(iterator
)), "has next check");
675 /* check second ts */
677 iterator
->current(iterator
,(void **)&ts2
);
679 tester
->assert_true(tester
,(ts2
->get_protocol_id(ts2
) == 3), "ip protocol id check");
680 start_host2
= ts2
->get_start_host(ts2
);
681 end_host2
= ts2
->get_end_host(ts2
);
682 tester
->assert_true(tester
,(start_host2
->get_port(start_host2
) == 0), "start port check");
683 tester
->assert_true(tester
,(end_host2
->get_port(end_host2
) == 65535), "start port check");
684 tester
->assert_true(tester
,(memcmp(start_host2
->get_address(start_host2
),"0.0.0.0",strlen("0.0.0.0")) == 0), "start address check");
685 tester
->assert_true(tester
,(memcmp(end_host2
->get_address(end_host2
),"255.255.255.255",strlen("255.255.255.255")) == 0), "end address check");
686 start_host2
->destroy(start_host2
);
687 end_host2
->destroy(end_host2
);
691 tester
->assert_false(tester
,(iterator
->has_next(iterator
)), "has next check");
693 iterator
->destroy(iterator
);
695 ts_payload
->destroy(ts_payload
);
699 * Described in Header
701 void test_parser_with_cert_payload(protected_tester_t
*tester
)
704 cert_payload_t
*cert_payload
;
706 chunk_t cert_chunk
, result
;
708 u_int8_t cert_bytes
[] = {
709 0x00,0x00,0x00,0x11, /* payload header */
711 0x04,0x05,0x06,0x07,/* 12 Byte nonce */
716 cert_chunk
.ptr
= cert_bytes
;
717 cert_chunk
.len
= sizeof(cert_bytes
);
719 parser
= parser_create(cert_chunk
);
720 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
721 status
= parser
->parse_payload(parser
, CERTIFICATE
, (payload_t
**)&cert_payload
);
722 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
723 parser
->destroy(parser
);
725 if (status
!= SUCCESS
)
729 result
= cert_payload
->get_data_clone(cert_payload
);
730 tester
->assert_true(tester
,(cert_payload
->get_cert_encoding(cert_payload
) == DNS_SIGNED_KEY
), "is DNS_SIGNED_KEY encoding");
731 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
732 tester
->assert_false(tester
,(memcmp(cert_bytes
+ 5, result
.ptr
, result
.len
)), "parsed data");
733 cert_payload
->destroy(cert_payload
);
734 allocator_free_chunk(&result
);
738 * Described in Header
740 void test_parser_with_certreq_payload(protected_tester_t
*tester
)
743 certreq_payload_t
*certreq_payload
;
745 chunk_t certreq_chunk
, result
;
747 u_int8_t certreq_bytes
[] = {
748 0x00,0x00,0x00,0x11, /* payload header */
750 0x04,0x05,0x06,0x07,/* 12 Byte data */
755 certreq_chunk
.ptr
= certreq_bytes
;
756 certreq_chunk
.len
= sizeof(certreq_bytes
);
758 parser
= parser_create(certreq_chunk
);
759 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
760 status
= parser
->parse_payload(parser
, CERTIFICATE_REQUEST
, (payload_t
**)&certreq_payload
);
761 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
762 parser
->destroy(parser
);
764 if (status
!= SUCCESS
)
768 result
= certreq_payload
->get_data_clone(certreq_payload
);
769 tester
->assert_true(tester
,(certreq_payload
->get_cert_encoding(certreq_payload
) == DNS_SIGNED_KEY
), "is DNS_SIGNED_KEY encoding");
770 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
771 tester
->assert_false(tester
,(memcmp(certreq_bytes
+ 5, result
.ptr
, result
.len
)), "parsed data");
772 certreq_payload
->destroy(certreq_payload
);
773 allocator_free_chunk(&result
);
777 * Described in Header
779 void test_parser_with_delete_payload(protected_tester_t
*tester
)
782 delete_payload_t
*delete_payload
;
784 chunk_t delete_chunk
, result
;
786 u_int8_t delete_bytes
[] = {
787 0x00,0x00,0x00,0x14, /* payload header */
789 0x04,0x05,0x06,0x07,/* 12 Byte data */
794 delete_chunk
.ptr
= delete_bytes
;
795 delete_chunk
.len
= sizeof(delete_bytes
);
797 parser
= parser_create(delete_chunk
);
798 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
799 status
= parser
->parse_payload(parser
, DELETE
, (payload_t
**)&delete_payload
);
800 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
801 parser
->destroy(parser
);
803 if (status
!= SUCCESS
)
807 result
= delete_payload
->get_spis(delete_payload
);
808 tester
->assert_true(tester
,(delete_payload
->get_protocol_id(delete_payload
) == ESP
), "is ESP protocol");
809 tester
->assert_true(tester
,(delete_payload
->get_spi_size(delete_payload
) == 3), "SPI size check");
810 tester
->assert_true(tester
,(delete_payload
->get_spi_count(delete_payload
) == 4), "SPI count check");
811 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
812 tester
->assert_false(tester
,(memcmp(delete_bytes
+ 8, result
.ptr
, result
.len
)), "parsed data");
813 tester
->assert_true(tester
,(((payload_t
*)delete_payload
)->verify((payload_t
*)delete_payload
) == SUCCESS
), "verify check");
815 delete_payload
->destroy(delete_payload
);
820 * Described in Header
822 void test_parser_with_vendor_id_payload(protected_tester_t
*tester
)
825 vendor_id_payload_t
*vendor_id_payload
;
827 chunk_t vendor_id_chunk
, result
;
829 u_int8_t vendor_id_bytes
[] = {
830 0x00,0x00,0x00,0x10, /* payload header */
831 0x04,0x05,0x06,0x07,/* 12 Byte data */
836 vendor_id_chunk
.ptr
= vendor_id_bytes
;
837 vendor_id_chunk
.len
= sizeof(vendor_id_bytes
);
839 parser
= parser_create(vendor_id_chunk
);
840 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
841 status
= parser
->parse_payload(parser
, VENDOR_ID
, (payload_t
**)&vendor_id_payload
);
842 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
843 parser
->destroy(parser
);
845 if (status
!= SUCCESS
)
849 result
= vendor_id_payload
->get_data(vendor_id_payload
);
850 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
851 tester
->assert_false(tester
,(memcmp(vendor_id_bytes
+ 4, result
.ptr
, result
.len
)), "parsed data");
852 tester
->assert_true(tester
,(((payload_t
*)vendor_id_payload
)->verify((payload_t
*)vendor_id_payload
) == SUCCESS
), "verify check");
854 vendor_id_payload
->destroy(vendor_id_payload
);
858 * Described in Header
860 void test_parser_with_cp_payload(protected_tester_t
*tester
)
863 cp_payload_t
*cp_payload
;
864 configuration_attribute_t
*attribute
;
867 iterator_t
*iterator
;
869 /* first test generic parsing functionality */
871 u_int8_t cp_bytes
[] = {
872 /* cp payload header */
875 /* configuration attribute 1*/
878 /* configuration attribute 2*/
883 cp_chunk
.ptr
= cp_bytes
;
884 cp_chunk
.len
= sizeof(cp_bytes
);
887 parser
= parser_create(cp_chunk
);
888 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
889 status
= parser
->parse_payload(parser
, CONFIGURATION
, (payload_t
**)&cp_payload
);
890 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
892 iterator
= cp_payload
->create_configuration_attribute_iterator(cp_payload
,TRUE
);
894 tester
->assert_true(tester
,(iterator
->has_next(iterator
)),"has_next call check");
896 iterator
->current(iterator
,(void **)&attribute
);
899 tester
->assert_true(tester
,(attribute
->get_attribute_type(attribute
) == 3),"get type check");
900 tester
->assert_true(tester
,(attribute
->get_attribute_length(attribute
) == 4),"get type check");
902 tester
->assert_true(tester
,(iterator
->has_next(iterator
)),"has_next call check");
904 iterator
->current(iterator
,(void **)&attribute
);
907 tester
->assert_true(tester
,(attribute
->get_attribute_type(attribute
) == 4),"get type check");
908 tester
->assert_true(tester
,(attribute
->get_attribute_length(attribute
) == 4),"get type check");
910 iterator
->current(iterator
,(void **)&attribute
);
912 tester
->assert_false(tester
,(iterator
->has_next(iterator
)),"has_next call check");
915 iterator
->destroy(iterator
);
917 if (status
!= SUCCESS
)
922 cp_payload
->destroy(cp_payload
);
923 parser
->destroy(parser
);
928 * Described in Header
930 void test_parser_with_eap_payload(protected_tester_t
*tester
)
933 eap_payload_t
*eap_payload
;
935 chunk_t eap_chunk
, result
;
937 u_int8_t eap_bytes
[] = {
938 0x00,0x00,0x00,0x10, /* payload header */
939 0x04,0x05,0x06,0x07,/* 12 Byte data */
944 eap_chunk
.ptr
= eap_bytes
;
945 eap_chunk
.len
= sizeof(eap_bytes
);
947 parser
= parser_create(eap_chunk
);
948 tester
->assert_true(tester
,(parser
!= NULL
), "parser create check");
949 status
= parser
->parse_payload(parser
, VENDOR_ID
, (payload_t
**)&eap_payload
);
950 tester
->assert_true(tester
,(status
== SUCCESS
),"parse_payload call check");
951 parser
->destroy(parser
);
953 if (status
!= SUCCESS
)
957 result
= eap_payload
->get_message(eap_payload
);
958 tester
->assert_true(tester
,(result
.len
== 12), "parsed data lenght");
959 tester
->assert_false(tester
,(memcmp(eap_bytes
+ 4, result
.ptr
, result
.len
)), "parsed data");
960 tester
->assert_true(tester
,(((payload_t
*)eap_payload
)->verify((payload_t
*)eap_payload
) == SUCCESS
), "verify check");
962 eap_payload
->destroy(eap_payload
);