Skip to content

Commit

Permalink
Adds initial dtls 1.3 structs and definitions
Browse files Browse the repository at this point in the history
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from #22259)
  • Loading branch information
fwh-dc authored and mattcaswell committed Apr 23, 2024
1 parent 264ff64 commit e381120
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/openssl/prov_ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C" {
# define TLS1_3_VERSION 0x0304
# define DTLS1_VERSION 0xFEFF
# define DTLS1_2_VERSION 0xFEFD
# define DTLS1_3_VERSION 0xFEFC
# define DTLS1_BAD_VER 0x0100

/* QUIC uses a 4 byte unsigned version number */
Expand Down
1 change: 1 addition & 0 deletions include/openssl/ssl.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ typedef int (*SSL_async_callback_fn)(SSL *s, void *arg);
# define SSL_OP_NO_TLSv1_3 SSL_OP_BIT(29)
# define SSL_OP_NO_DTLSv1 SSL_OP_BIT(26)
# define SSL_OP_NO_DTLSv1_2 SSL_OP_BIT(27)
# define SSL_OP_NO_DTLSv1_3 SSL_OP_BIT(29)
/* Disallow all renegotiation */
# define SSL_OP_NO_RENEGOTIATION SSL_OP_BIT(30)
/*
Expand Down
15 changes: 15 additions & 0 deletions ssl/d1_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ const SSL3_ENC_METHOD DTLSv1_2_enc_data = {
dtls1_handshake_write
};

const SSL3_ENC_METHOD DTLSv1_3_enc_data = {
tls13_setup_key_block,
tls13_generate_master_secret,
tls13_change_cipher_state,
tls13_final_finish_mac,
TLS_MD_CLIENT_FINISH_CONST, TLS_MD_CLIENT_FINISH_CONST_SIZE,
TLS_MD_SERVER_FINISH_CONST, TLS_MD_SERVER_FINISH_CONST_SIZE,
tls13_alert_code,
tls13_export_keying_material,
SSL_ENC_FLAG_DTLS | SSL_ENC_FLAG_SIGALGS | SSL_ENC_FLAG_SHA256_PRF,
dtls1_set_handshake_header,
dtls1_close_construct_packet,
dtls1_handshake_write
};

OSSL_TIME dtls1_default_timeout(void)
{
/*
Expand Down
18 changes: 18 additions & 0 deletions ssl/methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ IMPLEMENT_dtls1_meth_func(DTLS1_2_VERSION, 0, SSL_OP_NO_DTLSv1_2,
ossl_statem_accept,
ossl_statem_connect, DTLSv1_2_enc_data)
#endif
#ifndef OPENSSL_NO_DTLS1_3_METHOD
IMPLEMENT_dtls1_meth_func(DTLS1_3_VERSION, 0, SSL_OP_NO_DTLSv1_3,
dtlsv1_3_method,
ossl_statem_accept,
ossl_statem_connect, DTLSv1_3_enc_data)
#endif
IMPLEMENT_dtls1_meth_func(DTLS_ANY_VERSION, 0, 0,
DTLS_method,
ossl_statem_accept,
Expand All @@ -145,6 +151,12 @@ IMPLEMENT_dtls1_meth_func(DTLS1_2_VERSION, 0, SSL_OP_NO_DTLSv1_2,
ossl_statem_accept,
ssl_undefined_function, DTLSv1_2_enc_data)
#endif
#ifndef OPENSSL_NO_DTLS1_3_METHOD
IMPLEMENT_dtls1_meth_func(DTLS1_3_VERSION, 0, SSL_OP_NO_DTLSv1_3,
dtlsv1_3_server_method,
ossl_statem_accept,
ssl_undefined_function, DTLSv1_3_enc_data)
#endif
IMPLEMENT_dtls1_meth_func(DTLS_ANY_VERSION, 0, 0,
DTLS_server_method,
ossl_statem_accept,
Expand All @@ -169,6 +181,12 @@ IMPLEMENT_dtls1_meth_func(DTLS1_2_VERSION, 0, SSL_OP_NO_DTLSv1_2,
ssl_undefined_function,
ossl_statem_connect, DTLSv1_2_enc_data)
#endif
#ifndef OPENSSL_NO_DTLS1_3_METHOD
IMPLEMENT_dtls1_meth_func(DTLS1_3_VERSION, 0, SSL_OP_NO_DTLSv1_3,
dtlsv1_3_client_method,
ssl_undefined_function,
ossl_statem_connect, DTLSv1_3_enc_data)
#endif
IMPLEMENT_dtls1_meth_func(DTLS_ANY_VERSION, 0, 0,
DTLS_client_method,
ssl_undefined_function,
Expand Down
1 change: 1 addition & 0 deletions ssl/record/methods/recmethod_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ extern const struct record_functions_st tls_1_funcs;
extern const struct record_functions_st tls_1_3_funcs;
extern const struct record_functions_st tls_any_funcs;
extern const struct record_functions_st dtls_1_funcs;
extern const struct record_functions_st dtls_1_3_funcs;
extern const struct record_functions_st dtls_any_funcs;

void ossl_rlayer_fatal(OSSL_RECORD_LAYER *rl, int al, int reason,
Expand Down
21 changes: 21 additions & 0 deletions ssl/record/methods/tls13_meth.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,24 @@ const struct record_functions_st tls_1_3_funcs = {
tls_post_encryption_processing_default,
NULL
};

const struct record_functions_st dtls_1_3_funcs = {
tls13_set_crypto_state,
tls13_cipher,
NULL,
tls_default_set_protocol_version,
tls_default_read_n,
dtls_get_more_records,
NULL,
tls13_post_process_record,
NULL,
tls_write_records_default,
tls_allocate_write_buffers_default,
tls_initialise_write_packets_default,
tls13_get_record_type,
dtls_prepare_record_header,
tls13_add_record_padding,
tls_prepare_for_encryption_default,
dtls_post_encryption_processing,
NULL
};
11 changes: 10 additions & 1 deletion ssl/ssl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,18 @@
# define SSL_CONNECTION_IS_DTLS(s) \
(SSL_CONNECTION_GET_SSL(s)->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS)

/* Check if we are using DTLSv1.3 */
# define SSL_CONNECTION_IS_DTLS13(s) (SSL_CONNECTION_IS_DTLS(s) \
&& DTLS_VERSION_GE(SSL_CONNECTION_GET_SSL(s)->method->version, DTLS1_3_VERSION) \
&& SSL_CONNECTION_GET_SSL(s)->method->version != DTLS_ANY_VERSION)

/* Check if we are using TLSv1.3 */
# define SSL_CONNECTION_IS_TLS13(s) (!SSL_CONNECTION_IS_DTLS(s) \
&& SSL_CONNECTION_GET_SSL(s)->method->version >= TLS1_3_VERSION \
&& SSL_CONNECTION_GET_SSL(s)->method->version != TLS_ANY_VERSION)

# define SSL_CONNECTION_TREAT_AS_TLS13(s) \
(SSL_CONNECTION_IS_TLS13(s) \
((SSL_CONNECTION_IS_TLS13(s) || SSL_CONNECTION_IS_DTLS13(s)) \
|| (s)->early_data_state == SSL_EARLY_DATA_CONNECTING \
|| (s)->early_data_state == SSL_EARLY_DATA_CONNECT_RETRY \
|| (s)->early_data_state == SSL_EARLY_DATA_WRITING \
Expand Down Expand Up @@ -2261,6 +2266,9 @@ __owur const SSL_METHOD *dtls_bad_ver_client_method(void);
__owur const SSL_METHOD *dtlsv1_2_method(void);
__owur const SSL_METHOD *dtlsv1_2_server_method(void);
__owur const SSL_METHOD *dtlsv1_2_client_method(void);
__owur const SSL_METHOD *dtlsv1_3_method(void);
__owur const SSL_METHOD *dtlsv1_3_server_method(void);
__owur const SSL_METHOD *dtlsv1_3_client_method(void);

extern const SSL3_ENC_METHOD TLSv1_enc_data;
extern const SSL3_ENC_METHOD TLSv1_1_enc_data;
Expand All @@ -2269,6 +2277,7 @@ extern const SSL3_ENC_METHOD TLSv1_3_enc_data;
extern const SSL3_ENC_METHOD SSLv3_enc_data;
extern const SSL3_ENC_METHOD DTLSv1_enc_data;
extern const SSL3_ENC_METHOD DTLSv1_2_enc_data;
extern const SSL3_ENC_METHOD DTLSv1_3_enc_data;

/*
* Flags for SSL methods
Expand Down

0 comments on commit e381120

Please sign in to comment.