diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-11-17 21:15:50 +0100 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-11-17 21:15:50 +0100 |
commit | 73ed8d8b99030c336ec1c95291b5d5571eecbbd0 (patch) | |
tree | cba3be1d437b5eb7550848a9f659be1c60b9de6c /tests | |
parent | 31a5679d33dbb2d4b677debc13860d9acd387c47 (diff) | |
download | gnutls-73ed8d8b99030c336ec1c95291b5d5571eecbbd0.tar.gz |
Use more warnings. Fix many warnings.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/anonself.c | 51 | ||||
-rw-r--r-- | tests/crypto_rng.c | 14 | ||||
-rw-r--r-- | tests/dhepskself.c | 53 | ||||
-rw-r--r-- | tests/dn.c | 4 | ||||
-rw-r--r-- | tests/finished.c | 14 | ||||
-rw-r--r-- | tests/gc.c | 6 | ||||
-rw-r--r-- | tests/mini.c | 10 | ||||
-rw-r--r-- | tests/openpgpself.c | 50 | ||||
-rw-r--r-- | tests/pkcs12_s2k.c | 8 | ||||
-rw-r--r-- | tests/pskself.c | 51 | ||||
-rw-r--r-- | tests/resume.c | 53 | ||||
-rw-r--r-- | tests/set_pkcs12_cred.c | 2 | ||||
-rw-r--r-- | tests/tlsia.c | 59 | ||||
-rw-r--r-- | tests/utils.c | 4 | ||||
-rw-r--r-- | tests/utils.h | 16 | ||||
-rw-r--r-- | tests/x509dn.c | 50 | ||||
-rw-r--r-- | tests/x509self.c | 50 | ||||
-rw-r--r-- | tests/x509signself.c | 53 |
19 files changed, 103 insertions, 447 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index c34a9dd830..da9e5d2277 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -28,8 +28,8 @@ endif EXTRA_DIST = libgcrypt.supp hostname-check.README +AM_CFLAGS = $(WARN_CFLAGS) AM_CPPFLAGS = \ - $(WARN_CFLAGS) \ -I$(top_srcdir)/gl \ -I$(top_builddir)/gl \ -I$(top_srcdir)/lib/includes \ diff --git a/tests/anonself.c b/tests/anonself.c index d2286bdb2a..2819becd54 100644 --- a/tests/anonself.c +++ b/tests/anonself.c @@ -37,6 +37,8 @@ #include <unistd.h> #include <gnutls/gnutls.h> +#include "tcp.c" + #include "utils.h" static void @@ -51,46 +53,7 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -void +static void client (void) { int ret, sd, ii; @@ -189,7 +152,7 @@ end: /* These are global */ gnutls_anon_server_credentials_t anoncred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -215,7 +178,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -235,7 +198,7 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -void +static void server_start (void) { /* Socket operations @@ -274,7 +237,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/crypto_rng.c b/tests/crypto_rng.c index e7fd425f14..5fd8557daf 100644 --- a/tests/crypto_rng.c +++ b/tests/crypto_rng.c @@ -32,28 +32,20 @@ #include <gnutls/crypto.h> #include "../lib/random.h" -void -mylogfn (int level, const char *ptr) -{ - printf ("Got Logs: "); - if (ptr) - printf ("%s", ptr); -} - -int +static int rng_init (void **ctx) { return 0; } -int +static int rng_rnd (void *ctx, int level, void *data, size_t datasize) { memset (data, 1, datasize); return 0; } -void +static void rng_deinit (void *ctx) { } diff --git a/tests/dhepskself.c b/tests/dhepskself.c index f0bf5d9d54..3d41f24c82 100644 --- a/tests/dhepskself.c +++ b/tests/dhepskself.c @@ -37,6 +37,8 @@ #include <unistd.h> #include <gnutls/gnutls.h> +#include "tcp.c" + #include "utils.h" /* A very basic TLS client, with PSK authentication. @@ -51,53 +53,14 @@ tls_log_func (int level, const char *str) fprintf (stderr, "|<%d>| %s", level, str); } -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -void +static void client (void) { int ret, sd, ii; gnutls_session_t session; char buffer[MAX_BUF + 1]; gnutls_psk_client_credentials_t pskcred; - const gnutls_datum_t key = { "DEADBEEF", 8 }; + const gnutls_datum_t key = { (char*) "DEADBEEF", 8 }; gnutls_global_init (); @@ -183,7 +146,7 @@ end: /* These are global */ gnutls_psk_server_credentials_t server_pskcred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -205,7 +168,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -238,7 +201,7 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -void +static void server_start (void) { success ("Launched, generating DH parameters...\n"); @@ -279,7 +242,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/dn.c b/tests/dn.c index 5528312b98..abae077665 100644 --- a/tests/dn.c +++ b/tests/dn.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007 Free Software Foundation + * Copyright (C) 2006, 2007, 2008 Free Software Foundation * Author: Simon Josefsson, Howard Chu * * This file is part of GNUTLS. @@ -59,7 +59,7 @@ static char pem[] = "bHarWgDg9CKVP1DggVkcD838s//kE1Vl2DReyfAtEQ1agSXLFncgxL+yOi1o3lcq\n" "+dmDgpDn168TY1Iug80uVKg7AfkLrA==\n" "-----END CERTIFICATE-----\n"; -void +static void print_dn (gnutls_x509_dn_t dn) { int i, j, ret = 0; diff --git a/tests/finished.c b/tests/finished.c index 4d82cd5403..5a5810ff4b 100644 --- a/tests/finished.c +++ b/tests/finished.c @@ -46,7 +46,7 @@ size_t to_server_len; char *to_client; size_t to_client_len; -ssize_t +static ssize_t client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { success ("client_pull len %d has %d\n", len, to_client_len); @@ -65,7 +65,7 @@ client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) return len; } -ssize_t +static ssize_t client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_server_len + len; @@ -88,7 +88,7 @@ client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) return len; } -ssize_t +static ssize_t server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { success ("server_pull len %d has %d\n", len, to_server_len); @@ -107,7 +107,7 @@ server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) return len; } -ssize_t +static ssize_t server_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_client_len + len; @@ -131,7 +131,7 @@ server_push (gnutls_transport_ptr_t tr, const void *data, size_t len) return len; } -void +static void client_finished_callback (gnutls_session_t session, const void *finished, size_t len) { @@ -139,7 +139,7 @@ client_finished_callback (gnutls_session_t session, hexprint (finished, len); } -void +static void server_finished_callback (gnutls_session_t session, const void *finished, size_t len) { @@ -155,7 +155,7 @@ doit (void) { /* Server stuff. */ gnutls_anon_server_credentials_t s_anoncred; - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; static gnutls_dh_params_t dh_params; gnutls_session_t server; int sret = GNUTLS_E_AGAIN; diff --git a/tests/gc.c b/tests/gc.c index 777a4a8992..70c6180525 100644 --- a/tests/gc.c +++ b/tests/gc.c @@ -32,12 +32,6 @@ #include "../lib/x509/pbkdf2-sha1.h" #include "../lib/debug.h" -int -is_secure_mem (const void *ign) -{ - return 0; -} - void doit (void) { diff --git a/tests/mini.c b/tests/mini.c index edda9f96b6..b64401db62 100644 --- a/tests/mini.c +++ b/tests/mini.c @@ -44,7 +44,7 @@ size_t to_server_len; char *to_client; size_t to_client_len; -ssize_t +static ssize_t client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { success ("client_pull len %d has %d\n", len, to_client_len); @@ -63,7 +63,7 @@ client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) return len; } -ssize_t +static ssize_t client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_server_len + len; @@ -86,7 +86,7 @@ client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) return len; } -ssize_t +static ssize_t server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { success ("server_pull len %d has %d\n", len, to_server_len); @@ -105,7 +105,7 @@ server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) return len; } -ssize_t +static ssize_t server_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_client_len + len; @@ -137,7 +137,7 @@ doit (void) { /* Server stuff. */ gnutls_anon_server_credentials_t s_anoncred; - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; static gnutls_dh_params_t dh_params; gnutls_session_t server; int sret = GNUTLS_E_AGAIN; diff --git a/tests/openpgpself.c b/tests/openpgpself.c index b399a111e8..fc802880cb 100644 --- a/tests/openpgpself.c +++ b/tests/openpgpself.c @@ -42,6 +42,7 @@ #include "ex-session-info.c" #include "ex-x509-info.c" +#include "tcp.c" pid_t child; @@ -57,45 +58,6 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - static unsigned char cert_txt[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" "Version: GnuPG v1.0.6 (GNU/Linux)\n" @@ -139,7 +101,7 @@ static unsigned char key_txt[] = "=4M0W\n" "-----END PGP PRIVATE KEY BLOCK-----\n"; const gnutls_datum_t key = { key_txt, sizeof (key_txt) }; -void +static void client (void) { int ret, sd, ii; @@ -249,7 +211,7 @@ end: /* These are global */ gnutls_certificate_credentials_t pgp_cred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -277,7 +239,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -372,7 +334,7 @@ static unsigned char server_key_txt[] = "=mZnW\n" "-----END PGP PRIVATE KEY BLOCK-----\n"; const gnutls_datum_t server_key = { server_key_txt, sizeof (server_key_txt) }; -void +static void server_start (void) { /* Socket operations @@ -411,7 +373,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/pkcs12_s2k.c b/tests/pkcs12_s2k.c index 03d1c66be9..f576137b35 100644 --- a/tests/pkcs12_s2k.c +++ b/tests/pkcs12_s2k.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Free Software Foundation + * Copyright (C) 2007, 2008 Free Software Foundation * * Author: Simon Josefsson * @@ -37,10 +37,10 @@ tls_log_func (int level, const char *str) fprintf (stderr, "|<%d>| %s", level, str); } -char *salt[3] = { "salt1", "ltsa22", "balt33" }; -char *pw[3] = { "secret1", "verysecret2", "veryverysecret3" }; +static const char *salt[3] = { "salt1", "ltsa22", "balt33" }; +static const char *pw[3] = { "secret1", "verysecret2", "veryverysecret3" }; -char *values[] = { +static const char *values[] = { /* 1.0 */ "85a3c676a66f0960f4807144a28c8d61a0001b81846f301a1ac164289879972f", /* 1.2 */ diff --git a/tests/pskself.c b/tests/pskself.c index 107b4e4324..3fb3c5875a 100644 --- a/tests/pskself.c +++ b/tests/pskself.c @@ -37,6 +37,8 @@ #include <unistd.h> #include <gnutls/gnutls.h> +#include "tcp.c" + #include "utils.h" /* A very basic TLS client, with PSK authentication. @@ -45,46 +47,7 @@ #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -void +static void client (void) { int ret, sd, ii; @@ -93,7 +56,7 @@ client (void) gnutls_psk_client_credentials_t pskcred; /* Need to enable anonymous KX specifically. */ const int kx_prio[] = { GNUTLS_KX_PSK, 0 }; - const gnutls_datum_t key = { "DEADBEEF", 8 }; + const gnutls_datum_t key = { (char*) "DEADBEEF", 8 }; gnutls_global_init (); @@ -181,7 +144,7 @@ end: /* These are global */ gnutls_psk_server_credentials_t server_pskcred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -223,7 +186,7 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -void +static void server_start (void) { success ("Launched...\n"); @@ -264,7 +227,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/resume.c b/tests/resume.c index 2dd656fee1..b70bac444b 100644 --- a/tests/resume.c +++ b/tests/resume.c @@ -37,6 +37,8 @@ #include <unistd.h> #include <gnutls/gnutls.h> +#include "tcp.c" + #include "utils.h" static void wrap_db_init (void); @@ -53,46 +55,7 @@ static int wrap_db_delete (void *dbf, gnutls_datum_t key); #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -void +static void client (void) { int ret, sd, ii; @@ -223,7 +186,7 @@ client (void) /* These are global */ gnutls_anon_server_credentials_t anoncred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -257,7 +220,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -277,7 +240,7 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -void +static void global_start (void) { /* Socket operations @@ -316,7 +279,7 @@ global_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void global_stop (void) { success ("global stop\n"); @@ -328,7 +291,7 @@ global_stop (void) gnutls_global_deinit (); } -void +static void server (void) { size_t t; diff --git a/tests/set_pkcs12_cred.c b/tests/set_pkcs12_cred.c index c0349a24c3..ebdf8b111e 100644 --- a/tests/set_pkcs12_cred.c +++ b/tests/set_pkcs12_cred.c @@ -32,7 +32,7 @@ void doit (void) { gnutls_certificate_credentials_t x509cred; - char *file, *password; + const char *file, *password; int ret; ret = gnutls_global_init (); diff --git a/tests/tlsia.c b/tests/tlsia.c index 80e82be311..3b03b251bc 100644 --- a/tests/tlsia.c +++ b/tests/tlsia.c @@ -40,6 +40,8 @@ #include "utils.h" +#include "tcp.c" + #include <readline.h> /* A very basic TLS client, with anonymous authentication. @@ -48,51 +50,12 @@ #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -int +static int client_avp (gnutls_session_t session, void *ptr, const char *last, size_t lastlen, char **new, size_t * newlen) { static int iter = 0; - char *p; + const char *p; if (last) printf ("client: received %d bytes AVP: `%.*s'\n", @@ -137,7 +100,7 @@ client_avp (gnutls_session_t session, void *ptr, return 0; } -void +static void client (void) { int ret, sd, ii; @@ -273,7 +236,7 @@ end: gnutls_anon_server_credentials_t anoncred; gnutls_ia_server_credentials_t iacred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -299,7 +262,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -319,12 +282,12 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -int +static int server_avp (gnutls_session_t session, void *ptr, const char *last, size_t lastlen, char **new, size_t * newlen) { static int iter = 0; - char *p; + const char *p; if (last) printf ("server: received %d bytes AVP: `%.*s'\n", @@ -397,7 +360,7 @@ server_avp (gnutls_session_t session, void *ptr, return 0; } -void +static void server_start (void) { /* Socket operations @@ -436,7 +399,7 @@ server_start (void) success ("server: ready. Listening to port '%d'\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/utils.c b/tests/utils.c index 3630318bb4..441a9d0511 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation * * Author: Simon Josefsson * @@ -33,7 +33,7 @@ int debug = 0; int error_count = 0; int break_on_error = 0; -char *pkcs3 = +const char *pkcs3 = "-----BEGIN DH PARAMETERS-----\n" "MIGGAoGAtkxw2jlsVCsrfLqxrN+IrF/3W8vVFvDzYbLmxi2GQv9s/PQGWP1d9i22\n" "P2DprfcJknWt7KhCI1SaYseOQIIIAYP78CfyIpGScW/vS8khrw0rlQiyeCvQgF3O\n" diff --git a/tests/utils.h b/tests/utils.h index 88d100f73d..cb3c57b6ee 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007 Free Software Foundation + * Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation * * Author: Simon Josefsson * @@ -27,14 +27,22 @@ # include <stdarg.h> # include <gnutls/gnutls.h> +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# define __attribute__(Spec) /* empty */ +# endif +#endif + extern int debug; extern int error_count; extern int break_on_error; -extern char *pkcs3; +extern const char *pkcs3; -extern void fail (const char *format, ...); -extern void success (const char *format, ...); +extern void fail (const char *format, ...) + __attribute__ ((format (printf, 1, 2))); +extern void success (const char *format, ...) + __attribute__ ((format (printf, 1, 2))); extern void escapeprint (const char *str, size_t len); extern void hexprint (const char *str, size_t len); diff --git a/tests/x509dn.c b/tests/x509dn.c index 9434ee9979..27ad6f1cd4 100644 --- a/tests/x509dn.c +++ b/tests/x509dn.c @@ -41,6 +41,7 @@ #include "ex-session-info.c" #include "ex-x509-info.c" +#include "tcp.c" pid_t child; @@ -56,45 +57,6 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - static unsigned char ca_pem[] = "-----BEGIN CERTIFICATE-----\n" "MIIB5zCCAVKgAwIBAgIERiYdJzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n" @@ -210,7 +172,7 @@ cert_callback (gnutls_session session, } -void +static void client (void) { int ret, sd, ii; @@ -315,7 +277,7 @@ end: /* These are global */ gnutls_certificate_credentials_t x509_cred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -343,7 +305,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -405,7 +367,7 @@ const gnutls_datum_t server_key = { server_key_pem, sizeof (server_key_pem) }; -void +static void server_start (void) { /* Socket operations @@ -444,7 +406,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/x509self.c b/tests/x509self.c index 1d6c26e045..fd95190156 100644 --- a/tests/x509self.c +++ b/tests/x509self.c @@ -41,6 +41,7 @@ #include "ex-session-info.c" #include "ex-x509-info.c" +#include "tcp.c" pid_t child; @@ -56,45 +57,6 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - static unsigned char ca_pem[] = "-----BEGIN CERTIFICATE-----\n" "MIIB5zCCAVKgAwIBAgIERiYdJzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n" @@ -144,7 +106,7 @@ static unsigned char key_pem[] = "-----END RSA PRIVATE KEY-----\n"; const gnutls_datum_t key = { key_pem, sizeof (key_pem) }; -void +static void client (void) { int ret, sd, ii; @@ -249,7 +211,7 @@ end: /* These are global */ gnutls_certificate_credentials_t x509_cred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -277,7 +239,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -339,7 +301,7 @@ const gnutls_datum_t server_key = { server_key_pem, sizeof (server_key_pem) }; -void +static void server_start (void) { /* Socket operations @@ -378,7 +340,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/x509signself.c b/tests/x509signself.c index 7920cc6f00..7b1586a149 100644 --- a/tests/x509signself.c +++ b/tests/x509signself.c @@ -40,7 +40,7 @@ #include "ex-session-info.c" #include "ex-x509-info.c" -extern int print_info (gnutls_session_t session); +#include "tcp.c" #include "utils.h" @@ -58,45 +58,6 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - static char ca_pem[] = "-----BEGIN CERTIFICATE-----\n" "MIIB5zCCAVKgAwIBAgIERiYdJzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n" @@ -128,7 +89,7 @@ static char cert_pem[] = "dc8Siq5JojruiMizAf0pA7in\n" "-----END CERTIFICATE-----\n"; const gnutls_datum_t cert = { cert_pem, sizeof (cert_pem) }; -int +static int sign_func (gnutls_session_t session, void *userdata, gnutls_certificate_type_t cert_type, @@ -174,7 +135,7 @@ done: return ret; } -void +static void client (void) { int ret, sd, ii; @@ -282,7 +243,7 @@ end: /* These are global */ gnutls_certificate_credentials_t x509_cred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -310,7 +271,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -371,7 +332,7 @@ const gnutls_datum_t server_key = { server_key_pem, sizeof (server_key_pem) }; -void +static void server_start (void) { /* Socket operations @@ -410,7 +371,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program |