Introduce TKM specific charon daemon (charon-tkm)
Analogous to charon-nm the charon-tkm daemon is a specialized charon instance used in combination with the trusted key manager (TKM) written in Ada. The charon-tkm is basically a copy of the charon-nm code which will register it's own TKM specific plugins. The daemon binary is built using the gprbuild utility. This is needed because it uses the tkm-rpc Ada library and consequently the Ada runtime. gprbuild takes care of the complete binding and linker steps required to properly initialize the Ada runtime.
This commit is contained in:
committed by
Tobias Brunner
parent
4dc3ef94a1
commit
559fe48c50
@@ -0,0 +1 @@
|
||||
test_runner
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Reto Buerki
|
||||
* Copyright (C) 2012 Adrian-Ken Rueegsegger
|
||||
* 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 <stdlib.h>
|
||||
#include <check.h>
|
||||
|
||||
#include "tkm_id_manager.h"
|
||||
|
||||
START_TEST(test_id_mgr_creation)
|
||||
{
|
||||
tkm_id_manager_t *idmgr = NULL;
|
||||
|
||||
idmgr = tkm_id_manager_create();
|
||||
fail_if(idmgr == NULL, "Error creating tkm id manager");
|
||||
|
||||
idmgr->destroy(idmgr);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_acquire_id)
|
||||
{
|
||||
int i, id = 0;
|
||||
tkm_id_manager_t *idmgr = tkm_id_manager_create();
|
||||
|
||||
for (i = 0; i < TKM_CTX_MAX; i++)
|
||||
{
|
||||
id = idmgr->acquire_id(idmgr, i);
|
||||
fail_unless(id > 0, "Error acquiring id of context kind %d", i);
|
||||
|
||||
/* Reset test variable */
|
||||
id = 0;
|
||||
}
|
||||
|
||||
idmgr->destroy(idmgr);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_acquire_id_invalid_kind)
|
||||
{
|
||||
int id = 0;
|
||||
tkm_id_manager_t *idmgr = tkm_id_manager_create();
|
||||
|
||||
id = idmgr->acquire_id(idmgr, TKM_CTX_MAX);
|
||||
fail_unless(id == 0, "Acquired id for invalid context kind %d", TKM_CTX_MAX);
|
||||
|
||||
/* Reset test variable */
|
||||
id = 0;
|
||||
|
||||
id = idmgr->acquire_id(idmgr, -1);
|
||||
fail_unless(id == 0, "Acquired id for invalid context kind %d", -1);
|
||||
|
||||
idmgr->destroy(idmgr);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_release_id)
|
||||
{
|
||||
int i, id = 0;
|
||||
bool released = false;
|
||||
tkm_id_manager_t *idmgr = tkm_id_manager_create();
|
||||
|
||||
for (i = 0; i < TKM_CTX_MAX; i++)
|
||||
{
|
||||
id = idmgr->acquire_id(idmgr, i);
|
||||
released = idmgr->release_id(idmgr, i, id);
|
||||
|
||||
fail_unless(released, "Error releasing id of context kind %d", i);
|
||||
|
||||
/* Reset released variable */
|
||||
released = FALSE;
|
||||
}
|
||||
|
||||
idmgr->destroy(idmgr);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_release_id_invalid_kind)
|
||||
{
|
||||
bool released = TRUE;
|
||||
tkm_id_manager_t *idmgr = tkm_id_manager_create();
|
||||
|
||||
released = idmgr->release_id(idmgr, TKM_CTX_MAX, 1);
|
||||
fail_if(released, "Released id for invalid context kind %d", TKM_CTX_MAX);
|
||||
|
||||
/* Reset test variable */
|
||||
released = TRUE;
|
||||
|
||||
released = idmgr->release_id(idmgr, -1, 1);
|
||||
fail_if(released, "Released id for invalid context kind %d", -1);
|
||||
|
||||
idmgr->destroy(idmgr);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_release_id_nonexistent)
|
||||
{
|
||||
bool released = FALSE;
|
||||
tkm_id_manager_t *idmgr = tkm_id_manager_create();
|
||||
|
||||
released = idmgr->release_id(idmgr, TKM_CTX_NONCE, 1);
|
||||
fail_unless(released, "Release of nonexistent id failed");
|
||||
|
||||
idmgr->destroy(idmgr);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
TCase *make_id_manager_tests(void)
|
||||
{
|
||||
TCase *tc = tcase_create("Context id manager tests");
|
||||
tcase_add_test(tc, test_id_mgr_creation);
|
||||
tcase_add_test(tc, test_acquire_id);
|
||||
tcase_add_test(tc, test_acquire_id_invalid_kind);
|
||||
tcase_add_test(tc, test_release_id);
|
||||
tcase_add_test(tc, test_release_id_invalid_kind);
|
||||
tcase_add_test(tc, test_release_id_nonexistent);
|
||||
|
||||
return tc;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Reto Buerki
|
||||
* Copyright (C) 2012 Adrian-Ken Rueegsegger
|
||||
* 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 <check.h>
|
||||
#include <tkm/client.h>
|
||||
|
||||
#include "tkm.h"
|
||||
#include "tkm_nonceg.h"
|
||||
|
||||
START_TEST(test_nonceg_creation)
|
||||
{
|
||||
tkm_nonceg_t *ng = NULL;
|
||||
|
||||
ng = tkm_nonceg_create();
|
||||
fail_if(ng == NULL, "Error creating tkm nonce generator");
|
||||
|
||||
ng->nonce_gen.destroy(&ng->nonce_gen);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_nonceg_allocate_nonce)
|
||||
{
|
||||
tkm_nonceg_t *ng = tkm_nonceg_create();
|
||||
|
||||
const size_t length = 256;
|
||||
u_int8_t zero[length];
|
||||
memset(zero, 0, length);
|
||||
|
||||
chunk_t nonce;
|
||||
const bool got_nonce = ng->nonce_gen.allocate_nonce(&ng->nonce_gen,
|
||||
length, &nonce);
|
||||
|
||||
fail_unless(got_nonce, "Call to allocate_nonce failed");
|
||||
fail_unless(nonce.len = length, "Allocated nonce length mismatch");
|
||||
fail_if(memcmp(nonce.ptr, zero, length) == 0, "Unable to allocate nonce");
|
||||
|
||||
tkm->idmgr->release_id(tkm->idmgr, TKM_CTX_NONCE, 1);
|
||||
ike_nc_reset(1);
|
||||
|
||||
chunk_free(&nonce);
|
||||
ng->nonce_gen.destroy(&ng->nonce_gen);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_nonceg_get_nonce)
|
||||
{
|
||||
tkm_nonceg_t *ng = tkm_nonceg_create();
|
||||
|
||||
const size_t length = 128;
|
||||
u_int8_t zero[length];
|
||||
memset(zero, 0, length);
|
||||
|
||||
u_int8_t *buf = malloc(length + 1);
|
||||
memset(buf, 0, length);
|
||||
/* set end marker */
|
||||
buf[length] = 255;
|
||||
|
||||
const bool got_nonce = ng->nonce_gen.get_nonce(&ng->nonce_gen, length, buf);
|
||||
fail_unless(got_nonce, "Call to get_nonce failed");
|
||||
fail_if(memcmp(buf, zero, length) == 0, "Unable to get nonce");
|
||||
fail_if(buf[length] != 255, "End marker not found");
|
||||
|
||||
tkm->idmgr->release_id(tkm->idmgr, TKM_CTX_NONCE, 1);
|
||||
ike_nc_reset(1);
|
||||
|
||||
free(buf);
|
||||
ng->nonce_gen.destroy(&ng->nonce_gen);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
TCase *make_nonceg_tests(void)
|
||||
{
|
||||
TCase *tc = tcase_create("Nonce generator tests");
|
||||
tcase_add_test(tc, test_nonceg_creation);
|
||||
tcase_add_test(tc, test_nonceg_allocate_nonce);
|
||||
tcase_add_test(tc, test_nonceg_get_nonce);
|
||||
|
||||
return tc;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Reto Buerki
|
||||
* Copyright (C) 2012 Adrian-Ken Rueegsegger
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include "test_runner.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int number_failed;
|
||||
Suite *s = suite_create("TKM tests");
|
||||
suite_add_tcase(s, make_id_manager_tests());
|
||||
suite_add_tcase(s, make_nonceg_tests());
|
||||
|
||||
SRunner *sr = srunner_create(s);
|
||||
|
||||
srunner_run_all(sr, CK_NORMAL);
|
||||
number_failed = srunner_ntests_failed(sr);
|
||||
|
||||
srunner_free(sr);
|
||||
|
||||
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Reto Buerki
|
||||
* Copyright (C) 2012 Adrian-Ken Rueegsegger
|
||||
* 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 TEST_RUNNER_H_
|
||||
#define TEST_RUNNER_H_
|
||||
|
||||
#include <check.h>
|
||||
|
||||
TCase *make_id_manager_tests(void);
|
||||
TCase *make_nonceg_tests(void);
|
||||
|
||||
#endif /** TEST_RUNNER_H_ */
|
||||
Reference in New Issue
Block a user