Skip to content

Commit

Permalink
enforce consistent encryption level for handshake messages
Browse files Browse the repository at this point in the history
The QUIC-TLS spec requires that TLS handshake messages do not cross
encryption level boundaries, but we were not previously enforcing this.
  • Loading branch information
kaduk authored and tmshort committed Dec 11, 2020
1 parent 0bbcd60 commit 5b76e4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions ssl/ssl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ struct ssl_st {
#ifndef OPENSSL_NO_QUIC
OSSL_ENCRYPTION_LEVEL quic_read_level;
OSSL_ENCRYPTION_LEVEL quic_write_level;
OSSL_ENCRYPTION_LEVEL quic_latest_level_received;
BUF_MEM *quic_buf; /* buffer incoming handshake messages */
QUIC_DATA *quic_input_data_head;
QUIC_DATA *quic_input_data_tail;
Expand Down
12 changes: 11 additions & 1 deletion ssl/ssl_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,

/* Level can be different than the current read, but not less */
if (level < ssl->quic_read_level
|| (ssl->quic_input_data_tail != NULL && level < ssl->quic_input_data_tail->level)) {
|| (ssl->quic_input_data_tail != NULL && level < ssl->quic_input_data_tail->level)
|| level < ssl->quic_latest_level_received) {
SSLerr(SSL_F_SSL_PROVIDE_QUIC_DATA, SSL_R_WRONG_ENCRYPTION_LEVEL_RECEIVED);
return 0;
}
Expand All @@ -122,6 +123,15 @@ int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
buf = NULL;
}

/* A TLS message must not cross an encryption level boundary */
if (ssl->quic_buf->length != ssl->quic_next_record_start
&& level != ssl->quic_latest_level_received) {
SSLerr(SSL_F_SSL_PROVIDE_QUIC_DATA,
SSL_R_WRONG_ENCRYPTION_LEVEL_RECEIVED);
return 0;
}
ssl->quic_latest_level_received = level;

offset = ssl->quic_buf->length;
if (!BUF_MEM_grow(ssl->quic_buf, offset + len)) {
SSLerr(SSL_F_SSL_PROVIDE_QUIC_DATA, SSL_R_INTERNAL_ERROR);
Expand Down

0 comments on commit 5b76e4f

Please sign in to comment.