int main(int argc, char** argv) { func_args args; tcp_ready ready; StartTCP(); args.argc = argc; args.argv = argv; args.signal = &ready; InitTcpReady(&ready); #if defined(DEBUG_CYASSL) && !defined(WOLFSSL_MDK_SHELL) CyaSSL_Debugging_ON(); #endif CyaSSL_Init(); ChangeToWolfRoot(); #ifdef HAVE_STACK_SIZE StackSizeCheck(&args, server_test); #else server_test(&args); #endif CyaSSL_Cleanup(); FreeTcpReady(&ready); #ifdef HAVE_WNR if (wc_FreeNetRandom() < 0) err_sys("Failed to free netRandom context"); #endif /* HAVE_WNR */ return args.return_code; }
static void test_CyaSSL_read_write(void) { #ifdef HAVE_IO_TESTS_DEPENDENCIES /* The unit testing for read and write shall happen simutaneously, since * one can't do anything with one without the other. (Except for a failure * test case.) This function will call all the others that will set up, * execute, and report their test findings. * * Set up the success case first. This function will become the template * for the other tests. This should eventually be renamed * * The success case isn't interesting, how can this fail? * - Do not give the client context a CA certificate. The connect should * fail. Do not need server for this? * - Using NULL for the ssl object on server. Do not need client for this. * - Using NULL for the ssl object on client. Do not need server for this. * - Good ssl objects for client and server. Client write() without server * read(). * - Good ssl objects for client and server. Server write() without client * read(). * - Forgetting the password callback? */ tcp_ready ready; func_args client_args; func_args server_args; THREAD_TYPE serverThread; #ifdef CYASSL_TIRTOS fdOpenSession(Task_self()); #endif StartTCP(); InitTcpReady(&ready); server_args.signal = &ready; client_args.signal = &ready; start_thread(test_server_nofail, &server_args, &serverThread); wait_tcp_ready(&server_args); test_client_nofail(&client_args); join_thread(serverThread); AssertTrue(client_args.return_code); AssertTrue(server_args.return_code); FreeTcpReady(&ready); #ifdef CYASSL_TIRTOS fdOpenSession(Task_self()); #endif #endif }
static void execute_test_case(int svr_argc, char** svr_argv, int cli_argc, char** cli_argv) { func_args cliArgs = {cli_argc, cli_argv, 0, NULL}; func_args svrArgs = {svr_argc, svr_argv, 0, NULL}; tcp_ready ready; THREAD_TYPE serverThread; char commandLine[MAX_COMMAND_SZ]; int i; static int tests = 1; commandLine[0] = '\0'; for (i = 0; i < svr_argc; i++) { strcat(commandLine, svr_argv[i]); strcat(commandLine, " "); } printf("trying server command line[%d]: %s\n", tests, commandLine); commandLine[0] = '\0'; for (i = 0; i < cli_argc; i++) { strcat(commandLine, cli_argv[i]); strcat(commandLine, " "); } printf("trying client 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); }
static int test_CyaSSL_read_write(void) { /* The unit testing for read and write shall happen simutaneously, since * one can't do anything with one without the other. (Except for a failure * test case.) This function will call all the others that will set up, * execute, and report their test findings. * * Set up the success case first. This function will become the template * for the other tests. This should eventually be renamed * * The success case isn't interesting, how can this fail? * - Do not give the client context a CA certificate. The connect should * fail. Do not need server for this? * - Using NULL for the ssl object on server. Do not need client for this. * - Using NULL for the ssl object on client. Do not need server for this. * - Good ssl objects for client and server. Client write() without server * read(). * - Good ssl objects for client and server. Server write() without client * read(). * - Forgetting the password callback? */ int test_result = TEST_SUCCESS; tcp_ready ready; func_args client_args; func_args server_args; THREAD_TYPE serverThread; StartTCP(); InitTcpReady(&ready); server_args.signal = &ready; start_thread(test_server_nofail, &server_args, &serverThread); wait_tcp_ready(&server_args); test_client_nofail(&client_args); join_thread(serverThread); if (client_args.return_code != TEST_SUCCESS) { printf(resultFmt, "client failure"); test_result = TEST_FAIL; } if (server_args.return_code != TEST_SUCCESS) { printf(resultFmt, "server failure"); test_result = TEST_FAIL; } FreeTcpReady(&ready); return test_result; };
int main(int argc, char** argv) { func_args args; tcp_ready ready; #ifdef HAVE_CAVIUM int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID); if (ret != 0) err_sys("Cavium OpenNitroxDevice failed"); #endif /* HAVE_CAVIUM */ StartTCP(); args.argc = argc; args.argv = argv; args.signal = &ready; InitTcpReady(&ready); #if defined(DEBUG_CYASSL) && !defined(WOLFSSL_MDK_SHELL) CyaSSL_Debugging_ON(); #endif CyaSSL_Init(); ChangeToWolfRoot(); #ifdef HAVE_STACK_SIZE StackSizeCheck(&args, server_test); #else server_test(&args); #endif CyaSSL_Cleanup(); FreeTcpReady(&ready); #ifdef HAVE_CAVIUM CspShutdown(CAVIUM_DEV_ID); #endif #ifdef HAVE_WNR if (wc_FreeNetRandom() < 0) err_sys("Failed to free netRandom context"); #endif /* HAVE_WNR */ return args.return_code; }
static void test_CyaSSL_client_server(callback_functions* client_callbacks, callback_functions* server_callbacks) { #ifdef HAVE_IO_TESTS_DEPENDENCIES tcp_ready ready; func_args client_args; func_args server_args; THREAD_TYPE serverThread; StartTCP(); client_args.callbacks = client_callbacks; server_args.callbacks = server_callbacks; #ifdef CYASSL_TIRTOS fdOpenSession(Task_self()); #endif /* RUN Server side */ InitTcpReady(&ready); server_args.signal = &ready; client_args.signal = &ready; start_thread(run_cyassl_server, &server_args, &serverThread); wait_tcp_ready(&server_args); /* RUN Client side */ run_cyassl_client(&client_args); join_thread(serverThread); FreeTcpReady(&ready); #ifdef CYASSL_TIRTOS fdCloseSession(Task_self()); #endif #else (void)client_callbacks; (void)server_callbacks; #endif }
static int execute_test_case(int svr_argc, char** svr_argv, int cli_argc, char** cli_argv, int addNoVerify, int addNonBlocking) { #ifdef WOLFSSL_TIRTOS func_args cliArgs = {0}; func_args svrArgs = {0}; cliArgs.argc = cli_argc; cliArgs.argv = cli_argv; svrArgs.argc = svr_argc; svrArgs.argv = svr_argv; #else func_args cliArgs = {cli_argc, cli_argv, 0, NULL, NULL}; func_args svrArgs = {svr_argc, svr_argv, 0, NULL, NULL}; #endif 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; commandLine[0] = '\0'; for (i = 0; i < svr_argc; i++) { added += strlen(svr_argv[i]) + 2; if (added >= MAX_COMMAND_SZ) { printf("server command line too long\n"); break; } strcat(commandLine, svr_argv[i]); strcat(commandLine, flagSep); } if (IsValidCipherSuite(commandLine, cipherSuite) == 0) { #ifdef DEBUG_SUITE_TESTS printf("cipher suite %s not supported in build\n", cipherSuite); #endif return NOT_BUILT_IN; } #ifndef WOLFSSL_ALLOW_SSLV3 if (IsSslVersion(commandLine) == 1) { #ifdef DEBUG_SUITE_TESTS printf("protocol version on line %s is too old\n", commandLine); #endif return VERSION_TOO_OLD; } #endif #ifdef NO_OLD_TLS if (IsOldTlsVersion(commandLine) == 1) { #ifdef DEBUG_SUITE_TESTS printf("protocol version on line %s is too old\n", commandLine); #endif return VERSION_TOO_OLD; } #endif if (addNoVerify) { printf("repeating test with client cert request off\n"); added += 4; /* -d plus space plus terminator */ if (added >= MAX_COMMAND_SZ || svr_argc >= MAX_ARGS) printf("server command line too long\n"); else { svr_argv[svr_argc++] = noVerifyFlag; svrArgs.argc = svr_argc; strcat(commandLine, noVerifyFlag); strcat(commandLine, flagSep); } } if (addNonBlocking) { printf("repeating test with non blocking on\n"); added += 4; /* -N plus terminator */ if (added >= MAX_COMMAND_SZ || svr_argc >= MAX_ARGS) printf("server command line too long\n"); else { svr_argv[svr_argc++] = nonblockFlag; svrArgs.argc = svr_argc; strcat(commandLine, nonblockFlag); strcat(commandLine, flagSep); } } #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS) /* add port 0 */ if (svr_argc + 2 > MAX_ARGS) printf("cannot add the magic port number flag to server\n"); else { svr_argv[svr_argc++] = portFlag; svr_argv[svr_argc++] = svrPort; svrArgs.argc = svr_argc; } #endif printf("trying server command line[%d]: %s\n", tests, commandLine); commandLine[0] = '\0'; added = 0; for (i = 0; i < cli_argc; i++) { added += strlen(cli_argv[i]) + 2; if (added >= MAX_COMMAND_SZ) { printf("client command line too long\n"); break; } strcat(commandLine, cli_argv[i]); strcat(commandLine, flagSep); } if (addNonBlocking) { added += 4; /* -N plus space plus terminator */ if (added >= MAX_COMMAND_SZ) printf("client command line too long\n"); else { cli_argv[cli_argc++] = nonblockFlag; strcat(commandLine, nonblockFlag); strcat(commandLine, flagSep); cliArgs.argc = cli_argc; } } printf("trying client command line[%d]: %s\n", tests++, commandLine); InitTcpReady(&ready); #ifdef WOLFSSL_TIRTOS fdOpenSession(Task_self()); #endif /* start server */ svrArgs.signal = &ready; start_thread(server_test, &svrArgs, &serverThread); wait_tcp_ready(&svrArgs); #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS) if (ready.port != 0) { if (cli_argc + 2 > MAX_ARGS) printf("cannot add the magic port number flag to client\n"); else { char portNumber[8]; snprintf(portNumber, sizeof(portNumber), "%d", ready.port); cli_argv[cli_argc++] = portFlag; cli_argv[cli_argc++] = portNumber; cliArgs.argc = cli_argc; } } #endif /* 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); } #ifdef WOLFSSL_TIRTOS fdCloseSession(Task_self()); #endif FreeTcpReady(&ready); return 0; }
int main(int argc, char** argv) { func_args server_args; tcp_ready ready; THREAD_TYPE serverThread; #ifdef HAVE_CAVIUM int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID); if (ret != 0) err_sys("Cavium OpenNitroxDevice failed"); #endif /* HAVE_CAVIUM */ StartTCP(); server_args.argc = argc; server_args.argv = argv; CyaSSL_Init(); #if defined(DEBUG_CYASSL) && !defined(HAVE_VALGRIND) CyaSSL_Debugging_ON(); #endif if (CurrentDir("testsuite") || CurrentDir("_build")) ChangeDirBack(1); else if (CurrentDir("Debug") || CurrentDir("Release")) ChangeDirBack(3); /* Xcode->Preferences->Locations->Locations*/ /* Derived Data Advanced -> Custom */ /* Relative to Workspace, Build/Products */ /* Debug or Release */ server_args.signal = &ready; InitTcpReady(&ready); /* CTaoCrypt test */ ctaocrypt_test(&server_args); if (server_args.return_code != 0) return server_args.return_code; /* Simple CyaSSL client server test */ simple_test(&server_args); if (server_args.return_code != 0) return server_args.return_code; /* Echo input yaSSL client server test */ start_thread(echoserver_test, &server_args, &serverThread); wait_tcp_ready(&server_args); { func_args echo_args; char* myArgv[NUMARGS]; char argc0[32]; char argc1[32]; char argc2[32]; myArgv[0] = argc0; myArgv[1] = argc1; myArgv[2] = argc2; echo_args.argc = NUMARGS; echo_args.argv = myArgv; strcpy(echo_args.argv[0], "echoclient"); strcpy(echo_args.argv[1], "input"); strcpy(echo_args.argv[2], outputName); remove(outputName); /* Share the signal, it has the new port number in it. */ echo_args.signal = server_args.signal; /* make sure OK */ echoclient_test(&echo_args); if (echo_args.return_code != 0) return echo_args.return_code; #ifdef CYASSL_DTLS wait_tcp_ready(&server_args); #endif /* send quit to echoserver */ echo_args.argc = 2; strcpy(echo_args.argv[1], "quit"); echoclient_test(&echo_args); if (echo_args.return_code != 0) return echo_args.return_code; join_thread(serverThread); if (server_args.return_code != 0) return server_args.return_code; } /* validate output equals input */ { byte input[SHA256_DIGEST_SIZE]; byte output[SHA256_DIGEST_SIZE]; file_test("input", input); file_test(outputName, output); if (memcmp(input, output, sizeof(input)) != 0) return EXIT_FAILURE; } CyaSSL_Cleanup(); FreeTcpReady(&ready); #ifdef HAVE_CAVIUM CspShutdown(CAVIUM_DEV_ID); #endif printf("\nAll tests passed!\n"); return EXIT_SUCCESS; }
int testsuite_test(int argc, char** argv) { func_args server_args; tcp_ready ready; THREAD_TYPE serverThread; #ifndef USE_WINDOWS_API char tempName[] = "/tmp/output-XXXXXX"; int len = 18; int num = 6; #else char tempName[] = "fnXXXXXX"; int len = 8; int num = 6; #endif #ifdef HAVE_CAVIUM int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID); if (ret != 0) err_sys("Cavium OpenNitroxDevice failed"); #endif /* HAVE_CAVIUM */ #ifdef HAVE_WNR if (wc_InitNetRandom(wnrConfig, NULL, 5000) != 0) { err_sys("Whitewood netRandom global config failed"); return -1237; } #endif /* HAVE_WNR */ StartTCP(); server_args.argc = argc; server_args.argv = argv; wolfSSL_Init(); #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND) wolfSSL_Debugging_ON(); #endif #if !defined(WOLFSSL_TIRTOS) ChangeToWolfRoot(); #endif #ifdef WOLFSSL_TIRTOS fdOpenSession(Task_self()); #endif server_args.signal = &ready; InitTcpReady(&ready); #ifndef NO_CRYPT_TEST /* wc_ test */ wolfcrypt_test(&server_args); if (server_args.return_code != 0) return server_args.return_code; #endif /* Simple wolfSSL client server test */ simple_test(&server_args); if (server_args.return_code != 0) return server_args.return_code; /* Echo input wolfSSL client server test */ start_thread(echoserver_test, &server_args, &serverThread); wait_tcp_ready(&server_args); { func_args echo_args; char* myArgv[NUMARGS]; char argc0[32]; char argc1[32]; char argc2[32]; myArgv[0] = argc0; myArgv[1] = argc1; myArgv[2] = argc2; echo_args.argc = 3; echo_args.argv = myArgv; /* Create unique file name */ outputName = mymktemp(tempName, len, num); if (outputName == NULL) { printf("Could not create unique file name"); return EXIT_FAILURE; } strcpy(echo_args.argv[0], "echoclient"); strcpy(echo_args.argv[1], "input"); strcpy(echo_args.argv[2], outputName); /* Share the signal, it has the new port number in it. */ echo_args.signal = server_args.signal; /* make sure OK */ echoclient_test(&echo_args); if (echo_args.return_code != 0) return echo_args.return_code; #ifdef WOLFSSL_DTLS wait_tcp_ready(&server_args); #endif /* send quit to echoserver */ echo_args.argc = 2; strcpy(echo_args.argv[1], "quit"); echoclient_test(&echo_args); if (echo_args.return_code != 0) return echo_args.return_code; join_thread(serverThread); if (server_args.return_code != 0) return server_args.return_code; } /* show ciphers */ { char ciphers[1024]; XMEMSET(ciphers, 0, sizeof(ciphers)); wolfSSL_get_ciphers(ciphers, sizeof(ciphers)-1); printf("ciphers = %s\n", ciphers); } /* validate output equals input */ { byte input[SHA256_DIGEST_SIZE]; byte output[SHA256_DIGEST_SIZE]; file_test("input", input); file_test(outputName, output); remove(outputName); if (memcmp(input, output, sizeof(input)) != 0) return EXIT_FAILURE; } wolfSSL_Cleanup(); FreeTcpReady(&ready); #ifdef WOLFSSL_TIRTOS fdCloseSession(Task_self()); #endif #ifdef HAVE_CAVIUM CspShutdown(CAVIUM_DEV_ID); #endif #ifdef HAVE_WNR if (wc_FreeNetRandom() < 0) err_sys("Failed to free netRandom context"); #endif /* HAVE_WNR */ printf("\nAll tests passed!\n"); return EXIT_SUCCESS; }
static int execute_test_case(int svr_argc, char** svr_argv, int cli_argc, char** cli_argv, int addNoVerify, int addNonBlocking) { func_args cliArgs = {cli_argc, cli_argv, 0, NULL}; func_args svrArgs = {svr_argc, svr_argv, 0, NULL}; 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; commandLine[0] = '\0'; for (i = 0; i < svr_argc; i++) { added += strlen(svr_argv[i]) + 2; if (added >= MAX_COMMAND_SZ) { printf("server command line too long\n"); break; } strcat(commandLine, svr_argv[i]); strcat(commandLine, " "); } if (IsValidCipherSuite(commandLine, cipherSuite) == 0) { #ifdef DEBUG_SUITE_TESTS printf("cipher suite %s not supported in build\n", cipherSuite); #endif return NOT_BUILT_IN; } #ifdef NO_OLD_TLS if (IsOldTlsVersion(commandLine) == 1) { #ifdef DEBUG_SUITE_TESTS printf("protocol version on line %s is too old\n", commandLine); #endif return VERSION_TOO_OLD; } #endif if (addNoVerify) { printf("repeating test with client cert request off\n"); added += 4; /* -d plus space plus terminator */ if (added >= MAX_COMMAND_SZ) printf("server command line too long\n"); else strcat(commandLine, "-d "); } if (addNonBlocking) { printf("repeating test with non blocking on\n"); added += 4; /* -N plus terminator */ if (added >= MAX_COMMAND_SZ) printf("server command line too long\n"); else strcat(commandLine, "-N "); } printf("trying server command line[%d]: %s\n", tests, commandLine); commandLine[0] = '\0'; added = 0; for (i = 0; i < cli_argc; i++) { added += strlen(cli_argv[i]) + 2; if (added >= MAX_COMMAND_SZ) { printf("client command line too long\n"); break; } strcat(commandLine, cli_argv[i]); strcat(commandLine, " "); } if (addNonBlocking) { added += 4; /* -N plus space plus terminator */ if (added >= MAX_COMMAND_SZ) printf("client command line too long\n"); else strcat(commandLine, "-N "); } printf("trying client 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); return 0; }
int main(int argc, char** argv) { func_args args; func_args server_args; tcp_ready ready; THREAD_TYPE serverThread; StartTCP(); args.argc = server_args.argc = argc; args.argv = server_args.argv = argv; /* CTaoCrypt test */ ctaocrypt_test(&args); if (args.return_code != 0) return args.return_code; /* Simple CyaSSL client server test */ InitCyaSSL(); InitTcpReady(&ready); server_args.signal = &ready; start_thread(server_test, &server_args, &serverThread); wait_tcp_ready(&server_args); client_test(&args); if (args.return_code != 0) return args.return_code; join_thread(serverThread); if (server_args.return_code != 0) return server_args.return_code; /* Echo input yaSSL client server test */ start_thread(echoserver_test, &server_args, &serverThread); wait_tcp_ready(&server_args); { func_args echo_args; char* myArgv[NUMARGS]; char argc0[32]; char argc1[32]; char argc2[32]; myArgv[0] = argc0; myArgv[1] = argc1; myArgv[2] = argc2; echo_args.argc = NUMARGS; echo_args.argv = myArgv; strcpy(echo_args.argv[0], "echoclient"); strcpy(echo_args.argv[1], "input"); strcpy(echo_args.argv[2], "output"); remove("output"); /* make sure OK */ echoclient_test(&echo_args); if (echo_args.return_code != 0) return echo_args.return_code; #ifdef CYASSL_DTLS wait_tcp_ready(&server_args); #endif /* send quit to echoserver */ echo_args.argc = 2; strcpy(echo_args.argv[1], "quit"); echoclient_test(&echo_args); if (echo_args.return_code != 0) return echo_args.return_code; join_thread(serverThread); if (server_args.return_code != 0) return server_args.return_code; } /* validate output equals input */ { byte input[MD5_DIGEST_SIZE]; byte output[MD5_DIGEST_SIZE]; file_test("input", input); file_test("output", output); if (memcmp(input, output, sizeof(input)) != 0) return -1; } FreeCyaSSL(); FreeTcpReady(&ready); printf("\nAll tests passed!\n"); return 0; }