From 4f043807106c29e08860daf7539770ed5ad40688 Mon Sep 17 00:00:00 2001 From: Frederik Wedel-Heinen Date: Tue, 3 Oct 2023 12:43:19 +0200 Subject: Integrate dtls1.3 in s_client and s_server Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/22260) --- apps/include/opt.h | 6 +++--- apps/lib/s_cb.c | 6 +++++- apps/s_client.c | 23 +++++++++++++++++++---- apps/s_server.c | 24 +++++++++++++++++++----- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/apps/include/opt.h b/apps/include/opt.h index 2bd2fb2484..3f412566d7 100644 --- a/apps/include/opt.h +++ b/apps/include/opt.h @@ -216,12 +216,12 @@ "Groups to advertise (colon-separated list)" }, \ {"named_curve", OPT_S_NAMEDCURVE, 's', \ "Elliptic curve used for ECDHE (server-side only)" }, \ - {"cipher", OPT_S_CIPHER, 's', "Specify TLSv1.2 and below cipher list to be used"}, \ - {"ciphersuites", OPT_S_CIPHERSUITES, 's', "Specify TLSv1.3 ciphersuites to be used"}, \ + {"cipher", OPT_S_CIPHER, 's', "Specify (D)TLSv1.2 and below cipher list to be used"}, \ + {"ciphersuites", OPT_S_CIPHERSUITES, 's', "Specify (D)TLSv1.3 ciphersuites to be used"}, \ {"min_protocol", OPT_S_MINPROTO, 's', "Specify the minimum protocol version to be used"}, \ {"max_protocol", OPT_S_MAXPROTO, 's', "Specify the maximum protocol version to be used"}, \ {"record_padding", OPT_S_RECORD_PADDING, 's', \ - "Block size to pad TLS 1.3 records to."}, \ + "Block size to pad (D)TLS 1.3 records to."}, \ {"debug_broken_protocol", OPT_S_DEBUGBROKE, '-', \ "Perform all sorts of protocol violations for testing purposes"}, \ {"no_middlebox", OPT_S_NO_MIDDLEBOX, '-', \ diff --git a/apps/lib/s_cb.c b/apps/lib/s_cb.c index 7a719b9b0c..5d9d43e2fd 100644 --- a/apps/lib/s_cb.c +++ b/apps/lib/s_cb.c @@ -550,6 +550,8 @@ static STRINT_PAIR ssl_versions[] = { {"TLS 1.2", TLS1_2_VERSION}, {"TLS 1.3", TLS1_3_VERSION}, {"DTLS 1.0", DTLS1_VERSION}, + {"DTLS 1.2", DTLS1_2_VERSION}, + {"DTLS 1.3", DTLS1_3_VERSION}, {"DTLS 1.0 (bad)", DTLS1_BAD_VER}, {NULL} }; @@ -632,7 +634,9 @@ void msg_cb(int write_p, int version, int content_type, const void *buf, version == TLS1_1_VERSION || version == TLS1_2_VERSION || version == TLS1_3_VERSION || - version == DTLS1_VERSION || version == DTLS1_BAD_VER) { + version == DTLS1_VERSION || + version == DTLS1_2_VERSION || + version == DTLS1_3_VERSION || version == DTLS1_BAD_VER) { str_version = lookup(version, ssl_versions, "???"); switch (content_type) { case SSL3_RT_CHANGE_CIPHER_SPEC: diff --git a/apps/s_client.c b/apps/s_client.c index 78a44755cb..433e9bb5b5 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -490,9 +490,9 @@ typedef enum OPTION_choice { #endif OPT_SSL3, OPT_SSL_CONFIG, OPT_TLS1_3, OPT_TLS1_2, OPT_TLS1_1, OPT_TLS1, OPT_DTLS, OPT_DTLS1, - OPT_DTLS1_2, OPT_QUIC, OPT_SCTP, OPT_TIMEOUT, OPT_MTU, OPT_KEYFORM, - OPT_PASS, OPT_CERT_CHAIN, OPT_KEY, OPT_RECONNECT, OPT_BUILD_CHAIN, - OPT_NEXTPROTONEG, OPT_ALPN, + OPT_DTLS1_2, OPT_DTLS1_3, OPT_QUIC, OPT_SCTP, OPT_TIMEOUT, OPT_MTU, + OPT_KEYFORM, OPT_PASS, OPT_CERT_CHAIN, OPT_KEY, OPT_RECONNECT, + OPT_BUILD_CHAIN, OPT_NEXTPROTONEG, OPT_ALPN, OPT_CAPATH, OPT_NOCAPATH, OPT_CHAINCAPATH, OPT_VERIFYCAPATH, OPT_CAFILE, OPT_NOCAFILE, OPT_CHAINCAFILE, OPT_VERIFYCAFILE, OPT_CASTORE, OPT_NOCASTORE, OPT_CHAINCASTORE, OPT_VERIFYCASTORE, @@ -695,6 +695,9 @@ const OPTIONS s_client_options[] = { #ifndef OPENSSL_NO_DTLS1_2 {"dtls1_2", OPT_DTLS1_2, '-', "Just use DTLSv1.2"}, #endif +#ifndef OPENSSL_NO_DTLS1_3 + {"dtls1_3", OPT_DTLS1_3, '-', "Just use DTLSv1.3"}, +#endif #ifndef OPENSSL_NO_SCTP {"sctp", OPT_SCTP, '-', "Use SCTP"}, {"sctp_label_bug", OPT_SCTP_LABEL_BUG, '-', "Enable SCTP label length bug"}, @@ -797,7 +800,7 @@ static const OPT_PAIR services[] = { #define IS_PROT_FLAG(o) \ (o == OPT_SSL3 || o == OPT_TLS1 || o == OPT_TLS1_1 || o == OPT_TLS1_2 \ || o == OPT_TLS1_3 || o == OPT_DTLS || o == OPT_DTLS1 || o == OPT_DTLS1_2 \ - || o == OPT_QUIC) + || o == OPT_DTLS1_3 || o == OPT_QUIC) /* Free |*dest| and optionally set it to a copy of |source|. */ static void freeandcopy(char **dest, const char *source) @@ -1349,6 +1352,18 @@ int s_client_main(int argc, char **argv) socket_type = SOCK_DGRAM; isdtls = 1; isquic = 0; +#endif + break; + case OPT_DTLS1_3: +#ifndef OPENSSL_NO_DTLS1_3 + meth = DTLS_client_method(); + min_version = DTLS1_3_VERSION; + max_version = DTLS1_3_VERSION; + socket_type = SOCK_DGRAM; + isdtls = 1; +# ifndef OPENSS_NO_QUIC + isquic = 0; +# endif #endif break; case OPT_QUIC: diff --git a/apps/s_server.c b/apps/s_server.c index 07086ef0f6..7c16a66d6a 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -54,6 +54,7 @@ typedef unsigned int u_int; #include #endif #include "internal/sockets.h" +#include "ssl/ssl_local.h" static int not_resumable_sess_cb(SSL *s, int is_forward_secure); static int sv_body(int s, int stype, int prot, unsigned char *context); @@ -134,7 +135,8 @@ static unsigned int psk_server_cb(SSL *ssl, const char *identity, if (s_debug) BIO_printf(bio_s_out, "psk_server_cb\n"); - if (!SSL_is_dtls(ssl) && SSL_version(ssl) >= TLS1_3_VERSION) { + if ((SSL_is_dtls(ssl) && DTLS_VERSION_GE(SSL_version(ssl), DTLS1_3_VERSION)) + || (!SSL_is_dtls(ssl) && SSL_version(ssl) >= TLS1_3_VERSION)) { /* * This callback is designed for use in (D)TLSv1.2 (or below). It is * possible to use a single callback for all protocol versions - but it @@ -730,8 +732,8 @@ typedef enum OPTION_choice { OPT_UPPER_WWW, OPT_HTTP, OPT_ASYNC, OPT_SSL_CONFIG, OPT_MAX_SEND_FRAG, OPT_SPLIT_SEND_FRAG, OPT_MAX_PIPELINES, OPT_READ_BUF, OPT_SSL3, OPT_TLS1_3, OPT_TLS1_2, OPT_TLS1_1, OPT_TLS1, OPT_DTLS, OPT_DTLS1, - OPT_DTLS1_2, OPT_SCTP, OPT_TIMEOUT, OPT_MTU, OPT_LISTEN, OPT_STATELESS, - OPT_ID_PREFIX, OPT_SERVERNAME, OPT_SERVERNAME_FATAL, + OPT_DTLS1_2, OPT_DTLS1_3, OPT_SCTP, OPT_TIMEOUT, OPT_MTU, OPT_LISTEN, + OPT_STATELESS, OPT_ID_PREFIX, OPT_SERVERNAME, OPT_SERVERNAME_FATAL, OPT_CERT2, OPT_KEY2, OPT_NEXTPROTONEG, OPT_ALPN, OPT_SENDFILE, OPT_SRTP_PROFILES, OPT_KEYMATEXPORT, OPT_KEYMATEXPORTLEN, OPT_KEYLOG_FILE, OPT_MAX_EARLY, OPT_RECV_MAX_EARLY, OPT_EARLY_DATA, @@ -939,7 +941,7 @@ const OPTIONS s_server_options[] = { "The maximum number of bytes of early data (hard limit)"}, {"early_data", OPT_EARLY_DATA, '-', "Attempt to read early data"}, {"num_tickets", OPT_S_NUM_TICKETS, 'n', - "The number of TLSv1.3 session tickets that a server will automatically issue" }, + "The number of (D)TLSv1.3 session tickets that a server will automatically issue" }, {"anti_replay", OPT_ANTI_REPLAY, '-', "Switch on anti-replay protection (default)"}, {"no_anti_replay", OPT_NO_ANTI_REPLAY, '-', "Switch off anti-replay protection"}, {"http_server_binmode", OPT_HTTP_SERVER_BINMODE, '-', "opening files in binary mode when acting as http server (-WWW and -HTTP)"}, @@ -972,6 +974,9 @@ const OPTIONS s_server_options[] = { #ifndef OPENSSL_NO_DTLS1_2 {"dtls1_2", OPT_DTLS1_2, '-', "Just talk DTLSv1.2"}, #endif +#ifndef OPENSSL_NO_DTLS1_3 + {"dtls1_3", OPT_DTLS1_3, '-', "Just talk DTLSv1.3"}, +#endif #ifndef OPENSSL_NO_SCTP {"sctp", OPT_SCTP, '-', "Use SCTP"}, {"sctp_label_bug", OPT_SCTP_LABEL_BUG, '-', "Enable SCTP label length bug"}, @@ -1004,7 +1009,8 @@ const OPTIONS s_server_options[] = { #define IS_PROT_FLAG(o) \ (o == OPT_SSL3 || o == OPT_TLS1 || o == OPT_TLS1_1 || o == OPT_TLS1_2 \ - || o == OPT_TLS1_3 || o == OPT_DTLS || o == OPT_DTLS1 || o == OPT_DTLS1_2) + || o == OPT_TLS1_3 || o == OPT_DTLS || o == OPT_DTLS1 || o == OPT_DTLS1_2 \ + || o == OPT_DTLS1_3) int s_server_main(int argc, char *argv[]) { @@ -1554,6 +1560,14 @@ int s_server_main(int argc, char *argv[]) min_version = DTLS1_2_VERSION; max_version = DTLS1_2_VERSION; socket_type = SOCK_DGRAM; +#endif + break; + case OPT_DTLS1_3: +#ifndef OPENSSL_NO_DTLS + meth = DTLS_server_method(); + min_version = DTLS1_3_VERSION; + max_version = DTLS1_3_VERSION; + socket_type = SOCK_DGRAM; #endif break; case OPT_SCTP: -- cgit v1.2.3