aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorReto Buerki <reet@codelabs.ch>2012-08-29 09:48:14 +0200
committerTobias Brunner <tobias@strongswan.org>2013-03-19 15:23:46 +0100
commit4be8471fab1bccd078d7ee2fccba77e97f76b52b (patch)
treeeabb827d9475ff27681ba0713e7200c8122e7110 /src
parent3290b9995c2de88979bb6a4dd1fc8b743f2080eb (diff)
downloadstrongswan-4be8471fab1bccd078d7ee2fccba77e97f76b52b.tar.bz2
strongswan-4be8471fab1bccd078d7ee2fccba77e97f76b52b.tar.xz
Add keymat IKE key derivation test case
Diffstat (limited to 'src')
-rw-r--r--src/charon-tkm/tests/keymat_tests.c103
-rw-r--r--src/charon-tkm/tests/test_runner.c1
-rw-r--r--src/charon-tkm/tests/test_runner.h1
3 files changed, 105 insertions, 0 deletions
diff --git a/src/charon-tkm/tests/keymat_tests.c b/src/charon-tkm/tests/keymat_tests.c
new file mode 100644
index 000000000..fbaed24e4
--- /dev/null
+++ b/src/charon-tkm/tests/keymat_tests.c
@@ -0,0 +1,103 @@
+/*
+ * 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 <daemon.h>
+#include <hydra.h>
+#include <config/proposal.h>
+#include <encoding/payloads/ike_header.h>
+#include <tkm/client.h>
+
+#include "tkm.h"
+#include "tkm_nonceg.h"
+#include "tkm_diffie_hellman.h"
+#include "tkm_keymat.h"
+
+START_TEST(test_derive_ike_keys)
+{
+ fail_if(!library_init(NULL), "Unable to init library");
+ fail_if(!libhydra_init("tkm-tests"), "Unable to init libhydra");
+ fail_if(!libcharon_init("tkm-tests"), "Unable to init libcharon");
+
+ /* Register TKM specific plugins */
+ static plugin_feature_t features[] = {
+ PLUGIN_REGISTER(NONCE_GEN, tkm_nonceg_create),
+ PLUGIN_PROVIDE(NONCE_GEN),
+ PLUGIN_REGISTER(DH, tkm_diffie_hellman_create),
+ PLUGIN_PROVIDE(DH, MODP_3072_BIT),
+ PLUGIN_PROVIDE(DH, MODP_4096_BIT),
+ };
+ lib->plugins->add_static_features(lib->plugins, "tkm-tests", features,
+ countof(features), TRUE);
+
+ fail_if(!charon->initialize(charon, PLUGINS), "Unable to init charon");
+
+ proposal_t *proposal = proposal_create_from_string(PROTO_IKE,
+ "aes256-sha512-modp4096");
+ fail_if(!proposal, "Unable to create proposal");
+ ike_sa_id_t *ike_sa_id = ike_sa_id_create(IKEV2_MAJOR_VERSION,
+ 123912312312, 32312313122, TRUE);
+ fail_if(!ike_sa_id, "Unable to create IKE SA ID");
+
+ tkm_keymat_t *keymat = tkm_keymat_create(TRUE);
+ fail_if(!keymat, "Unable to create keymat");
+
+ chunk_t nonce;
+ tkm_nonceg_t *ng = tkm_nonceg_create();
+ fail_if(!ng, "Unable to create nonce generator");
+ fail_unless(ng->nonce_gen.allocate_nonce(&ng->nonce_gen, 32, &nonce),
+ "Unable to allocate nonce");
+ ng->nonce_gen.destroy(&ng->nonce_gen);
+
+ tkm_diffie_hellman_t *dh = tkm_diffie_hellman_create(MODP_4096_BIT);
+ fail_if(!dh, "Unable to create DH");
+
+ /* Use the same pubvalue for both sides */
+ chunk_t pubvalue;
+ dh->dh.get_my_public_value(&dh->dh, &pubvalue);
+ dh->dh.set_other_public_value(&dh->dh, pubvalue);
+
+ fail_unless(keymat->derive_ike_keys(keymat, proposal, &dh->dh, nonce, nonce,
+ ike_sa_id, PRF_UNDEFINED, chunk_empty), "Key derivation failed");
+ chunk_free(&nonce);
+
+ aead_t * const aead = keymat->keymat.get_aead(&keymat->keymat, TRUE);
+ fail_if(!aead, "AEAD is NULL");
+
+ fail_if(aead->get_key_size(aead) != 96, "Key size mismatch %d",
+ aead->get_key_size(aead));
+ fail_if(aead->get_block_size(aead) != 16, "Block size mismatch %d",
+ aead->get_block_size(aead));
+
+ proposal->destroy(proposal);
+ dh->dh.destroy(&dh->dh);
+ ike_sa_id->destroy(ike_sa_id);
+ keymat->keymat.destroy(&keymat->keymat);
+ chunk_free(&pubvalue);
+
+ libcharon_deinit();
+ libhydra_deinit();
+ library_deinit();
+}
+END_TEST
+
+TCase *make_keymat_tests(void)
+{
+ TCase *tc = tcase_create("Keymat tests");
+ tcase_add_test(tc, test_derive_ike_keys);
+
+ return tc;
+}
diff --git a/src/charon-tkm/tests/test_runner.c b/src/charon-tkm/tests/test_runner.c
index d29396c99..6ab990d92 100644
--- a/src/charon-tkm/tests/test_runner.c
+++ b/src/charon-tkm/tests/test_runner.c
@@ -32,6 +32,7 @@ int main(void)
suite_add_tcase(s, make_utility_tests());
suite_add_tcase(s, make_nonceg_tests());
suite_add_tcase(s, make_diffie_hellman_tests());
+ suite_add_tcase(s, make_keymat_tests());
SRunner *sr = srunner_create(s);
diff --git a/src/charon-tkm/tests/test_runner.h b/src/charon-tkm/tests/test_runner.h
index c3dee9820..c8cc0c0db 100644
--- a/src/charon-tkm/tests/test_runner.h
+++ b/src/charon-tkm/tests/test_runner.h
@@ -24,5 +24,6 @@ TCase *make_chunk_map_tests(void);
TCase *make_utility_tests(void);
TCase *make_nonceg_tests(void);
TCase *make_diffie_hellman_tests(void);
+TCase *make_keymat_tests(void);
#endif /** TEST_RUNNER_H_ */