Skip to content

Commit

Permalink
Add renegotiation info to test clients.
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
  • Loading branch information
boaks committed Jul 14, 2023
1 parent 555f461 commit 94dd297
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 14 additions & 5 deletions tests/dtls-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 <bergmann@tzi.org>\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);
}
Expand Down Expand Up @@ -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' :
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions tests/dtls-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 <bergmann@tzi.org>\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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 94dd297

Please sign in to comment.