forked from wolfSSL/wolfssl
add cipher suite client/server driver
This commit is contained in:
@ -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)
|
||||
|
||||
|
@ -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*);
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
57
tests/api.c
57
tests/api.c
@ -23,7 +23,7 @@
|
||||
#include <cyassl/ssl.h>
|
||||
#define NO_MAIN_DRIVER
|
||||
#include <cyassl/test.h>
|
||||
#include "unit.h"
|
||||
#include <tests/unit.h>
|
||||
|
||||
#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 */
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include <cyassl/ctaocrypt/ripemd.h>
|
||||
#include <cyassl/ctaocrypt/hmac.h>
|
||||
|
||||
#include "unit.h"
|
||||
#include <tests/unit.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
115
tests/suites.c
115
tests/suites.c
@ -22,21 +22,58 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <cyassl/ssl.h>
|
||||
#include <cyassl/test.h>
|
||||
#include <tests/unit.h>
|
||||
|
||||
|
||||
#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 */
|
||||
|
10
tests/test-openssl.conf
Normal file
10
tests/test-openssl.conf
Normal 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
|
@ -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
|
||||
|
80
tests/unit.c
80
tests/unit.c
@ -1,6 +1,6 @@
|
||||
/* unit.c unit tests driver */
|
||||
#include <stdio.h>
|
||||
#include "unit.h"
|
||||
#include <tests/unit.h>
|
||||
|
||||
|
||||
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
|
||||
}
|
@ -1,6 +1,13 @@
|
||||
/* 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 SuiteTest(void);
|
||||
int HashTest(void);
|
||||
|
||||
|
||||
#endif /* CyaSSL_UNIT_H */
|
@ -32,7 +32,6 @@
|
||||
and the examples/ individually
|
||||
#endif
|
||||
|
||||
void wait_tcp_ready(func_args*);
|
||||
void ctaocrypt_test(void*);
|
||||
|
||||
void client_test(void*);
|
||||
|
Reference in New Issue
Block a user