diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-12-16 17:30:42 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-12-16 17:30:42 +0100 |
commit | 6eb6bbfe8e504a611145f454f4045e8f49fd5e44 (patch) | |
tree | baba850cc86ee2d9d61de89da1cdfe408ad8694a /tests | |
parent | bdcfdac13179eccee6294402f2654fece149f82b (diff) | |
download | gnutls-6eb6bbfe8e504a611145f454f4045e8f49fd5e44.tar.gz |
Indented code. Use same indentation but with -nut to avoid usage of tabs. In several editors tabs can be configured not to be 8 spaces and this produces artifacts with the current indentation that is a mixture of tabs and spaces.
Diffstat (limited to 'tests')
43 files changed, 1367 insertions, 1365 deletions
diff --git a/tests/anonself.c b/tests/anonself.c index 40ef7bc4e5..f110e18c71 100644 --- a/tests/anonself.c +++ b/tests/anonself.c @@ -103,13 +103,13 @@ client (void) else { if (debug) - success ("client: Handshake was completed\n"); + success ("client: Handshake was completed\n"); } if (debug) success ("client: TLS version is: %s\n", - gnutls_protocol_get_name (gnutls_protocol_get_version - (session))); + gnutls_protocol_get_name (gnutls_protocol_get_version + (session))); gnutls_record_send (session, MSG, strlen (MSG)); @@ -117,7 +117,7 @@ client (void) if (ret == 0) { if (debug) - success ("client: Peer has closed the TLS connection\n"); + success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -130,9 +130,9 @@ client (void) { printf ("- Received %d bytes: ", ret); for (ii = 0; ii < ret; ii++) - { - fputc (buffer[ii], stdout); - } + { + fputc (buffer[ii], stdout); + } fputs ("\n", stdout); } @@ -154,7 +154,7 @@ end: #define SA struct sockaddr #define MAX_BUF 1024 -#define PORT 5556 /* listen to 5556 port */ +#define PORT 5556 /* listen to 5556 port */ #define DH_BITS 1024 /* These are global */ @@ -222,10 +222,10 @@ server_start (void) memset (&sa_serv, '\0', sizeof (sa_serv)); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = INADDR_ANY; - sa_serv.sin_port = htons (PORT); /* Server Port number */ + sa_serv.sin_port = htons (PORT); /* Server Port number */ setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, - sizeof (int)); + sizeof (int)); err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv)); if (err == -1) @@ -275,8 +275,8 @@ server (void) 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)); + inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, + sizeof (topbuf)), ntohs (sa_cli.sin_port)); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); ret = gnutls_handshake (session); @@ -292,8 +292,8 @@ server (void) if (debug) success ("server: TLS version is: %s\n", - gnutls_protocol_get_name (gnutls_protocol_get_version - (session))); + gnutls_protocol_get_name (gnutls_protocol_get_version + (session))); /* see the Getting peer's information example */ /* print_info(session); */ @@ -305,22 +305,22 @@ server (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) - { - if (debug) - success ("server: Peer has closed the GnuTLS connection\n"); - break; - } + { + if (debug) + success ("server: Peer has closed the GnuTLS connection\n"); + break; + } else if (ret < 0) - { - fail ("server: Received corrupted data(%d). Closing...\n", ret); - break; - } + { + fail ("server: Received corrupted data(%d). Closing...\n", ret); + break; + } else if (ret > 0) - { - /* echo data back to the client - */ - gnutls_record_send (session, buffer, strlen (buffer)); - } + { + /* echo data back to the client + */ + gnutls_record_send (session, buffer, strlen (buffer)); + } } /* do not wait for the peer to close the connection. */ diff --git a/tests/certificate_set_x509_crl.c b/tests/certificate_set_x509_crl.c index b242ccd0f1..20ebb3085a 100644 --- a/tests/certificate_set_x509_crl.c +++ b/tests/certificate_set_x509_crl.c @@ -67,12 +67,12 @@ main (void) if (rc) { printf ("gnutls_certificate_allocate_credentials rc %d: %s\n", - rc, gnutls_strerror (rc)); + rc, gnutls_strerror (rc)); return 1; } rc = gnutls_certificate_set_x509_crl_mem (crt, &crldatum, - GNUTLS_X509_FMT_PEM); + GNUTLS_X509_FMT_PEM); if (rc != 1) { printf ("gnutls_certificate_set_x509_crl_mem num %d\n", rc); @@ -97,7 +97,7 @@ main (void) if (rc) { printf ("gnutls_certificate_set_x509_crl rc %d: %s\n", - rc, gnutls_strerror (rc)); + rc, gnutls_strerror (rc)); return 1; } diff --git a/tests/chainverify.c b/tests/chainverify.c index eb2e761650..800b005a53 100644 --- a/tests/chainverify.c +++ b/tests/chainverify.c @@ -781,97 +781,97 @@ doit (void) size_t j; if (debug) - printf ("Chain '%s' (%d)...\n", chains[i].name, (int) i); + printf ("Chain '%s' (%d)...\n", chains[i].name, (int) i); for (j = 0; chains[i].chain[j]; j++) - { - if (debug > 2) - printf ("\tAdding certificate %d...", (int) j); - - ret = gnutls_x509_crt_init (&certs[j]); - if (ret < 0) - error (EXIT_FAILURE, 0, "gnutls_x509_crt_init[%d,%d]: %s", - (int) i, (int) j, gnutls_strerror (ret)); - - tmp.data = (char *) chains[i].chain[j]; - tmp.size = strlen (chains[i].chain[j]); - - ret = gnutls_x509_crt_import (certs[j], &tmp, GNUTLS_X509_FMT_PEM); - if (debug > 2) - 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); - if (debug) - printf ("\tCertificate %d: %.*s\n", (int) j, tmp.size, tmp.data); - gnutls_free (tmp.data); - } + { + if (debug > 2) + printf ("\tAdding certificate %d...", (int) j); + + ret = gnutls_x509_crt_init (&certs[j]); + if (ret < 0) + error (EXIT_FAILURE, 0, "gnutls_x509_crt_init[%d,%d]: %s", + (int) i, (int) j, gnutls_strerror (ret)); + + tmp.data = (char *) chains[i].chain[j]; + tmp.size = strlen (chains[i].chain[j]); + + ret = gnutls_x509_crt_import (certs[j], &tmp, GNUTLS_X509_FMT_PEM); + if (debug > 2) + 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); + if (debug) + printf ("\tCertificate %d: %.*s\n", (int) j, tmp.size, tmp.data); + gnutls_free (tmp.data); + } if (debug > 2) - printf ("\tAdding CA certificate..."); + printf ("\tAdding CA certificate..."); ret = gnutls_x509_crt_init (&ca); if (ret < 0) - error (EXIT_FAILURE, 0, "gnutls_x509_crt_init: %s", - gnutls_strerror (ret)); + error (EXIT_FAILURE, 0, "gnutls_x509_crt_init: %s", + gnutls_strerror (ret)); tmp.data = (char *) *chains[i].ca; tmp.size = strlen (*chains[i].ca); ret = gnutls_x509_crt_import (ca, &tmp, GNUTLS_X509_FMT_PEM); if (ret < 0) - error (EXIT_FAILURE, 0, "gnutls_x509_crt_import: %s", - gnutls_strerror (ret)); + error (EXIT_FAILURE, 0, "gnutls_x509_crt_import: %s", + gnutls_strerror (ret)); if (debug > 2) - printf ("done\n"); + printf ("done\n"); gnutls_x509_crt_print (ca, GNUTLS_CRT_PRINT_ONELINE, &tmp); if (debug) - printf ("\tCA Certificate: %.*s\n", tmp.size, tmp.data); + printf ("\tCA Certificate: %.*s\n", tmp.size, tmp.data); gnutls_free (tmp.data); if (debug) - printf ("\tVerifying..."); + printf ("\tVerifying..."); ret = gnutls_x509_crt_list_verify (certs, j, - &ca, 1, NULL, 0, - chains[i].verify_flags, - &verify_status); + &ca, 1, NULL, 0, + chains[i].verify_flags, + &verify_status); if (ret < 0) - error (EXIT_FAILURE, 0, "gnutls_x509_crt_list_verify[%d,%d]: %s", - (int) i, (int) j, gnutls_strerror (ret)); + error (EXIT_FAILURE, 0, "gnutls_x509_crt_list_verify[%d,%d]: %s", + (int) i, (int) j, gnutls_strerror (ret)); if (verify_status != chains[i].expected_verify_result) - { - fail ("chain[%s]: verify_status: %d expected: %d\n", chains[i].name, - verify_status, chains[i].expected_verify_result); + { + fail ("chain[%s]: verify_status: %d expected: %d\n", chains[i].name, + verify_status, chains[i].expected_verify_result); #if 0 - j = 0; - do - { - fprintf (stderr, "%s\n", chains[i].chain[j]); - } - while (chains[i].chain[++j] != NULL); + j = 0; + do + { + fprintf (stderr, "%s\n", chains[i].chain[j]); + } + while (chains[i].chain[++j] != NULL); #endif - if (!debug) - exit (1); - } + if (!debug) + exit (1); + } else if (debug) - printf ("done\n"); + printf ("done\n"); if (debug) - printf ("\tCleanup..."); + printf ("\tCleanup..."); gnutls_x509_crt_deinit (ca); for (j = 0; chains[i].chain[j]; j++) - gnutls_x509_crt_deinit (certs[j]); + gnutls_x509_crt_deinit (certs[j]); if (debug) - printf ("done\n\n\n"); + printf ("done\n\n\n"); } gnutls_global_deinit (); diff --git a/tests/crq_apis.c b/tests/crq_apis.c index f61e89cd2a..d316495394 100644 --- a/tests/crq_apis.c +++ b/tests/crq_apis.c @@ -133,7 +133,7 @@ doit (void) ret = gnutls_x509_crq_get_challenge_password (crq, smallbuf, &s); if (ret != 0 || s != 3 || strcmp (smallbuf, "foo") != 0) fail ("gnutls_x509_crq_get_challenge_password3 %d/%d/%s\n", - ret, (int) s, smallbuf); + ret, (int) s, smallbuf); s = 0; ret = gnutls_x509_crq_get_extension_info (crq, 0, NULL, &s, NULL); @@ -146,22 +146,22 @@ doit (void) fail ("gnutls_x509_crq_get_extension_data\n"); ret = gnutls_x509_crq_set_subject_alt_name (crq, GNUTLS_SAN_DNSNAME, - "foo", 3, 1); + "foo", 3, 1); if (ret != 0) fail ("gnutls_x509_crq_set_subject_alt_name\n"); ret = gnutls_x509_crq_set_subject_alt_name (crq, GNUTLS_SAN_DNSNAME, - "bar", 3, 1); + "bar", 3, 1); if (ret != 0) fail ("gnutls_x509_crq_set_subject_alt_name\n"); ret = gnutls_x509_crq_set_subject_alt_name (crq, GNUTLS_SAN_DNSNAME, - "apa", 3, 0); + "apa", 3, 0); if (ret != 0) fail ("gnutls_x509_crq_set_subject_alt_name\n"); ret = gnutls_x509_crq_set_subject_alt_name (crq, GNUTLS_SAN_DNSNAME, - "foo", 3, 1); + "foo", 3, 1); if (ret != 0) fail ("gnutls_x509_crq_set_subject_alt_name\n"); diff --git a/tests/crq_key_id.c b/tests/crq_key_id.c index 6696ba7132..da2461c645 100644 --- a/tests/crq_key_id.c +++ b/tests/crq_key_id.c @@ -67,113 +67,113 @@ doit (void) { ret = gnutls_x509_crq_init (&crq); if (ret < 0) - fail ("gnutls_x509_crq_init: %d\n", ret); + fail ("gnutls_x509_crq_init: %d\n", ret); ret = gnutls_x509_privkey_init (&pkey); if (ret < 0) - { - fail ("gnutls_x509_privkey_init: %d\n", ret); - } + { + fail ("gnutls_x509_privkey_init: %d\n", ret); + } ret = gnutls_x509_privkey_generate (pkey, algorithm, 1024, 0); if (ret < 0) - { - fail ("gnutls_x509_privkey_generate (rsa): %d\n", ret); - } + { + fail ("gnutls_x509_privkey_generate (rsa): %d\n", ret); + } else if (debug) - { - success ("Key[%s] generation ok: %d\n", - gnutls_pk_algorithm_get_name (algorithm), ret); - } + { + success ("Key[%s] generation ok: %d\n", + gnutls_pk_algorithm_get_name (algorithm), ret); + } pkey_key_id_len = 0; ret = gnutls_x509_privkey_get_key_id (pkey, 0, pkey_key_id, - &pkey_key_id_len); + &pkey_key_id_len); if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER) - { - fail ("gnutls_x509_privkey_get_key_id incorrectly returns %d\n", - ret); - } + { + fail ("gnutls_x509_privkey_get_key_id incorrectly returns %d\n", + ret); + } pkey_key_id = malloc (sizeof (unsigned char) * pkey_key_id_len); ret = gnutls_x509_privkey_get_key_id (pkey, 0, pkey_key_id, - &pkey_key_id_len); + &pkey_key_id_len); if (ret != GNUTLS_E_SUCCESS) - { - fail ("gnutls_x509_privkey_get_key_id incorrectly returns %d\n", - ret); - } + { + fail ("gnutls_x509_privkey_get_key_id incorrectly returns %d\n", + ret); + } ret = gnutls_x509_crq_set_version (crq, 1); if (ret < 0) - { - fail ("gnutls_x509_crq_set_version: %d\n", ret); - } + { + fail ("gnutls_x509_crq_set_version: %d\n", ret); + } ret = gnutls_x509_crq_set_key (crq, pkey); if (ret < 0) - { - fail ("gnutls_x509_crq_set_key: %d\n", ret); - } + { + fail ("gnutls_x509_crq_set_key: %d\n", ret); + } ret = gnutls_x509_crq_set_dn_by_oid (crq, GNUTLS_OID_X520_COMMON_NAME, - 0, "CN-Test", 7); + 0, "CN-Test", 7); if (ret < 0) - { - fail ("gnutls_x509_crq_set_dn_by_oid: %d\n", ret); - } + { + fail ("gnutls_x509_crq_set_dn_by_oid: %d\n", ret); + } ret = gnutls_x509_crq_sign (crq, pkey); if (ret) - { - fail ("gnutls_x509_crq_sign: %d\n", ret); - } + { + fail ("gnutls_x509_crq_sign: %d\n", ret); + } crq_key_id_len = 0; ret = gnutls_x509_crq_get_key_id (crq, 0, crq_key_id, &crq_key_id_len); if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER) - { - fail ("gnutls_x509_crq_get_key_id incorrectly returns %d\n", ret); - } + { + fail ("gnutls_x509_crq_get_key_id incorrectly returns %d\n", ret); + } crq_key_id = malloc (sizeof (unsigned char) * crq_key_id_len); ret = gnutls_x509_crq_get_key_id (crq, 0, crq_key_id, &crq_key_id_len); if (ret != GNUTLS_E_SUCCESS) - { - fail ("gnutls_x509_crq_get_key_id incorrectly returns %d\n", ret); - } + { + fail ("gnutls_x509_crq_get_key_id incorrectly returns %d\n", ret); + } if (crq_key_id_len == pkey_key_id_len) - { - ret = memcmp (crq_key_id, pkey_key_id, crq_key_id_len); - if (ret == 0) - { - if (debug) - success ("Key ids are identical. OK.\n"); - } - else - { - fail ("Key ids differ incorrectly: %d\n", ret); - } - } + { + ret = memcmp (crq_key_id, pkey_key_id, crq_key_id_len); + if (ret == 0) + { + if (debug) + success ("Key ids are identical. OK.\n"); + } + else + { + fail ("Key ids differ incorrectly: %d\n", ret); + } + } else - { - fail ("Key_id lengths differ incorrectly: %d - %d\n", - (int) crq_key_id_len, (int) pkey_key_id_len); - } + { + fail ("Key_id lengths differ incorrectly: %d - %d\n", + (int) crq_key_id_len, (int) pkey_key_id_len); + } if (pkey_key_id) - { - free (pkey_key_id); - pkey_key_id = NULL; - } + { + free (pkey_key_id); + pkey_key_id = NULL; + } if (crq_key_id) - { - free (crq_key_id); - crq_key_id = NULL; - } + { + free (crq_key_id); + crq_key_id = NULL; + } gnutls_x509_crq_deinit (crq); gnutls_x509_privkey_deinit (pkey); diff --git a/tests/cve-2008-4989.c b/tests/cve-2008-4989.c index 40af8623d8..2e6de335f5 100644 --- a/tests/cve-2008-4989.c +++ b/tests/cve-2008-4989.c @@ -165,22 +165,22 @@ main (int argc, char *argv[]) { ret = gnutls_x509_crt_init (&certs[i]); if (ret < 0) - error (EXIT_FAILURE, 0, "gnutls_x509_crt_init[%d]: %s", (int) i, - gnutls_strerror (ret)); + error (EXIT_FAILURE, 0, "gnutls_x509_crt_init[%d]: %s", (int) i, + gnutls_strerror (ret)); tmp.data = (char *) pem_certs[i]; tmp.size = strlen (pem_certs[i]); ret = gnutls_x509_crt_import (certs[i], &tmp, GNUTLS_X509_FMT_PEM); if (ret < 0) - error (EXIT_FAILURE, 0, "gnutls_x509_crt_import[%d]: %s", (int) i, - gnutls_strerror (ret)); + error (EXIT_FAILURE, 0, "gnutls_x509_crt_import[%d]: %s", (int) i, + gnutls_strerror (ret)); } ret = gnutls_x509_crt_init (&ca); if (ret < 0) error (EXIT_FAILURE, 0, "gnutls_x509_crt_init: %s", - gnutls_strerror (ret)); + gnutls_strerror (ret)); tmp.data = (char *) pem_ca; tmp.size = strlen (pem_ca); @@ -188,16 +188,16 @@ main (int argc, char *argv[]) ret = gnutls_x509_crt_import (ca, &tmp, GNUTLS_X509_FMT_PEM); if (ret < 0) error (EXIT_FAILURE, 0, "gnutls_x509_crt_import: %s", - gnutls_strerror (ret)); + gnutls_strerror (ret)); ret = gnutls_x509_crt_list_verify (certs, CHAIN_LENGTH, - &ca, 1, - NULL, 0, - GNUTLS_VERIFY_DISABLE_TIME_CHECKS, - &verify_status); + &ca, 1, + NULL, 0, + GNUTLS_VERIFY_DISABLE_TIME_CHECKS, + &verify_status); if (ret < 0) error (EXIT_FAILURE, 0, "gnutls_x509_crt_list_verify[%d]: %s", (int) i, - gnutls_strerror (ret)); + gnutls_strerror (ret)); if (verify_status != (GNUTLS_CERT_SIGNER_NOT_FOUND | GNUTLS_CERT_INVALID)) error (EXIT_FAILURE, 0, "verify_status: %d", verify_status); @@ -212,7 +212,7 @@ main (int argc, char *argv[]) ret = gnutls_x509_crt_init (&self_cert); if (ret < 0) error (EXIT_FAILURE, 0, "gnutls_x509_crt_init: %s", - gnutls_strerror (ret)); + gnutls_strerror (ret)); tmp.data = (char *) pem_self_cert; tmp.size = strlen (pem_self_cert); @@ -220,16 +220,16 @@ main (int argc, char *argv[]) ret = gnutls_x509_crt_import (self_cert, &tmp, GNUTLS_X509_FMT_PEM); if (ret < 0) error (EXIT_FAILURE, 0, "gnutls_x509_crt_import: %s", - gnutls_strerror (ret)); + gnutls_strerror (ret)); ret = gnutls_x509_crt_list_verify (&self_cert, 1, - &self_cert, 1, - NULL, 0, - GNUTLS_VERIFY_DISABLE_TIME_CHECKS, - &verify_status); + &self_cert, 1, + NULL, 0, + GNUTLS_VERIFY_DISABLE_TIME_CHECKS, + &verify_status); if (ret < 0) error (EXIT_FAILURE, 0, "gnutls_x509_crt_list_verify[%d]: %s", (int) i, - gnutls_strerror (ret)); + gnutls_strerror (ret)); if (verify_status != 0) error (EXIT_FAILURE, 0, "verify_status: %d", verify_status); diff --git a/tests/dhepskself.c b/tests/dhepskself.c index 54c48134c1..00bf679062 100644 --- a/tests/dhepskself.c +++ b/tests/dhepskself.c @@ -71,7 +71,7 @@ client (void) gnutls_psk_allocate_client_credentials (&pskcred); gnutls_psk_set_client_credentials (pskcred, "test", &key, - GNUTLS_PSK_KEY_HEX); + GNUTLS_PSK_KEY_HEX); /* Initialize TLS session */ @@ -103,7 +103,7 @@ client (void) else { if (debug) - success ("client: Handshake was completed\n"); + success ("client: Handshake was completed\n"); } gnutls_record_send (session, MSG, strlen (MSG)); @@ -112,7 +112,7 @@ client (void) if (ret == 0) { if (debug) - success ("client: Peer has closed the TLS connection\n"); + success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -125,7 +125,7 @@ client (void) { printf ("- Received %d bytes: ", ret); for (ii = 0; ii < ret; ii++) - fputc (buffer[ii], stdout); + fputc (buffer[ii], stdout); fputs ("\n", stdout); } @@ -147,7 +147,7 @@ end: #define SA struct sockaddr #define MAX_BUF 1024 -#define PORT 5556 /* listen to 5556 port */ +#define PORT 5556 /* listen to 5556 port */ /* These are global */ gnutls_psk_server_credentials_t server_pskcred; @@ -227,10 +227,10 @@ server_start (void) memset (&sa_serv, '\0', sizeof (sa_serv)); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = INADDR_ANY; - sa_serv.sin_port = htons (PORT); /* Server Port number */ + sa_serv.sin_port = htons (PORT); /* Server Port number */ setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, - sizeof (int)); + sizeof (int)); err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv)); if (err == -1) @@ -277,8 +277,8 @@ server (void) 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)); + inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, + sizeof (topbuf)), ntohs (sa_cli.sin_port)); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); ret = gnutls_handshake (session); @@ -302,22 +302,22 @@ server (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) - { - if (debug) - success ("server: Peer has closed the GnuTLS connection\n"); - break; - } + { + if (debug) + success ("server: Peer has closed the GnuTLS connection\n"); + break; + } else if (ret < 0) - { - fail ("server: Received corrupted data(%d). Closing...\n", ret); - break; - } + { + fail ("server: Received corrupted data(%d). Closing...\n", ret); + break; + } else if (ret > 0) - { - /* echo data back to the client - */ - gnutls_record_send (session, buffer, strlen (buffer)); - } + { + /* echo data back to the client + */ + gnutls_record_send (session, buffer, strlen (buffer)); + } } /* do not wait for the peer to close the connection. */ diff --git a/tests/dn.c b/tests/dn.c index d86af537c0..0fc624ba05 100644 --- a/tests/dn.c +++ b/tests/dn.c @@ -68,21 +68,21 @@ print_dn (gnutls_x509_dn_t dn) for (i = 0; ret == 0; i++) for (j = 0; ret == 0; j++) { - ret = gnutls_x509_dn_get_rdn_ava (dn, i, j, &ava); - if (ret == GNUTLS_E_ASN1_ELEMENT_NOT_FOUND) - { - if (j > 0) - { - j = 0; - ret = 0; - } - break; - } - if (ret < 0) - fail ("get_rdn_ava %d\n", ret); - 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); + ret = gnutls_x509_dn_get_rdn_ava (dn, i, j, &ava); + if (ret == GNUTLS_E_ASN1_ELEMENT_NOT_FOUND) + { + if (j > 0) + { + j = 0; + ret = 0; + } + break; + } + if (ret < 0) + fail ("get_rdn_ava %d\n", ret); + 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); } } diff --git a/tests/dn2.c b/tests/dn2.c index 3caccd4291..36672d6978 100644 --- a/tests/dn2.c +++ b/tests/dn2.c @@ -92,7 +92,7 @@ doit (void) 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); + out.size, (int) strlen (info), info, out.size, out.data); gnutls_x509_crt_deinit (cert); gnutls_global_deinit (); diff --git a/tests/gc.c b/tests/gc.c index 3f0b1b8353..da3c211d2d 100644 --- a/tests/gc.c +++ b/tests/gc.c @@ -48,37 +48,37 @@ doit (void) else { if (memcmp (digest, "\x3c\xb0\x9d\x83\x28\x01\xef\xc0" - "\x7b\xb3\xaf\x42\x69\xe5\x93\x9a", 16) == 0) - { - if (debug) - success ("_gnutls_hmac_fast(MD5) OK\n"); - } + "\x7b\xb3\xaf\x42\x69\xe5\x93\x9a", 16) == 0) + { + if (debug) + success ("_gnutls_hmac_fast(MD5) OK\n"); + } else - { - hexprint (digest, 16); - fail ("_gnutls_hmac_fast(MD5) failure\n"); - } + { + hexprint (digest, 16); + fail ("_gnutls_hmac_fast(MD5) failure\n"); + } } err = _gnutls_hmac_fast (GNUTLS_MAC_SHA1, "keykeykey", 9, "abcdefgh", 8, - digest); + digest); if (err < 0) fail ("_gnutls_hmac_fast(SHA1) failed: %d\n", err); else { 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) - { - if (debug) - success ("_gnutls_hmac_fast(SHA1) OK\n"); - } + "\x0e\x64\x62\x01\x40\x2b\x2c\xed\x5d\x54\xc1\xfa", + 20) == 0) + { + if (debug) + success ("_gnutls_hmac_fast(SHA1) OK\n"); + } else - { - hexprint (digest, 20); - fail ("_gnutls_hmac_fast(SHA1) failure\n"); - } + { + hexprint (digest, 20); + fail ("_gnutls_hmac_fast(SHA1) failure\n"); + } } err = _gnutls_pbkdf2_sha1 ("password", 8, "salt", 4, 4711, digest, 16); @@ -87,16 +87,16 @@ doit (void) else { if (memcmp (digest, "\x09\xb7\x85\x57\xdd\xf6\x07\x15" - "\x1c\x52\x34\xde\xba\x5c\xdc\x59", 16) == 0) - { - if (debug) - success ("_gnutls_pkcs5_pbkdf2_sha1() OK\n"); - } + "\x1c\x52\x34\xde\xba\x5c\xdc\x59", 16) == 0) + { + if (debug) + success ("_gnutls_pkcs5_pbkdf2_sha1() OK\n"); + } else - { - hexprint (digest, 16); - fail ("_gnutls_pkcs5_pbkdf2_sha1() failure\n"); - } + { + hexprint (digest, 16); + fail ("_gnutls_pkcs5_pbkdf2_sha1() failure\n"); + } } gnutls_global_deinit (); diff --git a/tests/mini-eagain.c b/tests/mini-eagain.c index 7dbbce6d26..92c912aee1 100644 --- a/tests/mini-eagain.c +++ b/tests/mini-eagain.c @@ -198,18 +198,18 @@ doit (void) do { if (cret == GNUTLS_E_AGAIN) - { - //success ("loop invoking client:\n"); - cret = gnutls_handshake (client); - //success ("client %d: %s\n", cret, gnutls_strerror (cret)); - } + { + //success ("loop invoking client:\n"); + cret = gnutls_handshake (client); + //success ("client %d: %s\n", cret, gnutls_strerror (cret)); + } if (sret == GNUTLS_E_AGAIN) - { - //success ("loop invoking server:\n"); - sret = gnutls_handshake (server); - //success ("server %d: %s\n", sret, gnutls_strerror (sret)); - } + { + //success ("loop invoking server:\n"); + sret = gnutls_handshake (server); + //success ("server %d: %s\n", sret, gnutls_strerror (sret)); + } } while (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN); @@ -226,64 +226,64 @@ doit (void) ret = gnutls_record_recv (server, buffer, MAX_BUF); if (ret == 0) - fail ("server: didn't receive any data\n"); + fail ("server: didn't receive any data\n"); else if (ret < 0) - { + { // if (debug) // fputs ("#", stdout); - if (ret != GNUTLS_E_AGAIN) - { - fail ("server: error: %s\n", gnutls_strerror (ret)); - break; - } - } + if (ret != GNUTLS_E_AGAIN) + { + fail ("server: error: %s\n", gnutls_strerror (ret)); + break; + } + } else - { - transferred += ret; + { + transferred += ret; // if (debug) // fputs ("*", stdout); - } + } msglen = strlen (MSG); do - { - ns = gnutls_record_send (server, MSG, msglen); - } + { + ns = gnutls_record_send (server, MSG, msglen); + } while (ns == GNUTLS_E_AGAIN); ret = gnutls_record_recv (client, buffer, MAX_BUF); if (ret == 0) - { - fail ("client: Peer has closed the TLS connection\n"); - } + { + fail ("client: Peer has closed the TLS connection\n"); + } else if (ret < 0) - { - if (debug) - fputs ("!", stdout); - if (ret != GNUTLS_E_AGAIN) - { - fail ("client: Error: %s\n", gnutls_strerror (ret)); - break; - } - } + { + if (debug) + fputs ("!", stdout); + if (ret != GNUTLS_E_AGAIN) + { + fail ("client: Error: %s\n", gnutls_strerror (ret)); + break; + } + } else - { - if (msglen != ret || memcmp (buffer, MSG, msglen) != 0) - { - fail ("client: Transmitted data do not match\n"); - } - - /* echo back */ - do - { - ns = gnutls_record_send (client, buffer, msglen); - } - while (ns == GNUTLS_E_AGAIN); - - transferred += ret; - if (debug) - fputs (".", stdout); - } + { + if (msglen != ret || memcmp (buffer, MSG, msglen) != 0) + { + fail ("client: Transmitted data do not match\n"); + } + + /* echo back */ + do + { + ns = gnutls_record_send (client, buffer, msglen); + } + while (ns == GNUTLS_E_AGAIN); + + transferred += ret; + if (debug) + fputs (".", stdout); + } } while (transferred < 70000); if (debug) diff --git a/tests/mini-x509-rehandshake.c b/tests/mini-x509-rehandshake.c index f95c3796f6..4004a77952 100644 --- a/tests/mini-x509-rehandshake.c +++ b/tests/mini-x509-rehandshake.c @@ -173,8 +173,8 @@ main (int argc, char *argv[]) /* Init server */ gnutls_certificate_allocate_credentials (&serverx509cred); gnutls_certificate_set_x509_key_mem (serverx509cred, - &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); gnutls_init (&server, GNUTLS_SERVER); gnutls_credentials_set (server, GNUTLS_CRD_CERTIFICATE, serverx509cred); gnutls_priority_set_direct (server, "NORMAL", NULL); @@ -193,35 +193,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = EXIT_FAILURE; @@ -249,35 +249,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = 1; @@ -298,9 +298,9 @@ main (int argc, char *argv[]) if (debug_level > 0) { if (exit_code == 0) - puts ("Self-test successful"); + puts ("Self-test successful"); else - puts ("Self-test failed"); + puts ("Self-test failed"); } return exit_code; diff --git a/tests/mini-x509.c b/tests/mini-x509.c index 551da19961..8b57ca8441 100644 --- a/tests/mini-x509.c +++ b/tests/mini-x509.c @@ -173,8 +173,8 @@ main (int argc, char *argv[]) /* Init server */ gnutls_certificate_allocate_credentials (&serverx509cred); gnutls_certificate_set_x509_key_mem (serverx509cred, - &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); gnutls_init (&server, GNUTLS_SERVER); gnutls_credentials_set (server, GNUTLS_CRD_CERTIFICATE, serverx509cred); gnutls_priority_set_direct (server, "NORMAL", NULL); @@ -193,35 +193,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = EXIT_FAILURE; @@ -242,9 +242,9 @@ main (int argc, char *argv[]) if (debug_level > 0) { if (exit_code == 0) - puts ("Self-test successful"); + puts ("Self-test successful"); else - puts ("Self-test failed"); + puts ("Self-test failed"); } return exit_code; diff --git a/tests/mini.c b/tests/mini.c index 54706c021f..30678ecb5a 100644 --- a/tests/mini.c +++ b/tests/mini.c @@ -189,22 +189,22 @@ doit (void) do { if (cret == GNUTLS_E_AGAIN) - { - if (debug) - success ("loop invoking client:\n"); - cret = gnutls_handshake (client); - if (debug) - success ("client %d: %s\n", cret, gnutls_strerror (cret)); - } + { + if (debug) + success ("loop invoking client:\n"); + cret = gnutls_handshake (client); + if (debug) + success ("client %d: %s\n", cret, gnutls_strerror (cret)); + } if (sret == GNUTLS_E_AGAIN) - { - if (debug) - success ("loop invoking server:\n"); - sret = gnutls_handshake (server); - if (debug) - success ("server %d: %s\n", sret, gnutls_strerror (sret)); - } + { + if (debug) + success ("loop invoking server:\n"); + sret = gnutls_handshake (server); + if (debug) + success ("server %d: %s\n", sret, gnutls_strerror (sret)); + } } while (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN); @@ -223,12 +223,12 @@ doit (void) else { if (debug) - { - printf ("server: received %d: ", ret); - for (n = 0; n < ret; n++) - fputc (buffer[n], stdout); - fputs ("\n", stdout); - } + { + 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)); @@ -247,12 +247,12 @@ doit (void) else { if (debug) - { - printf ("client: received %d: ", ret); - for (n = 0; n < ret; n++) - fputc (buffer[n], stdout); - fputs ("\n", stdout); - } + { + 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/mpi.c b/tests/mpi.c index f670490b45..23289de559 100644 --- a/tests/mpi.c +++ b/tests/mpi.c @@ -38,7 +38,7 @@ tls_log_func (int level, const char *str) fprintf (stderr, "|<%d>| %s", level, str); } -#define RND_BITS 510 /* not multiple of 8 */ +#define RND_BITS 510 /* not multiple of 8 */ void doit (void) { diff --git a/tests/nul-in-x509-names.c b/tests/nul-in-x509-names.c index f8bf78283f..a321fb3eac 100644 --- a/tests/nul-in-x509-names.c +++ b/tests/nul-in-x509-names.c @@ -121,7 +121,7 @@ doit (void) if (ret == 0) { if (debug) - success ("gnutls_x509_crt_check_hostname OK (NUL-IN-CN)"); + success ("gnutls_x509_crt_check_hostname OK (NUL-IN-CN)"); } else { @@ -139,7 +139,7 @@ doit (void) if (ret == 0) { if (debug) - success ("gnutls_x509_crt_check_hostname OK (NUL-IN-SAN)"); + success ("gnutls_x509_crt_check_hostname OK (NUL-IN-SAN)"); } else { diff --git a/tests/openpgp-auth.c b/tests/openpgp-auth.c index d348f5bb84..77a1bfd340 100644 --- a/tests/openpgp-auth.c +++ b/tests/openpgp-auth.c @@ -127,32 +127,32 @@ doit () ssize_t sent; if (debug) - printf ("client process %i\n", getpid ()); + printf ("client process %i\n", getpid ()); err = gnutls_init (&session, GNUTLS_CLIENT); if (err != 0) - fail ("client session %d\n", err); + fail ("client session %d\n", err); gnutls_set_default_priority (session); gnutls_transport_set_ptr (session, - (gnutls_transport_ptr_t) (intptr_t) - sockets[0]); + (gnutls_transport_ptr_t) (intptr_t) + sockets[0]); err = gnutls_certificate_allocate_credentials (&cred); if (err != 0) - fail ("client credentials %d\n", err); + fail ("client credentials %d\n", err); err = - gnutls_certificate_set_openpgp_key_file2 (cred, - pub_key_path, priv_key_path, - key_id, - GNUTLS_OPENPGP_FMT_BASE64); + gnutls_certificate_set_openpgp_key_file2 (cred, + pub_key_path, priv_key_path, + key_id, + GNUTLS_OPENPGP_FMT_BASE64); if (err != 0) - fail ("client openpgp keys %d\n", err); + fail ("client openpgp keys %d\n", err); err = gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, cred); if (err != 0) - fail ("client credential_set %d\n", err); + fail ("client credential_set %d\n", err); gnutls_protocol_set_priority (session, protocols); gnutls_certificate_type_set_priority (session, cert_types); @@ -163,21 +163,21 @@ doit () err = gnutls_handshake (session); if (err != 0) - fail ("client handshake %d\n", err); + fail ("client handshake %d\n", err); else if (debug) - printf ("client handshake successful\n"); + printf ("client handshake successful\n"); sent = gnutls_record_send (session, message, sizeof (message)); if (sent != sizeof (message)) - fail ("client sent %li vs. %li\n", - (long) sent, (long) sizeof (message)); + fail ("client sent %li vs. %li\n", + (long) sent, (long) sizeof (message)); err = gnutls_bye (session, GNUTLS_SHUT_RDWR); if (err != 0) - fail ("client bye %d\n", err); + fail ("client bye %d\n", err); if (debug) - printf ("client done\n"); + printf ("client done\n"); } else { @@ -195,60 +195,60 @@ doit () const gnutls_datum_t p3 = { (char *) pkcs3, strlen (pkcs3) }; if (debug) - printf ("server process %i (child %i)\n", getpid (), child); + printf ("server process %i (child %i)\n", getpid (), child); err = gnutls_init (&session, GNUTLS_SERVER); if (err != 0) - fail ("server session %d\n", err); + fail ("server session %d\n", err); gnutls_set_default_priority (session); gnutls_transport_set_ptr (session, - (gnutls_transport_ptr_t) (intptr_t) - sockets[1]); + (gnutls_transport_ptr_t) (intptr_t) + sockets[1]); err = gnutls_certificate_allocate_credentials (&cred); if (err != 0) - fail ("server credentials %d\n", err); + fail ("server credentials %d\n", err); err = - gnutls_certificate_set_openpgp_key_file2 (cred, - pub_key_path, priv_key_path, - key_id, - GNUTLS_OPENPGP_FMT_BASE64); + gnutls_certificate_set_openpgp_key_file2 (cred, + pub_key_path, priv_key_path, + key_id, + GNUTLS_OPENPGP_FMT_BASE64); if (err != 0) - fail ("server openpgp keys %d\n", err); + fail ("server openpgp keys %d\n", err); err = gnutls_dh_params_init (&dh_params); if (err) - fail ("server DH params init %d\n", err); + fail ("server DH params init %d\n", err); err = - gnutls_dh_params_import_pkcs3 (dh_params, &p3, GNUTLS_X509_FMT_PEM); + gnutls_dh_params_import_pkcs3 (dh_params, &p3, GNUTLS_X509_FMT_PEM); if (err) - fail ("server DH params generate %d\n", err); + fail ("server DH params generate %d\n", err); gnutls_certificate_set_dh_params (cred, dh_params); rsa_data.data = - (unsigned char *) read_binary_file (rsa_params_path, &rsa_size); + (unsigned char *) read_binary_file (rsa_params_path, &rsa_size); if (rsa_data.data == NULL) - fail ("server rsa params error\n"); + fail ("server rsa params error\n"); rsa_data.size = rsa_size; err = gnutls_rsa_params_init (&rsa_params); if (err) - fail ("server RSA params init %d\n", err); + fail ("server RSA params init %d\n", err); err = gnutls_rsa_params_import_pkcs1 (rsa_params, &rsa_data, - GNUTLS_X509_FMT_PEM); + GNUTLS_X509_FMT_PEM); if (err) - fail ("server RSA params import %d\n", err); + fail ("server RSA params import %d\n", err); gnutls_certificate_set_rsa_export_params (cred, rsa_params); err = gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, cred); if (err != 0) - fail ("server credential_set %d\n", err); + fail ("server credential_set %d\n", err); gnutls_protocol_set_priority (session, protocols); gnutls_certificate_type_set_priority (session, cert_types); @@ -259,36 +259,36 @@ doit () err = gnutls_handshake (session); if (err != 0) - fail ("server handshake %d\n", err); + fail ("server handshake %d\n", err); received = gnutls_record_recv (session, greetings, sizeof (greetings)); if (received != sizeof (message) - || memcmp (greetings, message, sizeof (message))) - fail ("server received %li vs. %li\n", - (long) received, (long) sizeof (message)); + || memcmp (greetings, message, sizeof (message))) + fail ("server received %li vs. %li\n", + (long) received, (long) sizeof (message)); err = gnutls_bye (session, GNUTLS_SHUT_RDWR); if (err != 0) - fail ("server bye %d\n", err); + fail ("server bye %d\n", err); if (debug) - printf ("server done\n"); + printf ("server done\n"); done = wait (&status); if (done < 0) - fail ("wait %s\n", strerror (errno)); + fail ("wait %s\n", strerror (errno)); if (done != child) - fail ("who's that?! %d\n", done); + fail ("who's that?! %d\n", done); if (WIFEXITED (status)) - { - if (WEXITSTATUS (status) != 0) - fail ("child exited with status %d\n", WEXITSTATUS (status)); - } + { + if (WEXITSTATUS (status) != 0) + fail ("child exited with status %d\n", WEXITSTATUS (status)); + } else if (WIFSIGNALED (status)) - fail ("child stopped by signal %d\n", WTERMSIG (status)); + fail ("child stopped by signal %d\n", WTERMSIG (status)); else - fail ("child failed: %d\n", status); + fail ("child failed: %d\n", status); } } diff --git a/tests/openpgp-keyring.c b/tests/openpgp-keyring.c index 6e3224d080..9095ed8ea1 100644 --- a/tests/openpgp-keyring.c +++ b/tests/openpgp-keyring.c @@ -213,7 +213,7 @@ doit (void) data.data = raw_keyring; data.size = sizeof (raw_keyring) / sizeof (raw_keyring[0]); ret = gnutls_openpgp_keyring_import (keyring, &data, - GNUTLS_OPENPGP_FMT_RAW); + GNUTLS_OPENPGP_FMT_RAW); if (ret < 0) fail ("keyring-import %d\n", ret); diff --git a/tests/openpgp_test.c b/tests/openpgp_test.c index 2d1f163ada..4648477b53 100644 --- a/tests/openpgp_test.c +++ b/tests/openpgp_test.c @@ -36,7 +36,7 @@ get_pktime (long timestamp) tb = localtime (×tamp); sprintf (buf, "%04d-%02d-%02d", tb->tm_year + 1900, tb->tm_mon + 1, - tb->tm_mday); + tb->tm_mday); return buf; } diff --git a/tests/openpgpself.c b/tests/openpgpself.c index 3732d3b39f..e3f2c9ffd2 100644 --- a/tests/openpgpself.c +++ b/tests/openpgpself.c @@ -124,7 +124,7 @@ client (void) success ("Setting key files...\n"); ret = gnutls_certificate_set_openpgp_key_mem (xcred, &cert, &key, - GNUTLS_OPENPGP_FMT_BASE64); + GNUTLS_OPENPGP_FMT_BASE64); if (ret < 0) { fail ("Could not set key files...\n"); @@ -166,8 +166,8 @@ client (void) if (debug) success ("client: TLS version is: %s\n", - gnutls_protocol_get_name (gnutls_protocol_get_version - (session))); + gnutls_protocol_get_name (gnutls_protocol_get_version + (session))); /* see the Getting peer's information example */ if (debug) @@ -179,7 +179,7 @@ client (void) if (ret == 0) { if (debug) - success ("client: Peer has closed the TLS connection\n"); + success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -192,9 +192,9 @@ client (void) { printf ("- Received %d bytes: ", ret); for (ii = 0; ii < ret; ii++) - { - fputc (buffer[ii], stdout); - } + { + fputc (buffer[ii], stdout); + } fputs ("\n", stdout); } @@ -216,7 +216,7 @@ end: #define SA struct sockaddr #define MAX_BUF 1024 -#define PORT 5556 /* listen to 5556 port */ +#define PORT 5556 /* listen to 5556 port */ #define DH_BITS 1024 /* These are global */ @@ -361,10 +361,10 @@ server_start (void) memset (&sa_serv, '\0', sizeof (sa_serv)); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = INADDR_ANY; - sa_serv.sin_port = htons (PORT); /* Server Port number */ + sa_serv.sin_port = htons (PORT); /* Server Port number */ setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, - sizeof (int)); + sizeof (int)); err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv)); if (err == -1) @@ -400,8 +400,8 @@ server (void) gnutls_certificate_allocate_credentials (&pgp_cred); ret = gnutls_certificate_set_openpgp_key_mem2 (pgp_cred, &server_crt, - &server_key, "auto", - GNUTLS_OPENPGP_FMT_BASE64); + &server_key, "auto", + GNUTLS_OPENPGP_FMT_BASE64); if (err < 0) { fail ("Could not set server key files...\n"); @@ -422,8 +422,8 @@ server (void) 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)); + inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, + sizeof (topbuf)), ntohs (sa_cli.sin_port)); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); ret = gnutls_handshake (session); @@ -439,8 +439,8 @@ server (void) if (debug) success ("server: TLS version is: %s\n", - gnutls_protocol_get_name (gnutls_protocol_get_version - (session))); + gnutls_protocol_get_name (gnutls_protocol_get_version + (session))); /* see the Getting peer's information example */ if (debug) @@ -453,22 +453,22 @@ server (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) - { - if (debug) - success ("server: Peer has closed the GnuTLS connection\n"); - break; - } + { + if (debug) + success ("server: Peer has closed the GnuTLS connection\n"); + break; + } else if (ret < 0) - { - fail ("server: Received corrupted data(%d). Closing...\n", ret); - break; - } + { + fail ("server: Received corrupted data(%d). Closing...\n", ret); + break; + } else if (ret > 0) - { - /* echo data back to the client - */ - gnutls_record_send (session, buffer, strlen (buffer)); - } + { + /* echo data back to the client + */ + gnutls_record_send (session, buffer, strlen (buffer)); + } } /* do not wait for the peer to close the connection. */ diff --git a/tests/openssl.c b/tests/openssl.c index 188d82e9b2..72dc09a644 100644 --- a/tests/openssl.c +++ b/tests/openssl.c @@ -48,7 +48,7 @@ doit (void) MD5_Final (&(md[0]), &c); if (memcmp (md, "\x90\x01\x50\x98\x3c\xd2\x4f\xb0" - "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72", sizeof (md)) != 0) + "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72", sizeof (md)) != 0) { hexprint (md, sizeof (md)); fail ("MD5 failure\n"); diff --git a/tests/pgps2kgnu.c b/tests/pgps2kgnu.c index 1076bdea4f..f4ea214fdf 100644 --- a/tests/pgps2kgnu.c +++ b/tests/pgps2kgnu.c @@ -87,16 +87,16 @@ main (void) if (rc) { printf ("gnutls_openpgp_privkey_init rc %d: %s\n", - rc, gnutls_strerror (rc)); + rc, gnutls_strerror (rc)); return 1; } rc = gnutls_openpgp_privkey_import (key, &keydatum, - GNUTLS_OPENPGP_FMT_BASE64, NULL, 0); + GNUTLS_OPENPGP_FMT_BASE64, NULL, 0); if (rc) { printf ("gnutls_openpgp_privkey_import rc %d: %s\n", - rc, gnutls_strerror (rc)); + rc, gnutls_strerror (rc)); return 1; } diff --git a/tests/pkcs12_encode.c b/tests/pkcs12_encode.c index e69104f7e1..06e469c4bc 100644 --- a/tests/pkcs12_encode.c +++ b/tests/pkcs12_encode.c @@ -121,42 +121,42 @@ doit (void) { ret = gnutls_pkcs12_bag_init (&bag); if (ret < 0) - error (EXIT_FAILURE, 0, "bag_init: %d", ret); + error (EXIT_FAILURE, 0, "bag_init: %d", ret); ret = gnutls_pkcs12_bag_set_crt (bag, i == 0 ? client : ca); if (ret < 0) - error (EXIT_FAILURE, 0, "set_crt: %d", ret); + error (EXIT_FAILURE, 0, "set_crt: %d", ret); indx = ret; ret = gnutls_pkcs12_bag_set_friendly_name (bag, indx, - i == 0 ? "client" : "ca"); + i == 0 ? "client" : "ca"); if (ret < 0) - error (EXIT_FAILURE, 0, "set_friendly_name: %d", ret); + error (EXIT_FAILURE, 0, "set_friendly_name: %d", ret); size = sizeof (key_id_buf); ret = gnutls_x509_crt_get_key_id (i == 0 ? client : ca, 0, - key_id_buf, &size); + key_id_buf, &size); if (ret < 0) - error (EXIT_FAILURE, 0, "get_key_id: %d", ret); + error (EXIT_FAILURE, 0, "get_key_id: %d", ret); key_id.data = key_id_buf; key_id.size = size; ret = gnutls_pkcs12_bag_set_key_id (bag, indx, &key_id); if (ret < 0) - error (EXIT_FAILURE, 0, "bag_set_key_id: %d", ret); + error (EXIT_FAILURE, 0, "bag_set_key_id: %d", ret); ret = gnutls_pkcs12_bag_encrypt (bag, "pass", - i == 0 ? GNUTLS_PKCS8_USE_PKCS12_3DES - : GNUTLS_PKCS_USE_PKCS12_RC2_40); + i == 0 ? GNUTLS_PKCS8_USE_PKCS12_3DES + : GNUTLS_PKCS_USE_PKCS12_RC2_40); if (ret < 0) - error (EXIT_FAILURE, 0, "bag_encrypt: %d: %s", ret, - i == 0 ? "3DES" : "RC2-40"); + error (EXIT_FAILURE, 0, "bag_encrypt: %d: %s", ret, + i == 0 ? "3DES" : "RC2-40"); ret = gnutls_pkcs12_set_bag (pkcs12, bag); if (ret < 0) - error (EXIT_FAILURE, 0, "set_bag: %d", ret); + error (EXIT_FAILURE, 0, "set_bag: %d", ret); gnutls_pkcs12_bag_deinit (bag); } diff --git a/tests/pkcs12_s2k.c b/tests/pkcs12_s2k.c index 41c8d1299f..c00ba590ce 100644 --- a/tests/pkcs12_s2k.c +++ b/tests/pkcs12_s2k.c @@ -124,25 +124,25 @@ doit (void) for (i = 1; i < 4; i++) { for (j = 0; j < 3; j++) - { - rc = - _gnutls_pkcs12_string_to_key (i, salt[j], strlen (salt[j]), - j + i + 15, pw[j], sizeof (key), - key); - if (rc < 0) - fail ("_gnutls_pkcs12_string_to_key failed[0]: %d\n", rc); - - if (strcmp (_gnutls_bin2hex (key, sizeof (key), - tmp, sizeof (tmp), NULL), - values[x]) != 0) - fail ("_gnutls_pkcs12_string_to_key failed[1]\n"); - - if (debug) - printf ("ij: %d.%d: %s\n", i, j, - _gnutls_bin2hex (key, sizeof (key), tmp, sizeof (tmp), - NULL)); - x++; - } + { + rc = + _gnutls_pkcs12_string_to_key (i, salt[j], strlen (salt[j]), + j + i + 15, pw[j], sizeof (key), + key); + if (rc < 0) + fail ("_gnutls_pkcs12_string_to_key failed[0]: %d\n", rc); + + if (strcmp (_gnutls_bin2hex (key, sizeof (key), + tmp, sizeof (tmp), NULL), + values[x]) != 0) + fail ("_gnutls_pkcs12_string_to_key failed[1]\n"); + + if (debug) + printf ("ij: %d.%d: %s\n", i, j, + _gnutls_bin2hex (key, sizeof (key), tmp, sizeof (tmp), + NULL)); + x++; + } } if (debug) printf ("\n"); @@ -150,19 +150,19 @@ doit (void) for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) { rc = _gnutls_pkcs12_string_to_key (tv[i].id, tv[i].salt, 8, - tv[i].iter, tv[i].password, - tv[i].keylen, key); + tv[i].iter, tv[i].password, + tv[i].keylen, key); if (rc < 0) - fail ("_gnutls_pkcs12_string_to_key failed[2]: %d\n", rc); + fail ("_gnutls_pkcs12_string_to_key failed[2]: %d\n", rc); if (memcmp (_gnutls_bin2hex (key, tv[i].keylen, - tmp, sizeof (tmp), NULL), - tv[i].key, tv[i].keylen) != 0) - fail ("_gnutls_pkcs12_string_to_key failed[3]\n"); + tmp, sizeof (tmp), NULL), + tv[i].key, tv[i].keylen) != 0) + fail ("_gnutls_pkcs12_string_to_key failed[3]\n"); if (debug) - printf ("tv[%d]: %s\n", i, - _gnutls_bin2hex (key, tv[i].keylen, tmp, sizeof (tmp), NULL)); + printf ("tv[%d]: %s\n", i, + _gnutls_bin2hex (key, tv[i].keylen, tmp, sizeof (tmp), NULL)); } if (debug) printf ("\n"); diff --git a/tests/pkcs12_s2k_pem.c b/tests/pkcs12_s2k_pem.c index ccbd35455b..d20df0cdc5 100644 --- a/tests/pkcs12_s2k_pem.c +++ b/tests/pkcs12_s2k_pem.c @@ -273,19 +273,19 @@ main (void) ret = gnutls_x509_privkey_init (&key); if (ret < 0) - return 1; + return 1; tmp.data = (char *) keys[i].pkcs12key; tmp.size = strlen (tmp.data); ret = gnutls_x509_privkey_import_pkcs8 (key, &tmp, - GNUTLS_X509_FMT_PEM, - keys[i].password, 0); + GNUTLS_X509_FMT_PEM, + keys[i].password, 0); if (ret != keys[i].expected_result) - { - printf ("fail[%d]: %d: %s\n", (int) i, ret, gnutls_strerror (ret)); - return 1; - } + { + printf ("fail[%d]: %d: %s\n", (int) i, ret, gnutls_strerror (ret)); + return 1; + } gnutls_x509_privkey_deinit (key); } diff --git a/tests/pskself.c b/tests/pskself.c index 052e09027b..36377c23b2 100644 --- a/tests/pskself.c +++ b/tests/pskself.c @@ -62,7 +62,7 @@ client (void) gnutls_psk_allocate_client_credentials (&pskcred); gnutls_psk_set_client_credentials (pskcred, "test", &key, - GNUTLS_PSK_KEY_HEX); + GNUTLS_PSK_KEY_HEX); /* Initialize TLS session */ @@ -95,7 +95,7 @@ client (void) else { if (debug) - success ("client: Handshake was completed\n"); + success ("client: Handshake was completed\n"); } gnutls_record_send (session, MSG, strlen (MSG)); @@ -104,7 +104,7 @@ client (void) if (ret == 0) { if (debug) - success ("client: Peer has closed the TLS connection\n"); + success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -117,9 +117,9 @@ client (void) { printf ("- Received %d bytes: ", ret); for (ii = 0; ii < ret; ii++) - { - fputc (buffer[ii], stdout); - } + { + fputc (buffer[ii], stdout); + } fputs ("\n", stdout); } @@ -141,7 +141,7 @@ end: #define SA struct sockaddr #define MAX_BUF 1024 -#define PORT 5556 /* listen to 5556 port */ +#define PORT 5556 /* listen to 5556 port */ /* These are global */ gnutls_psk_server_credentials_t server_pskcred; @@ -208,10 +208,10 @@ server_start (void) memset (&sa_serv, '\0', sizeof (sa_serv)); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = INADDR_ANY; - sa_serv.sin_port = htons (PORT); /* Server Port number */ + sa_serv.sin_port = htons (PORT); /* Server Port number */ setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, - sizeof (int)); + sizeof (int)); err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv)); if (err == -1) @@ -251,8 +251,8 @@ server (void) 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)); + inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, + sizeof (topbuf)), ntohs (sa_cli.sin_port)); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); ret = gnutls_handshake (session); @@ -276,22 +276,22 @@ server (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) - { - if (debug) - success ("server: Peer has closed the GnuTLS connection\n"); - break; - } + { + if (debug) + success ("server: Peer has closed the GnuTLS connection\n"); + break; + } else if (ret < 0) - { - fail ("server: Received corrupted data(%d). Closing...\n", ret); - break; - } + { + fail ("server: Received corrupted data(%d). Closing...\n", ret); + break; + } else if (ret > 0) - { - /* echo data back to the client - */ - gnutls_record_send (session, buffer, strlen (buffer)); - } + { + /* echo data back to the client + */ + gnutls_record_send (session, buffer, strlen (buffer)); + } } /* do not wait for the peer to close the connection. */ diff --git a/tests/resume.c b/tests/resume.c index 76078b4a59..835d432579 100644 --- a/tests/resume.c +++ b/tests/resume.c @@ -108,7 +108,7 @@ client (struct params_res *params) gnutls_anon_allocate_client_credentials (&anoncred); for (t = 0; t < 2; t++) - { /* connect 2 times to the server */ + { /* connect 2 times to the server */ /* connect to the peer */ sd = tcp_connect (); @@ -127,16 +127,16 @@ client (struct params_res *params) #ifdef ENABLE_SESSION_TICKET if (params->enable_session_ticket_client) - gnutls_session_ticket_enable_client (session); + gnutls_session_ticket_enable_client (session); #endif if (t > 0) - { - /* if this is not the first time we connect */ - gnutls_session_set_data (session, session_data.data, - session_data.size); - gnutls_free (session_data.data); - } + { + /* if this is not the first time we connect */ + gnutls_session_set_data (session, session_data.data, + session_data.size); + gnutls_free (session_data.data); + } gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); @@ -145,75 +145,75 @@ client (struct params_res *params) ret = gnutls_handshake (session); if (ret < 0) - { - fail ("client: Handshake failed\n"); - gnutls_perror (ret); - goto end; - } + { + fail ("client: Handshake failed\n"); + gnutls_perror (ret); + goto end; + } else - { - if (debug) - success ("client: Handshake was completed\n"); - } + { + if (debug) + success ("client: Handshake was completed\n"); + } if (t == 0) - { /* the first time we connect */ - /* get the session data size */ - ret = gnutls_session_get_data2 (session, &session_data); - if (ret < 0) - fail ("Getting resume data failed\n"); - } + { /* the first time we connect */ + /* get the session data size */ + ret = gnutls_session_get_data2 (session, &session_data); + if (ret < 0) + fail ("Getting resume data failed\n"); + } else - { /* the second time we connect */ - - /* check if we actually resumed the previous session */ - if (gnutls_session_is_resumed (session) != 0) - { - if (params->expect_resume) - { - if (debug) - success ("- Previous session was resumed\n"); - } - else - fail ("- Previous session was resumed\n"); - } - else - { - if (params->expect_resume) - fail ("*** Previous session was NOT resumed\n"); - else - { - if (debug) - success - ("*** Previous session was NOT resumed (expected)\n"); - } - } - } + { /* the second time we connect */ + + /* check if we actually resumed the previous session */ + if (gnutls_session_is_resumed (session) != 0) + { + if (params->expect_resume) + { + if (debug) + success ("- Previous session was resumed\n"); + } + else + fail ("- Previous session was resumed\n"); + } + else + { + if (params->expect_resume) + fail ("*** Previous session was NOT resumed\n"); + else + { + if (debug) + success + ("*** Previous session was NOT resumed (expected)\n"); + } + } + } gnutls_record_send (session, MSG, strlen (MSG)); ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) - { - if (debug) - success ("client: Peer has closed the TLS connection\n"); - goto end; - } + { + if (debug) + success ("client: Peer has closed the TLS connection\n"); + goto end; + } else if (ret < 0) - { - fail ("client: Error: %s\n", gnutls_strerror (ret)); - goto end; - } + { + fail ("client: Error: %s\n", gnutls_strerror (ret)); + goto end; + } if (debug) - { - printf ("- Received %d bytes: ", ret); - for (ii = 0; ii < ret; ii++) - { - fputc (buffer[ii], stdout); - } - fputs ("\n", stdout); - } + { + printf ("- Received %d bytes: ", ret); + for (ii = 0; ii < ret; ii++) + { + fputc (buffer[ii], stdout); + } + fputs ("\n", stdout); + } gnutls_bye (session, GNUTLS_SHUT_RDWR); @@ -232,7 +232,7 @@ end: #define SA struct sockaddr #define MAX_BUF 1024 -#define PORT 5556 /* listen to 5556 port */ +#define PORT 5556 /* listen to 5556 port */ #define DH_BITS 1024 /* These are global */ @@ -313,10 +313,10 @@ global_start (void) memset (&sa_serv, '\0', sizeof (sa_serv)); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = INADDR_ANY; - sa_serv.sin_port = htons (PORT); /* Server Port number */ + sa_serv.sin_port = htons (PORT); /* Server Port number */ setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, - sizeof (int)); + sizeof (int)); err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv)); if (err == -1) @@ -394,50 +394,50 @@ server (struct params_res *params) sd = accept (listen_sd, (SA *) & sa_cli, &client_len); 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)); + success ("server: connection from %s, port %d\n", + inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, + sizeof (topbuf)), ntohs (sa_cli.sin_port)); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); ret = gnutls_handshake (session); if (ret < 0) - { - close (sd); - gnutls_deinit (session); - fail ("server: Handshake has failed (%s)\n\n", - gnutls_strerror (ret)); - return; - } + { + close (sd); + gnutls_deinit (session); + fail ("server: Handshake has failed (%s)\n\n", + gnutls_strerror (ret)); + return; + } if (debug) - success ("server: Handshake was completed\n"); + success ("server: Handshake was completed\n"); /* see the Getting peer's information example */ /* print_info(session); */ i = 0; for (;;) - { - memset (buffer, 0, MAX_BUF + 1); - ret = gnutls_record_recv (session, buffer, MAX_BUF); - - if (ret == 0) - { - if (debug) - success ("server: Peer has closed the GnuTLS connection\n"); - break; - } - else if (ret < 0) - { - fail ("server: Received corrupted data(%d). Closing...\n", ret); - break; - } - else if (ret > 0) - { - /* echo data back to the client - */ - gnutls_record_send (session, buffer, strlen (buffer)); - } - } + { + memset (buffer, 0, MAX_BUF + 1); + ret = gnutls_record_recv (session, buffer, MAX_BUF); + + if (ret == 0) + { + if (debug) + success ("server: Peer has closed the GnuTLS connection\n"); + break; + } + else if (ret < 0) + { + fail ("server: Received corrupted data(%d). Closing...\n", ret); + break; + } + else if (ret > 0) + { + /* echo data back to the client + */ + gnutls_record_send (session, buffer, strlen (buffer)); + } + } /* do not wait for the peer to close the connection. */ gnutls_bye (session, GNUTLS_SHUT_WR); @@ -469,34 +469,34 @@ doit (void) for (i = 0; resume_tests[i].desc; i++) { if (debug) - printf ("%s\n", resume_tests[i].desc); + printf ("%s\n", resume_tests[i].desc); global_start (); if (error_count) - return; + return; child = fork (); if (child < 0) - { - perror ("fork"); - fail ("fork"); - return; - } + { + perror ("fork"); + fail ("fork"); + return; + } if (child) - { - int status; - /* parent */ - server (&resume_tests[i]); - wait (&status); - global_stop (); - } + { + int status; + /* parent */ + server (&resume_tests[i]); + wait (&status); + global_stop (); + } else - { - client (&resume_tests[i]); - gnutls_global_deinit (); - exit (0); - } + { + client (&resume_tests[i]); + gnutls_global_deinit (); + exit (0); + } } } @@ -547,19 +547,19 @@ wrap_db_store (void *dbf, gnutls_datum_t key, gnutls_datum_t data) unsigned int i; printf ("key:\n"); for (i = 0; i < key.size; i++) - { - printf ("%02x ", key.data[i] & 0xFF); - if ((i + 1) % 16 == 0) - printf ("\n"); - } + { + printf ("%02x ", key.data[i] & 0xFF); + if ((i + 1) % 16 == 0) + printf ("\n"); + } printf ("\n"); printf ("data:\n"); for (i = 0; i < data.size; i++) - { - printf ("%02x ", data.data[i] & 0xFF); - if ((i + 1) % 16 == 0) - printf ("\n"); - } + { + printf ("%02x ", data.data[i] & 0xFF); + if ((i + 1) % 16 == 0) + printf ("\n"); + } printf ("\n"); } @@ -596,11 +596,11 @@ wrap_db_fetch (void *dbf, gnutls_datum_t key) unsigned int i; printf ("key:\n"); for (i = 0; i < key.size; i++) - { - printf ("%02x ", key.data[i] & 0xFF); - if ((i + 1) % 16 == 0) - printf ("\n"); - } + { + printf ("%02x ", key.data[i] & 0xFF); + if ((i + 1) % 16 == 0) + printf ("\n"); + } printf ("\n"); } @@ -610,34 +610,34 @@ wrap_db_fetch (void *dbf, gnutls_datum_t key) for (i = 0; i < TLS_SESSION_CACHE; i++) { if (key.size == cache_db[i].session_id_size && - memcmp (key.data, cache_db[i].session_id, key.size) == 0) - { - if (debug) - success ("resume db fetch... return info\n"); - - res.size = cache_db[i].session_data_size; - - res.data = gnutls_malloc (res.size); - if (res.data == NULL) - return res; - - memcpy (res.data, cache_db[i].session_data, res.size); - - if (debug) - { - unsigned int i; - printf ("data:\n"); - for (i = 0; i < res.size; i++) - { - printf ("%02x ", res.data[i] & 0xFF); - if ((i + 1) % 16 == 0) - printf ("\n"); - } - printf ("\n"); - } - - return res; - } + memcmp (key.data, cache_db[i].session_id, key.size) == 0) + { + if (debug) + success ("resume db fetch... return info\n"); + + res.size = cache_db[i].session_data_size; + + res.data = gnutls_malloc (res.size); + if (res.data == NULL) + return res; + + memcpy (res.data, cache_db[i].session_data, res.size); + + if (debug) + { + unsigned int i; + printf ("data:\n"); + for (i = 0; i < res.size; i++) + { + printf ("%02x ", res.data[i] & 0xFF); + if ((i + 1) % 16 == 0) + printf ("\n"); + } + printf ("\n"); + } + + return res; + } } return res; } @@ -653,14 +653,14 @@ wrap_db_delete (void *dbf, gnutls_datum_t key) for (i = 0; i < TLS_SESSION_CACHE; i++) { if (key.size == cache_db[i].session_id_size && - memcmp (key.data, cache_db[i].session_id, key.size) == 0) - { + memcmp (key.data, cache_db[i].session_id, key.size) == 0) + { - cache_db[i].session_id_size = 0; - cache_db[i].session_data_size = 0; + cache_db[i].session_id_size = 0; + cache_db[i].session_data_size = 0; - return 0; - } + return 0; + } } return -1; diff --git a/tests/safe-renegotiation/srn0.c b/tests/safe-renegotiation/srn0.c index 7310225578..629fd7664b 100644 --- a/tests/safe-renegotiation/srn0.c +++ b/tests/safe-renegotiation/srn0.c @@ -181,8 +181,8 @@ main (int argc, char *argv[]) /* Init server */ gnutls_certificate_allocate_credentials (&serverx509cred); gnutls_certificate_set_x509_key_mem (serverx509cred, - &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); gnutls_init (&server, GNUTLS_SERVER); gnutls_credentials_set (server, GNUTLS_CRD_CERTIFICATE, serverx509cred); gnutls_priority_set_direct (server, "NORMAL", NULL); @@ -201,35 +201,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = EXIT_FAILURE; @@ -264,35 +264,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = 1; @@ -301,7 +301,7 @@ main (int argc, char *argv[]) !gnutls_safe_renegotiation_status (server)) { tls_log_func (0, - "Rehandshaked session not using safe renegotiation!\n"); + "Rehandshaked session not using safe renegotiation!\n"); exit_code = EXIT_FAILURE; } @@ -321,9 +321,9 @@ main (int argc, char *argv[]) if (debug_level > 0) { if (exit_code == 0) - puts ("Self-test successful"); + puts ("Self-test successful"); else - puts ("Self-test failed"); + puts ("Self-test failed"); } return exit_code; diff --git a/tests/safe-renegotiation/srn1.c b/tests/safe-renegotiation/srn1.c index ee40c3a796..2b996b0c94 100644 --- a/tests/safe-renegotiation/srn1.c +++ b/tests/safe-renegotiation/srn1.c @@ -180,8 +180,8 @@ main (int argc, char *argv[]) /* Init server */ gnutls_certificate_allocate_credentials (&serverx509cred); gnutls_certificate_set_x509_key_mem (serverx509cred, - &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); gnutls_init (&server, GNUTLS_SERVER); gnutls_credentials_set (server, GNUTLS_CRD_CERTIFICATE, serverx509cred); gnutls_priority_set_direct (server, "NORMAL:%SAFE_RENEGOTIATION", NULL); @@ -193,7 +193,7 @@ main (int argc, char *argv[]) gnutls_init (&client, GNUTLS_CLIENT); gnutls_credentials_set (client, GNUTLS_CRD_CERTIFICATE, clientx509cred); gnutls_priority_set_direct (client, "NORMAL:%DISABLE_SAFE_RENEGOTIATION", - NULL); + NULL); gnutls_transport_set_push_function (client, client_push); gnutls_transport_set_pull_function (client, client_pull); @@ -209,32 +209,32 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ((cret == GNUTLS_E_AGAIN || cret == GNUTLS_E_SUCCESS) - && (sret == GNUTLS_E_AGAIN || sret == GNUTLS_E_SUCCESS)); + && (sret == GNUTLS_E_AGAIN || sret == GNUTLS_E_SUCCESS)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SAFE_RENEGOTIATION_FAILED) exit_code = EXIT_FAILURE; @@ -255,9 +255,9 @@ main (int argc, char *argv[]) if (debug_level > 0) { if (exit_code == 0) - puts ("Self-test successful"); + puts ("Self-test successful"); else - puts ("Self-test failed"); + puts ("Self-test failed"); } return exit_code; diff --git a/tests/safe-renegotiation/srn2.c b/tests/safe-renegotiation/srn2.c index 6bc92e9a24..8c9d444c6b 100644 --- a/tests/safe-renegotiation/srn2.c +++ b/tests/safe-renegotiation/srn2.c @@ -178,8 +178,8 @@ main (int argc, char *argv[]) /* Init server */ gnutls_certificate_allocate_credentials (&serverx509cred); gnutls_certificate_set_x509_key_mem (serverx509cred, - &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); gnutls_init (&server, GNUTLS_SERVER); gnutls_credentials_set (server, GNUTLS_CRD_CERTIFICATE, serverx509cred); gnutls_priority_set_direct (server, "NORMAL", NULL); @@ -206,35 +206,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = EXIT_FAILURE; @@ -270,35 +270,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = 1; @@ -338,35 +338,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = 1; @@ -397,35 +397,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = 1; @@ -446,9 +446,9 @@ main (int argc, char *argv[]) if (debug_level > 0) { if (exit_code == 0) - puts ("Self-test successful"); + puts ("Self-test successful"); else - puts ("Self-test failed"); + puts ("Self-test failed"); } return exit_code; diff --git a/tests/safe-renegotiation/srn3.c b/tests/safe-renegotiation/srn3.c index 06457a2dc1..71f0ac31ca 100644 --- a/tests/safe-renegotiation/srn3.c +++ b/tests/safe-renegotiation/srn3.c @@ -180,12 +180,12 @@ main (int argc, char *argv[]) /* Init server */ gnutls_certificate_allocate_credentials (&serverx509cred); gnutls_certificate_set_x509_key_mem (serverx509cred, - &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); gnutls_init (&server, GNUTLS_SERVER); gnutls_credentials_set (server, GNUTLS_CRD_CERTIFICATE, serverx509cred); gnutls_priority_set_direct (server, "NORMAL:%DISABLE_SAFE_RENEGOTIATION", - NULL); + NULL); gnutls_transport_set_push_function (server, server_push); gnutls_transport_set_pull_function (server, server_pull); @@ -209,32 +209,32 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ((cret == GNUTLS_E_AGAIN || cret == GNUTLS_E_SUCCESS) - && (sret == GNUTLS_E_AGAIN || sret == GNUTLS_E_SUCCESS)); + && (sret == GNUTLS_E_AGAIN || sret == GNUTLS_E_SUCCESS)); if (cret != GNUTLS_E_SAFE_RENEGOTIATION_FAILED && sret != GNUTLS_E_SUCCESS) exit_code = EXIT_FAILURE; @@ -255,9 +255,9 @@ main (int argc, char *argv[]) if (debug_level > 0) { if (exit_code == 0) - puts ("Self-test successful"); + puts ("Self-test successful"); else - puts ("Self-test failed"); + puts ("Self-test failed"); } return exit_code; diff --git a/tests/safe-renegotiation/srn4.c b/tests/safe-renegotiation/srn4.c index 488a0c3b69..8ab1bb2ea6 100644 --- a/tests/safe-renegotiation/srn4.c +++ b/tests/safe-renegotiation/srn4.c @@ -180,8 +180,8 @@ main (int argc, char *argv[]) /* Init server */ gnutls_certificate_allocate_credentials (&serverx509cred); gnutls_certificate_set_x509_key_mem (serverx509cred, - &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); gnutls_init (&server, GNUTLS_SERVER); gnutls_credentials_set (server, GNUTLS_CRD_CERTIFICATE, serverx509cred); gnutls_priority_set_direct (server, "NORMAL", NULL); @@ -193,7 +193,7 @@ main (int argc, char *argv[]) gnutls_init (&client, GNUTLS_CLIENT); gnutls_credentials_set (client, GNUTLS_CRD_CERTIFICATE, clientx509cred); gnutls_priority_set_direct (client, "NORMAL:%DISABLE_SAFE_RENEGOTIATION", - NULL); + NULL); gnutls_transport_set_push_function (client, client_push); gnutls_transport_set_pull_function (client, client_pull); @@ -201,35 +201,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = EXIT_FAILURE; @@ -264,36 +264,36 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_AGAIN - && sret == GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_AGAIN + && sret == GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_AGAIN && sret != GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED) exit_code = 1; @@ -302,7 +302,7 @@ main (int argc, char *argv[]) gnutls_safe_renegotiation_status (server)) { tls_log_func (0, - "Rehandshaked session not using safe renegotiation!\n"); + "Rehandshaked session not using safe renegotiation!\n"); exit_code = EXIT_FAILURE; } @@ -322,9 +322,9 @@ main (int argc, char *argv[]) if (debug_level > 0) { if (exit_code == 0) - puts ("Self-test successful"); + puts ("Self-test successful"); else - puts ("Self-test failed"); + puts ("Self-test failed"); } return exit_code; diff --git a/tests/safe-renegotiation/srn5.c b/tests/safe-renegotiation/srn5.c index 91d1b9474f..2eb1975143 100644 --- a/tests/safe-renegotiation/srn5.c +++ b/tests/safe-renegotiation/srn5.c @@ -181,12 +181,12 @@ main (int argc, char *argv[]) /* Init server */ gnutls_certificate_allocate_credentials (&serverx509cred); gnutls_certificate_set_x509_key_mem (serverx509cred, - &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + &server_cert, &server_key, + GNUTLS_X509_FMT_PEM); gnutls_init (&server, GNUTLS_SERVER); gnutls_credentials_set (server, GNUTLS_CRD_CERTIFICATE, serverx509cred); gnutls_priority_set_direct (server, "NORMAL:%DISABLE_SAFE_RENEGOTIATION", - NULL); + NULL); gnutls_transport_set_push_function (server, server_push); gnutls_transport_set_pull_function (server, server_pull); @@ -202,35 +202,35 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(cret == GNUTLS_E_SUCCESS && sret == GNUTLS_E_SUCCESS) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (cret != GNUTLS_E_SUCCESS && sret != GNUTLS_E_SUCCESS) exit_code = EXIT_FAILURE; @@ -270,36 +270,36 @@ main (int argc, char *argv[]) { static int max_iter = 0; if (max_iter++ > 10) - abort (); + abort (); if (cret == GNUTLS_E_AGAIN) - { - cret = gnutls_handshake (client); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (client)...\n"); - tls_log_func (0, gnutls_strerror (cret)); - tls_log_func (0, "\n"); - } - } + { + cret = gnutls_handshake (client); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (client)...\n"); + tls_log_func (0, gnutls_strerror (cret)); + tls_log_func (0, "\n"); + } + } if (sret == GNUTLS_E_AGAIN) - { - sret = gnutls_handshake (server); - if (debug_level > 0) - { - tls_log_func (0, "second gnutls_handshake (server)...\n"); - tls_log_func (0, gnutls_strerror (sret)); - tls_log_func (0, "\n"); - } - } + { + sret = gnutls_handshake (server); + if (debug_level > 0) + { + tls_log_func (0, "second gnutls_handshake (server)...\n"); + tls_log_func (0, gnutls_strerror (sret)); + tls_log_func (0, "\n"); + } + } } while ( - /* Not done: */ - !(sret == GNUTLS_E_AGAIN - && cret == GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED) - /* No error: */ - && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); + /* Not done: */ + !(sret == GNUTLS_E_AGAIN + && cret == GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED) + /* No error: */ + && (cret == GNUTLS_E_AGAIN || sret == GNUTLS_E_AGAIN)); if (sret != GNUTLS_E_AGAIN && cret != GNUTLS_E_UNSAFE_RENEGOTIATION_DENIED) exit_code = 1; @@ -308,7 +308,7 @@ main (int argc, char *argv[]) gnutls_safe_renegotiation_status (server)) { tls_log_func (0, - "Rehandshaked session not using safe renegotiation!\n"); + "Rehandshaked session not using safe renegotiation!\n"); exit_code = EXIT_FAILURE; } @@ -328,9 +328,9 @@ main (int argc, char *argv[]) if (debug_level > 0) { if (exit_code == 0) - puts ("Self-test successful"); + puts ("Self-test successful"); else - puts ("Self-test failed"); + puts ("Self-test failed"); } return exit_code; diff --git a/tests/set_pkcs12_cred.c b/tests/set_pkcs12_cred.c index 579e7aaa6b..8fce5260cd 100644 --- a/tests/set_pkcs12_cred.c +++ b/tests/set_pkcs12_cred.c @@ -53,11 +53,11 @@ doit (void) if (debug) success ("Reading PKCS#12 blob from `%s' using password `%s'.\n", - file, password); + file, password); ret = gnutls_certificate_set_x509_simple_pkcs12_file (x509cred, - file, - GNUTLS_X509_FMT_DER, - password); + file, + GNUTLS_X509_FMT_DER, + password); if (ret < 0) fail ("x509_pkcs12 failed %d: %s\n", ret, gnutls_strerror (ret)); @@ -83,11 +83,11 @@ doit (void) if (debug) success ("Reading PKCS#12 blob from `%s' using password `%s'.\n", - file, password); + file, password); ret = gnutls_certificate_set_x509_simple_pkcs12_file (x509cred, - file, - GNUTLS_X509_FMT_DER, - password); + file, + GNUTLS_X509_FMT_DER, + password); if (ret < 0) fail ("x509_pkcs12 failed %d: %s\n", ret, gnutls_strerror (ret)); diff --git a/tests/simple.c b/tests/simple.c index 4124876b14..532d56d019 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -52,13 +52,13 @@ doit (void) for (i = 0; algs[i]; 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])) - != algs[i]) - fail ("gnutls_pk id's doesn't match\n"); + 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])) + != algs[i]) + fail ("gnutls_pk id's doesn't match\n"); } pk = gnutls_pk_get_id ("foo"); @@ -80,14 +80,14 @@ doit (void) for (i = 0; algs[i]; 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]))); - if (gnutls_sign_get_id (gnutls_sign_algorithm_get_name (algs[i])) != - algs[i]) - fail ("gnutls_sign id's doesn't match\n"); + 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]))); + if (gnutls_sign_get_id (gnutls_sign_algorithm_get_name (algs[i])) != + algs[i]) + fail ("gnutls_sign id's doesn't match\n"); } pk = gnutls_sign_get_id ("foo"); diff --git a/tests/tlsia.c b/tests/tlsia.c index d4ebce4a66..b63bc296e4 100644 --- a/tests/tlsia.c +++ b/tests/tlsia.c @@ -59,7 +59,7 @@ tls_log_func (int level, const char *str) static int client_avp (gnutls_session_t session, void *ptr, - const char *last, size_t lastlen, char **new, size_t * newlen) + const char *last, size_t lastlen, char **new, size_t * newlen) { static int iter = 0; const char *p; @@ -67,10 +67,10 @@ client_avp (gnutls_session_t session, void *ptr, if (debug) { if (last) - printf ("client: received %d bytes AVP: `%.*s'\n", - (int) lastlen, (int) lastlen, last); + printf ("client: received %d bytes AVP: `%.*s'\n", + (int) lastlen, (int) lastlen, last); else - printf ("client: new application phase\n"); + printf ("client: new application phase\n"); } switch (iter) @@ -171,7 +171,7 @@ client (void) else { if (debug) - success ("client: Handshake was completed\n"); + success ("client: Handshake was completed\n"); } /* @@ -186,21 +186,21 @@ client (void) else { if (debug) - success ("client: TLS/IA handshake\n"); + success ("client: TLS/IA handshake\n"); ret = gnutls_ia_handshake (session); if (ret < 0) - { - fail ("client: TLS/IA handshake failed\n"); - gnutls_perror (ret); - goto end; - } + { + fail ("client: TLS/IA handshake failed\n"); + gnutls_perror (ret); + goto end; + } else - { - if (debug) - success ("client: TLS/IA Handshake was completed\n"); - } + { + if (debug) + success ("client: TLS/IA Handshake was completed\n"); + } } gnutls_record_send (session, MSG, strlen (MSG)); @@ -209,7 +209,7 @@ client (void) if (ret == 0) { if (debug) - success ("client: Peer has closed the TLS connection\n"); + success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -222,9 +222,9 @@ client (void) { printf ("- Received %d bytes: ", ret); for (ii = 0; ii < ret; ii++) - { - fputc (buffer[ii], stdout); - } + { + fputc (buffer[ii], stdout); + } fputs ("\n", stdout); } @@ -248,7 +248,7 @@ end: #define SA struct sockaddr #define MAX_BUF 1024 -#define PORT 5556 /* listen to 5556 port */ +#define PORT 5556 /* listen to 5556 port */ #define DH_BITS 1024 /* These are global */ @@ -303,14 +303,14 @@ int optval = 1; static int server_avp (gnutls_session_t session, void *ptr, - const char *last, size_t lastlen, char **new, size_t * newlen) + const char *last, size_t lastlen, char **new, size_t * newlen) { static int iter = 0; const char *p; if (last && debug) printf ("server: received %d bytes AVP: `%.*s'\n", - (int) lastlen, (int) lastlen, last); + (int) lastlen, (int) lastlen, last); gnutls_ia_permute_inner_secret (session, 3, "foo"); @@ -360,14 +360,14 @@ server_avp (gnutls_session_t session, void *ptr, if (strcmp (p, "1") == 0) { if (debug) - success ("server: Sending IntermediatePhaseFinished...\n"); + success ("server: Sending IntermediatePhaseFinished...\n"); return 1; } if (strcmp (p, "2") == 0) { if (debug) - success ("server: Sending FinalPhaseFinished...\n"); + success ("server: Sending FinalPhaseFinished...\n"); return 2; } @@ -398,10 +398,10 @@ server_start (void) memset (&sa_serv, '\0', sizeof (sa_serv)); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = INADDR_ANY; - sa_serv.sin_port = htons (PORT); /* Server Port number */ + sa_serv.sin_port = htons (PORT); /* Server Port number */ setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, - sizeof (int)); + sizeof (int)); err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv)); if (err == -1) @@ -457,8 +457,8 @@ server (void) 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)); + inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, + sizeof (topbuf)), ntohs (sa_cli.sin_port)); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); @@ -482,21 +482,21 @@ server (void) else { if (debug) - success ("server: TLS/IA handshake\n"); + success ("server: TLS/IA handshake\n"); ret = gnutls_ia_handshake (session); if (ret < 0) - { - fail ("server: TLS/IA handshake failed\n"); - gnutls_perror (ret); - return; - } + { + fail ("server: TLS/IA handshake failed\n"); + gnutls_perror (ret); + return; + } else - { - if (debug) - success ("server: TLS/IA Handshake was completed\n"); - } + { + if (debug) + success ("server: TLS/IA Handshake was completed\n"); + } } /* see the Getting peer's information example */ @@ -509,32 +509,32 @@ server (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) - { - if (debug) - success ("server: Peer has closed the GnuTLS connection\n"); - break; - } + { + if (debug) + success ("server: Peer has closed the GnuTLS connection\n"); + break; + } else if (ret < 0) - { - if (ret == GNUTLS_E_FATAL_ALERT_RECEIVED) - { - gnutls_alert_description_t alert; - const char *err; - alert = gnutls_alert_get (session); - err = gnutls_alert_get_name (alert); - if (err) - printf ("Fatal alert: %s\n", err); - } - - fail ("server: Received corrupted data(%d). Closing...\n", ret); - break; - } + { + if (ret == GNUTLS_E_FATAL_ALERT_RECEIVED) + { + gnutls_alert_description_t alert; + const char *err; + alert = gnutls_alert_get (session); + err = gnutls_alert_get_name (alert); + if (err) + printf ("Fatal alert: %s\n", err); + } + + fail ("server: Received corrupted data(%d). Closing...\n", ret); + break; + } else if (ret > 0) - { - /* echo data back to the client - */ - gnutls_record_send (session, buffer, strlen (buffer)); - } + { + /* echo data back to the client + */ + gnutls_record_send (session, buffer, strlen (buffer)); + } } /* do not wait for the peer to close the connection. */ diff --git a/tests/utils.c b/tests/utils.c index 946c62d39d..105869c903 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -73,14 +73,14 @@ escapeprint (const char *str, size_t len) for (i = 0; i < len; i++) { if (((str[i] & 0xFF) >= 'A' && (str[i] & 0xFF) <= 'Z') || - ((str[i] & 0xFF) >= 'a' && (str[i] & 0xFF) <= 'z') || - ((str[i] & 0xFF) >= '0' && (str[i] & 0xFF) <= '9') - || (str[i] & 0xFF) == ' ' || (str[i] & 0xFF) == '.') - printf ("%c", (str[i] & 0xFF)); + ((str[i] & 0xFF) >= 'a' && (str[i] & 0xFF) <= 'z') || + ((str[i] & 0xFF) >= '0' && (str[i] & 0xFF) <= '9') + || (str[i] & 0xFF) == ' ' || (str[i] & 0xFF) == '.') + printf ("%c", (str[i] & 0xFF)); else - printf ("\\x%02X", (str[i] & 0xFF)); + printf ("\\x%02X", (str[i] & 0xFF)); if ((i + 1) % 16 == 0 && (i + 1) < len) - printf ("'\n\t'"); + printf ("'\n\t'"); } printf ("\n"); } @@ -95,9 +95,9 @@ hexprint (const char *str, size_t len) { printf ("%02x ", (str[i] & 0xFF)); if ((i + 1) % 8 == 0) - printf (" "); + printf (" "); if ((i + 1) % 16 == 0 && i + 1 < len) - printf ("\n\t;; "); + printf ("\n\t;; "); } printf ("\n"); } @@ -111,17 +111,17 @@ binprint (const char *str, size_t len) for (i = 0; i < len; i++) { printf ("%d%d%d%d%d%d%d%d ", - (str[i] & 0xFF) & 0x80 ? 1 : 0, - (str[i] & 0xFF) & 0x40 ? 1 : 0, - (str[i] & 0xFF) & 0x20 ? 1 : 0, - (str[i] & 0xFF) & 0x10 ? 1 : 0, - (str[i] & 0xFF) & 0x08 ? 1 : 0, - (str[i] & 0xFF) & 0x04 ? 1 : 0, - (str[i] & 0xFF) & 0x02 ? 1 : 0, (str[i] & 0xFF) & 0x01 ? 1 : 0); + (str[i] & 0xFF) & 0x80 ? 1 : 0, + (str[i] & 0xFF) & 0x40 ? 1 : 0, + (str[i] & 0xFF) & 0x20 ? 1 : 0, + (str[i] & 0xFF) & 0x10 ? 1 : 0, + (str[i] & 0xFF) & 0x08 ? 1 : 0, + (str[i] & 0xFF) & 0x04 ? 1 : 0, + (str[i] & 0xFF) & 0x02 ? 1 : 0, (str[i] & 0xFF) & 0x01 ? 1 : 0); if ((i + 1) % 3 == 0) - printf (" "); + printf (" "); if ((i + 1) % 6 == 0 && i + 1 < len) - printf ("\n\t;; "); + printf ("\n\t;; "); } printf ("\n"); } @@ -131,18 +131,18 @@ main (int argc, char *argv[]) { do if (strcmp (argv[argc - 1], "-v") == 0 || - strcmp (argv[argc - 1], "--verbose") == 0) + strcmp (argv[argc - 1], "--verbose") == 0) debug = 1; else if (strcmp (argv[argc - 1], "-b") == 0 || - strcmp (argv[argc - 1], "--break-on-error") == 0) + strcmp (argv[argc - 1], "--break-on-error") == 0) break_on_error = 1; else if (strcmp (argv[argc - 1], "-h") == 0 || - strcmp (argv[argc - 1], "-?") == 0 || - strcmp (argv[argc - 1], "--help") == 0) + strcmp (argv[argc - 1], "-?") == 0 || + strcmp (argv[argc - 1], "--help") == 0) { - printf ("Usage: %s [-vbh?] [--verbose] [--break-on-error] [--help]\n", - argv[0]); - return 1; + printf ("Usage: %s [-vbh?] [--verbose] [--break-on-error] [--help]\n", + argv[0]); + return 1; } while (argc-- > 1); diff --git a/tests/utils.h b/tests/utils.h index 47db94f61e..dfd6aef3e1 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -30,7 +30,7 @@ #ifndef __attribute__ #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) -#define __attribute__(Spec) /* empty */ +#define __attribute__(Spec) /* empty */ #endif #endif diff --git a/tests/x509_altname.c b/tests/x509_altname.c index 432b44fb98..392e226407 100644 --- a/tests/x509_altname.c +++ b/tests/x509_altname.c @@ -87,33 +87,33 @@ doit (void) for (alt_name_count = 0;; ++alt_name_count) { ret = - gnutls_x509_crt_get_issuer_alt_name (cert, alt_name_count, data, - &data_len, &critical); + gnutls_x509_crt_get_issuer_alt_name (cert, alt_name_count, data, + &data_len, &critical); if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) - break; + break; if (ret < 0) - fail ("get_issuer_alt_name: %d\n", ret); + fail ("get_issuer_alt_name: %d\n", ret); // TODO: print out / check results if (GNUTLS_SAN_URI == ret) - { - if (strcmp (data, "http://ca.su.se") != 0) - { - fail ("unexpected issuer GNUTLS_SAN_URI: %s\n", data); - } - } + { + if (strcmp (data, "http://ca.su.se") != 0) + { + fail ("unexpected issuer GNUTLS_SAN_URI: %s\n", data); + } + } else if (GNUTLS_SAN_RFC822NAME == ret) - { - if (strcmp (data, "ca@su.se") != 0) - { - fail ("unexpected issuer GNUTLS_SAN_RFC822NAME: %s\n", data); - } - } + { + if (strcmp (data, "ca@su.se") != 0) + { + fail ("unexpected issuer GNUTLS_SAN_RFC822NAME: %s\n", data); + } + } else - { - fail ("unexpected alt name type: %d\n", ret); - } + { + fail ("unexpected alt name type: %d\n", ret); + } data_len = MAX_DATA_SIZE; } diff --git a/tests/x509_test.c b/tests/x509_test.c index d1fa2065a1..27b6ad28ed 100644 --- a/tests/x509_test.c +++ b/tests/x509_test.c @@ -62,7 +62,7 @@ main () gnutls_global_init (); fprintf (stderr, - "This test will perform some checks on X.509 certificate\n"); + "This test will perform some checks on X.509 certificate\n"); fprintf (stderr, "verification functions.\n\n"); for (;;) @@ -71,30 +71,30 @@ main () file = test_files[i++].test_file; if (file == NULL) - break; + break; x = _verify_x509_file (file, CA_FILE); if (x < 0) - { - fprintf (stderr, "Unexpected error: %d\n", x); - exit (1); - } + { + fprintf (stderr, "Unexpected error: %d\n", x); + exit (1); + } printf ("Test %d, file %s: ", i, file); if (x != exp_result) - { - printf ("failed.\n"); - fflush (stdout); - fprintf (stderr, "Unexpected error in verification.\n"); - fprintf (stderr, "Certificate was found to be: \n"); - print_res (x); - } + { + printf ("failed.\n"); + fflush (stdout); + fprintf (stderr, "Unexpected error in verification.\n"); + fprintf (stderr, "Certificate was found to be: \n"); + print_res (x); + } else - { - printf ("ok."); + { + printf ("ok."); - printf ("\n"); - } + printf ("\n"); + } } printf ("\n"); @@ -112,7 +112,7 @@ main () */ int _verify_x509_mem (const char *cert, int cert_size, - const char *ca, int ca_size, const char *crl, int crl_size) + const char *ca, int ca_size, const char *crl, int crl_size) { int siz, i; const char *ptr; @@ -133,7 +133,7 @@ _verify_x509_mem (const char *cert, int cert_size, if (ret < 0) { fprintf (stderr, "Error parsing the CA certificate: %s\n", - gnutls_strerror (ret)); + gnutls_strerror (ret)); exit (1); } @@ -142,7 +142,7 @@ _verify_x509_mem (const char *cert, int cert_size, if (ret < 0) { fprintf (stderr, "Error parsing the CA certificate: %s\n", - gnutls_strerror (ret)); + gnutls_strerror (ret)); exit (1); } @@ -153,45 +153,45 @@ _verify_x509_mem (const char *cert, int cert_size, i = 1; - if (strstr (ptr, CRL_SEP) != NULL) /* if CRLs exist */ + if (strstr (ptr, CRL_SEP) != NULL) /* if CRLs exist */ do { - x509_crl_list = - (gnutls_x509_crl *) realloc (x509_crl_list, - i * sizeof (gnutls_x509_crl)); - if (x509_crl_list == NULL) - { - fprintf (stderr, "memory error\n"); - exit (1); - } - - tmp.data = (char *) ptr; - tmp.size = siz; - - ret = gnutls_x509_crl_init (&x509_crl_list[i - 1]); - if (ret < 0) - { - fprintf (stderr, "Error parsing the CRL[%d]: %s\n", i, - gnutls_strerror (ret)); - exit (1); - } - - ret = - gnutls_x509_crl_import (x509_crl_list[i - 1], &tmp, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - fprintf (stderr, "Error parsing the CRL[%d]: %s\n", i, - gnutls_strerror (ret)); - exit (1); - } - - /* now we move ptr after the pem header */ - ptr = strstr (ptr, CRL_SEP); - if (ptr != NULL) - ptr++; - - i++; + x509_crl_list = + (gnutls_x509_crl *) realloc (x509_crl_list, + i * sizeof (gnutls_x509_crl)); + if (x509_crl_list == NULL) + { + fprintf (stderr, "memory error\n"); + exit (1); + } + + tmp.data = (char *) ptr; + tmp.size = siz; + + ret = gnutls_x509_crl_init (&x509_crl_list[i - 1]); + if (ret < 0) + { + fprintf (stderr, "Error parsing the CRL[%d]: %s\n", i, + gnutls_strerror (ret)); + exit (1); + } + + ret = + gnutls_x509_crl_import (x509_crl_list[i - 1], &tmp, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + fprintf (stderr, "Error parsing the CRL[%d]: %s\n", i, + gnutls_strerror (ret)); + exit (1); + } + + /* now we move ptr after the pem header */ + ptr = strstr (ptr, CRL_SEP); + if (ptr != NULL) + ptr++; + + i++; } while ((ptr = strstr (ptr, CRL_SEP)) != NULL); @@ -208,39 +208,39 @@ _verify_x509_mem (const char *cert, int cert_size, do { x509_cert_list = - (gnutls_x509_crt *) realloc (x509_cert_list, - i * sizeof (gnutls_x509_crt)); + (gnutls_x509_crt *) realloc (x509_cert_list, + i * sizeof (gnutls_x509_crt)); if (x509_cert_list == NULL) - { - fprintf (stderr, "memory error\n"); - exit (1); - } + { + fprintf (stderr, "memory error\n"); + exit (1); + } tmp.data = (char *) ptr; tmp.size = siz; ret = gnutls_x509_crt_init (&x509_cert_list[i - 1]); if (ret < 0) - { - fprintf (stderr, "Error parsing the certificate[%d]: %s\n", i, - gnutls_strerror (ret)); - exit (1); - } + { + fprintf (stderr, "Error parsing the certificate[%d]: %s\n", i, + gnutls_strerror (ret)); + exit (1); + } ret = - gnutls_x509_crt_import (x509_cert_list[i - 1], &tmp, - GNUTLS_X509_FMT_PEM); + gnutls_x509_crt_import (x509_cert_list[i - 1], &tmp, + GNUTLS_X509_FMT_PEM); if (ret < 0) - { - fprintf (stderr, "Error parsing the certificate[%d]: %s\n", i, - gnutls_strerror (ret)); - exit (1); - } + { + fprintf (stderr, "Error parsing the certificate[%d]: %s\n", i, + gnutls_strerror (ret)); + exit (1); + } /* now we move ptr after the pem header */ ptr = strstr (ptr, CERT_SEP); if (ptr != NULL) - ptr++; + ptr++; i++; } @@ -249,8 +249,8 @@ _verify_x509_mem (const char *cert, int cert_size, x509_ncerts = i - 1; ret = gnutls_x509_crt_list_verify (x509_cert_list, x509_ncerts, - &x509_ca, 1, x509_crl_list, x509_ncrls, - 0, &output); + &x509_ca, 1, x509_crl_list, x509_ncrls, + 0, &output); gnutls_x509_crt_deinit (x509_ca); diff --git a/tests/x509dn.c b/tests/x509dn.c index 6095b3a8d2..f1518954cb 100644 --- a/tests/x509dn.c +++ b/tests/x509dn.c @@ -111,9 +111,9 @@ const gnutls_datum_t key = { key_pem, sizeof (key_pem) }; static int cert_callback (gnutls_session_t session, - const gnutls_datum_t * req_ca_rdn, int nreqs, - const gnutls_pk_algorithm_t * sign_algos, - int sign_algos_length, gnutls_retr2_st * st) + const gnutls_datum_t * req_ca_rdn, int nreqs, + const gnutls_pk_algorithm_t * sign_algos, + int sign_algos_length, gnutls_retr2_st * st) { int result; gnutls_x509_dn_t dn; @@ -140,31 +140,31 @@ cert_callback (gnutls_session_t session, gnutls_x509_ava_st val; if (debug) - success ("client: imported DN.\n"); + success ("client: imported DN.\n"); if (gnutls_x509_dn_get_rdn_ava (dn, 0, 0, &val) == 0) - { - 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) - { - if (debug) - success ("client: RND 0 correct.\n"); - } - else - { - fail ("client: RND 0 bad: %.*s\n", - val.value.size, val.value.data); - return -1; - } - } + { + 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) + { + if (debug) + success ("client: RND 0 correct.\n"); + } + else + { + fail ("client: RND 0 bad: %.*s\n", + val.value.size, val.value.data); + return -1; + } + } else - { - fail ("client: could not retrieve RDN 0.\n"); - return -1; - } + { + fail ("client: could not retrieve RDN 0.\n"); + return -1; + } gnutls_x509_dn_deinit (dn); } @@ -229,13 +229,13 @@ client (void) else { if (debug) - success ("client: Handshake was completed\n"); + success ("client: Handshake was completed\n"); } if (debug) success ("client: TLS version is: %s\n", - gnutls_protocol_get_name (gnutls_protocol_get_version - (session))); + gnutls_protocol_get_name (gnutls_protocol_get_version + (session))); /* see the Getting peer's information example */ if (debug) @@ -247,7 +247,7 @@ client (void) if (ret == 0) { if (debug) - success ("client: Peer has closed the TLS connection\n"); + success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -260,9 +260,9 @@ client (void) { printf ("- Received %d bytes: ", ret); for (ii = 0; ii < ret; ii++) - { - fputc (buffer[ii], stdout); - } + { + fputc (buffer[ii], stdout); + } fputs ("\n", stdout); } @@ -284,7 +284,7 @@ end: #define SA struct sockaddr #define MAX_BUF 1024 -#define PORT 5556 /* listen to 5556 port */ +#define PORT 5556 /* listen to 5556 port */ #define DH_BITS 1024 /* These are global */ @@ -396,10 +396,10 @@ server_start (void) memset (&sa_serv, '\0', sizeof (sa_serv)); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = INADDR_ANY; - sa_serv.sin_port = htons (PORT); /* Server Port number */ + sa_serv.sin_port = htons (PORT); /* Server Port number */ setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, - sizeof (int)); + sizeof (int)); err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv)); if (err == -1) @@ -436,7 +436,7 @@ server (void) gnutls_certificate_set_x509_trust_mem (x509_cred, &ca, GNUTLS_X509_FMT_PEM); gnutls_certificate_set_x509_key_mem (x509_cred, &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + GNUTLS_X509_FMT_PEM); if (debug) success ("Launched, generating DH parameters...\n"); @@ -453,8 +453,8 @@ server (void) 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)); + inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, + sizeof (topbuf)), ntohs (sa_cli.sin_port)); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); ret = gnutls_handshake (session); @@ -470,8 +470,8 @@ server (void) if (debug) success ("server: TLS version is: %s\n", - gnutls_protocol_get_name (gnutls_protocol_get_version - (session))); + gnutls_protocol_get_name (gnutls_protocol_get_version + (session))); /* see the Getting peer's information example */ if (debug) @@ -484,22 +484,22 @@ server (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) - { - if (debug) - success ("server: Peer has closed the GnuTLS connection\n"); - break; - } + { + if (debug) + success ("server: Peer has closed the GnuTLS connection\n"); + break; + } else if (ret < 0) - { - fail ("server: Received corrupted data(%d). Closing...\n", ret); - break; - } + { + fail ("server: Received corrupted data(%d). Closing...\n", ret); + break; + } else if (ret > 0) - { - /* echo data back to the client - */ - gnutls_record_send (session, buffer, strlen (buffer)); - } + { + /* echo data back to the client + */ + gnutls_record_send (session, buffer, strlen (buffer)); + } } /* do not wait for the peer to close the connection. */ @@ -545,18 +545,18 @@ doit (void) #if defined WIFEXITED && defined WEXITSTATUS if (WIFEXITED (status) && WEXITSTATUS (status)) - { - fail ("server: client failed with exit status %d\n", - WEXITSTATUS (status)); - } + { + fail ("server: client failed with exit status %d\n", + WEXITSTATUS (status)); + } #endif #if defined WIFSIGNALED && defined WTERMSIG if (WIFSIGNALED (status)) - { - fail ("server: client failed with fatal signal %d\n", - WTERMSIG (status)); - } + { + fail ("server: client failed with fatal signal %d\n", + WTERMSIG (status)); + } #endif } diff --git a/tests/x509self.c b/tests/x509self.c index 0039a49398..a25b31ffb1 100644 --- a/tests/x509self.c +++ b/tests/x509self.c @@ -128,7 +128,7 @@ client (void) */ gnutls_certificate_set_x509_trust_mem (xcred, &ca, GNUTLS_X509_FMT_PEM); gnutls_certificate_set_x509_key_mem (xcred, &cert, &key, - GNUTLS_X509_FMT_PEM); + GNUTLS_X509_FMT_PEM); /* Initialize TLS session */ @@ -164,8 +164,8 @@ client (void) if (debug) success ("client: TLS version is: %s\n", - gnutls_protocol_get_name (gnutls_protocol_get_version - (session))); + gnutls_protocol_get_name (gnutls_protocol_get_version + (session))); /* see the Getting peer's information example */ if (debug) @@ -176,7 +176,7 @@ client (void) if (ret == strlen (MSG)) { if (debug) - success ("client: sent record.\n"); + success ("client: sent record.\n"); } else { @@ -193,24 +193,24 @@ client (void) if (ret == GNUTLS_E_REHANDSHAKE) { if (debug) - success ("client: doing handshake!\n"); + success ("client: doing handshake!\n"); ret = gnutls_handshake (session); if (ret == 0) - { - if (debug) - success ("client: handshake complete, reading again.\n"); - ret = gnutls_record_recv (session, buffer, MAX_BUF); - } + { + if (debug) + success ("client: handshake complete, reading again.\n"); + ret = gnutls_record_recv (session, buffer, MAX_BUF); + } else - { - fail ("client: handshake failed.\n"); - } + { + fail ("client: handshake failed.\n"); + } } if (ret == 0) { if (debug) - success ("client: Peer has closed the TLS connection\n"); + success ("client: Peer has closed the TLS connection\n"); goto end; } else if (ret < 0) @@ -223,9 +223,9 @@ client (void) { printf ("- Received %d bytes: ", ret); for (ii = 0; ii < ret; ii++) - { - fputc (buffer[ii], stdout); - } + { + fputc (buffer[ii], stdout); + } fputs ("\n", stdout); } @@ -247,7 +247,7 @@ end: #define SA struct sockaddr #define MAX_BUF 1024 -#define PORT 5556 /* listen to 5556 port */ +#define PORT 5556 /* listen to 5556 port */ #define DH_BITS 1024 /* These are global */ @@ -360,10 +360,10 @@ server_start (void) memset (&sa_serv, '\0', sizeof (sa_serv)); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = INADDR_ANY; - sa_serv.sin_port = htons (PORT); /* Server Port number */ + sa_serv.sin_port = htons (PORT); /* Server Port number */ setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval, - sizeof (int)); + sizeof (int)); err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv)); if (err == -1) @@ -400,7 +400,7 @@ server (void) gnutls_certificate_set_x509_trust_mem (x509_cred, &ca, GNUTLS_X509_FMT_PEM); gnutls_certificate_set_x509_key_mem (x509_cred, &server_cert, &server_key, - GNUTLS_X509_FMT_PEM); + GNUTLS_X509_FMT_PEM); if (debug) success ("Launched, generating DH parameters...\n"); @@ -417,8 +417,8 @@ server (void) 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)); + inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf, + sizeof (topbuf)), ntohs (sa_cli.sin_port)); gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); ret = gnutls_handshake (session); @@ -433,8 +433,8 @@ server (void) { success ("server: Handshake was completed\n"); success ("server: TLS version is: %s\n", - gnutls_protocol_get_name (gnutls_protocol_get_version - (session))); + gnutls_protocol_get_name (gnutls_protocol_get_version + (session))); } /* see the Getting peer's information example */ @@ -448,47 +448,47 @@ server (void) ret = gnutls_record_recv (session, buffer, MAX_BUF); if (ret == 0) - { - if (debug) - success ("server: Peer has closed the GnuTLS connection\n"); - break; - } + { + if (debug) + success ("server: Peer has closed the GnuTLS connection\n"); + break; + } else if (ret < 0) - { - fail ("server: Received corrupted data(%d). Closing...\n", ret); - break; - } + { + fail ("server: Received corrupted data(%d). Closing...\n", ret); + break; + } else if (ret > 0) - { - gnutls_certificate_server_set_request (session, - GNUTLS_CERT_REQUEST); - - if (debug) - success ("server: got data, forcing rehandshake.\n"); - - ret = gnutls_rehandshake (session); - if (ret < 0) - { - fail ("server: rehandshake failed\n"); - gnutls_perror (ret); - break; - } - - ret = gnutls_handshake (session); - if (ret < 0) - { - fail ("server: (re)handshake failed\n"); - gnutls_perror (ret); - break; - } - - if (debug) - success ("server: rehandshake complete.\n"); - - /* echo data back to the client - */ - gnutls_record_send (session, buffer, strlen (buffer)); - } + { + gnutls_certificate_server_set_request (session, + GNUTLS_CERT_REQUEST); + + if (debug) + success ("server: got data, forcing rehandshake.\n"); + + ret = gnutls_rehandshake (session); + if (ret < 0) + { + fail ("server: rehandshake failed\n"); + gnutls_perror (ret); + break; + } + + ret = gnutls_handshake (session); + if (ret < 0) + { + fail ("server: (re)handshake failed\n"); + gnutls_perror (ret); + break; + } + + if (debug) + success ("server: rehandshake complete.\n"); + + /* echo data back to the client + */ + gnutls_record_send (session, buffer, strlen (buffer)); + } } /* do not wait for the peer to close the connection. */ diff --git a/tests/x509sign-verify.c b/tests/x509sign-verify.c index 8bde0118e0..32a6d67c86 100644 --- a/tests/x509sign-verify.c +++ b/tests/x509sign-verify.c @@ -159,13 +159,15 @@ doit (void) if (ret < 0) fail ("gnutls_x509_privkey_import\n"); - ret = gnutls_x509_privkey_sign_hash2 (key, GNUTLS_DIG_SHA1, 0, &hash_data, - &signature2); + ret = + gnutls_x509_privkey_sign_hash2 (key, GNUTLS_DIG_SHA1, 0, &hash_data, + &signature2); if (ret < 0) fail ("gnutls_x509_privkey_sign_hash\n"); - ret = gnutls_x509_privkey_sign_data2 (key, GNUTLS_DIG_SHA1, 0, &raw_data, - &signature); + ret = + gnutls_x509_privkey_sign_data2 (key, GNUTLS_DIG_SHA1, 0, &raw_data, + &signature); if (ret < 0) fail ("gnutls_x509_privkey_sign_hash\n"); |