summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libssl/Makefile7
-rw-r--r--lib/libssl/d1_clnt.c5
-rw-r--r--lib/libssl/d1_srvr.c5
-rw-r--r--lib/libssl/s23_clnt.c452
-rw-r--r--lib/libssl/s23_lib.c132
-rw-r--r--lib/libssl/s23_pkt.c116
-rw-r--r--lib/libssl/s23_srvr.c466
-rw-r--r--lib/libssl/s3_both.c18
-rw-r--r--lib/libssl/s3_clnt.c36
-rw-r--r--lib/libssl/s3_pkt.c11
-rw-r--r--lib/libssl/s3_srvr.c25
-rw-r--r--lib/libssl/ssl_locl.h9
-rw-r--r--lib/libssl/ssl_packet.c278
-rw-r--r--lib/libssl/t1_clnt.c22
-rw-r--r--lib/libssl/t1_meth.c20
-rw-r--r--lib/libssl/t1_srvr.c22
16 files changed, 395 insertions, 1229 deletions
diff --git a/lib/libssl/Makefile b/lib/libssl/Makefile
index 2e90b020547..7321c0d114a 100644
--- a/lib/libssl/Makefile
+++ b/lib/libssl/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.27 2016/11/05 15:32:19 schwarze Exp $
+# $OpenBSD: Makefile,v 1.28 2017/01/26 05:31:25 jsing Exp $
.include <bsd.own.mk>
.ifndef NOMAN
@@ -23,9 +23,8 @@ LDADD+= -L${BSDOBJDIR}/lib/libcrypto -lcrypto
VERSION_SCRIPT= Symbols.map
SYMBOL_LIST= ${.CURDIR}/Symbols.list
-SRCS=\
+SRCS= \
s3_srvr.c s3_clnt.c s3_lib.c s3_pkt.c s3_both.c \
- s23_srvr.c s23_clnt.c s23_lib.c s23_pkt.c \
t1_meth.c t1_srvr.c t1_clnt.c t1_lib.c t1_enc.c \
d1_meth.c d1_srvr.c d1_clnt.c d1_lib.c d1_pkt.c \
d1_both.c d1_enc.c d1_srtp.c \
@@ -33,7 +32,7 @@ SRCS=\
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 \
- pqueue.c
+ ssl_packet.c pqueue.c
SRCS+= s3_cbc.c
SRCS+= bs_ber.c bs_cbb.c bs_cbs.c
diff --git a/lib/libssl/d1_clnt.c b/lib/libssl/d1_clnt.c
index 6b5510c1e37..5f8b56ebed7 100644
--- a/lib/libssl/d1_clnt.c
+++ b/lib/libssl/d1_clnt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: d1_clnt.c,v 1.69 2017/01/23 13:36:13 jsing Exp $ */
+/* $OpenBSD: d1_clnt.c,v 1.70 2017/01/26 05:31:25 jsing Exp $ */
/*
* DTLS implementation written by Nagendra Modadugu
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -127,7 +127,6 @@
#include "bytestring.h"
-static const SSL_METHOD *dtls1_get_client_method(int ver);
static int dtls1_get_hello_verify(SSL *s);
static const SSL_METHOD_INTERNAL DTLSv1_client_method_internal_data = {
@@ -170,7 +169,7 @@ DTLSv1_client_method(void)
return &DTLSv1_client_method_data;
}
-static const SSL_METHOD *
+const SSL_METHOD *
dtls1_get_client_method(int ver)
{
if (ver == DTLS1_VERSION)
diff --git a/lib/libssl/d1_srvr.c b/lib/libssl/d1_srvr.c
index 1787412bf52..1be0e4b5963 100644
--- a/lib/libssl/d1_srvr.c
+++ b/lib/libssl/d1_srvr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: d1_srvr.c,v 1.79 2017/01/23 13:36:13 jsing Exp $ */
+/* $OpenBSD: d1_srvr.c,v 1.80 2017/01/26 05:31:25 jsing Exp $ */
/*
* DTLS implementation written by Nagendra Modadugu
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -125,7 +125,6 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
-static const SSL_METHOD *dtls1_get_server_method(int ver);
static int dtls1_send_hello_verify_request(SSL *s);
static const SSL_METHOD_INTERNAL DTLSv1_server_method_internal_data = {
@@ -168,7 +167,7 @@ DTLSv1_server_method(void)
return &DTLSv1_server_method_data;
}
-static const SSL_METHOD *
+const SSL_METHOD *
dtls1_get_server_method(int ver)
{
if (ver == DTLS1_VERSION)
diff --git a/lib/libssl/s23_clnt.c b/lib/libssl/s23_clnt.c
deleted file mode 100644
index 4a7641b818e..00000000000
--- a/lib/libssl/s23_clnt.c
+++ /dev/null
@@ -1,452 +0,0 @@
-/* $OpenBSD: s23_clnt.c,v 1.57 2017/01/25 10:54:23 jsing 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-2006 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 "ssl_locl.h"
-
-#include <openssl/buffer.h>
-#include <openssl/evp.h>
-#include <openssl/objects.h>
-
-static int ssl23_client_hello(SSL *s);
-static int ssl23_get_server_hello(SSL *s);
-
-int
-ssl23_connect(SSL *s)
-{
- void (*cb)(const SSL *ssl, int type, int val) = NULL;
- int ret = -1;
- int new_state, state;
-
- ERR_clear_error();
- errno = 0;
-
- if (s->internal->info_callback != NULL)
- cb = s->internal->info_callback;
- else if (s->ctx->internal->info_callback != NULL)
- cb = s->ctx->internal->info_callback;
-
- s->internal->in_handshake++;
- if (!SSL_in_init(s) || SSL_in_before(s))
- SSL_clear(s);
-
- for (;;) {
- state = s->internal->state;
-
- switch (s->internal->state) {
- case SSL_ST_BEFORE:
- case SSL_ST_CONNECT:
- case SSL_ST_BEFORE|SSL_ST_CONNECT:
- case SSL_ST_OK|SSL_ST_CONNECT:
-
- if (s->session != NULL) {
- SSLerr(SSL_F_SSL23_CONNECT, SSL_R_SSL23_DOING_SESSION_ID_REUSE);
- ret = -1;
- goto end;
- }
- s->server = 0;
- if (cb != NULL)
- cb(s, SSL_CB_HANDSHAKE_START, 1);
-
- /* s->version=TLS1_VERSION; */
- s->internal->type = SSL_ST_CONNECT;
-
- if (!ssl3_setup_init_buffer(s)) {
- ret = -1;
- goto end;
- }
- if (!ssl3_setup_buffers(s)) {
- ret = -1;
- goto end;
- }
- if (!tls1_init_finished_mac(s)) {
- ret = -1;
- goto end;
- }
-
- s->internal->state = SSL23_ST_CW_CLNT_HELLO_A;
- s->ctx->internal->stats.sess_connect++;
- s->internal->init_num = 0;
- break;
-
- case SSL23_ST_CW_CLNT_HELLO_A:
- case SSL23_ST_CW_CLNT_HELLO_B:
-
- s->internal->shutdown = 0;
- ret = ssl23_client_hello(s);
- if (ret <= 0)
- goto end;
- s->internal->state = SSL23_ST_CR_SRVR_HELLO_A;
- s->internal->init_num = 0;
-
- break;
-
- case SSL23_ST_CR_SRVR_HELLO_A:
- case SSL23_ST_CR_SRVR_HELLO_B:
- ret = ssl23_get_server_hello(s);
- if (ret >= 0)
- cb = NULL;
- goto end;
- /* break; */
-
- default:
- SSLerr(SSL_F_SSL23_CONNECT, SSL_R_UNKNOWN_STATE);
- ret = -1;
- goto end;
- /* break; */
- }
-
- if (s->internal->debug) {
- (void)BIO_flush(s->wbio);
- }
-
- if ((cb != NULL) && (s->internal->state != state)) {
- new_state = s->internal->state;
- s->internal->state = state;
- cb(s, SSL_CB_CONNECT_LOOP, 1);
- s->internal->state = new_state;
- }
- }
-
-end:
- s->internal->in_handshake--;
- if (cb != NULL)
- cb(s, SSL_CB_CONNECT_EXIT, ret);
-
- return (ret);
-}
-
-static int
-ssl23_client_hello(SSL *s)
-{
- unsigned char *buf;
- unsigned char *p, *d;
- unsigned long l;
- uint16_t version;
- size_t outlen;
- int ret;
-
- buf = (unsigned char *)s->internal->init_buf->data;
- if (s->internal->state == SSL23_ST_CW_CLNT_HELLO_A) {
- arc4random_buf(s->s3->client_random, SSL3_RANDOM_SIZE);
-
- if (ssl_supported_version_range(s, NULL, &version) != 1) {
- SSLerr(SSL_F_SSL23_CLIENT_HELLO,
- SSL_R_NO_PROTOCOLS_AVAILABLE);
- return (-1);
- }
- s->client_version = version;
-
- /* create Client Hello in SSL 3.0/TLS 1.0 format */
-
- /*
- * Do the record header (5 bytes) and handshake
- * message header (4 bytes) last
- */
- d = p = &(buf[SSL3_RT_HEADER_LENGTH + SSL3_HM_HEADER_LENGTH]);
-
- *(p++) = version >> 8;
- *(p++) = version & 0xff;
-
- /* Random stuff */
- memcpy(p, s->s3->client_random, SSL3_RANDOM_SIZE);
- p += SSL3_RANDOM_SIZE;
-
- /* Session ID (zero since there is no reuse) */
- *(p++) = 0;
-
- /* Ciphers supported (using SSL 3.0/TLS 1.0 format) */
- if (!ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), &p[2],
- buf - &p[2] + SSL3_RT_MAX_PLAIN_LENGTH, &outlen))
- return -1;
- if (outlen == 0) {
- SSLerr(SSL_F_SSL3_CLIENT_HELLO,
- SSL_R_NO_CIPHERS_AVAILABLE);
- return -1;
- }
- s2n(outlen, p);
- p += outlen;
-
- /* add in (no) COMPRESSION */
- *(p++) = 1;
- /* Add the NULL method */
- *(p++) = 0;
-
- /* TLS extensions*/
- if ((p = ssl_add_clienthello_tlsext(s, p,
- buf + SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) {
- SSLerr(SSL_F_SSL23_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
- return -1;
- }
-
- l = p - d;
-
- /* fill in 4-byte handshake header */
- d = &(buf[SSL3_RT_HEADER_LENGTH]);
- *(d++) = SSL3_MT_CLIENT_HELLO;
- l2n3(l, d);
-
- l += 4;
-
- if (l > SSL3_RT_MAX_PLAIN_LENGTH) {
- SSLerr(SSL_F_SSL23_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
- return -1;
- }
-
- /* fill in 5-byte record header */
- d = buf;
- *(d++) = SSL3_RT_HANDSHAKE;
- *(d++) = version >> 8;
-
- /*
- * Some servers hang if we use long client hellos
- * and a record number > TLS 1.0.
- */
- if (TLS1_get_client_version(s) > TLS1_VERSION)
- *(d++) = 1;
- else
- *(d++) = version & 0xff;
- s2n((int)l, d);
-
- /* number of bytes to write */
- s->internal->init_num = p - buf;
- s->internal->init_off = 0;
-
- tls1_finish_mac(s, &(buf[SSL3_RT_HEADER_LENGTH]),
- s->internal->init_num - SSL3_RT_HEADER_LENGTH);
-
- s->internal->state = SSL23_ST_CW_CLNT_HELLO_B;
- s->internal->init_off = 0;
- }
-
- /* SSL3_ST_CW_CLNT_HELLO_B */
- ret = ssl23_write_bytes(s);
-
- if ((ret >= 2) && s->internal->msg_callback) {
- /* Client Hello has been sent; tell msg_callback */
- s->internal->msg_callback(1, s->client_version, SSL3_RT_HANDSHAKE,
- s->internal->init_buf->data + 5, ret - 5, s, s->internal->msg_callback_arg);
- }
-
- return ret;
-}
-
-static int
-ssl23_get_server_hello(SSL *s)
-{
- char buf[8];
- unsigned char *p;
- int i;
- int n;
-
- n = ssl23_read_bytes(s, 7);
-
- if (n != 7)
- return (n);
- p = s->internal->packet;
-
- memcpy(buf, p, n);
-
- /* Old unsupported sslv2 handshake */
- if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) &&
- (p[5] == 0x00) && (p[6] == 0x02)) {
- SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,
- SSL_R_UNSUPPORTED_PROTOCOL);
- goto err;
- }
-
- if (p[1] == SSL3_VERSION_MAJOR &&
- p[2] <= TLS1_2_VERSION_MINOR &&
- ((p[0] == SSL3_RT_HANDSHAKE && p[5] == SSL3_MT_SERVER_HELLO) ||
- (p[0] == SSL3_RT_ALERT && p[3] == 0 && p[4] == 2))) {
- /* we have sslv3 or tls1 (server hello or alert) */
-
- if ((p[2] == TLS1_VERSION_MINOR) &&
- !(s->internal->options & SSL_OP_NO_TLSv1)) {
- s->version = TLS1_VERSION;
- s->method = TLSv1_client_method();
- } else if ((p[2] == TLS1_1_VERSION_MINOR) &&
- !(s->internal->options & SSL_OP_NO_TLSv1_1)) {
- s->version = TLS1_1_VERSION;
- s->method = TLSv1_1_client_method();
- } else if ((p[2] == TLS1_2_VERSION_MINOR) &&
- !(s->internal->options & SSL_OP_NO_TLSv1_2)) {
- s->version = TLS1_2_VERSION;
- s->method = TLSv1_2_client_method();
- } else {
- SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,
- SSL_R_UNSUPPORTED_PROTOCOL);
- goto err;
- }
-
- if (p[0] == SSL3_RT_ALERT && p[5] != SSL3_AL_WARNING) {
- /* fatal alert */
- void (*cb)(const SSL *ssl, int type, int val) = NULL;
- int j;
-
- if (s->internal->info_callback != NULL)
- cb = s->internal->info_callback;
- else if (s->ctx->internal->info_callback != NULL)
- cb = s->ctx->internal->info_callback;
-
- i = p[5];
- if (cb != NULL) {
- j = (i << 8) | p[6];
- cb(s, SSL_CB_READ_ALERT, j);
- }
-
- if (s->internal->msg_callback)
- s->internal->msg_callback(0, s->version, SSL3_RT_ALERT,
- p + 5, 2, s, s->internal->msg_callback_arg);
-
- s->internal->rwstate = SSL_NOTHING;
- SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,
- SSL_AD_REASON_OFFSET + p[6]);
- goto err;
- }
-
- if (!ssl_init_wbio_buffer(s, 1))
- goto err;
-
- /* we are in this state */
- s->internal->state = SSL3_ST_CR_SRVR_HELLO_A;
-
- /* put the 7 bytes we have read into the input buffer
- * for SSLv3 */
- s->internal->rstate = SSL_ST_READ_HEADER;
- s->internal->packet_length = n;
- if (s->s3->rbuf.buf == NULL)
- if (!ssl3_setup_read_buffer(s))
- goto err;
- s->internal->packet = &(s->s3->rbuf.buf[0]);
- memcpy(s->internal->packet, buf, n);
- s->s3->rbuf.left = n;
- s->s3->rbuf.offset = 0;
-
- s->internal->handshake_func = s->method->internal->ssl_connect;
- } else {
- SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, SSL_R_UNKNOWN_PROTOCOL);
- goto err;
- }
- s->internal->init_num = 0;
-
- /*
- * Since, if we are sending a ssl23 client hello, we are not
- * reusing a session-id
- */
- if (!ssl_get_new_session(s, 0))
- goto err;
-
- return (SSL_connect(s));
-err:
- return (-1);
-}
diff --git a/lib/libssl/s23_lib.c b/lib/libssl/s23_lib.c
deleted file mode 100644
index 5de30c69e63..00000000000
--- a/lib/libssl/s23_lib.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/* $OpenBSD: s23_lib.c,v 1.19 2017/01/23 04:55:26 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.]
- */
-
-#include <stdio.h>
-
-#include <openssl/objects.h>
-
-#include "ssl_locl.h"
-
-long
-ssl23_default_timeout(void)
-{
- return (300);
-}
-
-int
-ssl23_read(SSL *s, void *buf, int len)
-{
- int n;
-
- errno = 0;
- if (SSL_in_init(s) && (!s->internal->in_handshake)) {
- n = s->internal->handshake_func(s);
- if (n < 0)
- return (n);
- if (n == 0) {
- SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);
- return (-1);
- }
- return (SSL_read(s, buf, len));
- } else {
- ssl_undefined_function(s);
- return (-1);
- }
-}
-
-int
-ssl23_peek(SSL *s, void *buf, int len)
-{
- int n;
-
- errno = 0;
- if (SSL_in_init(s) && (!s->internal->in_handshake)) {
- n = s->internal->handshake_func(s);
- if (n < 0)
- return (n);
- if (n == 0) {
- SSLerr(SSL_F_SSL23_PEEK, SSL_R_SSL_HANDSHAKE_FAILURE);
- return (-1);
- }
- return (SSL_peek(s, buf, len));
- } else {
- ssl_undefined_function(s);
- return (-1);
- }
-}
-
-int
-ssl23_write(SSL *s, const void *buf, int len)
-{
- int n;
-
- errno = 0;
- if (SSL_in_init(s) && (!s->internal->in_handshake)) {
- n = s->internal->handshake_func(s);
- if (n < 0)
- return (n);
- if (n == 0) {
- SSLerr(SSL_F_SSL23_WRITE, SSL_R_SSL_HANDSHAKE_FAILURE);
- return (-1);
- }
- return (SSL_write(s, buf, len));
- } else {
- ssl_undefined_function(s);
- return (-1);
- }
-}
diff --git a/lib/libssl/s23_pkt.c b/lib/libssl/s23_pkt.c
deleted file mode 100644
index da1ee900abc..00000000000
--- a/lib/libssl/s23_pkt.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/* $OpenBSD: s23_pkt.c,v 1.10 2017/01/23 06:45:30 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.]
- */
-
-#include <errno.h>
-#include <stdio.h>
-
-#include "ssl_locl.h"
-
-#include <openssl/buffer.h>
-#include <openssl/evp.h>
-
-int
-ssl23_write_bytes(SSL *s)
-{
- int i, num, tot;
- char *buf;
-
- buf = s->internal->init_buf->data;
- tot = s->internal->init_off;
- num = s->internal->init_num;
- for (;;) {
- s->internal->rwstate = SSL_WRITING;
- i = BIO_write(s->wbio, &(buf[tot]), num);
- if (i <= 0) {
- s->internal->init_off = tot;
- s->internal->init_num = num;
- return (i);
- }
- s->internal->rwstate = SSL_NOTHING;
- if (i == num)
- return (tot + i);
-
- num -= i;
- tot += i;
- }
-}
-
-/* return regularly only when we have read (at least) 'n' bytes */
-int
-ssl23_read_bytes(SSL *s, int n)
-{
- unsigned char *p;
- int j;
-
- if (s->internal->packet_length < (unsigned int)n) {
- p = s->internal->packet;
-
- for (;;) {
- s->internal->rwstate = SSL_READING;
- j = BIO_read(s->rbio, (char *)&(p[s->internal->packet_length]),
- n - s->internal->packet_length);
- if (j <= 0)
- return (j);
- s->internal->rwstate = SSL_NOTHING;
- s->internal->packet_length += j;
- if (s->internal->packet_length >= (unsigned int)n)
- return (s->internal->packet_length);
- }
- }
- return (n);
-}
diff --git a/lib/libssl/s23_srvr.c b/lib/libssl/s23_srvr.c
deleted file mode 100644
index 1cd6721d1fe..00000000000
--- a/lib/libssl/s23_srvr.c
+++ /dev/null
@@ -1,466 +0,0 @@
-/* $OpenBSD: s23_srvr.c,v 1.57 2017/01/23 14:35:42 jsing 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-2006 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 "ssl_locl.h"
-
-#include <openssl/buffer.h>
-#include <openssl/evp.h>
-#include <openssl/objects.h>
-
-static int ssl23_get_client_hello(SSL *s);
-
-int
-ssl23_accept(SSL *s)
-{
- void (*cb)(const SSL *ssl, int type, int val) = NULL;
- int ret = -1;
- int new_state, state;
-
- ERR_clear_error();
- errno = 0;
-
- if (s->internal->info_callback != NULL)
- cb = s->internal->info_callback;
- else if (s->ctx->internal->info_callback != NULL)
- cb = s->ctx->internal->info_callback;
-
- s->internal->in_handshake++;
- if (!SSL_in_init(s) || SSL_in_before(s))
- SSL_clear(s);
-
- for (;;) {
- state = s->internal->state;
-
- switch (s->internal->state) {
- case SSL_ST_BEFORE:
- case SSL_ST_ACCEPT:
- case SSL_ST_BEFORE|SSL_ST_ACCEPT:
- case SSL_ST_OK|SSL_ST_ACCEPT:
-
- s->server = 1;
- if (cb != NULL)
- cb(s, SSL_CB_HANDSHAKE_START, 1);
-
- /* s->version=SSL3_VERSION; */
- s->internal->type = SSL_ST_ACCEPT;
-
- if (!ssl3_setup_init_buffer(s)) {
- ret = -1;
- goto end;
- }
- if (!tls1_init_finished_mac(s)) {
- ret = -1;
- goto end;
- }
-
- s->internal->state = SSL23_ST_SR_CLNT_HELLO_A;
- s->ctx->internal->stats.sess_accept++;
- s->internal->init_num = 0;
- break;
-
- case SSL23_ST_SR_CLNT_HELLO_A:
- case SSL23_ST_SR_CLNT_HELLO_B:
-
- s->internal->shutdown = 0;
- ret = ssl23_get_client_hello(s);
- if (ret >= 0)
- cb = NULL;
- goto end;
- /* break; */
-
- default:
- SSLerr(SSL_F_SSL23_ACCEPT, SSL_R_UNKNOWN_STATE);
- ret = -1;
- goto end;
- /* break; */
- }
-
- if ((cb != NULL) && (s->internal->state != state)) {
- new_state = s->internal->state;
- s->internal->state = state;
- cb(s, SSL_CB_ACCEPT_LOOP, 1);
- s->internal->state = new_state;
- }
- }
-
-end:
- s->internal->in_handshake--;
- if (cb != NULL)
- cb(s, SSL_CB_ACCEPT_EXIT, ret);
-
- return (ret);
-}
-
-
-int
-ssl23_get_client_hello(SSL *s)
-{
- char buf[11];
- /*
- * sizeof(buf) == 11, because we'll need to request this many bytes in
- * the initial read.
- * We can detect SSL 3.0/TLS 1.0 Client Hellos ('type == 3') correctly
- * only when the following is in a single record, which is not
- * guaranteed by the protocol specification:
- * Byte Content
- * 0 type \
- * 1/2 version > record header
- * 3/4 length /
- * 5 msg_type \
- * 6-8 length > Client Hello message
- * 9/10 client_version /
- */
- uint16_t client_version = 0;
- uint16_t shared_version;
- unsigned char *p, *d, *d_len, *dd;
- unsigned int i;
- unsigned int csl, sil, cl;
- int n = 0, j;
- int type = 0;
-
- if (s->internal->state == SSL23_ST_SR_CLNT_HELLO_A) {
- /* read the initial header */
- if (!ssl3_setup_buffers(s))
- return -1;
-
- n = ssl23_read_bytes(s, sizeof buf);
- if (n != sizeof buf)
- return(n);
-
- p = s->internal->packet;
-
- memcpy(buf, p, n);
-
- if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO)) {
- /*
- * SSLv2 header
- */
- client_version = p[3] << 8 | p[4];
-
- if (!ssl_max_shared_version(s, client_version,
- &shared_version))
- goto unsupported;
-
- s->version = shared_version;
- s->internal->state = SSL23_ST_SR_CLNT_HELLO_B;
- } else if ((p[0] == SSL3_RT_HANDSHAKE) &&
- (p[1] == SSL3_VERSION_MAJOR) &&
- (p[5] == SSL3_MT_CLIENT_HELLO) &&
- ((p[3] == 0 && p[4] < 5 /* silly record length? */) ||
- (p[9] >= p[1]))) {
- /*
- * SSLv3 or tls1 header
- */
-
- /* We must look at client_version inside the Client Hello message
- * to get the correct minor version.
- * However if we have only a pathologically small fragment of the
- * Client Hello message, this would be difficult, and we'd have
- * to read more records to find out.
- * No known SSL 3.0 client fragments ClientHello like this,
- * so we simply reject such connections to avoid
- * protocol version downgrade attacks. */
- if (p[3] == 0 && p[4] < 6) {
- SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,
- SSL_R_RECORD_TOO_SMALL);
- return -1;
- }
- client_version = p[9] << 8 | p[10];
-
- if (!ssl_max_shared_version(s, client_version,
- &shared_version)) {
- if (s->internal->options & SSL_OP_NO_TLSv1)
- goto unsupported;
- /*
- * We won't be able to use TLS of course,
- * but this will send an appropriate alert.
- */
- shared_version = TLS1_VERSION;
- }
- s->version = shared_version;
- type = 3;
- } else if ((strncmp("GET ", (char *)p, 4) == 0) ||
- (strncmp("POST ",(char *)p, 5) == 0) ||
- (strncmp("HEAD ",(char *)p, 5) == 0) ||
- (strncmp("PUT ", (char *)p, 4) == 0)) {
- SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_HTTP_REQUEST);
- return -1;
- } else if (strncmp("CONNECT", (char *)p, 7) == 0) {
- SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_HTTPS_PROXY_REQUEST);
- return -1;
- }
- }
-
- if (s->internal->state == SSL23_ST_SR_CLNT_HELLO_B) {
- /* we have SSLv3/TLSv1 in an SSLv2 header
- * (other cases skip this state) */
-
- /*
- * Limit the support of "backward compatible" headers
- * only to "backward" versions of TLS. If we have moved
- * on to modernity, just say no.
- */
- if (s->internal->options & SSL_OP_NO_TLSv1)
- goto unsupported;
-
- type = 2;
- p = s->internal->packet;
- client_version = p[3] << 8 | p[4];
-
- /* An SSLv3/TLSv1 backwards-compatible CLIENT-HELLO in an SSLv2
- * header is sent directly on the wire, not wrapped as a TLS
- * record. It's format is:
- * Byte Content
- * 0-1 msg_length
- * 2 msg_type
- * 3-4 version
- * 5-6 cipher_spec_length
- * 7-8 session_id_length
- * 9-10 challenge_length
- * ... ...
- */
- n = ((p[0] & 0x7f) << 8) | p[1];
- if (n > (1024 * 4)) {
- SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_RECORD_TOO_LARGE);
- return -1;
- }
- if (n < 9) {
- SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,
- SSL_R_RECORD_LENGTH_MISMATCH);
- return -1;
- }
-
- j = ssl23_read_bytes(s, n + 2);
- if (j != n + 2)
- return -1;
-
- tls1_finish_mac(s, s->internal->packet + 2, s->internal->packet_length - 2);
- if (s->internal->msg_callback)
- s->internal->msg_callback(0, SSL2_VERSION, 0, s->internal->packet + 2,
- s->internal->packet_length - 2, s, s->internal->msg_callback_arg);
-
- p = s->internal->packet;
- p += 5;
- n2s(p, csl);
- n2s(p, sil);
- n2s(p, cl);
- d = (unsigned char *)s->internal->init_buf->data;
- if ((csl + sil + cl + 11) != s->internal->packet_length) {
- /*
- * We can't have TLS extensions in SSL 2.0 format
- * Client Hello, can we ? Error condition should be
- * '>' otherwise
- */
- SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,
- SSL_R_RECORD_LENGTH_MISMATCH);
- return -1;
- }
-
- /* record header: msg_type ... */
- *(d++) = SSL3_MT_CLIENT_HELLO;
- /* ... and length (actual value will be written later) */
- d_len = d;
- d += 3;
-
- /* client_version */
- *(d++) = client_version >> 8;
- *(d++) = client_version & 0xff;
-
- /* lets populate the random area */
- /* get the challenge_length */
- i = (cl > SSL3_RANDOM_SIZE) ? SSL3_RANDOM_SIZE : cl;
- memset(d, 0, SSL3_RANDOM_SIZE);
- memcpy(&(d[SSL3_RANDOM_SIZE - i]), &(p[csl + sil]), i);
- d += SSL3_RANDOM_SIZE;
-
- /* no session-id reuse */
- *(d++) = 0;
-
- /* ciphers */
- j = 0;
- dd = d;
- d += 2;
- for (i = 0; i < csl; i += 3) {
- if (p[i] != 0)
- continue;
- *(d++) = p[i + 1];
- *(d++) = p[i + 2];
- j += 2;
- }
- s2n(j, dd);
-
- /* add in (no) COMPRESSION */
- *(d++) = 1;
- *(d++) = 0;
-
- i = (d - (unsigned char *)s->internal->init_buf->data) - 4;
- l2n3((long)i, d_len);
-
- /* get the data reused from the init_buf */
- S3I(s)->tmp.reuse_message = 1;
- S3I(s)->tmp.message_type = SSL3_MT_CLIENT_HELLO;
- S3I(s)->tmp.message_size = i;
- }
-
- /* imaginary new state (for program structure): */
- /* s->internal->state = SSL23_SR_CLNT_HELLO_C */
-
- if (type == 2 || type == 3) {
- /* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */
-
- if (!ssl_init_wbio_buffer(s, 1))
- return -1;
-
- /* we are in this state */
- s->internal->state = SSL3_ST_SR_CLNT_HELLO_A;
-
- if (type == 3) {
- /* put the 'n' bytes we have read into the input buffer
- * for SSLv3 */
- s->internal->rstate = SSL_ST_READ_HEADER;
- s->internal->packet_length = n;
- if (s->s3->rbuf.buf == NULL)
- if (!ssl3_setup_read_buffer(s))
- return -1;
-
- s->internal->packet = &(s->s3->rbuf.buf[0]);
- memcpy(s->internal->packet, buf, n);
- s->s3->rbuf.left = n;
- s->s3->rbuf.offset = 0;
- } else {
- s->internal->packet_length = 0;
- s->s3->rbuf.left = 0;
- s->s3->rbuf.offset = 0;
- }
- if (s->version == TLS1_2_VERSION)
- s->method = TLSv1_2_server_method();
- else if (s->version == TLS1_1_VERSION)
- s->method = TLSv1_1_server_method();
- else if (s->version == TLS1_VERSION)
- s->method = TLSv1_server_method();
- else
- goto unsupported;
- s->internal->handshake_func = s->method->internal->ssl_accept;
- } else {
- /* bad, very bad */
- SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_UNKNOWN_PROTOCOL);
- return -1;
- }
- s->internal->init_num = 0;
-
- return (SSL_accept(s));
-
- unsupported:
- SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_UNSUPPORTED_PROTOCOL);
- return -1;
-}
diff --git a/lib/libssl/s3_both.c b/lib/libssl/s3_both.c
index 033831e23d8..41b35e5de6a 100644
--- a/lib/libssl/s3_both.c
+++ b/lib/libssl/s3_both.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s3_both.c,v 1.56 2017/01/23 14:35:42 jsing Exp $ */
+/* $OpenBSD: s3_both.c,v 1.57 2017/01/26 05:31:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -524,11 +524,17 @@ ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
ssl3_take_mac(s);
/* Feed this message into MAC computation. */
- tls1_finish_mac(s, (unsigned char *)s->internal->init_buf->data, s->internal->init_num + 4);
- if (s->internal->msg_callback)
- s->internal->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,
- s->internal->init_buf->data, (size_t)s->internal->init_num + 4, s,
- s->internal->msg_callback_arg);
+ if (s->internal->mac_packet) {
+ tls1_finish_mac(s, (unsigned char *)s->internal->init_buf->data,
+ s->internal->init_num + 4);
+ s->internal->mac_packet = 0;
+
+ if (s->internal->msg_callback)
+ s->internal->msg_callback(0, s->version,
+ SSL3_RT_HANDSHAKE, s->internal->init_buf->data,
+ (size_t)s->internal->init_num + 4, s,
+ s->internal->msg_callback_arg);
+ }
*ok = 1;
return (s->internal->init_num);
diff --git a/lib/libssl/s3_clnt.c b/lib/libssl/s3_clnt.c
index 0600e7519ea..13915c2439d 100644
--- a/lib/libssl/s3_clnt.c
+++ b/lib/libssl/s3_clnt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s3_clnt.c,v 1.174 2017/01/24 15:11:55 jsing Exp $ */
+/* $OpenBSD: s3_clnt.c,v 1.175 2017/01/26 05:31:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -587,6 +587,7 @@ int
ssl3_client_hello(SSL *s)
{
unsigned char *bufend, *p, *d;
+ uint16_t max_version;
size_t outlen;
int i;
@@ -595,6 +596,13 @@ ssl3_client_hello(SSL *s)
if (s->internal->state == SSL3_ST_CW_CLNT_HELLO_A) {
SSL_SESSION *sess = s->session;
+ if (ssl_supported_version_range(s, NULL, &max_version) != 1) {
+ SSLerr(SSL_F_SSL3_CLIENT_HELLO,
+ SSL_R_NO_PROTOCOLS_AVAILABLE);
+ return (-1);
+ }
+ s->client_version = s->version = max_version;
+
if ((sess == NULL) ||
(sess->ssl_version != s->version) ||
(!sess->session_id_length && !sess->tlsext_tick) ||
@@ -644,6 +652,7 @@ ssl3_client_hello(SSL *s)
* client_version in client hello and not resetting it to
* the negotiated version.
*/
+
*(p++) = s->client_version >> 8;
*(p++) = s->client_version & 0xff;
@@ -719,20 +728,23 @@ ssl3_get_server_hello(SSL *s)
{
CBS cbs, server_random, session_id;
uint16_t server_version, cipher_suite;
+ uint16_t min_version, max_version;
uint8_t compression_method;
STACK_OF(SSL_CIPHER) *sk;
const SSL_CIPHER *cipher;
+ const SSL_METHOD *method;
unsigned char *p;
unsigned long alg_k;
size_t outlen;
int i, al, ok;
long n;
+ s->internal->first_packet = 1;
n = s->method->internal->ssl_get_message(s, SSL3_ST_CR_SRVR_HELLO_A,
SSL3_ST_CR_SRVR_HELLO_B, -1, 20000, /* ?? */ &ok);
-
if (!ok)
return ((int)n);
+ s->internal->first_packet = 0;
if (n < 0)
goto truncated;
@@ -764,12 +776,27 @@ ssl3_get_server_hello(SSL *s)
if (!CBS_get_u16(&cbs, &server_version))
goto truncated;
- if (s->version != server_version) {
+ if (ssl_supported_version_range(s, &min_version, &max_version) != 1) {
+ SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,
+ SSL_R_NO_PROTOCOLS_AVAILABLE);
+ goto err;
+ }
+
+ if (server_version < min_version || server_version > max_version) {
SSLerr(SSL_F_SSL3_GET_SERVER_HELLO, SSL_R_WRONG_SSL_VERSION);
s->version = (s->version & 0xff00) | (server_version & 0xff);
al = SSL_AD_PROTOCOL_VERSION;
goto f_err;
}
+ s->version = server_version;
+
+ if ((method = tls1_get_client_method(server_version)) == NULL)
+ method = dtls1_get_client_method(server_version);
+ if (method == NULL) {
+ SSLerr(SSL_F_SSL3_GET_SERVER_HELLO, ERR_R_INTERNAL_ERROR);
+ goto err;
+ }
+ s->method = method;
/* Server random. */
if (!CBS_get_bytes(&cbs, &server_random, SSL3_RANDOM_SIZE))
@@ -836,6 +863,7 @@ ssl3_get_server_hello(SSL *s)
goto f_err;
}
}
+
/*
* XXX - improve the handling for the case where there is a
* zero length session identifier.
@@ -844,6 +872,8 @@ ssl3_get_server_hello(SSL *s)
sizeof(s->session->session_id), &outlen))
goto err;
s->session->session_id_length = outlen;
+
+ s->session->ssl_version = s->version;
}
if ((cipher = ssl3_get_cipher_by_value(cipher_suite)) == NULL) {
diff --git a/lib/libssl/s3_pkt.c b/lib/libssl/s3_pkt.c
index 152e384a4bd..5dadc0654e1 100644
--- a/lib/libssl/s3_pkt.c
+++ b/lib/libssl/s3_pkt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s3_pkt.c,v 1.69 2017/01/25 06:13:02 jsing Exp $ */
+/* $OpenBSD: s3_pkt.c,v 1.70 2017/01/26 05:31:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -333,9 +333,16 @@ again:
if (n <= 0)
return (n);
+ s->internal->mac_packet = 1;
s->internal->rstate = SSL_ST_READ_BODY;
- CBS_init(&header, s->internal->packet, n);
+ if (s->server && s->internal->first_packet) {
+ if ((ret = ssl_server_legacy_first_packet(s)) != 1)
+ return (ret);
+ ret = -1;
+ }
+
+ CBS_init(&header, s->internal->packet, SSL3_RT_HEADER_LENGTH);
/* Pull apart the header into the SSL3_RECORD */
if (!CBS_get_u8(&header, &type) ||
diff --git a/lib/libssl/s3_srvr.c b/lib/libssl/s3_srvr.c
index c6d340026a8..28f0fc486a0 100644
--- a/lib/libssl/s3_srvr.c
+++ b/lib/libssl/s3_srvr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s3_srvr.c,v 1.153 2017/01/24 14:57:31 jsing Exp $ */
+/* $OpenBSD: s3_srvr.c,v 1.154 2017/01/26 05:31:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -730,6 +730,8 @@ ssl3_get_client_hello(SSL *s)
SSL_CIPHER *c;
STACK_OF(SSL_CIPHER) *ciphers = NULL;
unsigned long alg_k;
+ const SSL_METHOD *method;
+ uint16_t shared_version;
/*
* We do this so that we will respond with our native type.
@@ -741,6 +743,7 @@ ssl3_get_client_hello(SSL *s)
if (s->internal->state == SSL3_ST_SR_CLNT_HELLO_A) {
s->internal->state = SSL3_ST_SR_CLNT_HELLO_B;
}
+
s->internal->first_packet = 1;
n = s->method->internal->ssl_get_message(s, SSL3_ST_SR_CLNT_HELLO_B,
SSL3_ST_SR_CLNT_HELLO_C, SSL3_MT_CLIENT_HELLO,
@@ -749,6 +752,7 @@ ssl3_get_client_hello(SSL *s)
if (!ok)
return ((int)n);
s->internal->first_packet = 0;
+
d = p = (unsigned char *)s->internal->init_msg;
if (2 > n)
@@ -760,21 +764,28 @@ ssl3_get_client_hello(SSL *s)
s->client_version = (((int)p[0]) << 8)|(int)p[1];
p += 2;
- if ((s->version == DTLS1_VERSION && s->client_version > s->version) ||
- (s->version != DTLS1_VERSION && s->client_version < s->version)) {
- SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,
- SSL_R_WRONG_VERSION_NUMBER);
+ if (ssl_max_shared_version(s, s->client_version, &shared_version) != 1) {
+ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_WRONG_VERSION_NUMBER);
if ((s->client_version >> 8) == SSL3_VERSION_MAJOR &&
- !s->internal->enc_write_ctx && !s->internal->write_hash) {
+ !s->internal->enc_write_ctx && !s->internal->write_hash) {
/*
* Similar to ssl3_get_record, send alert using remote
- * version number
+ * version number.
*/
s->version = s->client_version;
}
al = SSL_AD_PROTOCOL_VERSION;
goto f_err;
}
+ s->version = shared_version;
+
+ if ((method = tls1_get_server_method(shared_version)) == NULL)
+ method = dtls1_get_server_method(shared_version);
+ if (method == NULL) {
+ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
+ goto err;
+ }
+ s->method = method;
/*
* If we require cookies (DTLS) and this ClientHello doesn't
diff --git a/lib/libssl/ssl_locl.h b/lib/libssl/ssl_locl.h
index b682fc062e2..bff28b17729 100644
--- a/lib/libssl/ssl_locl.h
+++ b/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_locl.h,v 1.168 2017/01/26 00:42:44 jsing Exp $ */
+/* $OpenBSD: ssl_locl.h,v 1.169 2017/01/26 05:31:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -769,6 +769,7 @@ typedef struct ssl_internal_st {
int state; /* where we are */
int rstate; /* where we are when reading */
+ int mac_packet;
} SSL_INTERNAL;
typedef struct ssl3_state_internal_st {
@@ -1082,6 +1083,11 @@ int ssl_supported_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver);
uint16_t ssl_max_server_version(SSL *s);
+const SSL_METHOD *dtls1_get_client_method(int ver);
+const SSL_METHOD *dtls1_get_server_method(int ver);
+const SSL_METHOD *tls1_get_client_method(int ver);
+const SSL_METHOD *tls1_get_server_method(int ver);
+
extern SSL3_ENC_METHOD DTLSv1_enc_data;
extern SSL3_ENC_METHOD TLSv1_enc_data;
extern SSL3_ENC_METHOD TLSv1_1_enc_data;
@@ -1197,6 +1203,7 @@ long tls1_default_timeout(void);
int dtls1_do_write(SSL *s, int type);
int ssl3_packet_read(SSL *s, int plen);
int ssl3_packet_extend(SSL *s, int plen);
+int ssl_server_legacy_first_packet(SSL *s);
int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
unsigned int len);
diff --git a/lib/libssl/ssl_packet.c b/lib/libssl/ssl_packet.c
new file mode 100644
index 00000000000..0c5b4c463bf
--- /dev/null
+++ b/lib/libssl/ssl_packet.c
@@ -0,0 +1,278 @@
+/*
+ * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "ssl_locl.h"
+
+#include "bytestring.h"
+
+static int
+ssl_is_sslv2_client_hello(CBS *header)
+{
+ uint16_t record_length;
+ uint8_t message_type;
+ CBS cbs;
+
+ CBS_dup(header, &cbs);
+
+ if (!CBS_get_u16(&cbs, &record_length) ||
+ !CBS_get_u8(&cbs, &message_type))
+ return 0;
+
+ /*
+ * The SSLv2 record length field uses variable length (2 or 3 byte)
+ * encoding. Given the size of a client hello, we expect/require the
+ * 2-byte form which is indicated by a one in the most significant bit.
+ */
+ if ((record_length & 0x8000) == 0)
+ return 0;
+ if ((record_length & ~0x8000) < 3)
+ return 0;
+ if (message_type != SSL2_MT_CLIENT_HELLO)
+ return 0;
+
+ return 1;
+}
+
+static int
+ssl_is_sslv3_handshake(CBS *header)
+{
+ uint16_t record_version;
+ uint8_t record_type;
+ CBS cbs;
+
+ CBS_dup(header, &cbs);
+
+ if (!CBS_get_u8(&cbs, &record_type) ||
+ !CBS_get_u16(&cbs, &record_version))
+ return 0;
+
+ if (record_type != SSL3_RT_HANDSHAKE)
+ return 0;
+ if ((record_version >> 8) != SSL3_VERSION_MAJOR)
+ return 0;
+
+ return 1;
+}
+
+static int
+ssl_convert_sslv2_client_hello(SSL *s)
+{
+ CBB cbb, handshake, client_hello, cipher_suites, compression, session_id;
+ CBS cbs, challenge, cipher_specs, session;
+ uint16_t record_length, client_version, cipher_specs_length;
+ uint16_t session_id_length, challenge_length;
+ unsigned char *client_random, *data = NULL;
+ uint32_t cipher_spec;
+ uint8_t message_type;
+ size_t data_len;
+ int rv = -1;
+ int n;
+
+ memset(&cbb, 0, sizeof(cbb));
+
+ CBS_init(&cbs, s->internal->packet, SSL3_RT_HEADER_LENGTH);
+
+ if (!CBS_get_u16(&cbs, &record_length) ||
+ !CBS_get_u8(&cbs, &message_type) ||
+ !CBS_get_u16(&cbs, &client_version))
+ return -1;
+
+ /*
+ * The SSLv2 record length field uses variable length (2 or 3 byte)
+ * encoding. Given the size of a client hello, we expect/require the
+ * 2-byte form which is indicated by a one in the most significant bit.
+ * Also note that the record length value does not include the bytes
+ * used for the record length field.
+ */
+ if ((record_length & 0x8000) == 0)
+ return -1;
+ record_length &= ~0x8000;
+ if (record_length < SSL3_RT_HEADER_LENGTH - 2)
+ return -1;
+ if (message_type != SSL2_MT_CLIENT_HELLO)
+ return -1;
+
+ if (record_length < 9) {
+ SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,
+ SSL_R_RECORD_LENGTH_MISMATCH);
+ return -1;
+ }
+ if (record_length > 4096) {
+ SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_RECORD_TOO_LARGE);
+ return -1;
+ }
+
+ n = ssl3_packet_extend(s, record_length + 2);
+ if (n != record_length + 2)
+ return n;
+
+ tls1_finish_mac(s, s->internal->packet + 2,
+ s->internal->packet_length - 2);
+ s->internal->mac_packet = 0;
+
+ if (s->internal->msg_callback)
+ s->internal->msg_callback(0, SSL2_VERSION, 0,
+ s->internal->packet + 2, s->internal->packet_length - 2, s,
+ s->internal->msg_callback_arg);
+
+ /* Decode the SSLv2 record containing the client hello. */
+ CBS_init(&cbs, s->internal->packet, s->internal->packet_length);
+
+ if (!CBS_get_u16(&cbs, &record_length))
+ return -1;
+ if (!CBS_get_u8(&cbs, &message_type))
+ return -1;
+ if (!CBS_get_u16(&cbs, &client_version))
+ return -1;
+ if (!CBS_get_u16(&cbs, &cipher_specs_length))
+ return -1;
+ if (!CBS_get_u16(&cbs, &session_id_length))
+ return -1;
+ if (!CBS_get_u16(&cbs, &challenge_length))
+ return -1;
+ if (!CBS_get_bytes(&cbs, &cipher_specs, cipher_specs_length))
+ return -1;
+ if (!CBS_get_bytes(&cbs, &session, session_id_length))
+ return -1;
+ if (!CBS_get_bytes(&cbs, &challenge, challenge_length))
+ return -1;
+ if (CBS_len(&cbs) != 0) {
+ SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,
+ SSL_R_RECORD_LENGTH_MISMATCH);
+ return -1;
+ }
+
+ /* Build SSLv3/TLS record with client hello. */
+ if (!CBB_init(&cbb, SSL3_RT_MAX_PLAIN_LENGTH))
+ goto err;
+ if (!CBB_add_u8(&cbb, SSL3_RT_HANDSHAKE))
+ goto err;
+ if (!CBB_add_u16(&cbb, 0x0301))
+ goto err;
+ if (!CBB_add_u16_length_prefixed(&cbb, &handshake))
+ goto err;
+ if (!CBB_add_u8(&handshake, SSL3_MT_CLIENT_HELLO))
+ goto err;
+ if (!CBB_add_u24_length_prefixed(&handshake, &client_hello))
+ goto err;
+ if (!CBB_add_u16(&client_hello, client_version))
+ goto err;
+ if (!CBB_add_space(&client_hello, &client_random, SSL3_RANDOM_SIZE))
+ goto err;
+ memset(client_random, 0, SSL3_RANDOM_SIZE);
+ if (!CBS_write_bytes(&challenge, client_random, SSL3_RANDOM_SIZE, NULL))
+ goto err;
+ if (!CBB_add_u8_length_prefixed(&client_hello, &session_id))
+ goto err;
+ if (!CBB_add_u16_length_prefixed(&client_hello, &cipher_suites))
+ goto err;
+ while (CBS_len(&cipher_specs) > 0) {
+ if (!CBS_get_u24(&cipher_specs, &cipher_spec))
+ goto err;
+ if ((cipher_spec & 0xff0000) != 0)
+ continue;
+ if (!CBB_add_u16(&cipher_suites, cipher_spec & 0xffff))
+ goto err;
+ }
+ if (!CBB_add_u8_length_prefixed(&client_hello, &compression))
+ goto err;
+ if (!CBB_add_u8(&compression, 0))
+ goto err;
+ if (!CBB_finish(&cbb, &data, &data_len))
+ goto err;
+
+ if (data_len > s->s3->rbuf.len)
+ goto err;
+
+ s->internal->packet = s->s3->rbuf.buf;
+ s->internal->packet_length = data_len;
+ memcpy(s->internal->packet, data, data_len);
+ rv = 1;
+
+ err:
+ CBB_cleanup(&cbb);
+ free(data);
+
+ return (rv);
+}
+
+/*
+ * Potentially do legacy processing on the first packet received by a TLS
+ * server. We return 1 if we want SSLv3/TLS record processing to continue
+ * normally, otherwise we must set an SSLerr and return -1.
+ */
+int
+ssl_server_legacy_first_packet(SSL *s)
+{
+ uint16_t min_version;
+ const char *data;
+ CBS header;
+
+ if (SSL_IS_DTLS(s))
+ return 1;
+
+ CBS_init(&header, s->internal->packet, SSL3_RT_HEADER_LENGTH);
+
+ if (ssl_is_sslv3_handshake(&header) == 1)
+ return 1;
+
+ /* Only continue if this is not a version locked method. */
+ if (s->method->internal->min_version == s->method->internal->max_version)
+ return 1;
+
+ if (ssl_is_sslv2_client_hello(&header) == 1) {
+ /* Only permit SSLv2 client hellos if TLSv1.0 is enabled. */
+ if (ssl_enabled_version_range(s, &min_version, NULL) != 1) {
+ SSLerr(SSL_F_SSL23_CLIENT_HELLO,
+ SSL_R_NO_PROTOCOLS_AVAILABLE);
+ return -1;
+ }
+ if (min_version > TLS1_VERSION)
+ return 1;
+
+ if (ssl_convert_sslv2_client_hello(s) != 1) {
+ SSLerr(SSL_F_SSL23_CLIENT_HELLO,
+ SSL_R_BAD_PACKET_LENGTH);
+ return -1;
+ }
+
+ return 1;
+ }
+
+ /* Ensure that we have SSL3_RT_HEADER_LENGTH (5 bytes) of the packet. */
+ if (CBS_len(&header) != SSL3_RT_HEADER_LENGTH) {
+ SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
+ return -1;
+ }
+ data = (const char *)CBS_data(&header);
+
+ /* Is this a cleartext protocol? */
+ if (strncmp("GET ", data, 4) == 0 ||
+ strncmp("POST ", data, 5) == 0 ||
+ strncmp("HEAD ", data, 5) == 0 ||
+ strncmp("PUT ", data, 4) == 0) {
+ SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_HTTP_REQUEST);
+ return -1;
+ }
+ if (strncmp("CONNE", data, 5) == 0) {
+ SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_HTTPS_PROXY_REQUEST);
+ return -1;
+ }
+
+ SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, SSL_R_UNKNOWN_PROTOCOL);
+
+ return -1;
+}
diff --git a/lib/libssl/t1_clnt.c b/lib/libssl/t1_clnt.c
index d185df3c79d..92b5efb11a2 100644
--- a/lib/libssl/t1_clnt.c
+++ b/lib/libssl/t1_clnt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: t1_clnt.c,v 1.23 2017/01/26 00:42:44 jsing Exp $ */
+/* $OpenBSD: t1_clnt.c,v 1.24 2017/01/26 05:31:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -64,8 +64,6 @@
#include <openssl/evp.h>
#include <openssl/objects.h>
-static const SSL_METHOD *tls1_get_client_method(int ver);
-
static const SSL_METHOD_INTERNAL TLS_client_method_internal_data = {
.version = TLS1_2_VERSION,
.min_version = TLS1_VERSION,
@@ -74,21 +72,21 @@ static const SSL_METHOD_INTERNAL TLS_client_method_internal_data = {
.ssl_clear = tls1_clear,
.ssl_free = tls1_free,
.ssl_accept = ssl_undefined_function,
- .ssl_connect = ssl23_connect,
- .ssl_read = ssl23_read,
- .ssl_peek = ssl23_peek,
- .ssl_write = ssl23_write,
- .ssl_shutdown = ssl_undefined_function,
- .ssl_pending = ssl_undefined_const_function,
+ .ssl_connect = ssl3_connect,
+ .ssl_read = ssl3_read,
+ .ssl_peek = ssl3_peek,
+ .ssl_write = ssl3_write,
+ .ssl_shutdown = ssl3_shutdown,
+ .ssl_pending = ssl3_pending,
.get_ssl_method = tls1_get_client_method,
- .get_timeout = ssl23_default_timeout,
+ .get_timeout = tls1_default_timeout,
.ssl_version = ssl_undefined_void_function,
.ssl_renegotiate = ssl_undefined_function,
.ssl_renegotiate_check = ssl_ok,
.ssl_get_message = ssl3_get_message,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl3_enc = NULL,
+ .ssl3_enc = &TLSv1_2_enc_data,
};
static const SSL_METHOD TLS_client_method_data = {
@@ -202,7 +200,7 @@ static const SSL_METHOD TLSv1_2_client_method_data = {
.internal = &TLSv1_2_client_method_internal_data,
};
-static const SSL_METHOD *
+const SSL_METHOD *
tls1_get_client_method(int ver)
{
if (ver == TLS1_2_VERSION)
diff --git a/lib/libssl/t1_meth.c b/lib/libssl/t1_meth.c
index d6262e48cd1..6a4a243b9df 100644
--- a/lib/libssl/t1_meth.c
+++ b/lib/libssl/t1_meth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: t1_meth.c,v 1.22 2017/01/26 00:42:44 jsing Exp $ */
+/* $OpenBSD: t1_meth.c,v 1.23 2017/01/26 05:31:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -71,22 +71,22 @@ static const SSL_METHOD_INTERNAL TLS_method_internal_data = {
.ssl_new = tls1_new,
.ssl_clear = tls1_clear,
.ssl_free = tls1_free,
- .ssl_accept = ssl23_accept,
- .ssl_connect = ssl23_connect,
- .ssl_read = ssl23_read,
- .ssl_peek = ssl23_peek,
- .ssl_write = ssl23_write,
- .ssl_shutdown = ssl_undefined_function,
- .ssl_pending = ssl_undefined_const_function,
+ .ssl_accept = ssl3_accept,
+ .ssl_connect = ssl3_connect,
+ .ssl_read = ssl3_read,
+ .ssl_peek = ssl3_peek,
+ .ssl_write = ssl3_write,
+ .ssl_shutdown = ssl3_shutdown,
+ .ssl_pending = ssl3_pending,
.get_ssl_method = tls1_get_method,
- .get_timeout = ssl23_default_timeout,
+ .get_timeout = tls1_default_timeout,
.ssl_version = ssl_undefined_void_function,
.ssl_renegotiate = ssl_undefined_function,
.ssl_renegotiate_check = ssl_ok,
.ssl_get_message = ssl3_get_message,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl3_enc = NULL,
+ .ssl3_enc = &TLSv1_2_enc_data,
};
static const SSL_METHOD TLS_method_data = {
diff --git a/lib/libssl/t1_srvr.c b/lib/libssl/t1_srvr.c
index 69da5cbb677..1fc0ebe6f74 100644
--- a/lib/libssl/t1_srvr.c
+++ b/lib/libssl/t1_srvr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: t1_srvr.c,v 1.24 2017/01/26 00:42:44 jsing Exp $ */
+/* $OpenBSD: t1_srvr.c,v 1.25 2017/01/26 05:31:25 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -65,8 +65,6 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
-static const SSL_METHOD *tls1_get_server_method(int ver);
-
static const SSL_METHOD_INTERNAL TLS_server_method_internal_data = {
.version = TLS1_2_VERSION,
.min_version = TLS1_VERSION,
@@ -74,22 +72,22 @@ static const SSL_METHOD_INTERNAL TLS_server_method_internal_data = {
.ssl_new = tls1_new,
.ssl_clear = tls1_clear,
.ssl_free = tls1_free,
- .ssl_accept = ssl23_accept,
+ .ssl_accept = ssl3_accept,
.ssl_connect = ssl_undefined_function,
- .ssl_read = ssl23_read,
- .ssl_peek = ssl23_peek,
- .ssl_write = ssl23_write,
- .ssl_shutdown = ssl_undefined_function,
- .ssl_pending = ssl_undefined_const_function,
+ .ssl_read = ssl3_read,
+ .ssl_peek = ssl3_peek,
+ .ssl_write = ssl3_write,
+ .ssl_shutdown = ssl3_shutdown,
+ .ssl_pending = ssl3_pending,
.get_ssl_method = tls1_get_server_method,
- .get_timeout = ssl23_default_timeout,
+ .get_timeout = tls1_default_timeout,
.ssl_version = ssl_undefined_void_function,
.ssl_renegotiate = ssl_undefined_function,
.ssl_renegotiate_check = ssl_ok,
.ssl_get_message = ssl3_get_message,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl3_enc = NULL,
+ .ssl3_enc = &TLSv1_2_enc_data,
};
static const SSL_METHOD TLS_server_method_data = {
@@ -203,7 +201,7 @@ static const SSL_METHOD TLSv1_2_server_method_data = {
.internal = &TLSv1_2_server_method_internal_data,
};
-static const SSL_METHOD *
+const SSL_METHOD *
tls1_get_server_method(int ver)
{
if (ver == TLS1_2_VERSION)