summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2017-07-24 17:10:32 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2017-07-24 17:10:32 +0000
commit2f773ba2f12c61489af746e6997a84296a115dc8 (patch)
treee4872bc7011f2baad7a00ee9c5918ac94b2c9742 /lib
parent20f6857189d1464e5b36bbd452b2c151452e7411 (diff)
Rewrite the TLS Renegotiation Indication extension handling using CBB/CBS
and the new extension framework. Feedback from doug@ ok inoguchi@
Diffstat (limited to 'lib')
-rw-r--r--lib/libssl/Makefile4
-rw-r--r--lib/libssl/ssl_locl.h13
-rw-r--r--lib/libssl/ssl_tlsext.c143
-rw-r--r--lib/libssl/ssl_tlsext.h9
-rw-r--r--lib/libssl/t1_lib.c63
-rw-r--r--lib/libssl/t1_reneg.c275
6 files changed, 161 insertions, 346 deletions
diff --git a/lib/libssl/Makefile b/lib/libssl/Makefile
index f0045070601..6ae361c00c4 100644
--- a/lib/libssl/Makefile
+++ b/lib/libssl/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.36 2017/07/16 18:14:37 jsing Exp $
+# $OpenBSD: Makefile,v 1.37 2017/07/24 17:10:31 jsing Exp $
.include <bsd.own.mk>
.ifndef NOMAN
@@ -32,7 +32,7 @@ SRCS= \
ssl_lib.c ssl_cert.c ssl_sess.c \
ssl_ciph.c ssl_stat.c ssl_rsa.c \
ssl_asn1.c ssl_txt.c ssl_algs.c \
- bio_ssl.c ssl_err.c t1_reneg.c \
+ bio_ssl.c ssl_err.c \
ssl_packet.c ssl_tlsext.c ssl_versions.c pqueue.c
SRCS+= s3_cbc.c
SRCS+= bs_ber.c bs_cbb.c bs_cbs.c
diff --git a/lib/libssl/ssl_locl.h b/lib/libssl/ssl_locl.h
index 8f1721ce5a8..0d489204710 100644
--- a/lib/libssl/ssl_locl.h
+++ b/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_locl.h,v 1.181 2017/05/07 04:22:24 beck Exp $ */
+/* $OpenBSD: ssl_locl.h,v 1.182 2017/07/24 17:10:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -881,6 +881,9 @@ typedef struct ssl3_state_internal_st {
unsigned char previous_server_finished_len;
int send_connection_binding; /* TODOEKR */
+ /* Set if we saw a Renegotiation Indication extension from our peer. */
+ int renegotiate_seen;
+
/* Set if we saw the Next Protocol Negotiation extension from our peer.
*/
int next_proto_neg_seen;
@@ -1344,14 +1347,6 @@ int tls12_get_sigid(const EVP_PKEY *pk);
const EVP_MD *tls12_get_hash(unsigned char hash_alg);
void ssl_clear_hash_ctx(EVP_MD_CTX **hash);
-int ssl_add_serverhello_renegotiate_ext(SSL *s, unsigned char *p,
- int *len, int maxlen);
-int ssl_parse_serverhello_renegotiate_ext(SSL *s, const unsigned char *d,
- int len, int *al);
-int ssl_add_clienthello_renegotiate_ext(SSL *s, unsigned char *p,
- int *len, int maxlen);
-int ssl_parse_clienthello_renegotiate_ext(SSL *s, const unsigned char *d,
- int len, int *al);
long ssl_get_algorithm2(SSL *s);
int tls1_process_sigalgs(SSL *s, const unsigned char *data, int dsize);
int tls12_get_req_sig_algs(SSL *s, unsigned char *p);
diff --git a/lib/libssl/ssl_tlsext.c b/lib/libssl/ssl_tlsext.c
index 18ac98103a7..539c380fb91 100644
--- a/lib/libssl/ssl_tlsext.c
+++ b/lib/libssl/ssl_tlsext.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_tlsext.c,v 1.1 2017/07/16 18:14:37 jsing Exp $ */
+/* $OpenBSD: ssl_tlsext.c,v 1.2 2017/07/24 17:10:31 jsing Exp $ */
/*
* Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org>
*
@@ -21,6 +21,138 @@
#include "ssl_tlsext.h"
/*
+ * Renegotiation Indication - RFC 5746.
+ */
+int
+tlsext_ri_clienthello_needs(SSL *s)
+{
+ return (s->internal->renegotiate);
+}
+
+int
+tlsext_ri_clienthello_build(SSL *s, CBB *cbb)
+{
+ CBB reneg;
+
+ if (!CBB_add_u8_length_prefixed(cbb, &reneg))
+ return 0;
+ if (!CBB_add_bytes(&reneg, S3I(s)->previous_client_finished,
+ S3I(s)->previous_client_finished_len))
+ return 0;
+ if (!CBB_flush(cbb))
+ return 0;
+
+ return 1;
+}
+
+int
+tlsext_ri_clienthello_parse(SSL *s, CBS *cbs, int *alert)
+{
+ CBS reneg;
+
+ if (!CBS_get_u8_length_prefixed(cbs, &reneg))
+ goto err;
+ if (CBS_len(cbs) != 0)
+ goto err;
+
+ if (!CBS_mem_equal(&reneg, S3I(s)->previous_client_finished,
+ S3I(s)->previous_client_finished_len)) {
+ SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
+ *alert = SSL_AD_HANDSHAKE_FAILURE;
+ return 0;
+ }
+
+ S3I(s)->renegotiate_seen = 1;
+ S3I(s)->send_connection_binding = 1;
+
+ return 1;
+
+ err:
+ SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
+ *alert = SSL_AD_DECODE_ERROR;
+ return 0;
+}
+
+int
+tlsext_ri_serverhello_needs(SSL *s)
+{
+ return (S3I(s)->send_connection_binding);
+}
+
+int
+tlsext_ri_serverhello_build(SSL *s, CBB *cbb)
+{
+ CBB reneg;
+
+ if (!CBB_add_u8_length_prefixed(cbb, &reneg))
+ return 0;
+ if (!CBB_add_bytes(&reneg, S3I(s)->previous_client_finished,
+ S3I(s)->previous_client_finished_len))
+ return 0;
+ if (!CBB_add_bytes(&reneg, S3I(s)->previous_server_finished,
+ S3I(s)->previous_server_finished_len))
+ return 0;
+ if (!CBB_flush(cbb))
+ return 0;
+
+ return 1;
+}
+
+int
+tlsext_ri_serverhello_parse(SSL *s, CBS *cbs, int *alert)
+{
+ CBS reneg, prev_client, prev_server;
+
+ /*
+ * Ensure that the previous client and server values are both not
+ * present, or that they are both present.
+ */
+ if ((S3I(s)->previous_client_finished_len == 0 &&
+ S3I(s)->previous_server_finished_len != 0) ||
+ (S3I(s)->previous_client_finished_len != 0 &&
+ S3I(s)->previous_server_finished_len == 0)) {
+ *alert = TLS1_AD_INTERNAL_ERROR;
+ return 0;
+ }
+
+ if (!CBS_get_u8_length_prefixed(cbs, &reneg))
+ goto err;
+ if (!CBS_get_bytes(&reneg, &prev_client,
+ S3I(s)->previous_client_finished_len))
+ goto err;
+ if (!CBS_get_bytes(&reneg, &prev_server,
+ S3I(s)->previous_server_finished_len))
+ goto err;
+ if (CBS_len(&reneg) != 0)
+ goto err;
+ if (CBS_len(cbs) != 0)
+ goto err;
+
+ if (!CBS_mem_equal(&prev_client, S3I(s)->previous_client_finished,
+ S3I(s)->previous_client_finished_len)) {
+ SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
+ *alert = SSL_AD_HANDSHAKE_FAILURE;
+ return 0;
+ }
+ if (!CBS_mem_equal(&prev_server, S3I(s)->previous_server_finished,
+ S3I(s)->previous_server_finished_len)) {
+ SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
+ *alert = SSL_AD_HANDSHAKE_FAILURE;
+ return 0;
+ }
+
+ S3I(s)->renegotiate_seen = 1;
+ S3I(s)->send_connection_binding = 1;
+
+ return 1;
+
+ err:
+ SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
+ *alert = SSL_AD_DECODE_ERROR;
+ return 0;
+}
+
+/*
* Server Name Indication - RFC 6066, section 3.
*/
int
@@ -150,6 +282,15 @@ static struct tls_extension tls_extensions[] = {
.serverhello_build = tlsext_sni_serverhello_build,
.serverhello_parse = tlsext_sni_serverhello_parse,
},
+ {
+ .type = TLSEXT_TYPE_renegotiate,
+ .clienthello_needs = tlsext_ri_clienthello_needs,
+ .clienthello_build = tlsext_ri_clienthello_build,
+ .clienthello_parse = tlsext_ri_clienthello_parse,
+ .serverhello_needs = tlsext_ri_serverhello_needs,
+ .serverhello_build = tlsext_ri_serverhello_build,
+ .serverhello_parse = tlsext_ri_serverhello_parse,
+ },
};
#define N_TLS_EXTENSIONS (sizeof(tls_extensions) / sizeof(*tls_extensions))
diff --git a/lib/libssl/ssl_tlsext.h b/lib/libssl/ssl_tlsext.h
index a8e478d9c0b..4b0194861a0 100644
--- a/lib/libssl/ssl_tlsext.h
+++ b/lib/libssl/ssl_tlsext.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_tlsext.h,v 1.1 2017/07/16 18:14:37 jsing Exp $ */
+/* $OpenBSD: ssl_tlsext.h,v 1.2 2017/07/24 17:10:31 jsing Exp $ */
/*
* Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org>
*
@@ -15,6 +15,13 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+int tlsext_ri_clienthello_needs(SSL *s);
+int tlsext_ri_clienthello_build(SSL *s, CBB *cbb);
+int tlsext_ri_clienthello_parse(SSL *s, CBS *cbs, int *alert);
+int tlsext_ri_serverhello_needs(SSL *s);
+int tlsext_ri_serverhello_build(SSL *s, CBB *cbb);
+int tlsext_ri_serverhello_parse(SSL *s, CBS *cbs, int *alert);
+
int tlsext_sni_clienthello_needs(SSL *s);
int tlsext_sni_clienthello_build(SSL *s, CBB *cbb);
int tlsext_sni_clienthello_parse(SSL *s, CBS *cbs, int *alert);
diff --git a/lib/libssl/t1_lib.c b/lib/libssl/t1_lib.c
index 8d56e747596..bf5e2de80be 100644
--- a/lib/libssl/t1_lib.c
+++ b/lib/libssl/t1_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: t1_lib.c,v 1.120 2017/07/23 16:27:44 jsing Exp $ */
+/* $OpenBSD: t1_lib.c,v 1.121 2017/07/24 17:10:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -720,29 +720,6 @@ ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
return NULL;
ret += len;
- /* Add RI if renegotiating */
- if (s->internal->renegotiate) {
- int el;
-
- if (!ssl_add_clienthello_renegotiate_ext(s, 0, &el, 0)) {
- SSLerror(s, ERR_R_INTERNAL_ERROR);
- return NULL;
- }
-
- if ((size_t)(limit - ret) < 4 + el)
- return NULL;
-
- s2n(TLSEXT_TYPE_renegotiate, ret);
- s2n(el, ret);
-
- if (!ssl_add_clienthello_renegotiate_ext(s, ret, &el, el)) {
- SSLerror(s, ERR_R_INTERNAL_ERROR);
- return NULL;
- }
-
- ret += el;
- }
-
if (using_ecc) {
size_t curveslen, formatslen, lenmax;
const uint16_t *curves;
@@ -1006,28 +983,6 @@ ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
return NULL;
ret += len;
- if (S3I(s)->send_connection_binding) {
- int el;
-
- if (!ssl_add_serverhello_renegotiate_ext(s, 0, &el, 0)) {
- SSLerror(s, ERR_R_INTERNAL_ERROR);
- return NULL;
- }
-
- if ((size_t)(limit - ret) < 4 + el)
- return NULL;
-
- s2n(TLSEXT_TYPE_renegotiate, ret);
- s2n(el, ret);
-
- if (!ssl_add_serverhello_renegotiate_ext(s, ret, &el, el)) {
- SSLerror(s, ERR_R_INTERNAL_ERROR);
- return NULL;
- }
-
- ret += el;
- }
-
if (using_ecc && s->version != DTLS1_VERSION) {
const unsigned char *formats;
size_t formatslen, lenmax;
@@ -1229,12 +1184,12 @@ ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d,
unsigned short len;
unsigned char *data = *p;
unsigned char *end = d + n;
- int renegotiate_seen = 0;
int sigalg_seen = 0;
CBS cbs;
s->internal->servername_done = 0;
s->tlsext_status_type = -1;
+ S3I(s)->renegotiate_seen = 0;
S3I(s)->next_proto_neg_seen = 0;
free(S3I(s)->alpn_selected);
S3I(s)->alpn_selected = NULL;
@@ -1335,10 +1290,6 @@ ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d,
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}
- } else if (type == TLSEXT_TYPE_renegotiate) {
- if (!ssl_parse_clienthello_renegotiate_ext(s, data, size, al))
- return 0;
- renegotiate_seen = 1;
} else if (type == TLSEXT_TYPE_signature_algorithms) {
int dsize;
if (sigalg_seen || size < 2) {
@@ -1513,7 +1464,7 @@ ri_check:
/* Need RI if renegotiating */
- if (!renegotiate_seen && s->internal->renegotiate) {
+ if (!S3I(s)->renegotiate_seen && s->internal->renegotiate) {
*al = SSL_AD_HANDSHAKE_FAILURE;
SSLerror(s, SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);
return 0;
@@ -1554,9 +1505,9 @@ ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, size_t n, int *al)
unsigned char *data = *p;
unsigned char *end = *p + n;
int tlsext_servername = 0;
- int renegotiate_seen = 0;
CBS cbs;
+ S3I(s)->renegotiate_seen = 0;
S3I(s)->next_proto_neg_seen = 0;
free(S3I(s)->alpn_selected);
S3I(s)->alpn_selected = NULL;
@@ -1719,10 +1670,6 @@ ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, size_t n, int *al)
memcpy(S3I(s)->alpn_selected, data + 3, len);
S3I(s)->alpn_selected_len = len;
- } else if (type == TLSEXT_TYPE_renegotiate) {
- if (!ssl_parse_serverhello_renegotiate_ext(s, data, size, al))
- return 0;
- renegotiate_seen = 1;
}
#ifndef OPENSSL_NO_SRTP
else if (SSL_IS_DTLS(s) && type == TLSEXT_TYPE_use_srtp) {
@@ -1769,7 +1716,7 @@ ri_check:
* which doesn't support RI so for the immediate future tolerate RI
* absence on initial connect only.
*/
- if (!renegotiate_seen &&
+ if (!S3I(s)->renegotiate_seen &&
!(s->internal->options & SSL_OP_LEGACY_SERVER_CONNECT)) {
*al = SSL_AD_HANDSHAKE_FAILURE;
SSLerror(s, SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);
diff --git a/lib/libssl/t1_reneg.c b/lib/libssl/t1_reneg.c
deleted file mode 100644
index 4e194dd5dfe..00000000000
--- a/lib/libssl/t1_reneg.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/* $OpenBSD: t1_reneg.c,v 1.15 2017/02/07 02:08:38 beck Exp $ */
-/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- *
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to. The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code. The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * "This product includes cryptographic software written by
- * Eric Young (eay@cryptsoft.com)"
- * The word 'cryptographic' can be left out if the rouines from the library
- * being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
- * the apps directory (application code) you must include an acknowledgement:
- * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed. i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-/* ====================================================================
- * Copyright (c) 1998-2009 The OpenSSL Project. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. All advertising materials mentioning features or use of this
- * software must display the following acknowledgment:
- * "This product includes software developed by the OpenSSL Project
- * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- * endorse or promote products derived from this software without
- * prior written permission. For written permission, please contact
- * openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- * nor may "OpenSSL" appear in their names without prior written
- * permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- * acknowledgment:
- * "This product includes software developed by the OpenSSL Project
- * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com). This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-#include <stdio.h>
-
-#include <openssl/objects.h>
-
-#include "ssl_locl.h"
-#include "bytestring.h"
-
-/* Add the client's renegotiation binding */
-int
-ssl_add_clienthello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
- int maxlen)
-{
- if (p) {
- if ((S3I(s)->previous_client_finished_len + 1) > maxlen) {
- SSLerror(s, SSL_R_RENEGOTIATE_EXT_TOO_LONG);
- return 0;
- }
-
- /* Length byte */
- *p = S3I(s)->previous_client_finished_len;
- p++;
-
- memcpy(p, S3I(s)->previous_client_finished,
- S3I(s)->previous_client_finished_len);
-
- }
-
- *len = S3I(s)->previous_client_finished_len + 1;
-
- return 1;
-}
-
-/* Parse the client's renegotiation binding and abort if it's not
- right */
-int
-ssl_parse_clienthello_renegotiate_ext(SSL *s, const unsigned char *d, int len,
- int *al)
-{
- CBS cbs, reneg;
-
- if (len < 0) {
- SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
- *al = SSL_AD_ILLEGAL_PARAMETER;
- return 0;
- }
-
- CBS_init(&cbs, d, len);
- if (!CBS_get_u8_length_prefixed(&cbs, &reneg) ||
- /* Consistency check */
- CBS_len(&cbs) != 0) {
- SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
- *al = SSL_AD_ILLEGAL_PARAMETER;
- return 0;
- }
-
- /* Check that the extension matches */
- if (CBS_len(&reneg) != S3I(s)->previous_client_finished_len) {
- SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
- *al = SSL_AD_HANDSHAKE_FAILURE;
- return 0;
- }
-
- if (!CBS_mem_equal(&reneg, S3I(s)->previous_client_finished,
- S3I(s)->previous_client_finished_len)) {
- SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
- *al = SSL_AD_HANDSHAKE_FAILURE;
- return 0;
- }
-
- S3I(s)->send_connection_binding = 1;
-
- return 1;
-}
-
-/* Add the server's renegotiation binding */
-int
-ssl_add_serverhello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
- int maxlen)
-{
- if (p) {
- if ((S3I(s)->previous_client_finished_len +
- S3I(s)->previous_server_finished_len + 1) > maxlen) {
- SSLerror(s, SSL_R_RENEGOTIATE_EXT_TOO_LONG);
- return 0;
- }
-
- /* Length byte */
- *p = S3I(s)->previous_client_finished_len +
- S3I(s)->previous_server_finished_len;
- p++;
-
- memcpy(p, S3I(s)->previous_client_finished,
- S3I(s)->previous_client_finished_len);
- p += S3I(s)->previous_client_finished_len;
-
- memcpy(p, S3I(s)->previous_server_finished,
- S3I(s)->previous_server_finished_len);
-
- }
-
- *len = S3I(s)->previous_client_finished_len +
- S3I(s)->previous_server_finished_len + 1;
-
- return 1;
-}
-
-/* Parse the server's renegotiation binding and abort if it's not
- right */
-int
-ssl_parse_serverhello_renegotiate_ext(SSL *s, const unsigned char *d, int len, int *al)
-{
- CBS cbs, reneg, previous_client, previous_server;
- int expected_len = S3I(s)->previous_client_finished_len +
- S3I(s)->previous_server_finished_len;
-
- /* Check for logic errors */
- OPENSSL_assert(!expected_len || S3I(s)->previous_client_finished_len);
- OPENSSL_assert(!expected_len || S3I(s)->previous_server_finished_len);
-
- if (len < 0) {
- SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
- *al = SSL_AD_ILLEGAL_PARAMETER;
- return 0;
- }
-
- CBS_init(&cbs, d, len);
-
- if (!CBS_get_u8_length_prefixed(&cbs, &reneg) ||
- /* Consistency check */
- CBS_len(&cbs) != 0) {
- SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
- *al = SSL_AD_ILLEGAL_PARAMETER;
- return 0;
- }
-
- /* Check that the extension matches */
- if (CBS_len(&reneg) != expected_len ||
- !CBS_get_bytes(&reneg, &previous_client,
- S3I(s)->previous_client_finished_len) ||
- !CBS_get_bytes(&reneg, &previous_server,
- S3I(s)->previous_server_finished_len) ||
- CBS_len(&reneg) != 0) {
- SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
- *al = SSL_AD_HANDSHAKE_FAILURE;
- return 0;
- }
-
- if (!CBS_mem_equal(&previous_client, S3I(s)->previous_client_finished,
- CBS_len(&previous_client))) {
- SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
- *al = SSL_AD_HANDSHAKE_FAILURE;
- return 0;
- }
- if (!CBS_mem_equal(&previous_server, S3I(s)->previous_server_finished,
- CBS_len(&previous_server))) {
- SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
- *al = SSL_AD_ILLEGAL_PARAMETER;
- return 0;
- }
-
- S3I(s)->send_connection_binding = 1;
-
- return 1;
-}