diff options
38 files changed, 408 insertions, 407 deletions
diff --git a/configure.ac b/configure.ac index 821c7bc86c..c2da2bb593 100644 --- a/configure.ac +++ b/configure.ac @@ -227,6 +227,7 @@ if test "$gl_gcc_warnings" = yes; then nw="$nw -Wformat-nonliteral" # Incompatible with gettext _() nw="$nw -Wunsafe-loop-optimizations" nw="$nw -Wstrict-overflow" + nw="$nw -Wmissing-noreturn" gl_MANYWARN_ALL_GCC([ws]) gl_MANYWARN_COMPLEMENT(ws, [$ws], [$nw]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 39dd595fe5..6f205331cf 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -97,4 +97,4 @@ TESTS_ENVIRONMENT = \ PKCS12FILE_2=$(srcdir)/pkcs12-decode/pkcs12_2certs.p12 \ PKCS12PASSWORD_2="" \ EXEEXT=$(EXEEXT) \ - $(VALGRIND) + $(VALGRIND) -q diff --git a/tests/anonself.c b/tests/anonself.c index fee0cd2a5b..9b0753e8e4 100644 --- a/tests/anonself.c +++ b/tests/anonself.c @@ -102,10 +102,10 @@ client (void) } else { - success ("client: Handshake was completed\n"); + if (debug) success ("client: Handshake was completed\n"); } - success ("client: TLS version is: %s\n", + if (debug) success ("client: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); gnutls_record_send (session, MSG, strlen (MSG)); @@ -113,7 +113,7 @@ client (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -122,12 +122,15 @@ client (void) goto end; } - printf ("- Received %d bytes: ", ret); - for (ii = 0; ii < ret; ii++) + if (debug) { - fputc (buffer[ii], stdout); + printf ("- Received %d bytes: ", ret); + for (ii = 0; ii < ret; ii++) + { + fputc (buffer[ii], stdout); + } + fputs ("\n", stdout); } - fputs ("\n", stdout); gnutls_bye (session, GNUTLS_SHUT_RDWR); @@ -236,7 +239,7 @@ server_start (void) return; } - success ("server: ready. Listening to port '%d'.\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'.\n", PORT); } static void @@ -252,7 +255,7 @@ server (void) gnutls_anon_allocate_server_credentials (&anoncred); - success ("Launched, generating DH parameters...\n"); + if (debug) success ("Launched, generating DH parameters...\n"); generate_dh_params (); @@ -264,7 +267,7 @@ server (void) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -277,9 +280,9 @@ server (void) fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); + if (debug) success ("server: Handshake was completed\n"); - success ("server: TLS version is: %s\n", + if (debug) success ("server: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); /* see the Getting peer's information example */ @@ -293,7 +296,7 @@ server (void) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -323,7 +326,7 @@ server (void) gnutls_global_deinit (); - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } void diff --git a/tests/certder.c b/tests/certder.c index b86d38dc28..3baa22d72f 100644 --- a/tests/certder.c +++ b/tests/certder.c @@ -325,7 +325,7 @@ doit (void) if (ret != GNUTLS_E_ASN1_DER_ERROR) fail ("crt3_import %d\n", ret); - success ("done\n"); + if (debug) success ("done\n"); gnutls_x509_crt_deinit (cert); diff --git a/tests/chainverify.c b/tests/chainverify.c index 3529aaee22..60bd0361e6 100644 --- a/tests/chainverify.c +++ b/tests/chainverify.c @@ -32,6 +32,8 @@ #include <gnutls/gnutls.h> #include <gnutls/x509.h> +#include "utils.h" + /* GnuTLS internally calls time() to find out the current time when verifying certificates. To avoid a time bomb, we hard code the current time. This should work fine on systems where the library @@ -754,8 +756,7 @@ tls_log_func (int level, const char *str) fprintf (stderr, "|<%d>| %s", level, str); } -int -main (int argc, char *argv[]) +void doit (void) { int exit_val = 0; size_t i; @@ -764,12 +765,13 @@ main (int argc, char *argv[]) ret = gnutls_global_init (); if (ret != 0) { - printf ("%d: %s\n", ret, gnutls_strerror (ret)); - return EXIT_FAILURE; + fail ("%d: %s\n", ret, gnutls_strerror (ret)); + exit(EXIT_FAILURE); } gnutls_global_set_log_function (tls_log_func); - gnutls_global_set_log_level (4711); + if (debug) + gnutls_global_set_log_level (4711); for (i = 0; chains[i].chain; i++) { @@ -779,11 +781,11 @@ main (int argc, char *argv[]) gnutls_datum_t tmp; size_t j; - printf ("Chain '%s' (%d)...\n", chains[i].name, (int) i); + if (debug) printf ("Chain '%s' (%d)...\n", chains[i].name, (int) i); for (j = 0; chains[i].chain[j]; j++) { - printf ("\tAdding certificate %d...", (int) j); + if (debug) printf ("\tAdding certificate %d...", (int) j); ret = gnutls_x509_crt_init (&certs[j]); if (ret < 0) @@ -794,17 +796,17 @@ main (int argc, char *argv[]) tmp.size = strlen (chains[i].chain[j]); ret = gnutls_x509_crt_import (certs[j], &tmp, GNUTLS_X509_FMT_PEM); - printf ("done\n"); + if (debug) printf ("done\n"); if (ret < 0) error (EXIT_FAILURE, 0, "gnutls_x509_crt_import[%d,%d]: %s", (int) i, (int) j, gnutls_strerror (ret)); gnutls_x509_crt_print (certs[j], GNUTLS_CRT_PRINT_ONELINE, &tmp); - printf ("\tCertificate %d: %.*s\n", (int) j, tmp.size, tmp.data); + if (debug) printf ("\tCertificate %d: %.*s\n", (int) j, tmp.size, tmp.data); gnutls_free (tmp.data); } - printf ("\tAdding CA certificate..."); + if (debug) printf ("\tAdding CA certificate..."); ret = gnutls_x509_crt_init (&ca); if (ret < 0) @@ -819,13 +821,13 @@ main (int argc, char *argv[]) error (EXIT_FAILURE, 0, "gnutls_x509_crt_import: %s", gnutls_strerror (ret)); - printf ("done\n"); + if (debug) printf ("done\n"); gnutls_x509_crt_print (ca, GNUTLS_CRT_PRINT_ONELINE, &tmp); - printf ("\tCA Certificate: %.*s\n", tmp.size, tmp.data); + if (debug) printf ("\tCA Certificate: %.*s\n", tmp.size, tmp.data); gnutls_free (tmp.data); - printf ("\tVerifying..."); + if (debug) printf ("\tVerifying..."); ret = gnutls_x509_crt_list_verify (certs, j, &ca, 1, NULL, 0, @@ -837,29 +839,25 @@ main (int argc, char *argv[]) if (verify_status != chains[i].expected_verify_result) { - error (0, 0, "verify_status: %d expected: %d", + fail("verify_status: %d expected: %d", verify_status, chains[i].expected_verify_result); - exit_val = 1; - if (argc > 1) - { - printf ("Exiting early with status...%d\n", exit_val); - return exit_val; - } + + if (debug) exit(1); } - else + else if (debug) printf ("done\n"); - printf ("\tCleanup..."); + if (debug) printf ("\tCleanup..."); gnutls_x509_crt_deinit (ca); for (j = 0; chains[i].chain[j]; j++) gnutls_x509_crt_deinit (certs[j]); - printf ("done\n"); + if (debug) printf ("done\n"); } gnutls_global_deinit (); - printf ("Exit status...%d\n", exit_val); + if (debug) printf ("Exit status...%d\n", exit_val); - return exit_val; + exit(exit_val); } diff --git a/tests/crq_apis.c b/tests/crq_apis.c index 6d875ef90e..bc71544a0e 100644 --- a/tests/crq_apis.c +++ b/tests/crq_apis.c @@ -76,7 +76,8 @@ doit (void) fail ("gnutls_global_init\n"); gnutls_global_set_log_function (tls_log_func); - gnutls_global_set_log_level (4711); + if (debug) + gnutls_global_set_log_level (4711); ret = gnutls_x509_crq_init (&crq); if (ret != 0) @@ -189,7 +190,7 @@ doit (void) ret = gnutls_x509_crq_print (crq, GNUTLS_CRT_PRINT_FULL, &out); if (ret != 0) fail ("gnutls_x509_crq_print\n"); - printf ("crq: %.*s\n", out.size, out.data); + if (debug) printf ("crq: %.*s\n", out.size, out.data); gnutls_free (out.data); ret = gnutls_x509_crt_set_version (crt, 3); @@ -203,7 +204,7 @@ doit (void) ret = gnutls_x509_crt_print (crt, GNUTLS_CRT_PRINT_FULL, &out); if (ret != 0) fail ("gnutls_x509_crt_print\n"); - printf ("crt: %.*s\n", out.size, out.data); + if (debug) printf ("crt: %.*s\n", out.size, out.data); gnutls_free (out.data); gnutls_x509_crq_deinit (crq); diff --git a/tests/crq_key_id.c b/tests/crq_key_id.c index 6c246bb8b5..7f28ef6496 100644 --- a/tests/crq_key_id.c +++ b/tests/crq_key_id.c @@ -62,7 +62,8 @@ doit (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); gnutls_global_set_log_function (tls_log_func); - gnutls_global_set_log_level (4711); + if (debug) + gnutls_global_set_log_level (4711); for (algorithm = GNUTLS_PK_RSA; algorithm <= GNUTLS_PK_DSA; algorithm++) { @@ -81,7 +82,7 @@ doit (void) { fail ("gnutls_x509_privkey_generate (rsa): %d\n", ret); } - else + else if (debug) { success ("Key[%s] generation ok: %d\n", gnutls_pk_algorithm_get_name (algorithm), ret); @@ -149,7 +150,7 @@ doit (void) ret = memcmp (crq_key_id, pkey_key_id, crq_key_id_len); if (ret == 0) { - success ("Key ids are identical. OK.\n"); + if (debug) success ("Key ids are identical. OK.\n"); } else { diff --git a/tests/cve-2009-1415.c b/tests/cve-2009-1415.c index 3f3561c59e..7c6f4e9052 100644 --- a/tests/cve-2009-1415.c +++ b/tests/cve-2009-1415.c @@ -95,7 +95,7 @@ main (void) if (ret < 0) return 1; - printf ("success!\n"); + //printf ("success!\n"); gnutls_x509_crt_deinit (crt); gnutls_global_deinit (); diff --git a/tests/dhepskself.c b/tests/dhepskself.c index 6f837766df..d3493f2d8a 100644 --- a/tests/dhepskself.c +++ b/tests/dhepskself.c @@ -66,7 +66,8 @@ client (void) gnutls_global_init (); gnutls_global_set_log_function (tls_log_func); -// gnutls_global_set_log_level (99); +// if (debug) +// gnutls_global_set_log_level (99); gnutls_psk_allocate_client_credentials (&pskcred); gnutls_psk_set_client_credentials (pskcred, "test", &key, @@ -101,7 +102,7 @@ client (void) } else { - success ("client: Handshake was completed\n"); + if (debug) success ("client: Handshake was completed\n"); } gnutls_record_send (session, MSG, strlen (MSG)); @@ -109,7 +110,7 @@ client (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -118,10 +119,13 @@ client (void) goto end; } - printf ("- Received %d bytes: ", ret); - for (ii = 0; ii < ret; ii++) - fputc (buffer[ii], stdout); - fputs ("\n", stdout); + if (debug) + { + printf ("- Received %d bytes: ", ret); + for (ii = 0; ii < ret; ii++) + fputc (buffer[ii], stdout); + fputs ("\n", stdout); + } gnutls_bye (session, GNUTLS_SHUT_RDWR); @@ -181,7 +185,7 @@ generate_dh_params (void) static int pskfunc (gnutls_session_t session, const char *username, gnutls_datum_t * key) { - printf ("psk callback to get %s's password\n", username); + if (debug) printf ("psk callback to get %s's password\n", username); key->data = gnutls_malloc (4); key->data[0] = 0xDE; key->data[1] = 0xAD; @@ -204,7 +208,7 @@ int optval = 1; static void server_start (void) { - success ("Launched, generating DH parameters...\n"); + if (debug) success ("Launched, generating DH parameters...\n"); /* Socket operations */ @@ -240,7 +244,7 @@ server_start (void) return; } - success ("server: ready. Listening to port '%d'.\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'.\n", PORT); } static void @@ -266,7 +270,7 @@ server (void) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -279,7 +283,7 @@ server (void) fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); + if (debug) success ("server: Handshake was completed\n"); /* see the Getting peer's information example */ /* print_info(session); */ @@ -292,7 +296,7 @@ server (void) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -322,7 +326,7 @@ server (void) gnutls_global_deinit (); - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } void diff --git a/tests/dn.c b/tests/dn.c index d6dfd5e010..79319cf083 100644 --- a/tests/dn.c +++ b/tests/dn.c @@ -80,7 +80,8 @@ print_dn (gnutls_x509_dn_t dn) } if (ret < 0) fail ("get_rdn_ava %d\n", ret); - printf ("dn[%d][%d] OID=%.*s\n\tDATA=%.*s\n", i, j, + if (debug) + printf ("dn[%d][%d] OID=%.*s\n\tDATA=%.*s\n", i, j, ava.oid.size, ava.oid.data, ava.value.size, ava.value.data); } } @@ -109,17 +110,23 @@ doit (void) if (ret < 0) fail ("get_issuer %d\n", ret); - printf ("Issuer:\n"); - print_dn (xdn); + if (debug) + { + printf ("Issuer:\n"); + print_dn (xdn); + } ret = gnutls_x509_crt_get_subject (cert, &xdn); if (ret < 0) fail ("get_subject %d\n", ret); - printf ("Subject:\n"); - print_dn (xdn); + if (debug) + { + printf ("Subject:\n"); + print_dn (xdn); + } - success ("done\n"); + if (debug) success ("done\n"); gnutls_x509_crt_deinit (cert); gnutls_global_deinit (); diff --git a/tests/dn2.c b/tests/dn2.c index de1ae6fba8..9b21690ec9 100644 --- a/tests/dn2.c +++ b/tests/dn2.c @@ -90,9 +90,7 @@ doit (void) if (ret < 0) fail ("x509_crt_print %d\n", ret); - if (out.size == strlen (info) && strcmp (out.data, info) == 0) - success ("comparison ok\n"); - else + if (out.size != strlen (info) || strcmp (out.data, info) != 0) fail ("comparison fail (%d/%d)\nexpect: %s\n got: %.*s\n", out.size, (int)strlen (info), info, out.size, out.data); @@ -100,5 +98,5 @@ doit (void) gnutls_global_deinit (); gnutls_free (out.data); - success ("done\n"); + if (debug) success ("done\n"); } diff --git a/tests/finished.c b/tests/finished.c index 9fea34a860..58df1afeba 100644 --- a/tests/finished.c +++ b/tests/finished.c @@ -49,7 +49,7 @@ size_t to_client_len; static ssize_t client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { - success ("client_pull len %d has %d\n", (int)len, (int)to_client_len); + if (debug) success ("client_pull len %d has %d\n", (int)len, (int)to_client_len); if (to_client_len < len) { @@ -71,8 +71,11 @@ client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) size_t newlen = to_server_len + len; char *tmp; - success ("client_push len %d has %d\n", (int)len, (int)to_server_len); - hexprint (data, len); + if (debug) + { + success ("client_push len %d has %d\n", (int)len, (int)to_server_len); + hexprint (data, len); + } tmp = realloc (to_server, newlen); if (!tmp) @@ -91,7 +94,7 @@ client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) static ssize_t server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { - success ("server_pull len %d has %d\n", (int)len, (int)to_server_len); + if (debug) success ("server_pull len %d has %d\n", (int)len, (int)to_server_len); if (to_server_len < len) { @@ -113,9 +116,11 @@ server_push (gnutls_transport_ptr_t tr, const void *data, size_t len) size_t newlen = to_client_len + len; char *tmp; - success ("server_push len %d has %d\n", (int)len, (int)to_client_len); - - hexprint (data, len); + if (debug) + { + success ("server_push len %d has %d\n", (int)len, (int)to_client_len); + hexprint (data, len); + } tmp = realloc (to_client, newlen); if (!tmp) @@ -135,16 +140,22 @@ static void client_finished_callback (gnutls_session_t session, const void *finished, size_t len) { - success ("client finished (length %d)\n", (int)len); - hexprint (finished, len); + if (debug) + { + success ("client finished (length %d)\n", (int)len); + hexprint (finished, len); + } } static void server_finished_callback (gnutls_session_t session, const void *finished, size_t len) { - success ("server finished (length %d)\n", (int)len); - hexprint (finished, len); + if (debug) + { + success ("server finished (length %d)\n", (int)len); + hexprint (finished, len); + } } #define MAX_BUF 1024 @@ -203,31 +214,31 @@ doit (void) { if (cret == GNUTLS_E_AGAIN) { - success ("loop invoking client:\n"); + if (debug) success ("loop invoking client:\n"); cret = gnutls_handshake (client); - success ("client %d: %s\n", cret, gnutls_strerror (cret)); + if (debug) success ("client %d: %s\n", cret, gnutls_strerror (cret)); } if (sret == GNUTLS_E_AGAIN) { - success ("loop invoking server:\n"); + if (debug) success ("loop invoking server:\n"); sret = gnutls_handshake (server); - success ("server %d: %s\n", sret, gnutls_strerror (sret)); + if (debug) success ("server %d: %s\n", sret, gnutls_strerror (sret)); } } while (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN); - success ("Handshake established\n"); + if (debug) success ("Handshake established\n"); ns = gnutls_record_send (client, MSG, strlen (MSG)); - success ("client: sent %d\n", (int)ns); + if (debug) success ("client: sent %d\n", (int)ns); ret = gnutls_record_recv (server, buffer, MAX_BUF); if (ret == 0) fail ("server: didn't receive any data\n"); else if (ret < 0) fail ("server: error: %s\n", gnutls_strerror (ret)); - else + else if (debug) { printf ("server: received %d: ", ret); for (n = 0; n < ret; n++) @@ -236,7 +247,7 @@ doit (void) } ns = gnutls_record_send (server, MSG, strlen (MSG)); - success ("server: sent %d\n", (int)ns); + if (debug) success ("server: sent %d\n", (int)ns); ret = gnutls_record_recv (client, buffer, MAX_BUF); if (ret == 0) @@ -247,7 +258,7 @@ doit (void) { fail ("client: Error: %s\n", gnutls_strerror (ret)); } - else + else if (debug) { printf ("client: received %d: ", ret); for (n = 0; n < ret; n++) diff --git a/tests/gc.c b/tests/gc.c index d9883a3a8b..47c927b8de 100644 --- a/tests/gc.c +++ b/tests/gc.c @@ -49,7 +49,9 @@ doit (void) { if (memcmp (digest, "\x3c\xb0\x9d\x83\x28\x01\xef\xc0" "\x7b\xb3\xaf\x42\x69\xe5\x93\x9a", 16) == 0) - success ("_gnutls_hmac_fast(MD5) OK\n"); + { + if (debug) success ("_gnutls_hmac_fast(MD5) OK\n"); + } else { hexprint (digest, 16); @@ -67,7 +69,9 @@ doit (void) if (memcmp (digest, "\x58\x93\x7a\x58\xfe\xea\x82\xf8" "\x0e\x64\x62\x01\x40\x2b\x2c\xed\x5d\x54\xc1\xfa", 20) == 0) - success ("_gnutls_hmac_fast(SHA1) OK\n"); + { + if (debug) success ("_gnutls_hmac_fast(SHA1) OK\n"); + } else { hexprint (digest, 20); @@ -82,7 +86,9 @@ doit (void) { if (memcmp (digest, "\x09\xb7\x85\x57\xdd\xf6\x07\x15" "\x1c\x52\x34\xde\xba\x5c\xdc\x59", 16) == 0) - success ("_gnutls_pkcs5_pbkdf2_sha1() OK\n"); + { + if (debug) success ("_gnutls_pkcs5_pbkdf2_sha1() OK\n"); + } else { hexprint (digest, 16); diff --git a/tests/hostname-check.c b/tests/hostname-check.c index 7cefa15130..5e9328d807 100644 --- a/tests/hostname-check.c +++ b/tests/hostname-check.c @@ -693,7 +693,7 @@ doit (void) fail ("gnutls_openpgp_crt_init: %d\n", ret); #endif - success ("Testing pem1...\n"); + if (debug) success ("Testing pem1...\n"); data.data = pem1; data.size = strlen (pem1); @@ -704,10 +704,8 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "foo"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); - success ("Testing pem2...\n"); + if (debug) success ("Testing pem2...\n"); data.data = pem2; data.size = strlen (pem2); @@ -718,22 +716,16 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "foo"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "www.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "*.example.org"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); - success ("Testing pem3...\n"); + if (debug) success ("Testing pem3...\n"); data.data = pem3; data.size = strlen (pem3); @@ -744,22 +736,16 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "foo"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "www.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "*.example.org"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); - success ("Testing pem4...\n"); + if (debug) success ("Testing pem4...\n"); data.data = pem4; data.size = strlen (pem4); @@ -770,28 +756,20 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "foo"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "www.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "foo.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "foo.example.com"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); - success ("Testing pem5...\n"); + if (debug) success ("Testing pem5...\n"); data.data = pem5; data.size = strlen (pem5); @@ -802,22 +780,16 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "foo"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "1.2.3.4"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "www.example.org"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); - success ("Testing pem6...\n"); + if (debug) success ("Testing pem6...\n"); data.data = pem6; data.size = strlen (pem6); @@ -828,16 +800,12 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "foo.example.org"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "bar.foo.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); - success ("Testing pem7...\n"); + if (debug) success ("Testing pem7...\n"); data.data = pem7; data.size = strlen (pem7); @@ -848,28 +816,20 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "foo.bar.example.org"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "foobar.bar.example.org"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "foobar.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "foobazbar.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); - success ("Testing pem8...\n"); + if (debug) success ("Testing pem8...\n"); data.data = pem8; data.size = strlen (pem8); @@ -878,30 +838,22 @@ doit (void) fail ("gnutls_x509_crt_import: %d\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "www.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "www.example."); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "www.example.com"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "www.example.foo.com"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); - success ("Testing pem9...\n"); + if (debug) success ("Testing pem9...\n"); data.data = pem9; data.size = strlen (pem9); @@ -912,16 +864,12 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "foo.example.org"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); ret = gnutls_x509_crt_check_hostname (x509, "bar.example.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); - success ("Testing pem10...\n"); + if (debug) success ("Testing pem10...\n"); data.data = pem10; data.size = strlen (pem10); @@ -932,11 +880,9 @@ doit (void) ret = gnutls_x509_crt_check_hostname (x509, "localhost"); if (ret) fail ("Hostname incorrectly matches (%d)\n", ret); - else - success ("Hostname correctly does not match (%d)\n", ret); #ifdef ENABLE_OPENPGP - success ("Testing pem11...\n"); + if (debug) success ("Testing pem11...\n"); data.data = pem11; data.size = strlen (pem11); @@ -945,9 +891,7 @@ doit (void) fail ("gnutls_openpgp_crt_import: %d\n", ret); ret = gnutls_openpgp_crt_check_hostname (pgp, "test.gnutls.org"); - if (ret) - success ("Hostname correctly matches (%d)\n", ret); - else + if (!ret) fail ("Hostname incorrectly does not match (%d)\n", ret); gnutls_openpgp_crt_deinit (pgp); diff --git a/tests/init_roundtrip.c b/tests/init_roundtrip.c index 1c6fca642c..e232f8de89 100644 --- a/tests/init_roundtrip.c +++ b/tests/init_roundtrip.c @@ -48,5 +48,5 @@ doit (void) gnutls_global_deinit (); - success ("init-deinit round-trip success\n"); + if (debug) success ("init-deinit round-trip success\n"); } diff --git a/tests/mini-eagain.c b/tests/mini-eagain.c index 3956b98911..872a16bd95 100644 --- a/tests/mini-eagain.c +++ b/tests/mini-eagain.c @@ -225,7 +225,7 @@ doit (void) } while (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN); handshake = 0; - success ("Handshake established\n"); + if (debug) success ("Handshake established\n"); ns = gnutls_record_send (client, MSG, strlen (MSG)); //success ("client: sent %d\n", ns); @@ -248,7 +248,7 @@ doit (void) else { transferred += ret; - fputs ("*", stdout); + if (debug) fputs ("*", stdout); } ns = gnutls_record_send (server, MSG, strlen (MSG)); @@ -270,11 +270,11 @@ doit (void) else { transferred += ret; - fputs (".", stdout); + if (debug) fputs (".", stdout); } } while (transferred < 7000); - fputs ("\n", stdout); + if (debug) fputs ("\n", stdout); gnutls_bye (client, GNUTLS_SHUT_RDWR); gnutls_bye (server, GNUTLS_SHUT_RDWR); diff --git a/tests/mini.c b/tests/mini.c index cef2cc457b..0813e5d23f 100644 --- a/tests/mini.c +++ b/tests/mini.c @@ -47,7 +47,8 @@ size_t to_client_len; static ssize_t client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { - success ("client_pull len %d has %d\n", (int)len, (int)to_client_len); + if (debug) + success ("client_pull len %d has %d\n", (int)len, (int)to_client_len); if (to_client_len < len) { @@ -69,8 +70,11 @@ client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) size_t newlen = to_server_len + len; char *tmp; - success ("client_push len %d has %d\n", (int)len, (int)to_server_len); - hexprint (data, len); + if (debug) + { + success ("client_push len %d has %d\n", (int)len, (int)to_server_len); + hexprint (data, len); + } tmp = realloc (to_server, newlen); if (!tmp) @@ -89,7 +93,8 @@ client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) static ssize_t server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { - success ("server_pull len %d has %d\n", (int)len, (int)to_server_len); + if (debug) + success ("server_pull len %d has %d\n", (int)len, (int)to_server_len); if (to_server_len < len) { @@ -111,9 +116,11 @@ server_push (gnutls_transport_ptr_t tr, const void *data, size_t len) size_t newlen = to_client_len + len; char *tmp; - success ("server_push len %d has %d\n", (int)len, (int)to_client_len); - - hexprint (data, len); + if (debug) + { + success ("server_push len %d has %d\n", (int)len, (int)to_client_len); + hexprint (data, len); + } tmp = realloc (to_client, newlen); if (!tmp) @@ -183,24 +190,25 @@ doit (void) { if (cret == GNUTLS_E_AGAIN) { - success ("loop invoking client:\n"); + if (debug) + success ("loop invoking client:\n"); cret = gnutls_handshake (client); - success ("client %d: %s\n", cret, gnutls_strerror (cret)); + if (debug) success ("client %d: %s\n", cret, gnutls_strerror (cret)); } if (sret == GNUTLS_E_AGAIN) { - success ("loop invoking server:\n"); + if (debug) success ("loop invoking server:\n"); sret = gnutls_handshake (server); - success ("server %d: %s\n", sret, gnutls_strerror (sret)); + if (debug) success ("server %d: %s\n", sret, gnutls_strerror (sret)); } } while (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN); - success ("Handshake established\n"); + if (debug) success ("Handshake established\n"); ns = gnutls_record_send (client, MSG, strlen (MSG)); - success ("client: sent %d\n", (int)ns); + if (debug) success ("client: sent %d\n", (int)ns); ret = gnutls_record_recv (server, buffer, MAX_BUF); if (ret == 0) @@ -209,14 +217,17 @@ doit (void) fail ("server: error: %s\n", gnutls_strerror (ret)); else { - printf ("server: received %d: ", ret); - for (n = 0; n < ret; n++) - fputc (buffer[n], stdout); - fputs ("\n", stdout); + if (debug) + { + printf ("server: received %d: ", ret); + for (n = 0; n < ret; n++) + fputc (buffer[n], stdout); + fputs ("\n", stdout); + } } ns = gnutls_record_send (server, MSG, strlen (MSG)); - success ("server: sent %d\n", (int)ns); + if (debug) success ("server: sent %d\n", (int)ns); ret = gnutls_record_recv (client, buffer, MAX_BUF); if (ret == 0) @@ -229,10 +240,13 @@ doit (void) } else { - printf ("client: received %d: ", ret); - for (n = 0; n < ret; n++) - fputc (buffer[n], stdout); - fputs ("\n", stdout); + if (debug) + { + printf ("client: received %d: ", ret); + for (n = 0; n < ret; n++) + fputc (buffer[n], stdout); + fputs ("\n", stdout); + } } gnutls_bye (client, GNUTLS_SHUT_RDWR); diff --git a/tests/moredn.c b/tests/moredn.c index 396accb5f1..d8782df282 100644 --- a/tests/moredn.c +++ b/tests/moredn.c @@ -67,51 +67,35 @@ doit (void) gnutls_global_init (); - if (gnutls_x509_crt_init (&cert) == 0) - success ("success: cert init\n"); - else + if (gnutls_x509_crt_init (&cert) != 0) fail ("cert init failure\n"); - if (gnutls_x509_crt_import (cert, &cert_datum, GNUTLS_X509_FMT_PEM) == 0) - success ("success: imported PEM cert\n"); - else + if (gnutls_x509_crt_import (cert, &cert_datum, GNUTLS_X509_FMT_PEM) != 0) fail ("FAIL: could not import PEM cert\n"); - if (gnutls_x509_crt_get_subject (cert, &sdn) == 0) - success ("success: got subject DN.\n"); - else + if (gnutls_x509_crt_get_subject (cert, &sdn) != 0) fail ("FAIL: could not get subject DN.\n"); buflen = sizeof buf; rv = gnutls_x509_dn_export (sdn, GNUTLS_X509_FMT_DER, buf, &buflen); - if (rv == 0) - success ("success: exported subject DN.\n"); - else + if (rv != 0) fail ("FAIL: could not export subject DN: %s\n", gnutls_strerror (rv)); - if (gnutls_x509_dn_init (&dn2) == 0) - success ("success: init DN.\n"); - else + if (gnutls_x509_dn_init (&dn2) != 0) fail ("FAIL: DN init.\n"); datum.data = buf; datum.size = buflen; - if (gnutls_x509_dn_import (dn2, &datum) == 0) - success ("success: re-import subject DN.\n"); - else + if (gnutls_x509_dn_import (dn2, &datum) != 0) fail ("FAIL: re-import subject DN.\n"); buf2len = sizeof buf2; rv = gnutls_x509_dn_export (dn2, GNUTLS_X509_FMT_DER, buf2, &buf2len); - if (rv == 0) - success ("success: exported subject DN.\n"); - else + if (rv != 0) fail ("FAIL: could not export subject DN: %s\n", gnutls_strerror (rv)); - if (buflen == buf2len && memcmp (buf, buf2, buflen) == 0) - success ("success: export/import/export match.\n"); - else + if (buflen == buf2len && memcmp (buf, buf2, buflen) != 0) fail ("FAIL: export/import/export differ.\n"); gnutls_x509_dn_deinit (dn2); diff --git a/tests/mpi.c b/tests/mpi.c index 73c3381013..2a4249b93a 100644 --- a/tests/mpi.c +++ b/tests/mpi.c @@ -48,7 +48,8 @@ doit (void) gnutls_global_init (); gnutls_global_set_log_function (tls_log_func); - gnutls_global_set_log_level (99); + if (debug) + gnutls_global_set_log_level (99); n1 = _gnutls_mpi_new (1000); if (n1 == NULL) diff --git a/tests/netconf-psk.c b/tests/netconf-psk.c index 6f82da679d..6b03257ac2 100644 --- a/tests/netconf-psk.c +++ b/tests/netconf-psk.c @@ -51,11 +51,14 @@ doit (void) gnutls_global_init (); gnutls_global_set_log_function (tls_log_func); - gnutls_global_set_log_level (2); + if (debug) + gnutls_global_set_log_level (2); if (gnutls_psk_netconf_derive_key ("password", "psk_identity", "psk_identity_hint", &key) == 0) - success ("success: gnutls_psk_netconf_derive_key\n"); + { + if (debug) success ("success: gnutls_psk_netconf_derive_key\n"); + } else fail ("gnutls_psk_netconf_derive_key failure\n"); @@ -63,7 +66,9 @@ doit (void) hexprint (key.data, key.size); if (key.size == 20 && memcmp (key.data, known, 20) == 0) - success ("success: match.\n"); + { + if (debug) success ("success: match.\n"); + } else fail ("FAIL: key differ.\n"); diff --git a/tests/nul-in-x509-names.c b/tests/nul-in-x509-names.c index 1b31bb8028..c4b85f7a6b 100644 --- a/tests/nul-in-x509-names.c +++ b/tests/nul-in-x509-names.c @@ -30,6 +30,8 @@ #include <gnutls/gnutls.h> #include <gnutls/x509.h> +#include "utils.h" + /* Thanks to Tomas Hoger <thoger@redhat.com> for generating the two certs that trigger this bug. */ @@ -88,66 +90,61 @@ const gnutls_datum_t badguy_nul_san = { badguy_nul_san_data, sizeof (badguy_nul_san_data) }; -int -main (void) +void doit(void) { gnutls_x509_crt_t crt; int ret; - int exit_code = 0; ret = gnutls_global_init (); if (ret < 0) { - puts ("gnutls_global_init"); - return 1; + fail ("gnutls_global_init"); + exit(1); } ret = gnutls_x509_crt_init (&crt); if (ret != 0) { - puts ("gnutls_x509_crt_init"); - return 1; + fail("gnutls_x509_crt_init"); + exit(1); } ret = gnutls_x509_crt_import (crt, &badguy_nul_cn, GNUTLS_X509_FMT_PEM); if (ret < 0) { - puts ("gnutls_x509_crt_import"); - return 1; + fail("gnutls_x509_crt_import"); + exit(1); } ret = gnutls_x509_crt_check_hostname (crt, "www.bank.com"); if (ret == 0) { - puts ("gnutls_x509_crt_check_hostname OK (NUL-IN-CN)"); + if (debug) success("gnutls_x509_crt_check_hostname OK (NUL-IN-CN)"); } else { - puts ("gnutls_x509_crt_check_hostname BROKEN (NUL-IN-CN)"); - exit_code = 1; + fail("gnutls_x509_crt_check_hostname BROKEN (NUL-IN-CN)"); } ret = gnutls_x509_crt_import (crt, &badguy_nul_san, GNUTLS_X509_FMT_PEM); if (ret < 0) { - puts ("gnutls_x509_crt_import"); - return 1; + fail ("gnutls_x509_crt_import"); + exit(1); } ret = gnutls_x509_crt_check_hostname (crt, "www.bank.com"); if (ret == 0) { - puts ("gnutls_x509_crt_check_hostname OK (NUL-IN-SAN)"); + if (debug) success("gnutls_x509_crt_check_hostname OK (NUL-IN-SAN)"); } else { - puts ("gnutls_x509_crt_check_hostname BROKEN (NUL-IN-SAN)"); - exit_code = 1; + fail("gnutls_x509_crt_check_hostname BROKEN (NUL-IN-SAN)"); } gnutls_x509_crt_deinit (crt); gnutls_global_deinit (); - return exit_code; } diff --git a/tests/openpgp-keyring.c b/tests/openpgp-keyring.c index 5cd50a58a2..df69ad1a4e 100644 --- a/tests/openpgp-keyring.c +++ b/tests/openpgp-keyring.c @@ -199,7 +199,8 @@ doit (void) fail ("init %d\n", ret); gnutls_global_set_log_function (tls_log_func); - gnutls_global_set_log_level (2); + if (debug) + gnutls_global_set_log_level (2); ret = gnutls_global_init_extra (); if (ret < 0) @@ -228,7 +229,7 @@ doit (void) if (ret != 0) fail ("keyring-check-id second key %d\n", ret); - success ("done\n"); + if (debug) success ("done\n"); gnutls_openpgp_keyring_deinit (keyring); gnutls_global_deinit (); diff --git a/tests/openpgpself.c b/tests/openpgpself.c index 67b84b7afb..edc42425ac 100644 --- a/tests/openpgpself.c +++ b/tests/openpgpself.c @@ -113,13 +113,14 @@ client (void) gnutls_global_init (); gnutls_global_set_log_function (tls_log_func); - gnutls_global_set_log_level (2); + if (debug) + gnutls_global_set_log_level (2); gnutls_certificate_allocate_credentials (&xcred); /* sets the trusted cas file */ - success ("Setting key files...\n"); + if (debug) success ("Setting key files...\n"); ret = gnutls_certificate_set_openpgp_key_mem (xcred, &cert, &key, GNUTLS_OPENPGP_FMT_BASE64); @@ -141,7 +142,7 @@ client (void) /* connect to the peer */ - success ("Connecting...\n"); + if (debug) success ("Connecting...\n"); sd = tcp_connect (); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); @@ -156,23 +157,23 @@ client (void) gnutls_perror (ret); goto end; } - else + else if (debug) { success ("client: Handshake was completed\n"); } - success ("client: TLS version is: %s\n", + if (debug) success ("client: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); /* see the Getting peer's information example */ - print_info (session); + if (debug) print_info (session); gnutls_record_send (session, MSG, strlen (MSG)); ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -181,12 +182,15 @@ client (void) goto end; } - printf ("- Received %d bytes: ", ret); - for (ii = 0; ii < ret; ii++) + if (debug) { - fputc (buffer[ii], stdout); + printf ("- Received %d bytes: ", ret); + for (ii = 0; ii < ret; ii++) + { + fputc (buffer[ii], stdout); + } + fputs ("\n", stdout); } - fputs ("\n", stdout); gnutls_bye (session, GNUTLS_SHUT_RDWR); @@ -372,7 +376,7 @@ server_start (void) return; } - success ("server: ready. Listening to port '%d'.\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'.\n", PORT); } static void @@ -396,7 +400,7 @@ server (void) fail ("Could not set server key files...\n"); } - success ("Launched, setting DH parameters...\n"); + if (debug) success ("Launched, setting DH parameters...\n"); generate_dh_params (); @@ -408,7 +412,7 @@ server (void) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -421,13 +425,13 @@ server (void) fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); + if (debug) success ("server: Handshake was completed\n"); - success ("server: TLS version is: %s\n", + if (debug) success ("server: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); /* see the Getting peer's information example */ - print_info (session); + if (debug) print_info (session); i = 0; for (;;) @@ -437,7 +441,7 @@ server (void) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -467,7 +471,7 @@ server (void) gnutls_global_deinit (); - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } diff --git a/tests/openssl.c b/tests/openssl.c index 8d1d8d4228..66ec586898 100644 --- a/tests/openssl.c +++ b/tests/openssl.c @@ -53,6 +53,6 @@ doit (void) hexprint (md, sizeof (md)); fail ("MD5 failure\n"); } - else + else if (debug) success ("MD5 OK\n"); } diff --git a/tests/parse_ca.c b/tests/parse_ca.c index b8900f5473..c02124a43f 100644 --- a/tests/parse_ca.c +++ b/tests/parse_ca.c @@ -76,5 +76,5 @@ doit (void) gnutls_global_deinit (); - success ("import ok\n"); + if (debug) success ("import ok\n"); } diff --git a/tests/pkcs12_encode.c b/tests/pkcs12_encode.c index f9a44c99ec..18c3fe8684 100644 --- a/tests/pkcs12_encode.c +++ b/tests/pkcs12_encode.c @@ -28,6 +28,8 @@ #include <gnutls/x509.h> #include <gnutls/pkcs12.h> +#include "utils.h" + #include <error.h> #include <stdio.h> #include <stdlib.h> @@ -63,8 +65,7 @@ static char ca_pem[] = "PfqUpIhz5Bbm7J4=\n" "-----END CERTIFICATE-----\n"; const gnutls_datum_t ca_dat = { ca_pem, sizeof (ca_pem) }; -int -main (void) +void doit(void) { gnutls_pkcs12_t pkcs12; gnutls_x509_crt_t client; @@ -157,7 +158,7 @@ main (void) if (ret < 0) error (EXIT_FAILURE, 0, "pkcs12_export: %d", ret); - fwrite (outbuf, size, 1, stdout); + if (debug) fwrite (outbuf, size, 1, stdout); /* Cleanup. */ gnutls_pkcs12_deinit (pkcs12); @@ -165,5 +166,4 @@ main (void) gnutls_x509_crt_deinit (ca); gnutls_global_deinit (); - return 0; } diff --git a/tests/pkcs12_s2k.c b/tests/pkcs12_s2k.c index 747c4ea7b3..447d628359 100644 --- a/tests/pkcs12_s2k.c +++ b/tests/pkcs12_s2k.c @@ -117,7 +117,8 @@ doit (void) gnutls_global_init (); gnutls_global_set_log_function (tls_log_func); - gnutls_global_set_log_level (99); + if (debug) + gnutls_global_set_log_level (99); x = 0; for (i = 1; i < 4; i++) @@ -135,12 +136,13 @@ doit (void) tmp, sizeof (tmp)), values[x]) != 0) fail ("_gnutls_pkcs12_string_to_key failed[1]\n"); - printf ("ij: %d.%d: %s\n", i, j, + if (debug) + printf ("ij: %d.%d: %s\n", i, j, _gnutls_bin2hex (key, sizeof (key), tmp, sizeof (tmp))); x++; } } - printf ("\n"); + if (debug) printf ("\n"); for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) { @@ -155,12 +157,13 @@ doit (void) tv[i].key, tv[i].keylen) != 0) fail ("_gnutls_pkcs12_string_to_key failed[3]\n"); - printf ("tv[%d]: %s\n", i, + if (debug) + printf ("tv[%d]: %s\n", i, _gnutls_bin2hex (key, tv[i].keylen, tmp, sizeof (tmp))); } - printf ("\n"); + if (debug) printf ("\n"); gnutls_global_deinit (); - success ("_gnutls_pkcs12_string_to_key ok\n"); + if (debug) success ("_gnutls_pkcs12_string_to_key ok\n"); } diff --git a/tests/pskself.c b/tests/pskself.c index 750e48d646..b4181188ed 100644 --- a/tests/pskself.c +++ b/tests/pskself.c @@ -94,7 +94,7 @@ client (void) } else { - success ("client: Handshake was completed\n"); + if (debug) success ("client: Handshake was completed\n"); } gnutls_record_send (session, MSG, strlen (MSG)); @@ -102,7 +102,7 @@ client (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -166,7 +166,7 @@ initialize_tls_session (void) static int pskfunc (gnutls_session_t session, const char *username, gnutls_datum_t * key) { - printf ("psk: username %s\n", username); + if (debug) printf ("psk: username %s\n", username); key->data = gnutls_malloc (4); key->data[0] = 0xDE; key->data[1] = 0xAD; @@ -189,7 +189,7 @@ int optval = 1; static void server_start (void) { - success ("Launched...\n"); + if (debug) success ("Launched...\n"); /* Socket operations */ @@ -225,7 +225,7 @@ server_start (void) return; } - success ("server: ready. Listening to port '%d'.\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'.\n", PORT); } static void @@ -244,7 +244,7 @@ server (void) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -257,7 +257,7 @@ server (void) fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); + if (debug) success ("server: Handshake was completed\n"); /* see the Getting peer's information example */ /* print_info(session); */ @@ -270,7 +270,7 @@ server (void) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -298,7 +298,7 @@ server (void) gnutls_global_deinit (); - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } void diff --git a/tests/resume.c b/tests/resume.c index afcc634ab1..1faf0b17d7 100644 --- a/tests/resume.c +++ b/tests/resume.c @@ -153,7 +153,7 @@ client (struct params_res *params) } else { - success ("client: Handshake was completed\n"); + if (debug) success ("client: Handshake was completed\n"); } if (t == 0) @@ -170,7 +170,9 @@ client (struct params_res *params) if (gnutls_session_is_resumed (session) != 0) { if (params->expect_resume) - success ("- Previous session was resumed\n"); + { + if (debug) success ("- Previous session was resumed\n"); + } else fail ("- Previous session was resumed\n"); } @@ -179,7 +181,9 @@ client (struct params_res *params) if (params->expect_resume) fail ("*** Previous session was NOT resumed\n"); else - success ("*** Previous session was NOT resumed (expected)\n"); + { + if (debug) success ("*** Previous session was NOT resumed (expected)\n"); + } } } @@ -188,7 +192,7 @@ client (struct params_res *params) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -326,13 +330,13 @@ global_start (void) return; } - success ("server: ready. Listening to port '%d'.\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'.\n", PORT); } static void global_stop (void) { - success ("global stop\n"); + if (debug) success ("global stop\n"); gnutls_anon_free_server_credentials (anoncred); @@ -359,7 +363,7 @@ server (struct params_res *params) gnutls_global_init (); gnutls_anon_allocate_server_credentials (&anoncred); - success ("Launched, generating DH parameters...\n"); + if (debug) success ("Launched, generating DH parameters...\n"); generate_dh_params (); @@ -382,7 +386,7 @@ server (struct params_res *params) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -396,7 +400,7 @@ server (struct params_res *params) gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); + if (debug) success ("server: Handshake was completed\n"); /* see the Getting peer's information example */ /* print_info(session); */ @@ -409,7 +413,7 @@ server (struct params_res *params) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -443,7 +447,7 @@ server (struct params_res *params) gnutls_free (session_ticket_key.data); session_ticket_key.data = NULL; - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } void @@ -453,7 +457,7 @@ doit (void) for (i = 0; resume_tests[i].desc; i++) { - printf ("%s\n", resume_tests[i].desc); + if (debug) printf ("%s\n", resume_tests[i].desc); global_start (); if (error_count) @@ -523,7 +527,7 @@ wrap_db_deinit (void) static int wrap_db_store (void *dbf, gnutls_datum_t key, gnutls_datum_t data) { - success ("resume db storing... (%d-%d)\n", key.size, data.size); + if (debug) success ("resume db storing... (%d-%d)\n", key.size, data.size); if (debug) { @@ -572,7 +576,7 @@ wrap_db_fetch (void *dbf, gnutls_datum_t key) gnutls_datum_t res = { NULL, 0 }; int i; - success ("resume db fetch... (%d)\n", key.size); + if (debug) success ("resume db fetch... (%d)\n", key.size); if (debug) { unsigned int i; @@ -594,7 +598,7 @@ wrap_db_fetch (void *dbf, gnutls_datum_t key) if (key.size == cache_db[i].session_id_size && memcmp (key.data, cache_db[i].session_id, key.size) == 0) { - success ("resume db fetch... return info\n"); + if (debug) success ("resume db fetch... return info\n"); res.size = cache_db[i].session_data_size; diff --git a/tests/set_pkcs12_cred.c b/tests/set_pkcs12_cred.c index d15ae76b79..200f8b661a 100644 --- a/tests/set_pkcs12_cred.c +++ b/tests/set_pkcs12_cred.c @@ -51,7 +51,7 @@ doit (void) if (!password) password = "foobar"; - success ("Reading PKCS#12 blob from `%s' using password `%s'.\n", + if (debug) success ("Reading PKCS#12 blob from `%s' using password `%s'.\n", file, password); ret = gnutls_certificate_set_x509_simple_pkcs12_file (x509cred, file, @@ -60,7 +60,7 @@ doit (void) if (ret < 0) fail ("x509_pkcs12 failed %d: %s\n", ret, gnutls_strerror (ret)); - success ("Read file OK\n"); + if (debug) success ("Read file OK\n"); gnutls_certificate_free_credentials (x509cred); @@ -79,7 +79,7 @@ doit (void) if (!password) password = ""; - success ("Reading PKCS#12 blob from `%s' using password `%s'.\n", + if (debug) success ("Reading PKCS#12 blob from `%s' using password `%s'.\n", file, password); ret = gnutls_certificate_set_x509_simple_pkcs12_file (x509cred, file, @@ -88,7 +88,7 @@ doit (void) if (ret < 0) fail ("x509_pkcs12 failed %d: %s\n", ret, gnutls_strerror (ret)); - success ("Read file OK\n"); + if (debug) success ("Read file OK\n"); gnutls_certificate_free_credentials (x509cred); diff --git a/tests/sha2/sha2 b/tests/sha2/sha2 index 3b77615a27..9170ce1bd8 100755 --- a/tests/sha2/sha2 +++ b/tests/sha2/sha2 @@ -31,7 +31,7 @@ echo cn = "SHA 512 CA" >> template $CERTTOOL --generate-self-signed --template template \ --load-privkey $srcdir/key-ca.pem \ --outfile new-ca.pem \ - --hash sha512 + --hash sha512 >/dev/null 2>&1 echo ca > template echo cn = "SHA 384 sub-CA" >> template @@ -41,7 +41,7 @@ $CERTTOOL --generate-certificate --template template \ --load-ca-certificate new-ca.pem \ --load-privkey $srcdir/key-subca.pem \ --outfile new-subca.pem \ - --hash sha384 + --hash sha384 >/dev/null 2>&1 echo ca > template echo cn = "SHA 256 sub-sub-CA" >> template @@ -51,7 +51,7 @@ $CERTTOOL --generate-certificate --template template \ --load-ca-certificate new-subca.pem \ --load-privkey $srcdir/key-subsubca.pem \ --outfile new-subsubca.pem \ - --hash sha256 + --hash sha256 >/dev/null 2>&1 echo ca > template echo cn = "End-user" >> template @@ -60,17 +60,15 @@ $CERTTOOL --generate-certificate --template template \ --load-ca-privkey $srcdir/key-subsubca.pem \ --load-ca-certificate new-subsubca.pem \ --load-privkey $srcdir/key-user.pem \ - --outfile new-user.pem + --outfile new-user.pem >/dev/null 2>&1 num=`cat new-user.pem new-subsubca.pem new-subca.pem new-ca.pem | $CERTTOOL --verify-chain | tee verify | grep -c Verified` -cat verify +#cat verify if test "$num" != "5"; then echo Verification failure exit 1 -else - echo Test OK fi rm -f verify new-user.pem new-subsubca.pem new-subca.pem new-ca.pem template diff --git a/tests/simple.c b/tests/simple.c index 0465bfaa80..3449de1a28 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -32,12 +32,13 @@ void doit (void) { - printf ("GnuTLS header version %s.\n", GNUTLS_VERSION); - printf ("GnuTLS library version %s.\n", gnutls_check_version (NULL)); + if (debug) + { + printf ("GnuTLS header version %s.\n", GNUTLS_VERSION); + printf ("GnuTLS library version %s.\n", gnutls_check_version (NULL)); + } - if (gnutls_check_version (GNUTLS_VERSION)) - success ("gnutls_check_version OK\n"); - else + if (!gnutls_check_version (GNUTLS_VERSION)) fail ("gnutls_check_version ERROR\n"); { @@ -51,7 +52,7 @@ doit (void) for (i = 0; algs[i]; i++) { - printf ("pk_list[%d] = %d = %s = %d\n", (int)i, algs[i], + if (debug) printf ("pk_list[%d] = %d = %s = %d\n", (int)i, algs[i], gnutls_pk_algorithm_get_name (algs[i]), gnutls_pk_get_id (gnutls_pk_algorithm_get_name (algs[i]))); if (gnutls_pk_get_id (gnutls_pk_algorithm_get_name (algs[i])) @@ -63,7 +64,7 @@ doit (void) if (pk != GNUTLS_PK_UNKNOWN) fail ("gnutls_pk unknown test failed (%d)\n", pk); - success ("gnutls_pk_list ok\n"); + if (debug) success ("gnutls_pk_list ok\n"); } { @@ -77,7 +78,8 @@ doit (void) for (i = 0; algs[i]; i++) { - printf ("sign_list[%d] = %d = %s = %d\n", (int)i, algs[i], + if (debug) + printf ("sign_list[%d] = %d = %s = %d\n", (int)i, algs[i], gnutls_sign_algorithm_get_name (algs[i]), gnutls_sign_get_id (gnutls_sign_algorithm_get_name (algs[i]))); @@ -90,6 +92,6 @@ doit (void) if (pk != GNUTLS_PK_UNKNOWN) fail ("gnutls_sign unknown test failed (%d)\n", pk); - success ("gnutls_sign_list ok\n"); + if (debug) success ("gnutls_sign_list ok\n"); } } diff --git a/tests/tlsia.c b/tests/tlsia.c index bce5f84d23..9e6bd6c785 100644 --- a/tests/tlsia.c +++ b/tests/tlsia.c @@ -58,11 +58,14 @@ client_avp (gnutls_session_t session, void *ptr, static int iter = 0; const char *p; - if (last) - printf ("client: received %d bytes AVP: `%.*s'\n", + if (debug) + { + if (last) + printf ("client: received %d bytes AVP: `%.*s'\n", (int)lastlen, (int) lastlen, last); - else - printf ("client: new application phase\n"); + else + printf ("client: new application phase\n"); + } switch (iter) { @@ -94,7 +97,7 @@ client_avp (gnutls_session_t session, void *ptr, return -1; *newlen = strlen (*new); - printf ("client: sending %d bytes AVP: `%s'\n", (int)*newlen, *new); + if (debug) printf ("client: sending %d bytes AVP: `%s'\n", (int)*newlen, *new); gnutls_ia_permute_inner_secret (session, 3, "foo"); @@ -156,7 +159,7 @@ client (void) } else { - success ("client: Handshake was completed\n"); + if (debug) success ("client: Handshake was completed\n"); } /* @@ -170,7 +173,7 @@ client (void) fail ("client: No TLS/IA negotiation\n"); else { - success ("client: TLS/IA handshake\n"); + if (debug) success ("client: TLS/IA handshake\n"); ret = gnutls_ia_handshake (session); @@ -182,7 +185,7 @@ client (void) } else { - success ("client: TLS/IA Handshake was completed\n"); + if (debug) success ("client: TLS/IA Handshake was completed\n"); } } @@ -191,7 +194,7 @@ client (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -290,7 +293,7 @@ server_avp (gnutls_session_t session, void *ptr, static int iter = 0; const char *p; - if (last) + if (last && debug) printf ("server: received %d bytes AVP: `%.*s'\n", (int)lastlen, (int) lastlen, last); @@ -341,13 +344,13 @@ server_avp (gnutls_session_t session, void *ptr, if (strcmp (p, "1") == 0) { - success ("server: Sending IntermediatePhaseFinished...\n"); + if (debug) success ("server: Sending IntermediatePhaseFinished...\n"); return 1; } if (strcmp (p, "2") == 0) { - success ("server: Sending FinalPhaseFinished...\n"); + if (debug) success ("server: Sending FinalPhaseFinished...\n"); return 2; } @@ -356,7 +359,7 @@ server_avp (gnutls_session_t session, void *ptr, return -1; *newlen = strlen (*new); - printf ("server: sending %d bytes AVP: `%s'\n", (int)*newlen, *new); + if (debug) printf ("server: sending %d bytes AVP: `%s'\n", (int)*newlen, *new); return 0; } @@ -398,7 +401,7 @@ server_start (void) return; } - success ("server: ready. Listening to port '%d'\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'\n", PORT); } static void @@ -416,7 +419,7 @@ server (void) gnutls_anon_allocate_server_credentials (&anoncred); gnutls_ia_allocate_server_credentials (&iacred); - success ("Launched, generating DH parameters...\n"); + if (debug) success ("Launched, generating DH parameters...\n"); generate_dh_params (); @@ -428,7 +431,7 @@ server (void) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -446,13 +449,13 @@ server (void) fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); + if (debug) success ("server: Handshake was completed\n"); if (!gnutls_ia_handshake_p (session)) fail ("server: No TLS/IA negotiation\n"); else { - success ("server: TLS/IA handshake\n"); + if (debug) success ("server: TLS/IA handshake\n"); ret = gnutls_ia_handshake (session); @@ -464,7 +467,7 @@ server (void) } else { - success ("server: TLS/IA Handshake was completed\n"); + if (debug) success ("server: TLS/IA Handshake was completed\n"); } } @@ -479,7 +482,7 @@ server (void) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -521,7 +524,7 @@ server (void) gnutls_global_deinit (); - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } void diff --git a/tests/x509_altname.c b/tests/x509_altname.c index eef77f7490..569aca96d2 100644 --- a/tests/x509_altname.c +++ b/tests/x509_altname.c @@ -122,7 +122,7 @@ doit (void) fail ("unexpected number of alt names: %i\n", alt_name_count); } - success ("done\n"); + if (debug) success ("done\n"); gnutls_x509_crt_deinit (cert); gnutls_global_deinit (); diff --git a/tests/x509dn.c b/tests/x509dn.c index 87c19e7c1d..08e7954bc3 100644 --- a/tests/x509dn.c +++ b/tests/x509dn.c @@ -124,7 +124,7 @@ cert_callback (gnutls_session_t session, return -1; } - success ("client: invoked to provide client cert.\n"); + if (debug) success ("client: invoked to provide client cert.\n"); result = gnutls_x509_dn_init (&dn); if (result < 0) @@ -138,16 +138,16 @@ cert_callback (gnutls_session_t session, { gnutls_x509_ava_st val; - success ("client: imported DN.\n"); + if (debug) success ("client: imported DN.\n"); if (gnutls_x509_dn_get_rdn_ava (dn, 0, 0, &val) == 0) { - success ("client: got RDN 0.\n"); + if (debug) success ("client: got RDN 0.\n"); if (val.value.size == strlen (EXPECT_RDN0) && strncmp (val.value.data, EXPECT_RDN0, val.value.size) == 0) { - success ("client: RND 0 correct.\n"); + if (debug) success ("client: RND 0 correct.\n"); } else { @@ -224,21 +224,21 @@ client (void) } else { - success ("client: Handshake was completed\n"); + if (debug) success ("client: Handshake was completed\n"); } - success ("client: TLS version is: %s\n", + if (debug) success ("client: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); /* see the Getting peer's information example */ - print_info (session); + if (debug) print_info (session); gnutls_record_send (session, MSG, strlen (MSG)); ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -247,12 +247,15 @@ client (void) goto end; } - printf ("- Received %d bytes: ", ret); - for (ii = 0; ii < ret; ii++) + if (debug) { - fputc (buffer[ii], stdout); + printf ("- Received %d bytes: ", ret); + for (ii = 0; ii < ret; ii++) + { + fputc (buffer[ii], stdout); + } + fputs ("\n", stdout); } - fputs ("\n", stdout); gnutls_bye (session, GNUTLS_SHUT_RDWR); @@ -405,7 +408,7 @@ server_start (void) return; } - success ("server: ready. Listening to port '%d'.\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'.\n", PORT); } static void @@ -425,7 +428,7 @@ server (void) gnutls_certificate_set_x509_key_mem (x509_cred, &server_cert, &server_key, GNUTLS_X509_FMT_PEM); - success ("Launched, generating DH parameters...\n"); + if (debug) success ("Launched, generating DH parameters...\n"); generate_dh_params (); @@ -437,7 +440,7 @@ server (void) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -450,13 +453,13 @@ server (void) fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); + if (debug) success ("server: Handshake was completed\n"); - success ("server: TLS version is: %s\n", + if (debug) success ("server: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); /* see the Getting peer's information example */ - print_info (session); + if (debug) print_info (session); i = 0; for (;;) @@ -466,7 +469,7 @@ server (void) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -496,7 +499,7 @@ server (void) gnutls_global_deinit (); - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } diff --git a/tests/x509self.c b/tests/x509self.c index 3bc4d094b8..e0e620f89e 100644 --- a/tests/x509self.c +++ b/tests/x509self.c @@ -156,22 +156,22 @@ client (void) gnutls_perror (ret); goto end; } - else + else if (debug) { success ("client: Handshake was completed\n"); } - success ("client: TLS version is: %s\n", + if (debug) success ("client: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); /* see the Getting peer's information example */ - print_info (session); + if (debug) print_info (session); ret = gnutls_record_send (session, MSG, strlen (MSG)); if (ret == strlen (MSG)) { - success ("client: sent record.\n"); + if (debug) success ("client: sent record.\n"); } else { @@ -182,15 +182,15 @@ client (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); - success ("client: recv returned %d.\n", ret); + if (debug) success ("client: recv returned %d.\n", ret); if (ret == GNUTLS_E_REHANDSHAKE) { - success ("client: doing handshake!\n"); + if (debug) success ("client: doing handshake!\n"); ret = gnutls_handshake (session); if (ret == 0) { - success ("client: handshake complete, reading again.\n"); + if (debug) success ("client: handshake complete, reading again.\n"); ret = gnutls_record_recv (session, buffer, MAX_BUF); } else @@ -201,7 +201,7 @@ client (void) if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -210,12 +210,15 @@ client (void) goto end; } - printf ("- Received %d bytes: ", ret); - for (ii = 0; ii < ret; ii++) + if (debug) { - fputc (buffer[ii], stdout); + printf ("- Received %d bytes: ", ret); + for (ii = 0; ii < ret; ii++) + { + fputc (buffer[ii], stdout); + } + fputs ("\n", stdout); } - fputs ("\n", stdout); gnutls_bye (session, GNUTLS_SHUT_RDWR); @@ -369,7 +372,7 @@ server_start (void) return; } - success ("server: ready. Listening to port '%d'.\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'.\n", PORT); } static void @@ -389,7 +392,7 @@ server (void) gnutls_certificate_set_x509_key_mem (x509_cred, &server_cert, &server_key, GNUTLS_X509_FMT_PEM); - success ("Launched, generating DH parameters...\n"); + if (debug) success ("Launched, generating DH parameters...\n"); generate_dh_params (); @@ -401,7 +404,7 @@ server (void) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -414,13 +417,15 @@ server (void) fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); - - success ("server: TLS version is: %s\n", + if (debug) + { + success ("server: Handshake was completed\n"); + success ("server: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); + } /* see the Getting peer's information example */ - print_info (session); + if (debug) print_info (session); i = 0; for (;;) @@ -430,7 +435,7 @@ server (void) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -443,7 +448,7 @@ server (void) gnutls_certificate_server_set_request (session, GNUTLS_CERT_REQUEST); - success ("server: got data, forcing rehandshake.\n"); + if (debug) success ("server: got data, forcing rehandshake.\n"); ret = gnutls_rehandshake (session); if (ret < 0) @@ -461,7 +466,7 @@ server (void) break; } - success ("server: rehandshake complete.\n"); + if (debug) success ("server: rehandshake complete.\n"); /* echo data back to the client */ @@ -483,7 +488,7 @@ server (void) gnutls_global_deinit (); - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } diff --git a/tests/x509sign-verify.c b/tests/x509sign-verify.c index 3ee9560435..4253864f5f 100644 --- a/tests/x509sign-verify.c +++ b/tests/x509sign-verify.c @@ -148,7 +148,7 @@ doit (void) for (i = 0; i < sizeof (key_dat) / sizeof (key_dat[0]); i++) { - success ("loop %d\n", (int)i); + if (debug) success ("loop %d\n", (int)i); ret = gnutls_x509_privkey_init (&key); if (ret < 0) diff --git a/tests/x509signself.c b/tests/x509signself.c index 6ab7238511..52115db7ee 100644 --- a/tests/x509signself.c +++ b/tests/x509signself.c @@ -190,21 +190,21 @@ client (void) } else { - success ("client: Handshake was completed\n"); + if (debug) success ("client: Handshake was completed\n"); } - success ("client: TLS version is: %s\n", + if (debug) success ("client: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); /* see the Getting peer's information example */ - print_info (session); + if (debug) print_info (session); gnutls_record_send (session, MSG, strlen (MSG)); ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) { - success ("client: Peer has closed the TLS connection\n"); + if (debug) success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -213,12 +213,15 @@ client (void) goto end; } - printf ("- Received %d bytes: ", ret); - for (ii = 0; ii < ret; ii++) + if (debug) { - fputc (buffer[ii], stdout); + printf ("- Received %d bytes: ", ret); + for (ii = 0; ii < ret; ii++) + { + fputc (buffer[ii], stdout); + } + fputs ("\n", stdout); } - fputs ("\n", stdout); gnutls_bye (session, GNUTLS_SHUT_RDWR); @@ -370,7 +373,7 @@ server_start (void) return; } - success ("server: ready. Listening to port '%d'.\n", PORT); + if (debug) success ("server: ready. Listening to port '%d'.\n", PORT); } static void @@ -390,7 +393,7 @@ server (void) gnutls_certificate_set_x509_key_mem (x509_cred, &server_cert, &server_key, GNUTLS_X509_FMT_PEM); - success ("Launched, generating DH parameters...\n"); + if (debug) success ("Launched, generating DH parameters...\n"); generate_dh_params (); @@ -402,7 +405,7 @@ server (void) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); - success ("server: connection from %s, port %d\n", + if (debug) success ("server: connection from %s, port %d\n", inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, sizeof (topbuf)), ntohs (sa_cli.sin_port)); @@ -415,13 +418,13 @@ server (void) fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret)); return; } - success ("server: Handshake was completed\n"); + if (debug) success ("server: Handshake was completed\n"); - success ("server: TLS version is: %s\n", + if (debug) success ("server: TLS version is: %s\n", gnutls_protocol_get_name (gnutls_protocol_get_version (session))); /* see the Getting peer's information example */ - print_info (session); + if (debug) print_info (session); i = 0; for (;;) @@ -431,7 +434,7 @@ server (void) if (ret == 0) { - success ("server: Peer has closed the GNUTLS connection\n"); + if (debug) success ("server: Peer has closed the GNUTLS connection\n"); break; } else if (ret < 0) @@ -461,7 +464,7 @@ server (void) gnutls_global_deinit (); - success ("server: finished\n"); + if (debug) success ("server: finished\n"); } |