summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2017-10-11 16:51:39 +0000
committerjsing <>2017-10-11 16:51:39 +0000
commite64dc34242390cd4a16eb683e606c5beccbb9aa7 (patch)
tree2fe8124781fd11334215e44437c46397432bc7a3 /src/lib
parent62790ade0e2b202d99093dd2d8dc2df8284e2543 (diff)
downloadopenbsd-e64dc34242390cd4a16eb683e606c5beccbb9aa7.tar.gz
openbsd-e64dc34242390cd4a16eb683e606c5beccbb9aa7.tar.bz2
openbsd-e64dc34242390cd4a16eb683e606c5beccbb9aa7.zip
Fully convert ssl3_send_server_hello() to CBB.
Based on a diff from doug@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/ssl_locl.h5
-rw-r--r--src/lib/libssl/ssl_srvr.c42
-rw-r--r--src/lib/libssl/t1_lib.c25
3 files changed, 19 insertions, 53 deletions
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index 9d9f9c3e41..2ce4b05600 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.196 2017/10/10 16:51:38 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.197 2017/10/11 16:51:39 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 *
@@ -1289,9 +1289,6 @@ int tls1_get_shared_curve(SSL *s);
1289unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, 1289unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p,
1290 unsigned char *limit); 1290 unsigned char *limit);
1291 1291
1292unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p,
1293 unsigned char *limit);
1294
1295int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **data, 1292int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **data,
1296 unsigned char *d, int n, int *al); 1293 unsigned char *d, int n, int *al);
1297int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **data, 1294int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **data,
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c
index 723d82fc82..5e10fa01f4 100644
--- a/src/lib/libssl/ssl_srvr.c
+++ b/src/lib/libssl/ssl_srvr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_srvr.c,v 1.24 2017/10/10 16:51:38 jsing Exp $ */ 1/* $OpenBSD: ssl_srvr.c,v 1.25 2017/10/11 16:51:39 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 *
@@ -166,6 +166,7 @@
166#include <openssl/x509.h> 166#include <openssl/x509.h>
167 167
168#include "bytestring.h" 168#include "bytestring.h"
169#include "ssl_tlsext.h"
169 170
170int 171int
171ssl3_accept(SSL *s) 172ssl3_accept(SSL *s)
@@ -1046,25 +1047,19 @@ err:
1046int 1047int
1047ssl3_send_server_hello(SSL *s) 1048ssl3_send_server_hello(SSL *s)
1048{ 1049{
1049 unsigned char *bufend; 1050 CBB cbb, server_hello, session_id;
1050 unsigned char *p, *d; 1051 size_t sl;
1051 CBB cbb, session_id;
1052 size_t outlen;
1053 int sl;
1054 1052
1055 memset(&cbb, 0, sizeof(cbb)); 1053 memset(&cbb, 0, sizeof(cbb));
1056 1054
1057 bufend = (unsigned char *)s->internal->init_buf->data + SSL3_RT_MAX_PLAIN_LENGTH;
1058
1059 if (S3I(s)->hs.state == SSL3_ST_SW_SRVR_HELLO_A) { 1055 if (S3I(s)->hs.state == SSL3_ST_SW_SRVR_HELLO_A) {
1060 d = p = ssl3_handshake_msg_start(s, SSL3_MT_SERVER_HELLO); 1056 if (!ssl3_handshake_msg_start_cbb(s, &cbb, &server_hello,
1061 1057 SSL3_MT_SERVER_HELLO))
1062 if (!CBB_init_fixed(&cbb, p, bufend - p))
1063 goto err; 1058 goto err;
1064 1059
1065 if (!CBB_add_u16(&cbb, s->version)) 1060 if (!CBB_add_u16(&server_hello, s->version))
1066 goto err; 1061 goto err;
1067 if (!CBB_add_bytes(&cbb, s->s3->server_random, 1062 if (!CBB_add_bytes(&server_hello, s->s3->server_random,
1068 sizeof(s->s3->server_random))) 1063 sizeof(s->s3->server_random)))
1069 goto err; 1064 goto err;
1070 1065
@@ -1091,35 +1086,32 @@ ssl3_send_server_hello(SSL *s)
1091 s->session->session_id_length = 0; 1086 s->session->session_id_length = 0;
1092 1087
1093 sl = s->session->session_id_length; 1088 sl = s->session->session_id_length;
1094 if (sl > (int)sizeof(s->session->session_id)) { 1089 if (sl > sizeof(s->session->session_id)) {
1095 SSLerror(s, ERR_R_INTERNAL_ERROR); 1090 SSLerror(s, ERR_R_INTERNAL_ERROR);
1096 goto err; 1091 goto err;
1097 } 1092 }
1098 1093 if (!CBB_add_u8_length_prefixed(&server_hello, &session_id))
1099 if (!CBB_add_u8_length_prefixed(&cbb, &session_id))
1100 goto err; 1094 goto err;
1101 if (!CBB_add_bytes(&session_id, s->session->session_id, sl)) 1095 if (!CBB_add_bytes(&session_id, s->session->session_id, sl))
1102 goto err; 1096 goto err;
1103 1097
1104 /* Cipher suite. */ 1098 /* Cipher suite. */
1105 if (!CBB_add_u16(&cbb, 1099 if (!CBB_add_u16(&server_hello,
1106 ssl3_cipher_get_value(S3I(s)->hs.new_cipher))) 1100 ssl3_cipher_get_value(S3I(s)->hs.new_cipher)))
1107 goto err; 1101 goto err;
1108 1102
1109 /* Compression method. */ 1103 /* Compression method (null). */
1110 if (!CBB_add_u8(&cbb, 0)) 1104 if (!CBB_add_u8(&server_hello, 0))
1111 goto err; 1105 goto err;
1112 1106
1113 if (!CBB_finish(&cbb, NULL, &outlen)) 1107 /* TLS extensions */
1114 goto err; 1108 if (!tlsext_serverhello_build(s, &server_hello)) {
1115
1116 if ((p = ssl_add_serverhello_tlsext(s, p + outlen,
1117 bufend)) == NULL) {
1118 SSLerror(s, ERR_R_INTERNAL_ERROR); 1109 SSLerror(s, ERR_R_INTERNAL_ERROR);
1119 goto err; 1110 goto err;
1120 } 1111 }
1121 1112
1122 ssl3_handshake_msg_finish(s, p - d); 1113 if (!ssl3_handshake_msg_finish_cbb(s, &cbb))
1114 goto err;
1123 } 1115 }
1124 1116
1125 /* SSL3_ST_SW_SRVR_HELLO_B */ 1117 /* SSL3_ST_SW_SRVR_HELLO_B */
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
index 0d03b45a97..8526ca167b 100644
--- a/src/lib/libssl/t1_lib.c
+++ b/src/lib/libssl/t1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t1_lib.c,v 1.137 2017/08/30 16:44:37 jsing Exp $ */ 1/* $OpenBSD: t1_lib.c,v 1.138 2017/10/11 16:51:39 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 *
@@ -684,29 +684,6 @@ ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
684 return (p + len); 684 return (p + len);
685} 685}
686 686
687unsigned char *
688ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
689{
690 size_t len;
691 CBB cbb;
692
693 if (p >= limit)
694 return NULL;
695
696 if (!CBB_init_fixed(&cbb, p, limit - p))
697 return NULL;
698 if (!tlsext_serverhello_build(s, &cbb)) {
699 CBB_cleanup(&cbb);
700 return NULL;
701 }
702 if (!CBB_finish(&cbb, NULL, &len)) {
703 CBB_cleanup(&cbb);
704 return NULL;
705 }
706
707 return (p + len);
708}
709
710int 687int
711ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, 688ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d,
712 int n, int *al) 689 int n, int *al)