Skip to content

Commit

Permalink
Handle partial handshake messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tmshort committed Aug 30, 2019
1 parent 363cf3d commit a472a8d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions ssl/ssl_locl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ typedef struct cert_pkey_st CERT_PKEY;
struct quic_data_st {
struct quic_data_st *next;
OSSL_ENCRYPTION_LEVEL level;
size_t offset;
size_t length;
};
typedef struct quic_data_st QUIC_DATA;
Expand Down
28 changes: 22 additions & 6 deletions ssl/ssl_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,26 @@ int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
QUIC_DATA *qd;
const uint8_t *p = data + 1;

/* Check for an incomplete block */
qd = ssl->quic_input_data_tail;
if (qd != NULL) {
l = ssl->quic_input_data_tail->length - ssl->quic_input_data_tail->offset;
if (l != 0) {
/* we still need to copy `l` bytes into the last data block */
if (l > len)
l = len;
memcpy((char*)(qd+1) + qd->offset, data, l);
qd->offset += l;
len -= l;
data += l;
continue;
}
}

n2l3(p, l);
l += SSL3_HM_HEADER_LENGTH;

if (l > len) {
SSLerr(SSL_F_SSL_PROVIDE_QUIC_DATA, SSL_R_BAD_DATA_LENGTH);
return 0;
}

qd = OPENSSL_malloc(sizeof(QUIC_DATA) + l);
qd = OPENSSL_zalloc(sizeof(QUIC_DATA) + l);
if (qd == NULL) {
SSLerr(SSL_F_SSL_PROVIDE_QUIC_DATA, SSL_R_INTERNAL_ERROR);
return 0;
Expand All @@ -131,6 +142,11 @@ int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
qd->next = NULL;
qd->length = l;
qd->level = level;
/* partial data received? */
if (l > len)
l = len;
qd->offset = l;

memcpy((void*)(qd + 1), data, l);
if (ssl->quic_input_data_tail != NULL)
ssl->quic_input_data_tail->next = qd;
Expand Down

0 comments on commit a472a8d

Please sign in to comment.