aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/testcases
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-12-04 01:30:35 +0000
committerMartin Willi <martin@strongswan.org>2005-12-04 01:30:35 +0000
commit8ff8c33d1d720a227db193c2105cbdcf119e5746 (patch)
tree7de51ee9de420cf13eca9c91f4dfb70901d41e10 /Source/charon/testcases
parenta374d1ee669a6b7674f242119369770cb9e5705c (diff)
downloadstrongswan-8ff8c33d1d720a227db193c2105cbdcf119e5746.tar.bz2
strongswan-8ff8c33d1d720a227db193c2105cbdcf119e5746.tar.xz
- implemented RSA, only signing and verifying esma_pkcs1 padded
- removed gmp-helper: chunk_to_mpz is now done with gmp functions, prime generation in prime-pool - added prime-pool (needs priority fix) - proof of concept RSA authentication - mpz uses LEAK_DETECTIVE - configuration-manager supports rsa keys
Diffstat (limited to 'Source/charon/testcases')
-rw-r--r--Source/charon/testcases/Makefile.testcases8
-rw-r--r--Source/charon/testcases/prime_pool_test.c67
-rw-r--r--Source/charon/testcases/prime_pool_test.h39
-rw-r--r--Source/charon/testcases/rsa_test.c85
-rw-r--r--Source/charon/testcases/rsa_test.h41
-rw-r--r--Source/charon/testcases/testcases.c19
6 files changed, 255 insertions, 4 deletions
diff --git a/Source/charon/testcases/Makefile.testcases b/Source/charon/testcases/Makefile.testcases
index 8463c1a00..bdb54c226 100644
--- a/Source/charon/testcases/Makefile.testcases
+++ b/Source/charon/testcases/Makefile.testcases
@@ -115,3 +115,11 @@ $(BUILD_DIR)init_config_test.o : $(TESTCASES_DIR)init_config_test.c $(TESTCASES_
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)rsa_test.o
+$(BUILD_DIR)rsa_test.o : $(TESTCASES_DIR)rsa_test.c $(TESTCASES_DIR)rsa_test.h
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+TEST_OBJS+= $(BUILD_DIR)prime_pool_test.o
+$(BUILD_DIR)prime_pool_test.o : $(TESTCASES_DIR)prime_pool_test.c $(TESTCASES_DIR)prime_pool_test.h
+ $(CC) $(CFLAGS) -c -o $@ $<
diff --git a/Source/charon/testcases/prime_pool_test.c b/Source/charon/testcases/prime_pool_test.c
new file mode 100644
index 000000000..a8fca0a9b
--- /dev/null
+++ b/Source/charon/testcases/prime_pool_test.c
@@ -0,0 +1,67 @@
+/**
+ * @file prime_pool_test.h
+ *
+ * @brief Tests for the hasher_t classes.
+ *
+ */
+
+/*
+ * 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 <string.h>
+#include <unistd.h>
+
+#include "prime_pool_test.h"
+
+#include <daemon.h>
+#include <utils/allocator.h>
+#include <utils/logger.h>
+#include <threads/prime_pool.h>
+
+
+/*
+ * described in Header-File
+ */
+void test_prime_pool(tester_t *tester)
+{
+ mpz_t p1, p2, p3, p4;
+ prime_pool_t *prime_pool;
+
+ prime_pool = prime_pool_create(20);
+
+ prime_pool->get_prime(prime_pool, 4, &p1);
+ sleep(1);
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 4) == 20, "number of 4 bytes primes");
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 8) == 0, "number of 8 bytes primes");
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 16) == 0, "number of 16 bytes primes");
+ prime_pool->get_prime(prime_pool, 8, &p2);
+ sleep(1);
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 4) == 20, "number of 4 bytes primes");
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 8) == 20, "number of 8 bytes primes");
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 16) == 0, "number of 16 bytes primes");
+ prime_pool->get_prime(prime_pool, 16, &p3);
+ sleep(1);
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 4) == 20, "number of 4 bytes primes");
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 8) == 20, "number of 8 bytes primes");
+ tester->assert_true(tester, prime_pool->get_count(prime_pool, 16) == 20, "number of 16 bytes primes");
+ prime_pool->get_prime(prime_pool, 16, &p4);
+
+ mpz_clear(p1);
+ mpz_clear(p2);
+ mpz_clear(p3);
+ mpz_clear(p4);
+ prime_pool->destroy(prime_pool);
+
+}
diff --git a/Source/charon/testcases/prime_pool_test.h b/Source/charon/testcases/prime_pool_test.h
new file mode 100644
index 000000000..5e6080f35
--- /dev/null
+++ b/Source/charon/testcases/prime_pool_test.h
@@ -0,0 +1,39 @@
+/**
+ * @file prime_pool_test.h
+ *
+ * @brief Tests for the prime_pool_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 PRIME_POOL_TEST_H
+#define PRIME_POOL_TEST_H
+
+#include <threads/prime_pool.h>
+#include <utils/tester.h>
+
+/**
+ * @brief Test function used to test the prime_pool functionality.
+ *
+ * @param tester associated tester object
+ *
+ * @ingroup testcases
+ */
+void test_prime_pool(tester_t *tester);
+
+
+#endif /*PRIME_POOL_TEST_H*/
diff --git a/Source/charon/testcases/rsa_test.c b/Source/charon/testcases/rsa_test.c
new file mode 100644
index 000000000..37f349558
--- /dev/null
+++ b/Source/charon/testcases/rsa_test.c
@@ -0,0 +1,85 @@
+/**
+ * @file rsa_test.h
+ *
+ * @brief Tests for the hasher_t classes.
+ *
+ */
+
+/*
+ * 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 <string.h>
+
+#include "rsa_test.h"
+
+#include <daemon.h>
+#include <utils/allocator.h>
+#include <utils/logger.h>
+
+
+/*
+ * described in Header-File
+ */
+void test_rsa(tester_t *tester)
+{
+ rsa_private_key_t *private_key;
+ rsa_public_key_t *public_key;
+ chunk_t data, signature, private_key_chunk, public_key_chunk;
+ logger_t *logger;
+ status_t status;
+ u_int8_t test_data[] = {
+ 0x01,0x02,0x03,0x04,
+ 0x01,0x02,0x03,0x04,
+ 0x01,0x02,0x03,0x04,
+ 0x01,0x02,0x03,0x04,
+ 0x01,0x02,0x03,0x04,
+ 0x01,0x02,0x03,0x04,
+ 0x01,0x02,0x03,0x04,
+ 0x01,0x02,0x03,0x04,
+ 0x01,0x02,0x03,0x04,
+ };
+ data.ptr = test_data;
+ data.len = sizeof(test_data);
+
+ logger = charon->logger_manager->create_logger(charon->logger_manager, TESTER, NULL);
+ logger->enable_level(logger, FULL);
+
+ private_key = rsa_private_key_create();
+
+ private_key->generate_key(private_key, 1024);
+
+ status = private_key->build_emsa_pkcs1_signature(private_key, HASH_MD5, data, &signature);
+ tester->assert_true(tester, status == SUCCESS, "build emsa_pkcs1_signature");
+
+ public_key = private_key->get_public_key(private_key);
+
+ status = public_key->verify_emsa_pkcs1_signature(public_key, data, signature);
+ tester->assert_true(tester, status == SUCCESS, "verify emsa_pkcs1_signature");
+
+ public_key->get_key(public_key, &public_key_chunk);
+ private_key->get_key(private_key, &private_key_chunk);
+
+ logger->log_chunk(logger, RAW, "Public Key", &public_key_chunk);
+ logger->log_chunk(logger, RAW, "Private Key", &private_key_chunk);
+
+
+ allocator_free(public_key_chunk.ptr);
+ allocator_free(private_key_chunk.ptr);
+ allocator_free(signature.ptr);
+
+ private_key->destroy(private_key);
+ public_key->destroy(public_key);
+
+}
diff --git a/Source/charon/testcases/rsa_test.h b/Source/charon/testcases/rsa_test.h
new file mode 100644
index 000000000..3bc749f62
--- /dev/null
+++ b/Source/charon/testcases/rsa_test.h
@@ -0,0 +1,41 @@
+/**
+ * @file rsa_test.h
+ *
+ * @brief Tests for the rsa_public_key_t and rsa_private_key classes.
+ *
+ */
+
+/*
+ * 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 RSA_TEST_H
+#define RSA_TEST_H
+
+#include <transforms/rsa/rsa_public_key.h>
+#include <transforms/rsa/rsa_private_key.h>
+
+#include <utils/tester.h>
+
+/**
+ * @brief Test function used to test the rsa functionality.
+ *
+ * @param tester associated tester object
+ *
+ * @ingroup testcases
+ */
+void test_rsa(tester_t *tester);
+
+
+#endif /*RSA_TEST_H*/
diff --git a/Source/charon/testcases/testcases.c b/Source/charon/testcases/testcases.c
index f02d9d4a0..03a318fcb 100644
--- a/Source/charon/testcases/testcases.c
+++ b/Source/charon/testcases/testcases.c
@@ -58,6 +58,8 @@
#include <testcases/encryption_payload_test.h>
#include <testcases/init_config_test.h>
#include <testcases/sa_config_test.h>
+#include <testcases/rsa_test.h>
+#include <testcases/prime_pool_test.h>
/* output for test messages */
extern FILE * stderr;
@@ -108,6 +110,8 @@ 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 rsa_test = {test_rsa, "RSA private/public key test"};
+test_t prime_pool_test = {test_prime_pool, "Prime pool"};
daemon_t* charon;
@@ -118,6 +122,7 @@ static void daemon_kill(daemon_t *this, char* none)
this->socket->destroy(this->socket);
this->ike_sa_manager->destroy(this->ike_sa_manager);
this->job_queue->destroy(this->job_queue);
+ this->prime_pool->destroy(this->prime_pool);
this->event_queue->destroy(this->event_queue);
this->send_queue->destroy(this->send_queue);
this->configuration_manager->destroy(this->configuration_manager);
@@ -130,18 +135,19 @@ static void daemon_kill(daemon_t *this, char* none)
* @return created daemon_t
*/
daemon_t *daemon_create()
-{
+{
charon = allocator_alloc_thing(daemon_t);
/* assign methods */
charon->kill = daemon_kill;
charon->logger_manager = logger_manager_create(0);
- charon->socket = socket_create(4601);
+ charon->socket = socket_create(4600);
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->prime_pool = prime_pool_create(0);
charon->configuration_manager = configuration_manager_create(RETRANSMIT_TIMEOUT,MAX_RETRANSMIT_COUNT);
charon->sender = NULL;
charon->receiver = NULL;
@@ -203,8 +209,13 @@ int main()
&encryption_payload_test,
&init_config_test,
&sa_config_test,
+ &rsa_test,
+ &prime_pool_test,
NULL
};
+
+ /* allocator needs initialization */
+ allocator_init();
daemon_create();
@@ -214,8 +225,8 @@ int main()
tester_t *tester = tester_create(test_output, FALSE);
- tester->perform_tests(tester,all_tests);
-// tester->perform_test(tester,&sa_config_test);
+// tester->perform_tests(tester,all_tests);
+ tester->perform_test(tester,&rsa_test);
tester->destroy(tester);