diff options
author | jsing <> | 2021-03-17 18:08:32 +0000 |
---|---|---|
committer | jsing <> | 2021-03-17 18:08:32 +0000 |
commit | e1e6bd710141831f3f7a3926738ccb4ae42103fb (patch) | |
tree | 4009074b3e330a781c67b90419e631a63ddf8425 /src/usr.bin/openssl/s_client.c | |
parent | f117ae71ebe1eb8f946b06304b3843715ad808b0 (diff) | |
download | openbsd-e1e6bd710141831f3f7a3926738ccb4ae42103fb.tar.gz openbsd-e1e6bd710141831f3f7a3926738ccb4ae42103fb.tar.bz2 openbsd-e1e6bd710141831f3f7a3926738ccb4ae42103fb.zip |
Add DTLSv1.2 support to openssl(1) s_client/s_server.
ok inoguchi@ tb@
Diffstat (limited to 'src/usr.bin/openssl/s_client.c')
-rw-r--r-- | src/usr.bin/openssl/s_client.c | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/src/usr.bin/openssl/s_client.c b/src/usr.bin/openssl/s_client.c index eeeecff1bb..f03f8a9505 100644 --- a/src/usr.bin/openssl/s_client.c +++ b/src/usr.bin/openssl/s_client.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: s_client.c,v 1.52 2020/10/14 05:36:18 tb Exp $ */ | 1 | /* $OpenBSD: s_client.c,v 1.53 2021/03/17 18:08:32 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -260,7 +260,7 @@ s_client_opt_keymatexportlen(char *arg) | |||
260 | return (0); | 260 | return (0); |
261 | } | 261 | } |
262 | 262 | ||
263 | #ifndef OPENSSL_NO_DTLS1 | 263 | #ifndef OPENSSL_NO_DTLS |
264 | static int | 264 | static int |
265 | s_client_opt_mtu(char *arg) | 265 | s_client_opt_mtu(char *arg) |
266 | { | 266 | { |
@@ -285,11 +285,35 @@ s_client_opt_port(char *arg) | |||
285 | return (0); | 285 | return (0); |
286 | } | 286 | } |
287 | 287 | ||
288 | #ifndef OPENSSL_NO_DTLS | ||
289 | static int | ||
290 | s_client_opt_protocol_version_dtls(void) | ||
291 | { | ||
292 | s_client_config.meth = DTLS_client_method(); | ||
293 | s_client_config.socket_type = SOCK_DGRAM; | ||
294 | return (0); | ||
295 | } | ||
296 | #endif | ||
297 | |||
288 | #ifndef OPENSSL_NO_DTLS1 | 298 | #ifndef OPENSSL_NO_DTLS1 |
289 | static int | 299 | static int |
290 | s_client_opt_protocol_version_dtls1(void) | 300 | s_client_opt_protocol_version_dtls1(void) |
291 | { | 301 | { |
292 | s_client_config.meth = DTLS_client_method(); | 302 | s_client_config.meth = DTLS_client_method(); |
303 | s_client_config.min_version = DTLS1_VERSION; | ||
304 | s_client_config.max_version = DTLS1_VERSION; | ||
305 | s_client_config.socket_type = SOCK_DGRAM; | ||
306 | return (0); | ||
307 | } | ||
308 | #endif | ||
309 | |||
310 | #ifndef OPENSSL_NO_DTLS1_2 | ||
311 | static int | ||
312 | s_client_opt_protocol_version_dtls1_2(void) | ||
313 | { | ||
314 | s_client_config.meth = DTLS_client_method(); | ||
315 | s_client_config.min_version = DTLS1_2_VERSION; | ||
316 | s_client_config.max_version = DTLS1_2_VERSION; | ||
293 | s_client_config.socket_type = SOCK_DGRAM; | 317 | s_client_config.socket_type = SOCK_DGRAM; |
294 | return (0); | 318 | return (0); |
295 | } | 319 | } |
@@ -472,6 +496,14 @@ static const struct option s_client_options[] = { | |||
472 | .type = OPTION_FLAG, | 496 | .type = OPTION_FLAG, |
473 | .opt.flag = &s_client_config.debug, | 497 | .opt.flag = &s_client_config.debug, |
474 | }, | 498 | }, |
499 | #ifndef OPENSSL_NO_DTLS | ||
500 | { | ||
501 | .name = "dtls", | ||
502 | .desc = "Use any version of DTLS", | ||
503 | .type = OPTION_FUNC, | ||
504 | .opt.func = s_client_opt_protocol_version_dtls, | ||
505 | }, | ||
506 | #endif | ||
475 | #ifndef OPENSSL_NO_DTLS1 | 507 | #ifndef OPENSSL_NO_DTLS1 |
476 | { | 508 | { |
477 | .name = "dtls1", | 509 | .name = "dtls1", |
@@ -480,6 +512,14 @@ static const struct option s_client_options[] = { | |||
480 | .opt.func = s_client_opt_protocol_version_dtls1, | 512 | .opt.func = s_client_opt_protocol_version_dtls1, |
481 | }, | 513 | }, |
482 | #endif | 514 | #endif |
515 | #ifndef OPENSSL_NO_DTLS1_2 | ||
516 | { | ||
517 | .name = "dtls1_2", | ||
518 | .desc = "Just use DTLSv1.2", | ||
519 | .type = OPTION_FUNC, | ||
520 | .opt.func = s_client_opt_protocol_version_dtls1_2, | ||
521 | }, | ||
522 | #endif | ||
483 | { | 523 | { |
484 | .name = "groups", | 524 | .name = "groups", |
485 | .argname = "list", | 525 | .argname = "list", |
@@ -546,7 +586,7 @@ static const struct option s_client_options[] = { | |||
546 | .type = OPTION_FLAG, | 586 | .type = OPTION_FLAG, |
547 | .opt.flag = &s_client_config.msg, | 587 | .opt.flag = &s_client_config.msg, |
548 | }, | 588 | }, |
549 | #ifndef OPENSSL_NO_DTLS1 | 589 | #ifndef OPENSSL_NO_DTLS |
550 | { | 590 | { |
551 | .name = "mtu", | 591 | .name = "mtu", |
552 | .argname = "mtu", | 592 | .argname = "mtu", |
@@ -745,7 +785,7 @@ static const struct option s_client_options[] = { | |||
745 | .type = OPTION_FLAG, | 785 | .type = OPTION_FLAG, |
746 | .opt.flag = &s_client_config.status_req, | 786 | .opt.flag = &s_client_config.status_req, |
747 | }, | 787 | }, |
748 | #ifndef OPENSSL_NO_DTLS1 | 788 | #ifndef OPENSSL_NO_DTLS |
749 | { | 789 | { |
750 | .name = "timeout", | 790 | .name = "timeout", |
751 | .desc = "Enable send/receive timeout on DTLS connections", | 791 | .desc = "Enable send/receive timeout on DTLS connections", |
@@ -828,7 +868,7 @@ sc_usage(void) | |||
828 | "[-4 | -6] [-alpn protocols] [-bugs] [-CAfile file]\n" | 868 | "[-4 | -6] [-alpn protocols] [-bugs] [-CAfile file]\n" |
829 | " [-CApath directory] [-cert file] [-certform der | pem] [-check_ss_sig]\n" | 869 | " [-CApath directory] [-cert file] [-certform der | pem] [-check_ss_sig]\n" |
830 | " [-cipher cipherlist] [-connect host[:port]] [-crl_check]\n" | 870 | " [-cipher cipherlist] [-connect host[:port]] [-crl_check]\n" |
831 | " [-crl_check_all] [-crlf] [-debug] [-dtls1] [-extended_crl]\n" | 871 | " [-crl_check_all] [-crlf] [-debug] [-dtls] [-dtls1] [-dtls1_2] [-extended_crl]\n" |
832 | " [-groups list] [-host host] [-ign_eof] [-ignore_critical]\n" | 872 | " [-groups list] [-host host] [-ign_eof] [-ignore_critical]\n" |
833 | " [-issuer_checks] [-key keyfile] [-keyform der | pem]\n" | 873 | " [-issuer_checks] [-key keyfile] [-keyform der | pem]\n" |
834 | " [-keymatexport label] [-keymatexportlen len] [-legacy_server_connect]\n" | 874 | " [-keymatexport label] [-keymatexportlen len] [-legacy_server_connect]\n" |
@@ -1090,8 +1130,7 @@ s_client_main(int argc, char **argv) | |||
1090 | if (s_client_config.pause & 0x01) | 1130 | if (s_client_config.pause & 0x01) |
1091 | SSL_set_debug(con, 1); | 1131 | SSL_set_debug(con, 1); |
1092 | 1132 | ||
1093 | if (SSL_version(con) == DTLS1_VERSION) { | 1133 | if (SSL_is_dtls(con)) { |
1094 | |||
1095 | sbio = BIO_new_dgram(s, BIO_NOCLOSE); | 1134 | sbio = BIO_new_dgram(s, BIO_NOCLOSE); |
1096 | if (getsockname(s, (struct sockaddr *)&peer, | 1135 | if (getsockname(s, (struct sockaddr *)&peer, |
1097 | (void *)&peerlen) == -1) { | 1136 | (void *)&peerlen) == -1) { |
@@ -1290,8 +1329,7 @@ s_client_main(int argc, char **argv) | |||
1290 | struct pollfd pfd[3]; /* stdin, stdout, socket */ | 1329 | struct pollfd pfd[3]; /* stdin, stdout, socket */ |
1291 | int ptimeout = -1; | 1330 | int ptimeout = -1; |
1292 | 1331 | ||
1293 | if ((SSL_version(con) == DTLS1_VERSION) && | 1332 | if (SSL_is_dtls(con) && DTLSv1_get_timeout(con, &timeout)) |
1294 | DTLSv1_get_timeout(con, &timeout)) | ||
1295 | ptimeout = timeout.tv_sec * 1000 + | 1333 | ptimeout = timeout.tv_sec * 1000 + |
1296 | timeout.tv_usec / 1000; | 1334 | timeout.tv_usec / 1000; |
1297 | 1335 | ||
@@ -1370,10 +1408,9 @@ s_client_main(int argc, char **argv) | |||
1370 | /* goto end; */ | 1408 | /* goto end; */ |
1371 | } | 1409 | } |
1372 | } | 1410 | } |
1373 | if ((SSL_version(con) == DTLS1_VERSION) && | 1411 | if (SSL_is_dtls(con) && |
1374 | DTLSv1_handle_timeout(con) > 0) { | 1412 | DTLSv1_handle_timeout(con) > 0) |
1375 | BIO_printf(bio_err, "TIMEOUT occured\n"); | 1413 | BIO_printf(bio_err, "TIMEOUT occured\n"); |
1376 | } | ||
1377 | if (!ssl_pending && | 1414 | if (!ssl_pending && |
1378 | (pfd[2].revents & (POLLOUT|POLLERR|POLLNVAL))) { | 1415 | (pfd[2].revents & (POLLOUT|POLLERR|POLLNVAL))) { |
1379 | if (pfd[2].revents & (POLLERR|POLLNVAL)) { | 1416 | if (pfd[2].revents & (POLLERR|POLLNVAL)) { |