From a4f376af7e98161c7513614cf4a110724a5a65f5 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Mon, 20 Feb 2017 15:44:42 +0000 Subject: [PATCH] Construct the early_data extension Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/2737) --- include/openssl/ssl.h | 1 + include/openssl/tls1.h | 1 + ssl/ssl_err.c | 2 ++ ssl/ssl_locl.h | 1 + ssl/statem/extensions.c | 5 +++++ ssl/statem/extensions_clnt.c | 20 ++++++++++++++++++++ ssl/statem/statem_locl.h | 2 ++ ssl/t1_trce.c | 3 ++- 8 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h index 7d3ac4e253..40965e6450 100644 --- a/include/openssl/ssl.h +++ b/include/openssl/ssl.h @@ -2330,6 +2330,7 @@ int ERR_load_SSL_strings(void); # define SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY 489 # define SSL_F_TLS_CONSTRUCT_CTOS_ALPN 466 # define SSL_F_TLS_CONSTRUCT_CTOS_CERTIFICATE 355 +# define SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA 521 # define SSL_F_TLS_CONSTRUCT_CTOS_EC_PT_FORMATS 467 # define SSL_F_TLS_CONSTRUCT_CTOS_EMS 468 # define SSL_F_TLS_CONSTRUCT_CTOS_ETM 469 diff --git a/include/openssl/tls1.h b/include/openssl/tls1.h index 63e9ee35cb..10544872b3 100644 --- a/include/openssl/tls1.h +++ b/include/openssl/tls1.h @@ -179,6 +179,7 @@ extern "C" { /* As defined for TLS1.3 */ # define TLSEXT_TYPE_key_share 40 # define TLSEXT_TYPE_psk 41 +# define TLSEXT_TYPE_early_data 42 # define TLSEXT_TYPE_supported_versions 43 # define TLSEXT_TYPE_psk_kex_modes 45 # define TLSEXT_TYPE_early_data_info 46 diff --git a/ssl/ssl_err.c b/ssl/ssl_err.c index 41d4a69dd8..c6cc375643 100644 --- a/ssl/ssl_err.c +++ b/ssl/ssl_err.c @@ -301,6 +301,8 @@ static ERR_STRING_DATA SSL_str_functs[] = { {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CTOS_ALPN), "tls_construct_ctos_alpn"}, {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CTOS_CERTIFICATE), "TLS_CONSTRUCT_CTOS_CERTIFICATE"}, + {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA), + "tls_construct_ctos_early_data"}, {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CTOS_EC_PT_FORMATS), "tls_construct_ctos_ec_pt_formats"}, {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CTOS_EMS), "tls_construct_ctos_ems"}, diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h index 86603a07c5..a168972613 100644 --- a/ssl/ssl_locl.h +++ b/ssl/ssl_locl.h @@ -1746,6 +1746,7 @@ typedef enum tlsext_index_en { TLSEXT_IDX_server_name, TLSEXT_IDX_srp, TLSEXT_IDX_early_data_info, + TLSEXT_IDX_early_data, TLSEXT_IDX_ec_point_formats, TLSEXT_IDX_supported_groups, TLSEXT_IDX_session_ticket, diff --git a/ssl/statem/extensions.c b/ssl/statem/extensions.c index 05e6acf340..a2efd0a739 100644 --- a/ssl/statem/extensions.c +++ b/ssl/statem/extensions.c @@ -135,6 +135,11 @@ static const EXTENSION_DEFINITION ext_defs[] = { NULL, NULL, tls_parse_stoc_early_data_info, tls_construct_stoc_early_data_info, NULL, NULL }, + { + TLSEXT_TYPE_early_data, + EXT_CLIENT_HELLO | EXT_TLS1_3_ENCRYPTED_EXTENSIONS, + NULL, NULL, NULL, NULL, tls_construct_ctos_early_data, NULL + }, #ifndef OPENSSL_NO_EC { TLSEXT_TYPE_ec_point_formats, diff --git a/ssl/statem/extensions_clnt.c b/ssl/statem/extensions_clnt.c index 7ef4c716cc..d80080740f 100644 --- a/ssl/statem/extensions_clnt.c +++ b/ssl/statem/extensions_clnt.c @@ -108,6 +108,26 @@ static int use_ecc(SSL *s) return i < end; } +int tls_construct_ctos_early_data(SSL *s, WPACKET *pkt, unsigned int context, + X509 *x, size_t chainidx, int *al) +{ + if (s->early_data_state != SSL_EARLY_DATA_CONNECTING + || s->session->ext.max_early_data == 0) { + s->max_early_data = 0; + return 1; + } + s->max_early_data = s->session->ext.max_early_data; + + if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_early_data) + || !WPACKET_start_sub_packet_u16(pkt) + || !WPACKET_close(pkt)) { + SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA, ERR_R_INTERNAL_ERROR); + return 0; + } + + return 1; +} + int tls_construct_ctos_ec_pt_formats(SSL *s, WPACKET *pkt, unsigned int context, X509 *x, size_t chainidx, int *al) { diff --git a/ssl/statem/statem_locl.h b/ssl/statem/statem_locl.h index 0274dcbcbe..99eb8ed319 100644 --- a/ssl/statem/statem_locl.h +++ b/ssl/statem/statem_locl.h @@ -288,6 +288,8 @@ int tls_construct_ctos_supported_groups(SSL *s, WPACKET *pkt, unsigned int context, X509 *x, size_t chainidx, int *al); #endif +int tls_construct_ctos_early_data(SSL *s, WPACKET *pkt, unsigned int context, + X509 *x, size_t chainidx, int *al); int tls_construct_ctos_session_ticket(SSL *s, WPACKET *pkt, unsigned int context, X509 *x, size_t chainidx, int *al); diff --git a/ssl/t1_trce.c b/ssl/t1_trce.c index 459827b76d..5cfaacd398 100644 --- a/ssl/t1_trce.c +++ b/ssl/t1_trce.c @@ -476,7 +476,8 @@ static ssl_trace_tbl ssl_exts_tbl[] = { {TLSEXT_TYPE_padding, "padding"}, {TLSEXT_TYPE_encrypt_then_mac, "encrypt_then_mac"}, {TLSEXT_TYPE_extended_master_secret, "extended_master_secret"}, - {TLSEXT_TYPE_early_data_info, "ticket_early_data_info"} + {TLSEXT_TYPE_early_data_info, "ticket_early_data_info"}, + {TLSEXT_TYPE_early_data, "early_data"} }; static ssl_trace_tbl ssl_groups_tbl[] = { -- 2.25.1