From e8034619ba447a5694b6fcdf385aa5f13d7eb2a5 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Tue, 21 Jul 2020 08:45:20 -0700 Subject: [PATCH 1/7] Add more if defined to ERR_print_errors_fp --- tests/api.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tests/api.c b/tests/api.c index fb7c1fe80..b864a7fd7 100644 --- a/tests/api.c +++ b/tests/api.c @@ -27143,7 +27143,79 @@ static void test_wolfSSL_ERR_print_errors_cb(void) printf(resultFmt, passed); #endif } +/* + * Testing WOLFSSL_ERROR_MSG + */ +static int test_WOLFSSL_ERROR_MSG (void) +{ + int ret = 0; +#if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\ + defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) + const char* msg = "Everyone gets Friday off."; + printf(testingFmt, "WOLFSSL_ERROR_MSG()"); + + WOLFSSL_ERROR_MSG(msg); + + printf(resultFmt, ret == 0 ? passed : failed); + +#endif + return ret; + +}/*End test_WOLFSSL_ERROR_MSG*/ +/* + * Testing wc_ERR_remove_state + */ +static int test_wc_ERR_remove_state (void) +{ + int ret = 0; + +#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE) + + printf(testingFmt, "wc_ERR_remove_state()"); + + ret = wc_ERR_remove_state(); + + printf(resultFmt, ret == 0 ? passed : failed); + +#endif + return ret; + +}/*End test_wc_ERR_remove_state*/ +/* + * Testing wc_ERR_print_errors_fp + */ +static int test_wc_ERR_print_errors_fp (void) +{ + int ret = 0; +#if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \ + (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)) + + printf(testingFmt, "wc_ERR_print_errors_fp()"); + + XFILE fp = XFOPEN("./certs/dsa2048.der", "rb"); + wc_ERR_print_errors_fp(fp); + + printf(resultFmt, ret == 0 ? passed : failed); + XFCLOSE(fp); +#endif + + return ret; + +}/*End test_wc_ERR_print_errors_fp*/ +/* + * Testing wolfSSL_GetLoggingCb + */ +static int test_wolfSSL_GetLoggingCb (void) +{ + int ret = 0; + printf(testingFmt, "wolfSSL_GetLoggingCb()"); + + wolfSSL_GetLoggingCb(); + + printf(resultFmt, ret == 0 ? passed : failed); + return ret; +}/*End test_wolfSSL_GetLoggingCb*/ static void test_wolfSSL_HMAC(void) { #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) @@ -34923,6 +34995,10 @@ void ApiTest(void) test_wolfSSL_ERR_peek_last_error_line(); #endif test_wolfSSL_ERR_print_errors_cb(); + AssertFalse(test_wolfSSL_GetLoggingCb()); + AssertFalse(test_WOLFSSL_ERROR_MSG()); + AssertFalse(test_wc_ERR_remove_state()); + AssertFalse(test_wc_ERR_print_errors_fp()); test_wolfSSL_set_options(); test_wolfSSL_sk_SSL_CIPHER(); test_wolfSSL_X509_STORE_CTX(); From b500a54fc59102de920afe34bedc9c9e82a1b9e0 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Tue, 21 Jul 2020 11:59:04 -0700 Subject: [PATCH 2/7] Added new file to read in and dump error message and added cleanup within cleanup script --- scripts/cleanup_testfiles.sh | 1 + tests/api.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/cleanup_testfiles.sh b/scripts/cleanup_testfiles.sh index c7f3885fc..f4ffd6906 100755 --- a/scripts/cleanup_testfiles.sh +++ b/scripts/cleanup_testfiles.sh @@ -12,3 +12,4 @@ rm -f ./certeccrsa.der rm -f ./ecc-key.der rm -f ./ecc-key.pem rm -f ./ecc-public-key.der +rm -f ./test-log-dump-to-file.txt diff --git a/tests/api.c b/tests/api.c index b864a7fd7..e85dad135 100644 --- a/tests/api.c +++ b/tests/api.c @@ -27169,16 +27169,16 @@ static int test_WOLFSSL_ERROR_MSG (void) static int test_wc_ERR_remove_state (void) { int ret = 0; - #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE) printf(testingFmt, "wc_ERR_remove_state()"); - ret = wc_ERR_remove_state(); - + wc_ERR_remove_state(); + printf(resultFmt, ret == 0 ? passed : failed); - + #endif + return ret; }/*End test_wc_ERR_remove_state*/ @@ -27190,16 +27190,22 @@ static int test_wc_ERR_print_errors_fp (void) int ret = 0; #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \ (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)) - + int sz; printf(testingFmt, "wc_ERR_print_errors_fp()"); - - XFILE fp = XFOPEN("./certs/dsa2048.der", "rb"); + WOLFSSL_ERROR(BAD_FUNC_ARG); + //XFILE fp = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb"); + XFILE fp = XFOPEN("./test-log-dump-to-file.txt", "ar"); wc_ERR_print_errors_fp(fp); - + + AssertTrue(XFSEEK(fp, 0, XSEEK_END) == 0); + sz = XFTELL(fp); + if (sz == 0) { + ret = BAD_FUNC_ARG; + } + printf(resultFmt, ret == 0 ? passed : failed); XFCLOSE(fp); #endif - return ret; }/*End test_wc_ERR_print_errors_fp*/ From 953e7cf18197a4d836aa4d89861f556c82dfe697 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Tue, 21 Jul 2020 15:28:17 -0700 Subject: [PATCH 3/7] Changed sz type from int to long --- tests/api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index e85dad135..23778d897 100644 --- a/tests/api.c +++ b/tests/api.c @@ -27190,7 +27190,7 @@ static int test_wc_ERR_print_errors_fp (void) int ret = 0; #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \ (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)) - int sz; + long sz; printf(testingFmt, "wc_ERR_print_errors_fp()"); WOLFSSL_ERROR(BAD_FUNC_ARG); //XFILE fp = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb"); From 5e515c12fba333a06003876344f0676840b67ed0 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Wed, 22 Jul 2020 08:28:43 -0700 Subject: [PATCH 4/7] Removed unneeded comment --- tests/api.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/api.c b/tests/api.c index 23778d897..f81ffbb46 100644 --- a/tests/api.c +++ b/tests/api.c @@ -27161,7 +27161,6 @@ static int test_WOLFSSL_ERROR_MSG (void) #endif return ret; - }/*End test_WOLFSSL_ERROR_MSG*/ /* * Testing wc_ERR_remove_state @@ -27174,13 +27173,11 @@ static int test_wc_ERR_remove_state (void) printf(testingFmt, "wc_ERR_remove_state()"); wc_ERR_remove_state(); - - printf(resultFmt, ret == 0 ? passed : failed); - -#endif - - return ret; + printf(resultFmt, ret == 0 ? passed : failed); + +#endif + return ret; }/*End test_wc_ERR_remove_state*/ /* * Testing wc_ERR_print_errors_fp @@ -27191,23 +27188,23 @@ static int test_wc_ERR_print_errors_fp (void) #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \ (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)) long sz; + printf(testingFmt, "wc_ERR_print_errors_fp()"); + WOLFSSL_ERROR(BAD_FUNC_ARG); - //XFILE fp = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb"); XFILE fp = XFOPEN("./test-log-dump-to-file.txt", "ar"); wc_ERR_print_errors_fp(fp); - + AssertTrue(XFSEEK(fp, 0, XSEEK_END) == 0); sz = XFTELL(fp); if (sz == 0) { ret = BAD_FUNC_ARG; - } - + } + printf(resultFmt, ret == 0 ? passed : failed); XFCLOSE(fp); #endif return ret; - }/*End test_wc_ERR_print_errors_fp*/ /* * Testing wolfSSL_GetLoggingCb @@ -33463,7 +33460,7 @@ static int test_wc_InitRngNonce(void) { int ret=0; #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \ - (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION >= 2)) + (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION >= 2)) WC_RNG rng; byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE" "\x45\xAC\x13\x7A\xE1\x48\xAF\x16"; @@ -33489,14 +33486,14 @@ static int test_wc_InitRngNonce_ex(void) { int ret=0; #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \ - (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION >= 2)) + (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION >= 2)) WC_RNG rng; byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE" "\x45\xAC\x13\x7A\xE1\x48\xAF\x16"; word32 nonceSz = sizeof(nonce); printf(testingFmt, "wc_InitRngNonce_ex()"); - + if (ret == 0){ ret = wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, devId); } From f7e4c1c8ad76e2dd076a1195d6b6120dcc52df38 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Wed, 22 Jul 2020 15:44:13 -0700 Subject: [PATCH 5/7] Added SetLoggingCb check --- tests/api.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/api.c b/tests/api.c index f81ffbb46..3664e615f 100644 --- a/tests/api.c +++ b/tests/api.c @@ -27206,17 +27206,47 @@ static int test_wc_ERR_print_errors_fp (void) #endif return ret; }/*End test_wc_ERR_print_errors_fp*/ +#ifdef DEBUG_WOLFSSL +static void Logging_cb(const int logLevel, const char *const logMessage) +{ + (void)logLevel; + (void)logMessage; +} +#endif /* * Testing wolfSSL_GetLoggingCb */ static int test_wolfSSL_GetLoggingCb (void) { int ret = 0; +#ifdef DEBUG_WOLFSSL printf(testingFmt, "wolfSSL_GetLoggingCb()"); - wolfSSL_GetLoggingCb(); - + /*Testing without wolfSSL_SetLoggingCb()*/ + if (ret == 0) { + if(wolfSSL_GetLoggingCb() == NULL){ /*Should be true*/ + ret = 0; + } + if(wolfSSL_GetLoggingCb() != NULL){ /*Should not be true*/ + ret = -1; + } + } + /*Testing with wolfSSL_SetLoggingCb()*/ + if (ret == 0) { + ret = wolfSSL_SetLoggingCb(Logging_cb); + if (ret == 0){ + if(wolfSSL_GetLoggingCb() == NULL){ /*Should not be true*/ + ret = -1; + } + if (ret == 0) { + if(wolfSSL_GetLoggingCb() == Logging_cb){ /*Should be true*/ + ret = 0; + } + } + } + } printf(resultFmt, ret == 0 ? passed : failed); +#endif return ret; }/*End test_wolfSSL_GetLoggingCb*/ static void test_wolfSSL_HMAC(void) From 563806c497faee5ee2f41300dcc51ddfe56425a6 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Thu, 23 Jul 2020 10:12:40 -0700 Subject: [PATCH 6/7] Changed the log dump txt file's directory to include /tests and added it to make clean --- Makefile.am | 3 ++- scripts/cleanup_testfiles.sh | 2 +- tests/api.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 37533fa23..94ce2f680 100644 --- a/Makefile.am +++ b/Makefile.am @@ -118,7 +118,8 @@ CLEANFILES+= cert.der \ pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256.der \ pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der \ pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256.der \ - pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der + pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der \ + tests/test-log-dump-to-file.txt exampledir = $(docdir)/example dist_example_DATA= diff --git a/scripts/cleanup_testfiles.sh b/scripts/cleanup_testfiles.sh index f4ffd6906..5d96211ed 100755 --- a/scripts/cleanup_testfiles.sh +++ b/scripts/cleanup_testfiles.sh @@ -12,4 +12,4 @@ rm -f ./certeccrsa.der rm -f ./ecc-key.der rm -f ./ecc-key.pem rm -f ./ecc-public-key.der -rm -f ./test-log-dump-to-file.txt +rm -f ./tests/test-log-dump-to-file.txt diff --git a/tests/api.c b/tests/api.c index 3664e615f..77e405484 100644 --- a/tests/api.c +++ b/tests/api.c @@ -27192,7 +27192,7 @@ static int test_wc_ERR_print_errors_fp (void) printf(testingFmt, "wc_ERR_print_errors_fp()"); WOLFSSL_ERROR(BAD_FUNC_ARG); - XFILE fp = XFOPEN("./test-log-dump-to-file.txt", "ar"); + XFILE fp = XFOPEN("./tests/test-log-dump-to-file.txt", "ar"); wc_ERR_print_errors_fp(fp); AssertTrue(XFSEEK(fp, 0, XSEEK_END) == 0); From 6088a7bd7904917d4b589f51a2f3c4da2fa72aa5 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Fri, 24 Jul 2020 10:03:49 -0700 Subject: [PATCH 7/7] Added if defined debug check to only print to file if debug is enabled --- tests/api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/api.c b/tests/api.c index 77e405484..842ae075a 100644 --- a/tests/api.c +++ b/tests/api.c @@ -27194,15 +27194,16 @@ static int test_wc_ERR_print_errors_fp (void) WOLFSSL_ERROR(BAD_FUNC_ARG); XFILE fp = XFOPEN("./tests/test-log-dump-to-file.txt", "ar"); wc_ERR_print_errors_fp(fp); - +#if defined(DEBUG_WOLFSSL) AssertTrue(XFSEEK(fp, 0, XSEEK_END) == 0); sz = XFTELL(fp); if (sz == 0) { ret = BAD_FUNC_ARG; } - +#endif printf(resultFmt, ret == 0 ? passed : failed); XFCLOSE(fp); + (void)sz; #endif return ret; }/*End test_wc_ERR_print_errors_fp*/