add cipher suite check to suite tests to make adding test cases easier

This commit is contained in:
toddouska 2013-03-11 10:59:08 -07:00
parent 01a5368ffc
commit 47e7e27bb2
2 changed files with 71 additions and 0 deletions

View File

@ -366,6 +366,9 @@ void c32to24(word32 in, word24 out);
#ifdef NO_DES3
#define DES_BLOCK_SIZE 8
#else
#undef BUILD_DES3
#define BUILD_DES3
#endif
#ifdef NO_AES
@ -375,6 +378,13 @@ void c32to24(word32 in, word24 out);
#define BUILD_AES
#endif
#ifndef NO_RC4
#undef BUILD_ARC4
#define BUILD_ARC4
#endif
#if defined(BUILD_AESGCM) || defined(HAVE_AESCCM)
#define HAVE_AEAD
#endif

View File

@ -32,10 +32,56 @@
#define MAX_ARGS 40
#define MAX_COMMAND_SZ 240
#define MAX_SUITE_SZ 80
#include "examples/client/client.h"
#include "examples/server/server.h"
CYASSL_CTX* cipherSuiteCtx = NULL;
/* if the cipher suite on line is valid store in suite and return 1, else 0 */
static int IsValidCipherSuite(const char* line, char* suite)
{
int found = 0;
int valid = 0;
const char* find = "-l ";
char* begin = strnstr(line, find, MAX_COMMAND_SZ);
char* end;
suite[0] = '\0';
if (begin) {
begin += 3;
end = strnstr(begin, " ", MAX_COMMAND_SZ);
if (end) {
long len = end - begin;
if (len > MAX_SUITE_SZ) {
printf("suite too long!\n");
return 0;
}
memcpy(suite, begin, len);
suite[len] = '\0';
}
else
strncpy(suite, begin, MAX_SUITE_SZ);
suite[MAX_SUITE_SZ] = '\0';
found = 1;
}
if (found) {
if (CyaSSL_CTX_set_cipher_list(cipherSuiteCtx, suite) == SSL_SUCCESS)
valid = 1;
}
return valid;
}
static void execute_test_case(int svr_argc, char** svr_argv,
int cli_argc, char** cli_argv, int addNoVerify)
{
@ -45,6 +91,7 @@ static void execute_test_case(int svr_argc, char** svr_argv,
tcp_ready ready;
THREAD_TYPE serverThread;
char commandLine[MAX_COMMAND_SZ];
char cipherSuite[MAX_SUITE_SZ+1];
int i;
size_t added = 0;
static int tests = 1;
@ -69,6 +116,12 @@ static void execute_test_case(int svr_argc, char** svr_argv,
}
printf("trying server command line[%d]: %s\n", tests, commandLine);
if (IsValidCipherSuite(commandLine, cipherSuite) == 0) {
printf("cipher suite %s not supported in build\n", cipherSuite);
return;
}
commandLine[0] = '\0';
added = 0;
for (i = 0; i < cli_argc; i++) {
@ -250,6 +303,12 @@ int SuiteTest(void)
(void)test_harness;
cipherSuiteCtx = CyaSSL_CTX_new(CyaTLSv1_2_client_method());
if (cipherSuiteCtx == NULL) {
printf("can't get cipher suite ctx\n");
exit(EXIT_FAILURE);
}
#if !defined(NO_RSA)
/* default case */
args.argc = 1;
@ -460,6 +519,8 @@ int SuiteTest(void)
printf(" End Cipher Suite Tests\n");
CyaSSL_CTX_free(cipherSuiteCtx);
return args.return_code;
}