From 94dd29772d9eea6c825c09b3c60aec4f7f706010 Mon Sep 17 00:00:00 2001 From: Achim Kraus Date: Tue, 24 Jan 2023 18:52:54 +0100 Subject: [PATCH] Add renegotiation info to test clients. Signed-off-by: Achim Kraus --- tests/dtls-client.c | 19 ++++++++++++++----- tests/dtls-server.c | 10 ++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/dtls-client.c b/tests/dtls-client.c index 84c530c6..f5f2809a 100644 --- a/tests/dtls-client.c +++ b/tests/dtls-client.c @@ -62,6 +62,7 @@ static dtls_context_t *orig_dtls_context = NULL; static const dtls_cipher_t* ciphers = NULL; static unsigned int force_extended_master_secret = 0; +static unsigned int force_renegotiation_info = 0; #ifdef DTLS_ECC @@ -238,6 +239,7 @@ get_user_parameters(struct dtls_context_t *ctx, (void) ctx; (void) session; user_parameters->force_extended_master_secret = force_extended_master_secret; + user_parameters->force_renegotiation_info = force_renegotiation_info; if (ciphers) { int index = 0; while (index < DTLS_MAX_CIPHER_SUITES) { @@ -353,19 +355,23 @@ usage( const char *program, const char *version) { fprintf(stderr, "%s v%s -- DTLS client implementation\n" "(c) 2011-2014 Olaf Bergmann \n\n" #ifdef DTLS_PSK - "usage: %s [-c cipher suites] [-e] [-i file] [-k file] [-o file] [-p port] [-v num] addr [port]\n", + "usage: %s [-c cipher suites] [-e] [-i file] [-k file] [-o file]\n" + " %*s [-p port] [-r] [-v num] addr [port]\n", #else /* DTLS_PSK */ - "usage: %s [-c cipher suites] [-e] [-o file] [-p port] [-v num] addr [port]\n", + "usage: %s [-c cipher suites] [-e] [-o file] [-p port] [-r]\n" + " %*s [-v num] addr [port]\n", #endif /* DTLS_PSK */ - program, version, program); + program, version, program, (int)strlen(program), ""); cipher_suites_usage(stderr, "\t"); fprintf(stderr, "\t-e\t\tforce extended master secret (RFC7627)\n" #ifdef DTLS_PSK "\t-i file\t\tread PSK identity from file\n" "\t-k file\t\tread pre-shared key from file\n" #endif /* DTLS_PSK */ - "\t-o file\t\toutput received data to this file (use '-' for STDOUT)\n" + "\t-o file\t\toutput received data to this file\n" + "\t \t\t(use '-' for STDOUT)\n" "\t-p port\t\tlisten on specified port (default is %d)\n" + "\t-r\t\tforce renegotiation info (RFC5746)\n" "\t-v num\t\tverbosity level (default: 3)\n", DEFAULT_PORT); } @@ -422,7 +428,7 @@ main(int argc, char **argv) { memcpy(psk_key, PSK_DEFAULT_KEY, psk_key_length); #endif /* DTLS_PSK */ - while ((opt = getopt(argc, argv, "c:eo:p:v:" PSK_OPTIONS)) != -1) { + while ((opt = getopt(argc, argv, "c:eo:p:rv:" PSK_OPTIONS)) != -1) { switch (opt) { #ifdef DTLS_PSK case 'i' : @@ -464,6 +470,9 @@ main(int argc, char **argv) { strncpy(port_str, optarg, NI_MAXSERV-1); port_str[NI_MAXSERV - 1] = '\0'; break; + case 'r' : + force_renegotiation_info = 1; + break; case 'v' : log_level = strtol(optarg, NULL, 10); break; diff --git a/tests/dtls-server.c b/tests/dtls-server.c index 309f0b5c..4b713ca4 100644 --- a/tests/dtls-server.c +++ b/tests/dtls-server.c @@ -48,6 +48,7 @@ static dtls_context_t *the_context = NULL; static volatile int cmd_exit = 0; static const dtls_cipher_t* ciphers = NULL; static unsigned int force_extended_master_secret = 0; +static unsigned int force_renegotiation_info = 0; #ifdef DTLS_ECC static const unsigned char ecdsa_priv_key[] = { @@ -199,6 +200,7 @@ get_user_parameters(struct dtls_context_t *ctx, (void) ctx; (void) session; user_parameters->force_extended_master_secret = force_extended_master_secret; + user_parameters->force_renegotiation_info = force_renegotiation_info; if (ciphers) { int index = 0; while (index < DTLS_MAX_CIPHER_SUITES) { @@ -307,12 +309,13 @@ usage(const char *program, const char *version) { fprintf(stderr, "%s v%s -- DTLS server implementation\n" "(c) 2011-2014 Olaf Bergmann \n\n" - "usage: %s [-A address] [-c cipher suites] [-e] [-p port] [-v num]\n" + "usage: %s [-A address] [-c cipher suites] [-e] [-p port] [-r] [-v num]\n" "\t-A address\t\tlisten on specified address (default is ::)\n", program, version, program); cipher_suites_usage(stderr, "\t"); fprintf(stderr, "\t-e\t\tforce extended master secret (RFC7627)\n" "\t-p port\t\tlisten on specified port (default is %d)\n" + "\t-r\t\tforce renegotiation info (RFC5746)\n" "\t-v num\t\tverbosity level (default: 3)\n", DEFAULT_PORT); } @@ -355,7 +358,7 @@ main(int argc, char **argv) { listen_addr.sin6_family = AF_INET6; listen_addr.sin6_addr = in6addr_any; - while ((opt = getopt(argc, argv, "A:c:ep:v:")) != -1) { + while ((opt = getopt(argc, argv, "A:c:ep:rv:")) != -1) { switch (opt) { case 'A' : if (resolve_address(optarg, (struct sockaddr *)&listen_addr) < 0) { @@ -372,6 +375,9 @@ main(int argc, char **argv) { case 'p' : port = htons(atoi(optarg)); break; + case 'r' : + force_renegotiation_info = 1; + break; case 'v' : log_level = strtol(optarg, NULL, 10); break;