From 706bd8a910a4544ffb3d750bd22d67e65231f1f7 Mon Sep 17 00:00:00 2001 From: toddouska Date: Mon, 6 Aug 2012 17:14:31 -0700 Subject: [PATCH] add cipher suite client/server driver --- configure.ac | 2 +- cyassl/test.h | 1 + examples/client/client.c | 1 + tests/api.c | 57 +------------------ tests/hash.c | 6 +- tests/include.am | 6 +- tests/suites.c | 115 +++++++++++++++++++++++++-------------- tests/test-openssl.conf | 10 ++++ tests/test.conf | 15 ++--- tests/unit.c | 80 +++++++++++++++++++++++++-- tests/unit.h | 7 +++ testsuite/testsuite.c | 1 - 12 files changed, 183 insertions(+), 118 deletions(-) create mode 100644 tests/test-openssl.conf diff --git a/configure.ac b/configure.ac index 842b83e0d..2c07da120 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ # # -AC_INIT([cyassl],[2.2.5],[http://www.yassl.com]) +AC_INIT([cyassl],[2.2.6],[http://www.yassl.com]) AC_CONFIG_AUX_DIR(config) diff --git a/cyassl/test.h b/cyassl/test.h index 700a82a03..91ecb9821 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -136,6 +136,7 @@ typedef struct func_args { tcp_ready* signal; } func_args; +void wait_tcp_ready(func_args*); typedef THREAD_RETURN CYASSL_THREAD THREAD_FUNC(void*); diff --git a/examples/client/client.c b/examples/client/client.c index 79f4abd23..e6df2d716 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -87,6 +87,7 @@ static void Usage(void) printf("-s Use pre Shared keys\n"); printf("-d Disable peer checks\n"); printf("-g Send server HTTP GET\n"); + printf("-u Use UDP DTLS\n"); } diff --git a/tests/api.c b/tests/api.c index 1df059dbf..99a4fe224 100644 --- a/tests/api.c +++ b/tests/api.c @@ -23,7 +23,7 @@ #include #define NO_MAIN_DRIVER #include -#include "unit.h" +#include #define TEST_FAIL (-1) #define TEST_SUCCESS (0) @@ -54,7 +54,6 @@ static int test_lvl(CYASSL_CTX *ctx, const char* file, const char* path, THREAD_RETURN CYASSL_THREAD test_server_nofail(void*); void test_client_nofail(void*); -void wait_tcp_ready(func_args*); #endif static const char* bogusFile = "/dev/null"; @@ -723,61 +722,7 @@ void test_client_nofail(void* args) -void wait_tcp_ready(func_args* args) -{ -#ifdef _POSIX_THREADS - pthread_mutex_lock(&args->signal->mutex); - - if (!args->signal->ready) - pthread_cond_wait(&args->signal->cond, &args->signal->mutex); - args->signal->ready = 0; /* reset */ - pthread_mutex_unlock(&args->signal->mutex); -#endif -} - - -void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread) -{ -#ifdef _POSIX_THREADS - pthread_create(thread, 0, fun, args); - return; -#else - *thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0); -#endif -} - - -void join_thread(THREAD_TYPE thread) -{ -#ifdef _POSIX_THREADS - pthread_join(thread, 0); -#else - int res = WaitForSingleObject(thread, INFINITE); - assert(res == WAIT_OBJECT_0); - res = CloseHandle(thread); - assert(res); -#endif -} - - -void InitTcpReady(tcp_ready* ready) -{ - ready->ready = 0; -#ifdef _POSIX_THREADS - pthread_mutex_init(&ready->mutex, 0); - pthread_cond_init(&ready->cond, 0); -#endif -} - - -void FreeTcpReady(tcp_ready* ready) -{ -#ifdef _POSIX_THREADS - pthread_mutex_destroy(&ready->mutex); - pthread_cond_destroy(&ready->cond); -#endif -} #endif /* NO_FILESYSTEM */ diff --git a/tests/hash.c b/tests/hash.c index 70dd00f4e..b3a6cc962 100644 --- a/tests/hash.c +++ b/tests/hash.c @@ -33,7 +33,7 @@ #include #include -#include "unit.h" +#include typedef struct testVector { char* input; @@ -55,6 +55,8 @@ int HashTest(void) { int ret = 0; + printf(" Begin HASH Tests\n"); + #ifndef NO_MD4 if ( (ret = md4_test()) ) { printf( " MD4 test failed!\n"); @@ -114,6 +116,8 @@ int HashTest(void) } else printf( " HMAC test passed!\n"); #endif + + printf(" End HASH Tests\n"); return 0; } diff --git a/tests/include.am b/tests/include.am index 6f3fe0bd2..adf43dce3 100644 --- a/tests/include.am +++ b/tests/include.am @@ -9,8 +9,10 @@ tests_unit_SOURCES = \ tests/unit.c \ tests/api.c \ tests/suites.c \ - tests/hash.c -tests_unit_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) + tests/hash.c \ + examples/client/client.c \ + examples/server/server.c +tests_unit_CFLAGS = -DNO_MAIN_DRIVER $(AM_CFLAGS) $(PTHREAD_CFLAGS) tests_unit_LDADD = src/libcyassl.la $(PTHREAD_LIBS) tests_unit_DEPENDENCIES = src/libcyassl.la EXTRA_DIST += tests/unit.h diff --git a/tests/suites.c b/tests/suites.c index 7499e7250..d74d7ae7d 100644 --- a/tests/suites.c +++ b/tests/suites.c @@ -22,21 +22,58 @@ #include #include #include -#include +#include -#define NO_MAIN_DRIVER #define MAX_ARGS 40 +#define MAX_COMMAND_SZ 240 + + +void client_test(void*); +THREAD_RETURN CYASSL_THREAD server_test(void*); + static void execute_test_case(int argc, char** argv) { func_args cliArgs = {argc, argv, 0, NULL}; func_args svrArgs = {argc, argv, 0, NULL}; - int i; - printf("argc = %d\n", argc); - for (i = 0; i < argc; i++) - printf(" argv[%d] = %s\n", i, argv[i]); + tcp_ready ready; + THREAD_TYPE serverThread; + char commandLine[MAX_COMMAND_SZ]; + int i; + static int tests = 0; + + commandLine[0] = '\0'; + for (i = 0; i < argc; i++) { + strcat(commandLine, argv[i]); + strcat(commandLine, " "); + } + printf("trying command line[%d]: %s\n", tests++, commandLine); + + InitTcpReady(&ready); + + /* start server */ + svrArgs.signal = &ready; + start_thread(server_test, &svrArgs, &serverThread); + wait_tcp_ready(&svrArgs); + + /* start client */ + client_test(&cliArgs); + + /* verify results */ + if (cliArgs.return_code != 0) { + printf("client_test failed\n"); + exit(EXIT_FAILURE); + } + + join_thread(serverThread); + if (svrArgs.return_code != 0) { + printf("server_test failed\n"); + exit(EXIT_FAILURE); + } + + FreeTcpReady(&ready); } @@ -52,6 +89,7 @@ void test_harness(void* vargs) char* comment; char* fname = "tests/test.conf"; + if (args->argc == 1) { printf("notice: using default file %s\n", fname); } @@ -145,46 +183,43 @@ void test_harness(void* vargs) int SuiteTest(void) { func_args args; - char argv0[32]; - char* myArgv[1]; + char argv0[2][32]; + char* myArgv[2]; - args.argc = 1; - myArgv[0] = argv0; + printf(" Begin Cipher Suite Tests\n"); + + /* setup */ + myArgv[0] = argv0[0]; + myArgv[1] = argv0[1]; args.argv = myArgv; - strcpy(argv0, "SuiteTest"); + strcpy(argv0[0], "SuiteTest"); + /* default case */ + args.argc = 1; + printf("starting default cipher suite tests\n"); test_harness(&args); + if (args.return_code != 0) { + printf("error from script %d\n", args.return_code); + exit(EXIT_FAILURE); + } + + /* any extra cases will need another argument */ + args.argc = 2; + +#ifdef OPENSSL_EXTRA + /* add openssl extra suites */ + strcpy(argv0[1], "tests/test-openssl.conf"); + printf("starting openssl extra cipher suite tests\n"); + test_harness(&args); + if (args.return_code != 0) { + printf("error from script %d\n", args.return_code); + exit(EXIT_FAILURE); + } +#endif + + printf(" End Cipher Suite Tests\n"); return args.return_code; } -/* so overall tests can pull in test function */ -#ifndef NO_MAIN_DRIVER - - int main(int argc, char** argv) - { - func_args args; - - StartTCP(); - - args.argc = argc; - args.argv = argv; - - CyaSSL_Init(); -#ifdef DEBUG_CYASSL - CyaSSL_Debugging_ON(); -#endif - if (CurrentDir("client") || CurrentDir("build")) - ChangeDirBack(2); - - test_harness(&args); - CyaSSL_Cleanup(); - - return args.return_code; - } - - int myoptind = 0; - char* myoptarg = NULL; - -#endif /* NO_MAIN_DRIVER */ diff --git a/tests/test-openssl.conf b/tests/test-openssl.conf new file mode 100644 index 000000000..365df1514 --- /dev/null +++ b/tests/test-openssl.conf @@ -0,0 +1,10 @@ +-l DHE-RSA-AES128-SHA + +-l DHE-RSA-AES128-SHA256 +-v 1 + +# The previous item ended and a new item hasn't started yet. + +# This blank line above accidentally became a new item with all defaults. +# The following leads into a simple test item. +-p 11211 diff --git a/tests/test.conf b/tests/test.conf index b54b41c3c..72b0d1c1c 100644 --- a/tests/test.conf +++ b/tests/test.conf @@ -1,17 +1,10 @@ --p 11111 --d --l AES256-GCM-SHA384:AES128-GCM-SHA256 --v tls_1_2 +-l AES128-SHA --p 11111 --l AES256-GCM-SHA384 --v tls_1_2 --k certs/new-key.pem --c certs/new-cert.pem --a certs/new-ca.pem +-l RC4-SHA +-v 0 # The previous item ended and a new item hasn't started yet. # This blank line above accidentally became a new item with all defaults. # The following leads into a simple test item. --p 1234 +-p 11211 diff --git a/tests/unit.c b/tests/unit.c index 273f2ab5d..1fbcc9cb5 100644 --- a/tests/unit.c +++ b/tests/unit.c @@ -1,6 +1,6 @@ /* unit.c unit tests driver */ #include -#include "unit.h" +#include int myoptind = 0; @@ -9,13 +9,81 @@ char* myoptarg = NULL; int main(int argc, char** argv) { - printf("hello unit tests\n"); + int ret; - if (ApiTest() != 0) - printf("api test failed\n"); + printf("staring unit tests...\n"); - if (HashTest() != 0) - printf("hash test failed\n"); + if ( (ret = ApiTest()) != 0) { + printf("api test failed with %d\n", ret); + return ret; + } + + if ( (ret = HashTest()) != 0){ + printf("hash test failed with %d\n", ret); + return ret; + } + + if ( (ret = SuiteTest()) != 0){ + printf("suite test failed with %d\n", ret); + return ret; + } return 0; } + + +void wait_tcp_ready(func_args* args) +{ +#ifdef _POSIX_THREADS + pthread_mutex_lock(&args->signal->mutex); + + if (!args->signal->ready) + pthread_cond_wait(&args->signal->cond, &args->signal->mutex); + args->signal->ready = 0; /* reset */ + + pthread_mutex_unlock(&args->signal->mutex); +#endif +} + + +void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread) +{ +#ifdef _POSIX_THREADS + pthread_create(thread, 0, fun, args); + return; +#else + *thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0); +#endif +} + + +void join_thread(THREAD_TYPE thread) +{ +#ifdef _POSIX_THREADS + pthread_join(thread, 0); +#else + int res = WaitForSingleObject(thread, INFINITE); + assert(res == WAIT_OBJECT_0); + res = CloseHandle(thread); + assert(res); +#endif +} + + +void InitTcpReady(tcp_ready* ready) +{ + ready->ready = 0; +#ifdef _POSIX_THREADS + pthread_mutex_init(&ready->mutex, 0); + pthread_cond_init(&ready->cond, 0); +#endif +} + + +void FreeTcpReady(tcp_ready* ready) +{ +#ifdef _POSIX_THREADS + pthread_mutex_destroy(&ready->mutex); + pthread_cond_destroy(&ready->cond); +#endif +} \ No newline at end of file diff --git a/tests/unit.h b/tests/unit.h index 36e1ba3a0..840893cda 100644 --- a/tests/unit.h +++ b/tests/unit.h @@ -1,6 +1,13 @@ /* unit.h unit tests driver */ +#ifndef CyaSSL_UNIT_H +#define CyaSSL_UNIT_H + +#include /* thread and tcp stuff */ + int ApiTest(void); int SuiteTest(void); int HashTest(void); + +#endif /* CyaSSL_UNIT_H */ \ No newline at end of file diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index bc4b54448..ebcb0c28f 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -32,7 +32,6 @@ and the examples/ individually #endif -void wait_tcp_ready(func_args*); void ctaocrypt_test(void*); void client_test(void*);