summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2020-07-14 18:56:00 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2020-07-14 18:56:00 +0000
commit6a3c58cd33ad6037517d2010f6c09b11cc665b90 (patch)
treee54b87e8f3fc48527db527b3d098ac36f5ad704a /lib
parentbc48936b2f76afc075cc5dc9a4aa7ffee84d1da4 (diff)
Dedup the use legacy stack code.
ok inoguchi@ tb@
Diffstat (limited to 'lib')
-rw-r--r--lib/libssl/tls13_legacy.c81
1 files changed, 25 insertions, 56 deletions
diff --git a/lib/libssl/tls13_legacy.c b/lib/libssl/tls13_legacy.c
index 39e34ab93ca..23f9c5f6645 100644
--- a/lib/libssl/tls13_legacy.c
+++ b/lib/libssl/tls13_legacy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls13_legacy.c,v 1.9 2020/06/24 18:04:33 jsing Exp $ */
+/* $OpenBSD: tls13_legacy.c,v 1.10 2020/07/14 18:55:59 jsing Exp $ */
/*
* Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
*
@@ -282,22 +282,18 @@ tls13_legacy_write_bytes(SSL *ssl, int type, const void *vbuf, int len)
}
}
-int
-tls13_use_legacy_client(struct tls13_ctx *ctx)
+static int
+tls13_use_legacy_stack(struct tls13_ctx *ctx)
{
SSL *s = ctx->ssl;
CBS cbs;
- s->method = tls_legacy_client_method();
- s->internal->handshake_func = s->method->internal->ssl_connect;
- s->client_version = s->version = s->method->internal->max_version;
-
if (!ssl3_setup_init_buffer(s))
- goto err;
+ return 0;
if (!ssl3_setup_buffers(s))
- goto err;
+ return 0;
if (!ssl_init_wbio_buffer(s, 0))
- goto err;
+ return 0;
if (s->bbio != s->wbio)
s->wbio = BIO_push(s->bbio, s->wbio);
@@ -308,7 +304,7 @@ tls13_use_legacy_client(struct tls13_ctx *ctx)
if (!CBS_write_bytes(&cbs,
S3I(s)->rbuf.buf + SSL3_RT_HEADER_LENGTH,
S3I(s)->rbuf.len - SSL3_RT_HEADER_LENGTH, NULL))
- goto err;
+ return 0;
S3I(s)->rbuf.offset = SSL3_RT_HEADER_LENGTH;
S3I(s)->rbuf.left = CBS_len(&cbs);
@@ -324,75 +320,48 @@ tls13_use_legacy_client(struct tls13_ctx *ctx)
tls13_handshake_msg_data(ctx->hs_msg, &cbs);
if (!CBS_write_bytes(&cbs, s->internal->init_buf->data,
s->internal->init_buf->length, NULL))
- goto err;
+ return 0;
S3I(s)->tmp.reuse_message = 1;
S3I(s)->tmp.message_type = tls13_handshake_msg_type(ctx->hs_msg);
S3I(s)->tmp.message_size = CBS_len(&cbs);
+ return 1;
+}
+
+int
+tls13_use_legacy_client(struct tls13_ctx *ctx)
+{
+ SSL *s = ctx->ssl;
+
+ s->method = tls_legacy_client_method();
+ s->internal->handshake_func = s->method->internal->ssl_connect;
+ s->client_version = s->version = s->method->internal->max_version;
+
+ if (!tls13_use_legacy_stack(ctx))
+ return 0;
+
S3I(s)->hs.state = SSL3_ST_CR_SRVR_HELLO_A;
return 1;
-
- err:
- return 0;
}
int
tls13_use_legacy_server(struct tls13_ctx *ctx)
{
SSL *s = ctx->ssl;
- CBS cbs;
s->method = tls_legacy_server_method();
s->internal->handshake_func = s->method->internal->ssl_accept;
s->client_version = s->version = s->method->internal->max_version;
s->server = 1;
- if (!ssl3_setup_init_buffer(s))
- goto err;
- if (!ssl3_setup_buffers(s))
- goto err;
- if (!ssl_init_wbio_buffer(s, 0))
- goto err;
-
- if (s->bbio != s->wbio)
- s->wbio = BIO_push(s->bbio, s->wbio);
-
- /* Stash any unprocessed data from the last record. */
- tls13_record_layer_rbuf(ctx->rl, &cbs);
- if (CBS_len(&cbs) > 0) {
- if (!CBS_write_bytes(&cbs,
- S3I(s)->rbuf.buf + SSL3_RT_HEADER_LENGTH,
- S3I(s)->rbuf.len - SSL3_RT_HEADER_LENGTH, NULL))
- goto err;
-
- S3I(s)->rbuf.offset = SSL3_RT_HEADER_LENGTH;
- S3I(s)->rbuf.left = CBS_len(&cbs);
- S3I(s)->rrec.type = SSL3_RT_HANDSHAKE;
- S3I(s)->rrec.length = CBS_len(&cbs);
- s->internal->rstate = SSL_ST_READ_BODY;
- s->internal->packet = S3I(s)->rbuf.buf;
- s->internal->packet_length = SSL3_RT_HEADER_LENGTH;
- s->internal->mac_packet = 1;
- }
-
- /* Stash the current handshake message. */
- tls13_handshake_msg_data(ctx->hs_msg, &cbs);
- if (!CBS_write_bytes(&cbs, s->internal->init_buf->data,
- s->internal->init_buf->length, NULL))
- goto err;
-
- S3I(s)->tmp.reuse_message = 1;
- S3I(s)->tmp.message_type = tls13_handshake_msg_type(ctx->hs_msg);
- S3I(s)->tmp.message_size = CBS_len(&cbs);
+ if (!tls13_use_legacy_stack(ctx))
+ return 0;
S3I(s)->hs.state = SSL3_ST_SR_CLNT_HELLO_A;
return 1;
-
- err:
- return 0;
}
int