diff options
Diffstat (limited to 'tests/send-data-before-handshake.c')
-rw-r--r-- | tests/send-data-before-handshake.c | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/tests/send-data-before-handshake.c b/tests/send-data-before-handshake.c index 6b0c2dffba..e932e14dc7 100644 --- a/tests/send-data-before-handshake.c +++ b/tests/send-data-before-handshake.c @@ -20,7 +20,7 @@ */ #ifdef HAVE_CONFIG_H -#include <config.h> +# include <config.h> #endif #include <stdio.h> @@ -35,19 +35,19 @@ int main(void) #else -#include <string.h> -#include <sys/types.h> -#include <netinet/in.h> -#include <sys/socket.h> -#include <sys/wait.h> -#include <arpa/inet.h> -#include <unistd.h> -#include <gnutls/gnutls.h> -#include <gnutls/dtls.h> -#include <signal.h> -#include <assert.h> -#include "cert-common.h" -#include "utils.h" +# include <string.h> +# include <sys/types.h> +# include <netinet/in.h> +# include <sys/socket.h> +# include <sys/wait.h> +# include <arpa/inet.h> +# include <unistd.h> +# include <gnutls/gnutls.h> +# include <gnutls/dtls.h> +# include <signal.h> +# include <assert.h> +# include "cert-common.h" +# include "utils.h" /* This program tests that a client cannot send any unencrypted data * during the handshake process. That is to ensure we protect buggy clients @@ -65,7 +65,8 @@ static void client_log_func(int level, const char *str) } static int handshake_callback(gnutls_session_t session, unsigned int htype, - unsigned post, unsigned int incoming, const gnutls_datum_t *msg) + unsigned post, unsigned int incoming, + const gnutls_datum_t * msg) { int ret; char c = 0; @@ -76,16 +77,18 @@ static int handshake_callback(gnutls_session_t session, unsigned int htype, /* sending */ ret = gnutls_record_send(session, &c, 1); if (ret != GNUTLS_E_UNAVAILABLE_DURING_HANDSHAKE) { - fail("gnutls_record_send returned %s/%d at %s\n", gnutls_strerror(ret), ret, gnutls_handshake_description_get_name(htype)); + fail("gnutls_record_send returned %s/%d at %s\n", + gnutls_strerror(ret), ret, + gnutls_handshake_description_get_name(htype)); } else { - success("expected behavior after %s\n", gnutls_handshake_description_get_name(htype)); + success("expected behavior after %s\n", + gnutls_handshake_description_get_name(htype)); } return 0; } - -#define MAX_BUF 1024 +# define MAX_BUF 1024 static void client(int fd, const char *prio) { @@ -108,11 +111,10 @@ static void client(int fd, const char *prio) */ gnutls_init(&session, GNUTLS_CLIENT); - assert(gnutls_priority_set_direct(session, prio, NULL)>=0); + assert(gnutls_priority_set_direct(session, prio, NULL) >= 0); gnutls_handshake_set_hook_function(session, GNUTLS_HANDSHAKE_ANY, - GNUTLS_HOOK_PRE, - handshake_callback); + GNUTLS_HOOK_PRE, handshake_callback); gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred); @@ -146,14 +148,12 @@ static void client(int fd, const char *prio) do { do { ret = gnutls_record_recv(session, buffer, MAX_BUF); - } while (ret == GNUTLS_E_AGAIN - || ret == GNUTLS_E_INTERRUPTED); + } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED); } while (ret > 0); 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) { fail("client: Error: %s\n", gnutls_strerror(ret)); @@ -162,7 +162,7 @@ static void client(int fd, const char *prio) gnutls_bye(session, GNUTLS_SHUT_WR); - end: + end: close(fd); @@ -173,7 +173,6 @@ static void client(int fd, const char *prio) gnutls_global_deinit(); } - /* These are global */ pid_t child; @@ -196,12 +195,11 @@ static void server(int fd, const char *prio) gnutls_certificate_allocate_credentials(&x509_cred); gnutls_certificate_set_x509_key_mem(x509_cred, &server_cert, - &server_key, - GNUTLS_X509_FMT_PEM); + &server_key, GNUTLS_X509_FMT_PEM); gnutls_init(&session, GNUTLS_SERVER); - assert(gnutls_priority_set_direct(session, prio, NULL)>=0); + assert(gnutls_priority_set_direct(session, prio, NULL) >= 0); gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred); |