diff --git a/ssl/statem/extensions_srvr.c b/ssl/statem/extensions_srvr.c index 7f30ac7792f13aac69c230c822f800f10e9aed47..9fe58a780ad0bcd8bddb8776b6911dcadc42aab6 100644 --- a/ssl/statem/extensions_srvr.c +++ b/ssl/statem/extensions_srvr.c @@ -678,6 +678,11 @@ int tls_parse_ctos_early_data(SSL *s, PACKET *pkt, unsigned int context, return 0; } + if (s->hello_retry_request) { + *al = SSL_AD_ILLEGAL_PARAMETER; + return 0; + } + return 1; } diff --git a/ssl/statem/statem.c b/ssl/statem/statem.c index 9eab8ceca73d1895a464205a96e28677901155f5..e5a50c482de83cb6ae7fcdc0f5e7f9bd3a1261e8 100644 --- a/ssl/statem/statem.c +++ b/ssl/statem/statem.c @@ -157,13 +157,8 @@ int ossl_statem_skip_early_data(SSL *s) if (s->ext.early_data != SSL_EARLY_DATA_REJECTED) return 0; - if (s->hello_retry_request) { - if (s->statem.hand_state != TLS_ST_SW_HELLO_RETRY_REQUEST) - return 0; - } else { - if (!s->server || s->statem.hand_state != TLS_ST_EARLY_DATA) - return 0; - } + if (!s->server || s->statem.hand_state != TLS_ST_EARLY_DATA) + return 0; return 1; } diff --git a/ssl/statem/statem_clnt.c b/ssl/statem/statem_clnt.c index 55ac4dd03ef29229b4afd039fb9fdaa9b82407b9..ed9bd5c209161dbf65c9ca4d19a3b24eebdefa7f 100644 --- a/ssl/statem/statem_clnt.c +++ b/ssl/statem/statem_clnt.c @@ -1571,6 +1571,13 @@ static MSG_PROCESS_RETURN tls_process_hello_retry_request(SSL *s, PACKET *pkt) s->hello_retry_request = 1; + /* + * If we were sending early_data then the enc_write_ctx is now invalid and + * should not be used. + */ + EVP_CIPHER_CTX_free(s->enc_write_ctx); + s->enc_write_ctx = NULL; + /* This will fail if it doesn't choose TLSv1.3+ */ errorcode = ssl_choose_client_version(s, sversion, 0, &al); if (errorcode != 0) { diff --git a/ssl/statem/statem_srvr.c b/ssl/statem/statem_srvr.c index f3f54d429bad77c5198901fd0b98025ab79f4ee8..9d3c387dcd66b8cc1a87b3465809b5330fb4eca4 100644 --- a/ssl/statem/statem_srvr.c +++ b/ssl/statem/statem_srvr.c @@ -48,15 +48,14 @@ static int ossl_statem_server13_read_transition(SSL *s, int mt) default: break; - case TLS_ST_SW_HELLO_RETRY_REQUEST: - if (mt == SSL3_MT_CLIENT_HELLO) { - st->hand_state = TLS_ST_SR_CLNT_HELLO; - return 1; - } - break; - case TLS_ST_EARLY_DATA: - if (s->ext.early_data == SSL_EARLY_DATA_ACCEPTED) { + if (s->hello_retry_request) { + if (mt == SSL3_MT_CLIENT_HELLO) { + st->hand_state = TLS_ST_SR_CLNT_HELLO; + return 1; + } + break; + } else if (s->ext.early_data == SSL_EARLY_DATA_ACCEPTED) { if (mt == SSL3_MT_END_OF_EARLY_DATA) { st->hand_state = TLS_ST_SR_END_OF_EARLY_DATA; return 1; @@ -397,7 +396,8 @@ static WRITE_TRAN ossl_statem_server13_write_transition(SSL *s) return WRITE_TRAN_CONTINUE; case TLS_ST_SW_HELLO_RETRY_REQUEST: - return WRITE_TRAN_FINISHED; + st->hand_state = TLS_ST_EARLY_DATA; + return WRITE_TRAN_CONTINUE; case TLS_ST_SW_SRVR_HELLO: st->hand_state = TLS_ST_SW_ENCRYPTED_EXTENSIONS;