Move post-handshake message handling out of read_app_data.
This finishes getting rid of ssl_read_bytes! Now we have separate
entry-points for the various cases. For now, I've kept TLS handshake
consuming records partially. When we do the BIO-less API, I expect that
will need to change, since we won't have the record buffer available.
(Instead, the ssl3_read_handshake_bytes and extend_handshake_buffer pair
will look more like the DTLS side or Go and pull the entire record into
init_buf.)
This change opts to make read_app_data drive the message to completion
in anticipation of DTLS 1.3. That hasn't been specified, but
NewSessionTicket certainly will exist. Knowing that DTLS necessarily has
interleave seems something better suited for the SSL_PROTOCOL_METHOD
internals to drive.
It needs refining, but SSL_PROTOCOL_METHOD is now actually a half-decent
abstraction boundary between the higher-level protocol logic and
DTLS/TLS-specific record-layer and message dispatchy bits.
BUG=83
Change-Id: I9b4626bb8a29d9cb30174d9e6912bb420ed45aff
Reviewed-on: https://boringssl-review.googlesource.com/9001
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/ssl/s3_both.c b/ssl/s3_both.c
index 7608c34..0dd67bc 100644
--- a/ssl/s3_both.c
+++ b/ssl/s3_both.c
@@ -337,10 +337,28 @@
* not accept peer certificate chains. */
static const size_t kMaxMessageLen = 16384;
- if ((!ssl->server || (ssl->verify_mode & SSL_VERIFY_PEER)) &&
- kMaxMessageLen < ssl->max_cert_list) {
- return ssl->max_cert_list;
+ if (SSL_in_init(ssl)) {
+ if ((!ssl->server || (ssl->verify_mode & SSL_VERIFY_PEER)) &&
+ kMaxMessageLen < ssl->max_cert_list) {
+ return ssl->max_cert_list;
+ }
+ return kMaxMessageLen;
}
+
+ if (ssl3_protocol_version(ssl) < TLS1_3_VERSION) {
+ /* In TLS 1.2 and below, the largest acceptable post-handshake message is
+ * a HelloRequest. */
+ return 0;
+ }
+
+ if (ssl->server) {
+ /* The largest acceptable post-handshake message for a server is a
+ * KeyUpdate. We will never initiate post-handshake auth. */
+ return 0;
+ }
+
+ /* Clients must accept NewSessionTicket and CertificateRequest, so allow the
+ * default size. */
return kMaxMessageLen;
}
@@ -349,10 +367,9 @@
return -1;
}
while (ssl->init_buf->length < length) {
- int ret =
- ssl3_read_bytes(ssl, SSL3_RT_HANDSHAKE,
- (uint8_t *)ssl->init_buf->data + ssl->init_buf->length,
- length - ssl->init_buf->length, 0);
+ int ret = ssl3_read_handshake_bytes(
+ ssl, (uint8_t *)ssl->init_buf->data + ssl->init_buf->length,
+ length - ssl->init_buf->length);
if (ret <= 0) {
return ret;
}
@@ -584,9 +601,9 @@
ssl->init_msg = (uint8_t*)ssl->init_buf->data + SSL3_HM_HEADER_LENGTH;
ssl->init_num = ssl->init_buf->length - SSL3_HM_HEADER_LENGTH;
- /* Ignore stray HelloRequest messages. Per RFC 5246, section 7.4.1.1, the
- * server may send HelloRequest at any time. */
- if (!ssl->server &&
+ /* Ignore stray HelloRequest messages in the handshake before TLS 1.3. Per RFC
+ * 5246, section 7.4.1.1, the server may send HelloRequest at any time. */
+ if (!ssl->server && SSL_in_init(ssl) &&
(!ssl->s3->have_version || ssl3_protocol_version(ssl) < TLS1_3_VERSION) &&
ssl->s3->tmp.message_type == SSL3_MT_HELLO_REQUEST &&
ssl->init_num == 0) {