- fixed alot of bugs in child_proposal

- near to working state ;-)
This commit is contained in:
Martin Willi
2006-02-08 15:25:34 +00:00
parent 384efc76d5
commit c06dbbabd1
29 changed files with 1233 additions and 674 deletions
@@ -116,6 +116,10 @@ TEST_OBJS+= $(BUILD_DIR)sa_config_test.o
$(BUILD_DIR)sa_config_test.o : $(TESTCASES_DIR)sa_config_test.c $(TESTCASES_DIR)sa_config_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)child_proposal_test.o
$(BUILD_DIR)child_proposal_test.o : $(TESTCASES_DIR)child_proposal_test.c $(TESTCASES_DIR)child_proposal_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)rsa_test.o
$(BUILD_DIR)rsa_test.o : $(TESTCASES_DIR)rsa_test.c $(TESTCASES_DIR)rsa_test.h
$(CC) $(CFLAGS) -c -o $@ $<
@@ -0,0 +1,99 @@
/**
* @file child_proposal_test.c
*
* @brief Tests for the child_proposal_t class.
*
*/
/*
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "child_proposal_test.h"
#include <daemon.h>
#include <config/child_proposal.h>
#include <utils/allocator.h>
#include <utils/logger.h>
/**
* Described in header.
*/
void test_child_proposal(protected_tester_t *tester)
{
child_proposal_t *proposal1, *proposal2, *proposal3;
iterator_t *iterator;
proposal1 = child_proposal_create(1);
proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 32);
proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 0);
proposal1->add_algorithm(proposal1, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
proposal1->add_algorithm(proposal1, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
proposal1->add_algorithm(proposal1, AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
proposal1->add_algorithm(proposal1, AH, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
proposal2 = child_proposal_create(2);
proposal2->add_algorithm(proposal2, ESP, ENCRYPTION_ALGORITHM, ENCR_3IDEA, 0);
proposal2->add_algorithm(proposal2, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
proposal2->add_algorithm(proposal2, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
//proposal1->add_algorithm(proposal2, AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
/* ah and esp prop */
proposal3 = proposal1->select(proposal1, proposal2);
tester->assert_false(tester, proposal3 == NULL, "proposal select");
if (proposal3)
{
iterator = proposal3->create_algorithm_iterator(proposal3, ESP, ENCRYPTION_ALGORITHM);
tester->assert_false(tester, iterator == NULL, "encryption algo select");
while(iterator->has_next(iterator))
{
algorithm_t *algo;
iterator->current(iterator, (void**)&algo);
tester->assert_true(tester, algo->algorithm == ENCR_AES_CBC, "encryption algo");
tester->assert_true(tester, algo->key_size == 16, "encryption keylen");
}
iterator->destroy(iterator);
iterator = proposal3->create_algorithm_iterator(proposal3, ESP, INTEGRITY_ALGORITHM);
tester->assert_false(tester, iterator == NULL, "integrity algo select");
while(iterator->has_next(iterator))
{
algorithm_t *algo;
iterator->current(iterator, (void**)&algo);
tester->assert_true(tester, algo->algorithm == AUTH_HMAC_MD5_96, "integrity algo");
tester->assert_true(tester, algo->key_size == 20, "integrity keylen");
}
iterator->destroy(iterator);
iterator = proposal3->create_algorithm_iterator(proposal3, AH, DIFFIE_HELLMAN_GROUP );
tester->assert_false(tester, iterator == NULL, "dh group algo select");
while(iterator->has_next(iterator))
{
algorithm_t *algo;
iterator->current(iterator, (void**)&algo);
tester->assert_true(tester, algo->algorithm == MODP_1024_BIT, "dh group algo");
tester->assert_true(tester, algo->key_size == 0, "dh gorup keylen");
}
iterator->destroy(iterator);
proposal3->destroy(proposal3);
}
proposal1->destroy(proposal1);
proposal2->destroy(proposal2);
return;
}
@@ -0,0 +1,42 @@
/**
* @file child_proposal_test.h
*
* @brief Tests for the child_proposal_t class.
*
*/
/*
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#ifndef CHILD_PROPOSAL_TEST_H_
#define CHILD_PROPOSAL_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the child_proposal_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_child_proposal(protected_tester_t *tester);
#endif //CHILD_PROPOSAL_TEST_H_
+28 -46
View File
@@ -424,8 +424,8 @@ void test_generator_with_sa_payload(protected_tester_t *tester)
transform_substructure_t *transform1, *transform2;
proposal_substructure_t *proposal1, *proposal2;
ike_proposal_t *ike_proposals;
size_t child_proposal_count;
child_proposal_t *child_proposals;
linked_list_t *list;
child_proposal_t *child_proposal1, *child_proposal2;
size_t ike_proposal_count;
sa_payload_t *sa_payload;
ike_header_t *ike_header;
@@ -655,52 +655,32 @@ void test_generator_with_sa_payload(protected_tester_t *tester)
tester->assert_true(tester,(generator != NULL), "generator create check");
child_proposal_count = 2;
child_proposals = allocator_alloc(child_proposal_count * (sizeof(child_proposal_t)));
child_proposals[0].ah.is_set = TRUE;
child_proposals[0].ah.integrity_algorithm = AUTH_HMAC_MD5_96;
child_proposals[0].ah.integrity_algorithm_key_size = 20;
child_proposals[0].ah.diffie_hellman_group = MODP_2048_BIT;
child_proposals[0].ah.extended_sequence_numbers = EXT_SEQ_NUMBERS;
child_proposals[0].ah.spi[0] = 1;
child_proposals[0].ah.spi[1] = 1;
child_proposals[0].ah.spi[2] = 1;
child_proposals[0].ah.spi[3] = 1;
child_proposals[0].esp.is_set = TRUE;
child_proposals[0].esp.diffie_hellman_group = MODP_1024_BIT;
child_proposals[0].esp.encryption_algorithm = ENCR_AES_CBC;
child_proposals[0].esp.encryption_algorithm_key_size = 32;
child_proposals[0].esp.integrity_algorithm = AUTH_UNDEFINED;
child_proposals[0].esp.spi[0] = 2;
child_proposals[0].esp.spi[1] = 2;
child_proposals[0].esp.spi[2] = 2;
child_proposals[0].esp.spi[3] = 2;
child_proposal1 = child_proposal_create(1);
child_proposals[1].ah.is_set = TRUE;
child_proposals[1].ah.integrity_algorithm = AUTH_HMAC_MD5_96;
child_proposals[1].ah.integrity_algorithm_key_size = 20;
child_proposals[1].ah.diffie_hellman_group = MODP_2048_BIT;
child_proposals[1].ah.extended_sequence_numbers = EXT_SEQ_NUMBERS;
child_proposals[1].ah.spi[0] = 1;
child_proposals[1].ah.spi[1] = 1;
child_proposals[1].ah.spi[2] = 1;
child_proposals[1].ah.spi[3] = 1;
child_proposals[1].esp.is_set = TRUE;
child_proposals[1].esp.diffie_hellman_group = MODP_1024_BIT;
child_proposals[1].esp.encryption_algorithm = ENCR_AES_CBC;
child_proposals[1].esp.encryption_algorithm_key_size = 32;
child_proposals[1].esp.integrity_algorithm = AUTH_HMAC_MD5_96;
child_proposals[1].esp.integrity_algorithm_key_size = 20;
child_proposals[1].esp.spi[0] = 2;
child_proposals[1].esp.spi[1] = 2;
child_proposals[1].esp.spi[2] = 2;
child_proposals[1].esp.spi[3] = 2;
child_proposal1->add_algorithm(child_proposal1, AH, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
child_proposal1->add_algorithm(child_proposal1, AH, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
child_proposal1->add_algorithm(child_proposal1, AH, EXTENDED_SEQUENCE_NUMBERS, EXT_SEQ_NUMBERS, 0);
child_proposal1->set_spi(child_proposal1, AH, 0x01010101l);
child_proposal1->add_algorithm(child_proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 20);
child_proposal1->add_algorithm(child_proposal1, ESP, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
child_proposal1->set_spi(child_proposal1, ESP, 0x02020202);
sa_payload = sa_payload_create_from_child_proposals(child_proposals,child_proposal_count);
child_proposal2->add_algorithm(child_proposal2, AH, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
child_proposal2->add_algorithm(child_proposal2, AH, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
child_proposal2->add_algorithm(child_proposal2, AH, EXTENDED_SEQUENCE_NUMBERS, EXT_SEQ_NUMBERS, 0);
child_proposal2->set_spi(child_proposal2, AH, 0x01010101);
child_proposal2->add_algorithm(child_proposal2, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 32);
child_proposal2->add_algorithm(child_proposal2, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
child_proposal2->add_algorithm(child_proposal2, ESP, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
child_proposal2->set_spi(child_proposal2, ESP, 0x02020202);
list->insert_last(list, (void*)child_proposal1);
list->insert_last(list, (void*)child_proposal2);
sa_payload = sa_payload_create_from_child_proposals(list);
tester->assert_true(tester,(sa_payload != NULL), "sa_payload create check");
generator->generate_payload(generator,(payload_t *)sa_payload);
@@ -774,7 +754,9 @@ void test_generator_with_sa_payload(protected_tester_t *tester)
tester->assert_true(tester,(memcmp(expected_generation3,generated_data.ptr,sizeof(expected_generation3)) == 0), "compare generated data");
sa_payload->destroy(sa_payload);
allocator_free(child_proposals);
child_proposal1->destroy(child_proposal1);
child_proposal2->destroy(child_proposal2);
list->destroy(list);
allocator_free_chunk(&generated_data);
generator->destroy(generator);
+3 -5
View File
@@ -106,8 +106,6 @@ void test_parser_with_sa_payload(protected_tester_t *tester)
iterator_t *proposals, *transforms, *attributes;
ike_proposal_t *ike_proposals;
size_t ike_proposal_count;
child_proposal_t *child_proposals;
size_t child_proposal_count;
/* first test generic parsing functionality */
@@ -352,7 +350,7 @@ void test_parser_with_sa_payload(protected_tester_t *tester)
status = sa_payload->get_ike_proposals (sa_payload, &ike_proposals, &ike_proposal_count);
tester->assert_false(tester,(status == SUCCESS),"get ike proposals call check");
/*
status = sa_payload->get_child_proposals (sa_payload, &child_proposals, &child_proposal_count);
tester->assert_true(tester,(status == SUCCESS),"get child proposals call check");
@@ -398,12 +396,12 @@ void test_parser_with_sa_payload(protected_tester_t *tester)
tester->assert_true(tester,(child_proposals[1].esp.spi[1] == 2),"spi check");
tester->assert_true(tester,(child_proposals[1].esp.spi[2] == 2),"spi check");
tester->assert_true(tester,(child_proposals[1].esp.spi[3] == 2),"spi check");
if (status == SUCCESS)
{
allocator_free(child_proposals);
}
*/
sa_payload->destroy(sa_payload);
}
+15 -30
View File
@@ -37,13 +37,12 @@ void test_sa_config(protected_tester_t *tester)
{
sa_config_t *sa_config;
traffic_selector_t *ts_policy[3], *ts_request[4], *ts_reference[3], **ts_result;
child_proposal_t prop[3], *prop_result;
child_proposal_t *proposal1, *proposal2, *proposal3, *proposal_sel;
linked_list_t *list;
size_t count;
logger_t *logger;
ts_payload_t *ts_payload;
u_int8_t spi[4] = {0x01,0x02,0x03,0x04};
logger = charon->logger_manager->create_logger(charon->logger_manager, TESTER, NULL);
logger->disable_level(logger, FULL);
@@ -61,43 +60,29 @@ void test_sa_config(protected_tester_t *tester)
*/
/* esp only prop */
prop[0].ah.is_set = FALSE;
prop[0].esp.is_set = TRUE;
prop[0].esp.encryption_algorithm = ENCR_AES_CBC;
prop[0].esp.encryption_algorithm_key_size = 16;
proposal1 = child_proposal_create(1);
proposal1->add_algorithm(proposal1, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
/* ah only prop */
prop[1].esp.is_set = FALSE;
prop[1].ah.is_set = TRUE;
prop[1].ah.integrity_algorithm = AUTH_HMAC_SHA1_96;
prop[1].ah.integrity_algorithm_key_size = 20;
proposal2 = child_proposal_create(2);
proposal2->add_algorithm(proposal2, AH, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
/* ah and esp prop */
prop[2].esp.is_set = TRUE;
prop[2].esp.encryption_algorithm = ENCR_3DES;
prop[2].esp.encryption_algorithm_key_size = 16;
prop[2].ah.is_set = TRUE;
prop[2].ah.integrity_algorithm = AUTH_HMAC_MD5_96;
prop[2].ah.integrity_algorithm_key_size = 20;
proposal3 = child_proposal_create(3);
proposal3->add_algorithm(proposal3, ESP, ENCRYPTION_ALGORITHM, ENCR_3DES, 16);
proposal3->add_algorithm(proposal3, AH, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
sa_config->add_proposal(sa_config, &prop[0]);
sa_config->add_proposal(sa_config, &prop[1]);
sa_config->add_proposal(sa_config, &prop[2]);
sa_config->add_proposal(sa_config, proposal1);
sa_config->add_proposal(sa_config, proposal2);
sa_config->add_proposal(sa_config, proposal3);
count = sa_config->get_proposals(sa_config, spi, spi, &prop_result);
tester->assert_true(tester, (count == 3), "proposal count");
allocator_free(prop_result);
list = sa_config->get_proposals(sa_config);
tester->assert_true(tester, (list->get_count(list) == 3), "proposal count");
prop_result = sa_config->select_proposal(sa_config, spi, spi, &prop[1], 2);
tester->assert_true(tester, prop_result->esp.is_set == prop[1].esp.is_set, "esp.is_set");
tester->assert_true(tester, prop_result->ah.integrity_algorithm == prop[1].ah.integrity_algorithm, "ah.integrity_algorithm");
tester->assert_true(tester, prop_result->ah.integrity_algorithm_key_size == prop[1].ah.integrity_algorithm_key_size, "ah.integrity_algorithm_key_size");
tester->assert_true(tester, memcmp(prop_result->ah.spi, spi, 4) == 0, "spi");
allocator_free(prop_result);
//proposal_sel = sa_config->select_proposal(sa_config, list);
/*
+7 -4
View File
@@ -58,6 +58,7 @@
#include <testcases/encryption_payload_test.h>
#include <testcases/init_config_test.h>
#include <testcases/sa_config_test.h>
#include <testcases/child_proposal_test.h>
#include <testcases/rsa_test.h>
#include <testcases/kernel_interface_test.h>
@@ -122,6 +123,7 @@ test_t hmac_signer_test2 = {test_hmac_sha1_signer, "HMAC SHA1 signer test"};
test_t encryption_payload_test = {test_encryption_payload, "encryption payload test"};
test_t init_config_test = {test_init_config, "init_config_t test"};
test_t sa_config_test = {test_sa_config, "sa_config_t test"};
test_t child_proposal_test = {test_child_proposal, "child_proposal_t test"};
test_t rsa_test = {test_rsa, "RSA private/public key test"};
test_t kernel_interface_test = {test_kernel_interface, "Kernel Interface"};
@@ -136,7 +138,7 @@ static void daemon_kill(daemon_t *this, char* none)
this->job_queue->destroy(this->job_queue);
this->event_queue->destroy(this->event_queue);
this->send_queue->destroy(this->send_queue);
this->configuration_manager->destroy(this->configuration_manager);
//this->configuration_manager->destroy(this->configuration_manager);
allocator_free(charon);
}
@@ -153,12 +155,12 @@ daemon_t *daemon_create()
charon->kill = daemon_kill;
charon->logger_manager = logger_manager_create(0);
charon->socket = socket_create(4600);
charon->socket = socket_create(4510);
charon->ike_sa_manager = ike_sa_manager_create();
charon->job_queue = job_queue_create();
charon->event_queue = event_queue_create();
charon->send_queue = send_queue_create();
charon->configuration_manager = configuration_manager_create(RETRANSMIT_TIMEOUT,MAX_RETRANSMIT_COUNT,HALF_OPEN_IKE_SA_TIMEOUT);
//charon->configuration_manager = configuration_manager_create(RETRANSMIT_TIMEOUT,MAX_RETRANSMIT_COUNT,HALF_OPEN_IKE_SA_TIMEOUT);
charon->sender = NULL;
charon->receiver = NULL;
charon->scheduler = NULL;
@@ -231,6 +233,7 @@ int main()
&encryption_payload_test,
&init_config_test,
&sa_config_test,
&child_proposal_test,
&rsa_test,
NULL
};
@@ -247,7 +250,7 @@ int main()
//tester->perform_tests(tester,all_tests);
tester->perform_test(tester,&kernel_interface_test);
tester->perform_test(tester,&child_proposal_test);
tester->destroy(tester);