diff options
author | David Benjamin <davidben@google.com> | 2016-07-28 00:51:49 +0300 |
---|---|---|
committer | CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org> | 2016-07-29 01:59:18 +0300 |
commit | 4497e589616910b42d5fa8b84b9c5059fb9d9f42 (patch) | |
tree | 135ee41769c1507fdcdb7ae0b5071ccbd642f967 /ssl/d1_both.c | |
parent | 02edcd009800c9d5354c1bb7080d0ec4dd4f23eb (diff) |
Switch finish_handshake to release_current_message.
With the previous DTLS change, the dispatch layer only cares about the
end of the handshake to know when to drop the current message. TLS 1.3
post-handshake messages will need a similar hook, so convert it to this
lower-level one.
BUG=83
Change-Id: I4c8c3ba55ba793afa065bf261a7bccac8816c348
Reviewed-on: https://boringssl-review.googlesource.com/8989
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Diffstat (limited to 'ssl/d1_both.c')
-rw-r--r-- | ssl/d1_both.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/ssl/d1_both.c b/ssl/d1_both.c index 1d9cd75c..712c63b7 100644 --- a/ssl/d1_both.c +++ b/ssl/d1_both.c @@ -262,17 +262,6 @@ static int dtls1_is_current_message_complete(const SSL *ssl) { return frag != NULL && frag->reassembly == NULL; } -/* dtls1_pop_message removes the current handshake message, which must be - * complete, and advances to the next one. */ -static void dtls1_pop_message(SSL *ssl) { - assert(dtls1_is_current_message_complete(ssl)); - - size_t index = ssl->d1->handshake_read_seq % SSL_MAX_HANDSHAKE_FLIGHT; - dtls1_hm_fragment_free(ssl->d1->incoming_messages[index]); - ssl->d1->incoming_messages[index] = NULL; - ssl->d1->handshake_read_seq++; -} - /* dtls1_get_incoming_message returns the incoming message corresponding to * |msg_hdr|. If none exists, it creates a new one and inserts it in the * queue. Otherwise, it checks |msg_hdr| is consistent with the existing one. It @@ -412,12 +401,12 @@ int dtls1_get_message(SSL *ssl, int msg_type, * ssl_dont_hash_message would have to have been applied to the previous * call. */ assert(hash_message == ssl_hash_message); - assert(dtls1_is_current_message_complete(ssl)); + assert(ssl->init_msg != NULL); ssl->s3->tmp.reuse_message = 0; hash_message = ssl_dont_hash_message; - } else if (dtls1_is_current_message_complete(ssl)) { - dtls1_pop_message(ssl); + } else { + dtls1_release_current_message(ssl, 0 /* don't free buffer */); } /* Process handshake records until the current message is ready. */ @@ -463,6 +452,21 @@ int dtls1_hash_current_message(SSL *ssl) { DTLS1_HM_HEADER_LENGTH + frag->msg_len); } +void dtls1_release_current_message(SSL *ssl, int free_buffer) { + if (ssl->init_msg == NULL) { + return; + } + + assert(dtls1_is_current_message_complete(ssl)); + size_t index = ssl->d1->handshake_read_seq % SSL_MAX_HANDSHAKE_FLIGHT; + dtls1_hm_fragment_free(ssl->d1->incoming_messages[index]); + ssl->d1->incoming_messages[index] = NULL; + ssl->d1->handshake_read_seq++; + + ssl->init_msg = NULL; + ssl->init_num = 0; +} + void dtls_clear_incoming_messages(SSL *ssl) { for (size_t i = 0; i < SSL_MAX_HANDSHAKE_FLIGHT; i++) { dtls1_hm_fragment_free(ssl->d1->incoming_messages[i]); @@ -471,13 +475,14 @@ void dtls_clear_incoming_messages(SSL *ssl) { } int dtls_has_incoming_messages(const SSL *ssl) { - /* This function may not be called if there is a pending |dtls1_get_message| - * operation. */ - assert(dtls1_is_current_message_complete(ssl)); - size_t current = ssl->d1->handshake_read_seq % SSL_MAX_HANDSHAKE_FLIGHT; for (size_t i = 0; i < SSL_MAX_HANDSHAKE_FLIGHT; i++) { - if (i != current && ssl->d1->incoming_messages[i] != NULL) { + /* Skip the current message. */ + if (ssl->init_msg != NULL && i == current) { + assert(dtls1_is_current_message_complete(ssl)); + continue; + } + if (ssl->d1->incoming_messages[i] != NULL) { return 1; } } |