add cipher suite client/server driver

This commit is contained in:
toddouska
2012-08-06 17:14:31 -07:00
parent cf4ea232e3
commit 706bd8a910
12 changed files with 183 additions and 118 deletions

View File

@@ -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) AC_CONFIG_AUX_DIR(config)

View File

@@ -136,6 +136,7 @@ typedef struct func_args {
tcp_ready* signal; tcp_ready* signal;
} func_args; } func_args;
void wait_tcp_ready(func_args*);
typedef THREAD_RETURN CYASSL_THREAD THREAD_FUNC(void*); typedef THREAD_RETURN CYASSL_THREAD THREAD_FUNC(void*);

View File

@@ -87,6 +87,7 @@ static void Usage(void)
printf("-s Use pre Shared keys\n"); printf("-s Use pre Shared keys\n");
printf("-d Disable peer checks\n"); printf("-d Disable peer checks\n");
printf("-g Send server HTTP GET\n"); printf("-g Send server HTTP GET\n");
printf("-u Use UDP DTLS\n");
} }

View File

@@ -23,7 +23,7 @@
#include <cyassl/ssl.h> #include <cyassl/ssl.h>
#define NO_MAIN_DRIVER #define NO_MAIN_DRIVER
#include <cyassl/test.h> #include <cyassl/test.h>
#include "unit.h" #include <tests/unit.h>
#define TEST_FAIL (-1) #define TEST_FAIL (-1)
#define TEST_SUCCESS (0) #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*); THREAD_RETURN CYASSL_THREAD test_server_nofail(void*);
void test_client_nofail(void*); void test_client_nofail(void*);
void wait_tcp_ready(func_args*);
#endif #endif
static const char* bogusFile = "/dev/null"; 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 */ #endif /* NO_FILESYSTEM */

View File

@@ -33,7 +33,7 @@
#include <cyassl/ctaocrypt/ripemd.h> #include <cyassl/ctaocrypt/ripemd.h>
#include <cyassl/ctaocrypt/hmac.h> #include <cyassl/ctaocrypt/hmac.h>
#include "unit.h" #include <tests/unit.h>
typedef struct testVector { typedef struct testVector {
char* input; char* input;
@@ -55,6 +55,8 @@ int HashTest(void)
{ {
int ret = 0; int ret = 0;
printf(" Begin HASH Tests\n");
#ifndef NO_MD4 #ifndef NO_MD4
if ( (ret = md4_test()) ) { if ( (ret = md4_test()) ) {
printf( " MD4 test failed!\n"); printf( " MD4 test failed!\n");
@@ -115,6 +117,8 @@ int HashTest(void)
printf( " HMAC test passed!\n"); printf( " HMAC test passed!\n");
#endif #endif
printf(" End HASH Tests\n");
return 0; return 0;
} }

View File

@@ -9,8 +9,10 @@ tests_unit_SOURCES = \
tests/unit.c \ tests/unit.c \
tests/api.c \ tests/api.c \
tests/suites.c \ tests/suites.c \
tests/hash.c tests/hash.c \
tests_unit_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) 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_LDADD = src/libcyassl.la $(PTHREAD_LIBS)
tests_unit_DEPENDENCIES = src/libcyassl.la tests_unit_DEPENDENCIES = src/libcyassl.la
EXTRA_DIST += tests/unit.h EXTRA_DIST += tests/unit.h

View File

@@ -22,21 +22,58 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <cyassl/ssl.h> #include <cyassl/ssl.h>
#include <cyassl/test.h> #include <tests/unit.h>
#define NO_MAIN_DRIVER
#define MAX_ARGS 40 #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) static void execute_test_case(int argc, char** argv)
{ {
func_args cliArgs = {argc, argv, 0, NULL}; func_args cliArgs = {argc, argv, 0, NULL};
func_args svrArgs = {argc, argv, 0, NULL}; func_args svrArgs = {argc, argv, 0, NULL};
int i;
printf("argc = %d\n", argc); tcp_ready ready;
for (i = 0; i < argc; i++) THREAD_TYPE serverThread;
printf(" argv[%d] = %s\n", i, argv[i]); 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* comment;
char* fname = "tests/test.conf"; char* fname = "tests/test.conf";
if (args->argc == 1) { if (args->argc == 1) {
printf("notice: using default file %s\n", fname); printf("notice: using default file %s\n", fname);
} }
@@ -145,46 +183,43 @@ void test_harness(void* vargs)
int SuiteTest(void) int SuiteTest(void)
{ {
func_args args; func_args args;
char argv0[32]; char argv0[2][32];
char* myArgv[1]; char* myArgv[2];
args.argc = 1; printf(" Begin Cipher Suite Tests\n");
myArgv[0] = argv0;
/* setup */
myArgv[0] = argv0[0];
myArgv[1] = argv0[1];
args.argv = myArgv; 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); test_harness(&args);
if (args.return_code != 0) {
return args.return_code; printf("error from script %d\n", args.return_code);
exit(EXIT_FAILURE);
} }
/* any extra cases will need another argument */
args.argc = 2;
/* so overall tests can pull in test function */ #ifdef OPENSSL_EXTRA
#ifndef NO_MAIN_DRIVER /* add openssl extra suites */
strcpy(argv0[1], "tests/test-openssl.conf");
int main(int argc, char** argv) printf("starting openssl extra cipher suite tests\n");
{ test_harness(&args);
func_args args; if (args.return_code != 0) {
printf("error from script %d\n", args.return_code);
StartTCP(); exit(EXIT_FAILURE);
}
args.argc = argc;
args.argv = argv;
CyaSSL_Init();
#ifdef DEBUG_CYASSL
CyaSSL_Debugging_ON();
#endif #endif
if (CurrentDir("client") || CurrentDir("build"))
ChangeDirBack(2);
test_harness(&args); printf(" End Cipher Suite Tests\n");
CyaSSL_Cleanup();
return args.return_code; return args.return_code;
} }
int myoptind = 0;
char* myoptarg = NULL;
#endif /* NO_MAIN_DRIVER */

10
tests/test-openssl.conf Normal file
View File

@@ -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

View File

@@ -1,17 +1,10 @@
-p 11111 -l AES128-SHA
-d
-l AES256-GCM-SHA384:AES128-GCM-SHA256
-v tls_1_2
-p 11111 -l RC4-SHA
-l AES256-GCM-SHA384 -v 0
-v tls_1_2
-k certs/new-key.pem
-c certs/new-cert.pem
-a certs/new-ca.pem
# The previous item ended and a new item hasn't started yet. # The previous item ended and a new item hasn't started yet.
# This blank line above accidentally became a new item with all defaults. # This blank line above accidentally became a new item with all defaults.
# The following leads into a simple test item. # The following leads into a simple test item.
-p 1234 -p 11211

View File

@@ -1,6 +1,6 @@
/* unit.c unit tests driver */ /* unit.c unit tests driver */
#include <stdio.h> #include <stdio.h>
#include "unit.h" #include <tests/unit.h>
int myoptind = 0; int myoptind = 0;
@@ -9,13 +9,81 @@ char* myoptarg = NULL;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
printf("hello unit tests\n"); int ret;
if (ApiTest() != 0) printf("staring unit tests...\n");
printf("api test failed\n");
if (HashTest() != 0) if ( (ret = ApiTest()) != 0) {
printf("hash test failed\n"); 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; 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
}

View File

@@ -1,6 +1,13 @@
/* unit.h unit tests driver */ /* unit.h unit tests driver */
#ifndef CyaSSL_UNIT_H
#define CyaSSL_UNIT_H
#include <cyassl/test.h> /* thread and tcp stuff */
int ApiTest(void); int ApiTest(void);
int SuiteTest(void); int SuiteTest(void);
int HashTest(void); int HashTest(void);
#endif /* CyaSSL_UNIT_H */

View File

@@ -32,7 +32,6 @@
and the examples/ individually and the examples/ individually
#endif #endif
void wait_tcp_ready(func_args*);
void ctaocrypt_test(void*); void ctaocrypt_test(void*);
void client_test(void*); void client_test(void*);