summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2021-03-29 16:46:09 +0000
committerjsing <>2021-03-29 16:46:09 +0000
commitffd3a25f2822ad41040600e98da045f9f9ca96dd (patch)
tree8a97f354c4119a96736fdf5834563fa25bf10bf4
parentf431352ee52eb3d8093a86cdc439cd6faf807ca7 (diff)
downloadopenbsd-ffd3a25f2822ad41040600e98da045f9f9ca96dd.tar.gz
openbsd-ffd3a25f2822ad41040600e98da045f9f9ca96dd.tar.bz2
openbsd-ffd3a25f2822ad41040600e98da045f9f9ca96dd.zip
Move finished and peer finished to the handshake struct.
This moves the finish_md and peer_finish_md from the 'tmp' struct to the handshake struct, renaming to finished and peer_finished in the process. This also allows the remaining S3I(s) references to be removed from the TLSv1.3 client and server. ok inoguchi@ tb@
-rw-r--r--src/lib/libssl/ssl_both.c24
-rw-r--r--src/lib/libssl/ssl_lib.c10
-rw-r--r--src/lib/libssl/ssl_locl.h16
-rw-r--r--src/lib/libssl/ssl_pkt.c6
-rw-r--r--src/lib/libssl/ssl_tlsext.c4
-rw-r--r--src/lib/libssl/tls13_client.c14
-rw-r--r--src/lib/libssl/tls13_server.c14
7 files changed, 44 insertions, 44 deletions
diff --git a/src/lib/libssl/ssl_both.c b/src/lib/libssl/ssl_both.c
index 789ab01213..4851231a8f 100644
--- a/src/lib/libssl/ssl_both.c
+++ b/src/lib/libssl/ssl_both.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_both.c,v 1.26 2021/03/27 17:56:28 tb Exp $ */ 1/* $OpenBSD: ssl_both.c,v 1.27 2021/03/29 16:46:09 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -176,25 +176,25 @@ ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen)
176 OPENSSL_assert(md_len <= EVP_MAX_MD_SIZE); 176 OPENSSL_assert(md_len <= EVP_MAX_MD_SIZE);
177 177
178 if (tls1_final_finish_mac(s, sender, slen, 178 if (tls1_final_finish_mac(s, sender, slen,
179 S3I(s)->tmp.finish_md) != md_len) 179 S3I(s)->hs.finished) != md_len)
180 return (0); 180 return (0);
181 S3I(s)->tmp.finish_md_len = md_len; 181 S3I(s)->hs.finished_len = md_len;
182 182
183 /* Copy finished so we can use it for renegotiation checks. */ 183 /* Copy finished so we can use it for renegotiation checks. */
184 if (!s->server) { 184 if (!s->server) {
185 memcpy(S3I(s)->previous_client_finished, 185 memcpy(S3I(s)->previous_client_finished,
186 S3I(s)->tmp.finish_md, md_len); 186 S3I(s)->hs.finished, md_len);
187 S3I(s)->previous_client_finished_len = md_len; 187 S3I(s)->previous_client_finished_len = md_len;
188 } else { 188 } else {
189 memcpy(S3I(s)->previous_server_finished, 189 memcpy(S3I(s)->previous_server_finished,
190 S3I(s)->tmp.finish_md, md_len); 190 S3I(s)->hs.finished, md_len);
191 S3I(s)->previous_server_finished_len = md_len; 191 S3I(s)->previous_server_finished_len = md_len;
192 } 192 }
193 193
194 if (!ssl3_handshake_msg_start(s, &cbb, &finished, 194 if (!ssl3_handshake_msg_start(s, &cbb, &finished,
195 SSL3_MT_FINISHED)) 195 SSL3_MT_FINISHED))
196 goto err; 196 goto err;
197 if (!CBB_add_bytes(&finished, S3I(s)->tmp.finish_md, md_len)) 197 if (!CBB_add_bytes(&finished, S3I(s)->hs.finished, md_len))
198 goto err; 198 goto err;
199 if (!ssl3_handshake_msg_finish(s, &cbb)) 199 if (!ssl3_handshake_msg_finish(s, &cbb))
200 goto err; 200 goto err;
@@ -235,9 +235,9 @@ ssl3_take_mac(SSL *s)
235 slen = TLS_MD_CLIENT_FINISH_CONST_SIZE; 235 slen = TLS_MD_CLIENT_FINISH_CONST_SIZE;
236 } 236 }
237 237
238 S3I(s)->tmp.peer_finish_md_len = 238 S3I(s)->hs.peer_finished_len =
239 tls1_final_finish_mac(s, sender, slen, 239 tls1_final_finish_mac(s, sender, slen,
240 S3I(s)->tmp.peer_finish_md); 240 S3I(s)->hs.peer_finished);
241} 241}
242 242
243int 243int
@@ -270,14 +270,14 @@ ssl3_get_finished(SSL *s, int a, int b)
270 270
271 CBS_init(&cbs, s->internal->init_msg, n); 271 CBS_init(&cbs, s->internal->init_msg, n);
272 272
273 if (S3I(s)->tmp.peer_finish_md_len != md_len || 273 if (S3I(s)->hs.peer_finished_len != md_len ||
274 CBS_len(&cbs) != md_len) { 274 CBS_len(&cbs) != md_len) {
275 al = SSL_AD_DECODE_ERROR; 275 al = SSL_AD_DECODE_ERROR;
276 SSLerror(s, SSL_R_BAD_DIGEST_LENGTH); 276 SSLerror(s, SSL_R_BAD_DIGEST_LENGTH);
277 goto fatal_err; 277 goto fatal_err;
278 } 278 }
279 279
280 if (!CBS_mem_equal(&cbs, S3I(s)->tmp.peer_finish_md, CBS_len(&cbs))) { 280 if (!CBS_mem_equal(&cbs, S3I(s)->hs.peer_finished, CBS_len(&cbs))) {
281 al = SSL_AD_DECRYPT_ERROR; 281 al = SSL_AD_DECRYPT_ERROR;
282 SSLerror(s, SSL_R_DIGEST_CHECK_FAILED); 282 SSLerror(s, SSL_R_DIGEST_CHECK_FAILED);
283 goto fatal_err; 283 goto fatal_err;
@@ -287,11 +287,11 @@ ssl3_get_finished(SSL *s, int a, int b)
287 OPENSSL_assert(md_len <= EVP_MAX_MD_SIZE); 287 OPENSSL_assert(md_len <= EVP_MAX_MD_SIZE);
288 if (s->server) { 288 if (s->server) {
289 memcpy(S3I(s)->previous_client_finished, 289 memcpy(S3I(s)->previous_client_finished,
290 S3I(s)->tmp.peer_finish_md, md_len); 290 S3I(s)->hs.peer_finished, md_len);
291 S3I(s)->previous_client_finished_len = md_len; 291 S3I(s)->previous_client_finished_len = md_len;
292 } else { 292 } else {
293 memcpy(S3I(s)->previous_server_finished, 293 memcpy(S3I(s)->previous_server_finished,
294 S3I(s)->tmp.peer_finish_md, md_len); 294 S3I(s)->hs.peer_finished, md_len);
295 S3I(s)->previous_server_finished_len = md_len; 295 S3I(s)->previous_server_finished_len = md_len;
296 } 296 }
297 297
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index c77fdd77e9..892922d761 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.253 2021/03/27 17:56:28 tb Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.254 2021/03/29 16:46:09 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -723,10 +723,10 @@ SSL_get_finished(const SSL *s, void *buf, size_t count)
723{ 723{
724 size_t ret; 724 size_t ret;
725 725
726 ret = S3I(s)->tmp.finish_md_len; 726 ret = S3I(s)->hs.finished_len;
727 if (count > ret) 727 if (count > ret)
728 count = ret; 728 count = ret;
729 memcpy(buf, S3I(s)->tmp.finish_md, count); 729 memcpy(buf, S3I(s)->hs.finished, count);
730 return (ret); 730 return (ret);
731} 731}
732 732
@@ -736,10 +736,10 @@ SSL_get_peer_finished(const SSL *s, void *buf, size_t count)
736{ 736{
737 size_t ret; 737 size_t ret;
738 738
739 ret = S3I(s)->tmp.peer_finish_md_len; 739 ret = S3I(s)->hs.peer_finished_len;
740 if (count > ret) 740 if (count > ret)
741 count = ret; 741 count = ret;
742 memcpy(buf, S3I(s)->tmp.peer_finish_md, count); 742 memcpy(buf, S3I(s)->hs.peer_finished, count);
743 return (ret); 743 return (ret);
744} 744}
745 745
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index 4b2f98f84d..3339c57390 100644
--- a/src/lib/libssl/ssl_locl.h
+++ b/src/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.332 2021/03/29 16:19:15 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.333 2021/03/29 16:46:09 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -492,6 +492,15 @@ typedef struct ssl_handshake_st {
492 uint8_t *sigalgs; 492 uint8_t *sigalgs;
493 size_t sigalgs_len; 493 size_t sigalgs_len;
494 494
495 /*
496 * Copies of the verify data sent in our finished message and the
497 * verify data received in the finished message sent by our peer.
498 */
499 uint8_t finished[EVP_MAX_MD_SIZE];
500 size_t finished_len;
501 uint8_t peer_finished[EVP_MAX_MD_SIZE];
502 size_t peer_finished_len;
503
495 SSL_HANDSHAKE_TLS12 tls12; 504 SSL_HANDSHAKE_TLS12 tls12;
496 SSL_HANDSHAKE_TLS13 tls13; 505 SSL_HANDSHAKE_TLS13 tls13;
497} SSL_HANDSHAKE; 506} SSL_HANDSHAKE;
@@ -918,11 +927,6 @@ typedef struct ssl3_state_internal_st {
918 struct { 927 struct {
919 unsigned char cert_verify_md[EVP_MAX_MD_SIZE]; 928 unsigned char cert_verify_md[EVP_MAX_MD_SIZE];
920 929
921 unsigned char finish_md[EVP_MAX_MD_SIZE];
922 size_t finish_md_len;
923 unsigned char peer_finish_md[EVP_MAX_MD_SIZE];
924 size_t peer_finish_md_len;
925
926 unsigned long message_size; 930 unsigned long message_size;
927 int message_type; 931 int message_type;
928 932
diff --git a/src/lib/libssl/ssl_pkt.c b/src/lib/libssl/ssl_pkt.c
index a93acdfa7f..a760f90a3a 100644
--- a/src/lib/libssl/ssl_pkt.c
+++ b/src/lib/libssl/ssl_pkt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_pkt.c,v 1.39 2021/03/24 18:44:00 jsing Exp $ */ 1/* $OpenBSD: ssl_pkt.c,v 1.40 2021/03/29 16:46:09 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1190,12 +1190,12 @@ ssl3_do_change_cipher_spec(SSL *s)
1190 } 1190 }
1191 1191
1192 i = tls1_final_finish_mac(s, sender, slen, 1192 i = tls1_final_finish_mac(s, sender, slen,
1193 S3I(s)->tmp.peer_finish_md); 1193 S3I(s)->hs.peer_finished);
1194 if (i == 0) { 1194 if (i == 0) {
1195 SSLerror(s, ERR_R_INTERNAL_ERROR); 1195 SSLerror(s, ERR_R_INTERNAL_ERROR);
1196 return 0; 1196 return 0;
1197 } 1197 }
1198 S3I(s)->tmp.peer_finish_md_len = i; 1198 S3I(s)->hs.peer_finished_len = i;
1199 1199
1200 return (1); 1200 return (1);
1201} 1201}
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c
index 5ffab919a2..797eb84001 100644
--- a/src/lib/libssl/ssl_tlsext.c
+++ b/src/lib/libssl/ssl_tlsext.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_tlsext.c,v 1.88 2021/03/21 18:36:34 jsing Exp $ */ 1/* $OpenBSD: ssl_tlsext.c,v 1.89 2021/03/29 16:46:09 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> 4 * Copyright (c) 2017 Doug Hogan <doug@openbsd.org>
@@ -36,7 +36,7 @@ tlsext_alpn_client_needs(SSL *s, uint16_t msg_type)
36{ 36{
37 /* ALPN protos have been specified and this is the initial handshake */ 37 /* ALPN protos have been specified and this is the initial handshake */
38 return s->internal->alpn_client_proto_list != NULL && 38 return s->internal->alpn_client_proto_list != NULL &&
39 S3I(s)->tmp.finish_md_len == 0; 39 S3I(s)->hs.finished_len == 0;
40} 40}
41 41
42int 42int
diff --git a/src/lib/libssl/tls13_client.c b/src/lib/libssl/tls13_client.c
index 78bf15ec59..e0febee926 100644
--- a/src/lib/libssl/tls13_client.c
+++ b/src/lib/libssl/tls13_client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_client.c,v 1.76 2021/03/24 18:44:00 jsing Exp $ */ 1/* $OpenBSD: tls13_client.c,v 1.77 2021/03/29 16:46:09 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -746,7 +746,6 @@ tls13_server_finished_recv(struct tls13_ctx *ctx, CBS *cbs)
746 uint8_t key[EVP_MAX_MD_SIZE]; 746 uint8_t key[EVP_MAX_MD_SIZE];
747 HMAC_CTX *hmac_ctx = NULL; 747 HMAC_CTX *hmac_ctx = NULL;
748 unsigned int hlen; 748 unsigned int hlen;
749 SSL *s = ctx->ssl;
750 int ret = 0; 749 int ret = 0;
751 750
752 /* 751 /*
@@ -781,9 +780,9 @@ tls13_server_finished_recv(struct tls13_ctx *ctx, CBS *cbs)
781 goto err; 780 goto err;
782 } 781 }
783 782
784 if (!CBS_write_bytes(cbs, S3I(s)->tmp.peer_finish_md, 783 if (!CBS_write_bytes(cbs, ctx->hs->peer_finished,
785 sizeof(S3I(s)->tmp.peer_finish_md), 784 sizeof(ctx->hs->peer_finished),
786 &S3I(s)->tmp.peer_finish_md_len)) 785 &ctx->hs->peer_finished_len))
787 goto err; 786 goto err;
788 787
789 if (!CBS_skip(cbs, verify_data_len)) 788 if (!CBS_skip(cbs, verify_data_len))
@@ -1032,7 +1031,6 @@ tls13_client_finished_send(struct tls13_ctx *ctx, CBB *cbb)
1032 unsigned int hlen; 1031 unsigned int hlen;
1033 HMAC_CTX *hmac_ctx = NULL; 1032 HMAC_CTX *hmac_ctx = NULL;
1034 CBS cbs; 1033 CBS cbs;
1035 SSL *s = ctx->ssl;
1036 int ret = 0; 1034 int ret = 0;
1037 1035
1038 if (!tls13_secret_init(&finished_key, EVP_MD_size(ctx->hash))) 1036 if (!tls13_secret_init(&finished_key, EVP_MD_size(ctx->hash)))
@@ -1064,8 +1062,8 @@ tls13_client_finished_send(struct tls13_ctx *ctx, CBB *cbb)
1064 goto err; 1062 goto err;
1065 1063
1066 CBS_init(&cbs, verify_data, verify_data_len); 1064 CBS_init(&cbs, verify_data, verify_data_len);
1067 if (!CBS_write_bytes(&cbs, S3I(s)->tmp.finish_md, 1065 if (!CBS_write_bytes(&cbs, ctx->hs->finished,
1068 sizeof(S3I(s)->tmp.finish_md), &S3I(s)->tmp.finish_md_len)) 1066 sizeof(ctx->hs->finished), &ctx->hs->finished_len))
1069 goto err; 1067 goto err;
1070 1068
1071 ret = 1; 1069 ret = 1;
diff --git a/src/lib/libssl/tls13_server.c b/src/lib/libssl/tls13_server.c
index bac9623a15..4fed1a43d0 100644
--- a/src/lib/libssl/tls13_server.c
+++ b/src/lib/libssl/tls13_server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_server.c,v 1.73 2021/03/24 18:44:00 jsing Exp $ */ 1/* $OpenBSD: tls13_server.c,v 1.74 2021/03/29 16:46:09 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2020 Bob Beck <beck@openbsd.org> 4 * Copyright (c) 2020 Bob Beck <beck@openbsd.org>
@@ -783,7 +783,6 @@ tls13_server_finished_send(struct tls13_ctx *ctx, CBB *cbb)
783 unsigned int hlen; 783 unsigned int hlen;
784 HMAC_CTX *hmac_ctx = NULL; 784 HMAC_CTX *hmac_ctx = NULL;
785 CBS cbs; 785 CBS cbs;
786 SSL *s = ctx->ssl;
787 int ret = 0; 786 int ret = 0;
788 787
789 if (!tls13_secret_init(&finished_key, EVP_MD_size(ctx->hash))) 788 if (!tls13_secret_init(&finished_key, EVP_MD_size(ctx->hash)))
@@ -815,8 +814,8 @@ tls13_server_finished_send(struct tls13_ctx *ctx, CBB *cbb)
815 goto err; 814 goto err;
816 815
817 CBS_init(&cbs, verify_data, verify_data_len); 816 CBS_init(&cbs, verify_data, verify_data_len);
818 if (!CBS_write_bytes(&cbs, S3I(s)->tmp.finish_md, 817 if (!CBS_write_bytes(&cbs, ctx->hs->finished,
819 sizeof(S3I(s)->tmp.finish_md), &S3I(s)->tmp.finish_md_len)) 818 sizeof(ctx->hs->finished), &ctx->hs->finished_len))
820 goto err; 819 goto err;
821 820
822 ret = 1; 821 ret = 1;
@@ -1050,7 +1049,6 @@ tls13_client_finished_recv(struct tls13_ctx *ctx, CBS *cbs)
1050 uint8_t key[EVP_MAX_MD_SIZE]; 1049 uint8_t key[EVP_MAX_MD_SIZE];
1051 HMAC_CTX *hmac_ctx = NULL; 1050 HMAC_CTX *hmac_ctx = NULL;
1052 unsigned int hlen; 1051 unsigned int hlen;
1053 SSL *s = ctx->ssl;
1054 int ret = 0; 1052 int ret = 0;
1055 1053
1056 /* 1054 /*
@@ -1085,9 +1083,9 @@ tls13_client_finished_recv(struct tls13_ctx *ctx, CBS *cbs)
1085 goto err; 1083 goto err;
1086 } 1084 }
1087 1085
1088 if (!CBS_write_bytes(cbs, S3I(s)->tmp.peer_finish_md, 1086 if (!CBS_write_bytes(cbs, ctx->hs->peer_finished,
1089 sizeof(S3I(s)->tmp.peer_finish_md), 1087 sizeof(ctx->hs->peer_finished),
1090 &S3I(s)->tmp.peer_finish_md_len)) 1088 &ctx->hs->peer_finished_len))
1091 goto err; 1089 goto err;
1092 1090
1093 if (!CBS_skip(cbs, verify_data_len)) 1091 if (!CBS_skip(cbs, verify_data_len))