Skip to content

Commit

Permalink
QUIC: Break up header/body processing
Browse files Browse the repository at this point in the history
As DTLS has changed, so too must QUIC.
  • Loading branch information
tmshort committed Aug 3, 2023
1 parent f3841a3 commit fe5ffe7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
9 changes: 6 additions & 3 deletions ssl/statem/statem.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ static SUB_STATE_RETURN read_state_machine(SSL *s)
#ifndef OPENSSL_NO_QUIC
} else if (SSL_IS_QUIC(s)) {
/* QUIC behaves like DTLS -- all in one go. */
ret = quic_get_message(s, &mt, &len);
ret = quic_get_message(s, &mt);
#endif
} else {
ret = tls_get_message_header(s, &mt);
Expand Down Expand Up @@ -636,8 +636,11 @@ static SUB_STATE_RETURN read_state_machine(SSL *s)
* opportunity to do any further processing.
*/
ret = dtls_get_message_body(s, &len);
} else if (!SSL_IS_QUIC(s)) {
/* We already got this above for QUIC */
#ifndef OPENSSL_NO_QUIC
} else if (SSL_IS_QUIC(s)) {
ret = quic_get_message_body(s, &len);
#endif
} else {
ret = tls_get_message_body(s, &len);
}
if (ret == 0) {
Expand Down
3 changes: 2 additions & 1 deletion ssl/statem/statem_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ __owur int tls_get_message_body(SSL *s, size_t *len);
__owur int dtls_get_message(SSL *s, int *mt);
__owur int dtls_get_message_body(SSL *s, size_t *len);
#ifndef OPENSSL_NO_QUIC
__owur int quic_get_message(SSL *s, int *mt, size_t *len);
__owur int quic_get_message(SSL *s, int *mt);
__owur int quic_get_message_body(SSL *s, size_t *len);
#endif

/* Message construction and processing functions */
Expand Down
25 changes: 15 additions & 10 deletions ssl/statem/statem_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@
#include "statem_local.h"
#include "internal/cryptlib.h"

int quic_get_message(SSL *s, int *mt, size_t *len)
int quic_get_message(SSL *s, int *mt)
{
size_t l;
QUIC_DATA *qd = s->quic_input_data_head;
uint8_t *p;

if (qd == NULL) {
s->rwstate = SSL_READING;
*mt = *len = 0;
*mt = 0;
return 0;
}

if (!ossl_assert(qd->length >= SSL3_HM_HEADER_LENGTH)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_LENGTH);
*mt = *len = 0;
*mt = 0;
return 0;
}

/* This is where we check for the proper level, not when data is given */
if (qd->level != s->quic_read_level) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_WRONG_ENCRYPTION_LEVEL_RECEIVED);
*mt = *len = 0;
*mt = 0;
return 0;
}

if (!BUF_MEM_grow_clean(s->init_buf, (int)qd->length)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_BUF_LIB);
*mt = *len = 0;
*mt = 0;
return 0;
}

Expand All @@ -53,28 +53,32 @@ int quic_get_message(SSL *s, int *mt, size_t *len)
s->s3.tmp.message_type = *mt = *(s->init_buf->data);
p = (uint8_t*)s->init_buf->data + 1;
n2l3(p, l);
s->init_num = s->s3.tmp.message_size = *len = l;
s->init_num = s->s3.tmp.message_size = l;
s->init_msg = s->init_buf->data + SSL3_HM_HEADER_LENGTH;

return 1;
}

int quic_get_message_body(SSL *s, size_t *len)
{
/* No CCS in QUIC/TLSv1.3? */
if (*mt == SSL3_MT_CHANGE_CIPHER_SPEC) {
if (s->s3.tmp.message_type == SSL3_MT_CHANGE_CIPHER_SPEC) {
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_R_CCS_RECEIVED_EARLY);
*len = 0;
return 0;
}
/* No KeyUpdate in QUIC */
if (*mt == SSL3_MT_KEY_UPDATE) {
if (s->s3.tmp.message_type == SSL3_MT_KEY_UPDATE) {
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_R_UNEXPECTED_MESSAGE);
*len = 0;
return 0;
}


/*
* If receiving Finished, record MAC of prior handshake messages for
* Finished verification.
*/
if (*mt == SSL3_MT_FINISHED && !ssl3_take_mac(s)) {
if (s->s3.tmp.message_type == SSL3_MT_FINISHED && !ssl3_take_mac(s)) {
/* SSLfatal() already called */
*len = 0;
return 0;
Expand Down Expand Up @@ -108,5 +112,6 @@ int quic_get_message(SSL *s, int *mt, size_t *len)
(size_t)s->init_num + SSL3_HM_HEADER_LENGTH, s,
s->msg_callback_arg);

*len = s->init_num;
return 1;
}

0 comments on commit fe5ffe7

Please sign in to comment.