diff options
Diffstat (limited to 'tests/tls13/post-handshake-with-psk.c')
-rw-r--r-- | tests/tls13/post-handshake-with-psk.c | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/tests/tls13/post-handshake-with-psk.c b/tests/tls13/post-handshake-with-psk.c index 6981bee7af..2333bd3ff6 100644 --- a/tests/tls13/post-handshake-with-psk.c +++ b/tests/tls13/post-handshake-with-psk.c @@ -20,7 +20,7 @@ */ #ifdef HAVE_CONFIG_H -# include <config.h> +#include <config.h> #endif #include <stdio.h> @@ -35,23 +35,23 @@ 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 <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 "tls13/ext-parse.h" -# include "utils.h" +#include "cert-common.h" +#include "tls13/ext-parse.h" +#include "utils.h" -# define MAX_AUTHS 4 +#define MAX_AUTHS 4 /* This program tests whether the Post Handshake Auth would work * under PSK authentication. */ @@ -66,7 +66,7 @@ static void client_log_func(int level, const char *str) fprintf(stderr, "client|<%d>| %s", level, str); } -# define MAX_BUF 1024 +#define MAX_BUF 1024 static void client(int fd, unsigned send_cert, unsigned max_auths) { @@ -93,22 +93,22 @@ static void client(int fd, unsigned send_cert, unsigned max_auths) /* Initialize TLS session */ - assert(gnutls_init(&session, GNUTLS_CLIENT | GNUTLS_POST_HANDSHAKE_AUTH) - >= 0); + assert(gnutls_init(&session, + GNUTLS_CLIENT | GNUTLS_POST_HANDSHAKE_AUTH) >= 0); gnutls_handshake_set_timeout(session, get_timeout()); - ret = - gnutls_priority_set_direct(session, - "NORMAL:-VERS-ALL:+VERS-TLS1.3:+VERS-TLS1.2:+VERS-TLS1.0:+ECDHE-PSK:+PSK", - NULL); + ret = gnutls_priority_set_direct( + session, + "NORMAL:-VERS-ALL:+VERS-TLS1.3:+VERS-TLS1.2:+VERS-TLS1.0:+ECDHE-PSK:+PSK", + NULL); if (ret < 0) fail("cannot set TLS 1.3 priorities\n"); if (send_cert) { - assert(gnutls_certificate_set_x509_key_mem - (x509_cred, &cli_ca3_cert, &cli_ca3_key, - GNUTLS_X509_FMT_PEM) >= 0); + assert(gnutls_certificate_set_x509_key_mem( + x509_cred, &cli_ca3_cert, &cli_ca3_key, + GNUTLS_X509_FMT_PEM) >= 0); } gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred); @@ -120,8 +120,7 @@ static void client(int fd, unsigned send_cert, unsigned max_auths) */ do { ret = gnutls_handshake(session); - } - while (ret < 0 && gnutls_error_is_fatal(ret) == 0); + } while (ret < 0 && gnutls_error_is_fatal(ret) == 0); if (ret != 0) fail("handshake failed: %s\n", gnutls_strerror(ret)); @@ -152,7 +151,8 @@ static void client(int fd, unsigned send_cert, unsigned max_auths) } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED); if (ret != 0) - fail("client: gnutls_reauth did not succeed as expected: %s\n", gnutls_strerror(ret)); + fail("client: gnutls_reauth did not succeed as expected: %s\n", + gnutls_strerror(ret)); } close(fd); @@ -168,9 +168,9 @@ static void client(int fd, unsigned send_cert, unsigned max_auths) static unsigned client_hello_ok = 0; static unsigned server_hello_ok = 0; -# define TLS_EXT_POST_HANDSHAKE 49 +#define TLS_EXT_POST_HANDSHAKE 49 -static void parse_ext(void *priv, gnutls_datum_t * msg) +static void parse_ext(void *priv, gnutls_datum_t *msg) { if (msg->size != 0) { fail("error in extension length: %d\n", (int)msg->size); @@ -179,11 +179,12 @@ static void parse_ext(void *priv, gnutls_datum_t * msg) static int hellos_callback(gnutls_session_t session, unsigned int htype, unsigned post, unsigned int incoming, - const gnutls_datum_t * msg) + const gnutls_datum_t *msg) { - if (htype == GNUTLS_HANDSHAKE_SERVER_HELLO && post == GNUTLS_HOOK_POST) { - if (find_server_extension - (msg, TLS_EXT_POST_HANDSHAKE, NULL, NULL)) { + if (htype == GNUTLS_HANDSHAKE_SERVER_HELLO && + post == GNUTLS_HOOK_POST) { + if (find_server_extension(msg, TLS_EXT_POST_HANDSHAKE, NULL, + NULL)) { fail("Post handshake extension seen in server hello!\n"); } server_hello_ok = 1; @@ -202,8 +203,8 @@ static int hellos_callback(gnutls_session_t session, unsigned int htype, return 0; } -static int -pskfunc(gnutls_session_t session, const char *username, gnutls_datum_t * key) +static int pskfunc(gnutls_session_t session, const char *username, + gnutls_datum_t *key) { if (debug) printf("psk: username %s\n", username); @@ -243,16 +244,16 @@ static void server(int fd, int err, int type, unsigned max_auths) &server_key, GNUTLS_X509_FMT_PEM) >= 0); - assert(gnutls_init(&session, GNUTLS_SERVER | GNUTLS_POST_HANDSHAKE_AUTH) - >= 0); + assert(gnutls_init(&session, + GNUTLS_SERVER | GNUTLS_POST_HANDSHAKE_AUTH) >= 0); gnutls_handshake_set_timeout(session, get_timeout()); gnutls_handshake_set_hook_function(session, GNUTLS_HANDSHAKE_ANY, GNUTLS_HOOK_BOTH, hellos_callback); - assert(gnutls_priority_set_direct - (session, "NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK:+ECDHE-PSK", - NULL) >= 0); + assert(gnutls_priority_set_direct( + session, "NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK:+ECDHE-PSK", + NULL) >= 0); gnutls_credentials_set(session, GNUTLS_CRD_PSK, server_pskcred); @@ -265,9 +266,8 @@ static void server(int fd, int err, int type, unsigned max_auths) if (ret != 0) fail("handshake failed: %s\n", gnutls_strerror(ret)); - if (! - (gnutls_session_get_flags(session) & - GNUTLS_SFLAGS_POST_HANDSHAKE_AUTH)) { + if (!(gnutls_session_get_flags(session) & + GNUTLS_SFLAGS_POST_HANDSHAKE_AUTH)) { fail("server: session flags did not contain GNUTLS_SFLAGS_POST_HANDSHAKE_AUTH\n"); } @@ -297,7 +297,8 @@ static void server(int fd, int err, int type, unsigned max_auths) gnutls_strerror(err), gnutls_strerror(ret)); } else if (ret != 0) { - fail("server: gnutls_reauth did not succeed as expected: %s\n", gnutls_strerror(ret)); + fail("server: gnutls_reauth did not succeed as expected: %s\n", + gnutls_strerror(ret)); } if (debug) @@ -324,9 +325,8 @@ static void ch_handler(int sig) return; } -static -void start(const char *name, int err, int type, unsigned max_auths, - unsigned send_cert) +static void start(const char *name, int err, int type, unsigned max_auths, + unsigned send_cert) { int fd[2]; int ret; @@ -363,7 +363,6 @@ void start(const char *name, int err, int type, unsigned max_auths, client(fd[1], send_cert, max_auths); exit(0); } - } void doit(void) @@ -373,4 +372,4 @@ void doit(void) GNUTLS_CERT_REQUIRE, 1, 0); start("reauth-request with no-cert", 0, GNUTLS_CERT_REQUEST, 1, 0); } -#endif /* _WIN32 */ +#endif /* _WIN32 */ |