remove obsolete files
This commit is contained in:
184
externals/libressl/ssl/d1_clnt.c
vendored
184
externals/libressl/ssl/d1_clnt.c
vendored
@@ -1,184 +0,0 @@
|
||||
/* $OpenBSD: d1_clnt.c,v 1.83 2020/01/23 10:48:37 jsing Exp $ */
|
||||
/*
|
||||
* DTLS implementation written by Nagendra Modadugu
|
||||
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2007 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).
|
||||
*
|
||||
*/
|
||||
/* 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 <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ssl_locl.h"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
#include "bytestring.h"
|
||||
|
||||
int
|
||||
dtls1_get_hello_verify(SSL *s)
|
||||
{
|
||||
long n;
|
||||
int al, ok = 0;
|
||||
size_t cookie_len;
|
||||
uint16_t ssl_version;
|
||||
CBS hello_verify_request, cookie;
|
||||
|
||||
n = ssl3_get_message(s, DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A,
|
||||
DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B, -1, s->internal->max_cert_list, &ok);
|
||||
if (!ok)
|
||||
return ((int)n);
|
||||
|
||||
if (S3I(s)->tmp.message_type != DTLS1_MT_HELLO_VERIFY_REQUEST) {
|
||||
D1I(s)->send_cookie = 0;
|
||||
S3I(s)->tmp.reuse_message = 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (n < 0)
|
||||
goto truncated;
|
||||
|
||||
CBS_init(&hello_verify_request, s->internal->init_msg, n);
|
||||
|
||||
if (!CBS_get_u16(&hello_verify_request, &ssl_version))
|
||||
goto truncated;
|
||||
|
||||
if (ssl_version != s->version) {
|
||||
SSLerror(s, SSL_R_WRONG_SSL_VERSION);
|
||||
s->version = (s->version & 0xff00) | (ssl_version & 0xff);
|
||||
al = SSL_AD_PROTOCOL_VERSION;
|
||||
goto f_err;
|
||||
}
|
||||
|
||||
if (!CBS_get_u8_length_prefixed(&hello_verify_request, &cookie))
|
||||
goto truncated;
|
||||
|
||||
if (!CBS_write_bytes(&cookie, D1I(s)->cookie,
|
||||
sizeof(D1I(s)->cookie), &cookie_len)) {
|
||||
D1I(s)->cookie_len = 0;
|
||||
al = SSL_AD_ILLEGAL_PARAMETER;
|
||||
goto f_err;
|
||||
}
|
||||
D1I(s)->cookie_len = cookie_len;
|
||||
D1I(s)->send_cookie = 1;
|
||||
|
||||
return 1;
|
||||
|
||||
truncated:
|
||||
al = SSL_AD_DECODE_ERROR;
|
||||
f_err:
|
||||
ssl3_send_alert(s, SSL3_AL_FATAL, al);
|
||||
return -1;
|
||||
}
|
165
externals/libressl/ssl/d1_srvr.c
vendored
165
externals/libressl/ssl/d1_srvr.c
vendored
@@ -1,165 +0,0 @@
|
||||
/* $OpenBSD: d1_srvr.c,v 1.95 2018/11/05 05:45:15 jsing Exp $ */
|
||||
/*
|
||||
* DTLS implementation written by Nagendra Modadugu
|
||||
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2007 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).
|
||||
*
|
||||
*/
|
||||
/* 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 "ssl_locl.h"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
int
|
||||
dtls1_send_hello_verify_request(SSL *s)
|
||||
{
|
||||
CBB cbb, verify, cookie;
|
||||
|
||||
memset(&cbb, 0, sizeof(cbb));
|
||||
|
||||
if (S3I(s)->hs.state == DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A) {
|
||||
if (s->ctx->internal->app_gen_cookie_cb == NULL ||
|
||||
s->ctx->internal->app_gen_cookie_cb(s, D1I(s)->cookie,
|
||||
&(D1I(s)->cookie_len)) == 0) {
|
||||
SSLerror(s, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ssl3_handshake_msg_start(s, &cbb, &verify,
|
||||
DTLS1_MT_HELLO_VERIFY_REQUEST))
|
||||
goto err;
|
||||
if (!CBB_add_u16(&verify, s->version))
|
||||
goto err;
|
||||
if (!CBB_add_u8_length_prefixed(&verify, &cookie))
|
||||
goto err;
|
||||
if (!CBB_add_bytes(&cookie, D1I(s)->cookie, D1I(s)->cookie_len))
|
||||
goto err;
|
||||
if (!ssl3_handshake_msg_finish(s, &cbb))
|
||||
goto err;
|
||||
|
||||
S3I(s)->hs.state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B;
|
||||
}
|
||||
|
||||
/* S3I(s)->hs.state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B */
|
||||
return (ssl3_handshake_write(s));
|
||||
|
||||
err:
|
||||
CBB_cleanup(&cbb);
|
||||
|
||||
return (-1);
|
||||
}
|
137
externals/libressl/ssl/tls13_buffer.c
vendored
137
externals/libressl/ssl/tls13_buffer.c
vendored
@@ -1,137 +0,0 @@
|
||||
/* $OpenBSD: tls13_buffer.c,v 1.3 2020/03/10 17:11:25 jsing Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2018, 2019 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"
|
||||
#include "tls13_internal.h"
|
||||
|
||||
struct tls13_buffer {
|
||||
size_t capacity;
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
size_t offset;
|
||||
};
|
||||
|
||||
static int tls13_buffer_resize(struct tls13_buffer *buf, size_t capacity);
|
||||
|
||||
struct tls13_buffer *
|
||||
tls13_buffer_new(size_t init_size)
|
||||
{
|
||||
struct tls13_buffer *buf = NULL;
|
||||
|
||||
if ((buf = calloc(1, sizeof(struct tls13_buffer))) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!tls13_buffer_resize(buf, init_size))
|
||||
goto err;
|
||||
|
||||
return buf;
|
||||
|
||||
err:
|
||||
tls13_buffer_free(buf);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
tls13_buffer_free(struct tls13_buffer *buf)
|
||||
{
|
||||
if (buf == NULL)
|
||||
return;
|
||||
|
||||
freezero(buf->data, buf->capacity);
|
||||
freezero(buf, sizeof(struct tls13_buffer));
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_buffer_resize(struct tls13_buffer *buf, size_t capacity)
|
||||
{
|
||||
uint8_t *data;
|
||||
|
||||
if (buf->capacity == capacity)
|
||||
return 1;
|
||||
|
||||
if ((data = recallocarray(buf->data, buf->capacity, capacity, 1)) == NULL)
|
||||
return 0;
|
||||
|
||||
buf->data = data;
|
||||
buf->capacity = capacity;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
tls13_buffer_set_data(struct tls13_buffer *buf, CBS *data)
|
||||
{
|
||||
if (!tls13_buffer_resize(buf, CBS_len(data)))
|
||||
return 0;
|
||||
memcpy(buf->data, CBS_data(data), CBS_len(data));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
tls13_buffer_extend(struct tls13_buffer *buf, size_t len,
|
||||
tls13_read_cb read_cb, void *cb_arg)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
if (len == buf->len)
|
||||
return buf->len;
|
||||
|
||||
if (len < buf->len)
|
||||
return TLS13_IO_FAILURE;
|
||||
|
||||
if (!tls13_buffer_resize(buf, len))
|
||||
return TLS13_IO_FAILURE;
|
||||
|
||||
for (;;) {
|
||||
if ((ret = read_cb(&buf->data[buf->len],
|
||||
buf->capacity - buf->len, cb_arg)) <= 0)
|
||||
return ret;
|
||||
|
||||
if (ret > buf->capacity - buf->len)
|
||||
return TLS13_IO_FAILURE;
|
||||
|
||||
buf->len += ret;
|
||||
|
||||
if (buf->len == buf->capacity)
|
||||
return buf->len;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tls13_buffer_cbs(struct tls13_buffer *buf, CBS *cbs)
|
||||
{
|
||||
CBS_init(cbs, buf->data, buf->len);
|
||||
}
|
||||
|
||||
int
|
||||
tls13_buffer_finish(struct tls13_buffer *buf, uint8_t **out, size_t *out_len)
|
||||
{
|
||||
if (out == NULL || out_len == NULL)
|
||||
return 0;
|
||||
|
||||
*out = buf->data;
|
||||
*out_len = buf->len;
|
||||
|
||||
buf->capacity = 0;
|
||||
buf->data = NULL;
|
||||
buf->len = 0;
|
||||
|
||||
return 1;
|
||||
}
|
324
externals/libressl/ssl/tls13_key_share.c
vendored
324
externals/libressl/ssl/tls13_key_share.c
vendored
@@ -1,324 +0,0 @@
|
||||
/* $OpenBSD: tls13_key_share.c,v 1.6 2020/04/18 14:07:56 jsing Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2020 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 <stdlib.h>
|
||||
|
||||
#include <openssl/curve25519.h>
|
||||
|
||||
#include "bytestring.h"
|
||||
#include "ssl_locl.h"
|
||||
#include "tls13_internal.h"
|
||||
|
||||
struct tls13_key_share {
|
||||
int nid;
|
||||
uint16_t group_id;
|
||||
|
||||
EC_KEY *ecdhe;
|
||||
EC_KEY *ecdhe_peer;
|
||||
|
||||
uint8_t *x25519_public;
|
||||
uint8_t *x25519_private;
|
||||
uint8_t *x25519_peer_public;
|
||||
};
|
||||
|
||||
struct tls13_key_share *
|
||||
tls13_key_share_new(uint16_t group_id)
|
||||
{
|
||||
struct tls13_key_share *ks;
|
||||
int nid;
|
||||
|
||||
if ((nid = tls1_ec_curve_id2nid(group_id)) == 0)
|
||||
return NULL;
|
||||
|
||||
if ((ks = calloc(1, sizeof(struct tls13_key_share))) == NULL)
|
||||
return NULL;
|
||||
|
||||
ks->group_id = group_id;
|
||||
ks->nid = nid;
|
||||
|
||||
return ks;
|
||||
}
|
||||
|
||||
struct tls13_key_share *
|
||||
tls13_key_share_new_nid(int nid)
|
||||
{
|
||||
uint16_t group_id;
|
||||
|
||||
if ((group_id = tls1_ec_nid2curve_id(nid)) == 0)
|
||||
return NULL;
|
||||
|
||||
return tls13_key_share_new(group_id);
|
||||
}
|
||||
|
||||
void
|
||||
tls13_key_share_free(struct tls13_key_share *ks)
|
||||
{
|
||||
if (ks == NULL)
|
||||
return;
|
||||
|
||||
EC_KEY_free(ks->ecdhe);
|
||||
EC_KEY_free(ks->ecdhe_peer);
|
||||
|
||||
freezero(ks->x25519_public, X25519_KEY_LENGTH);
|
||||
freezero(ks->x25519_private, X25519_KEY_LENGTH);
|
||||
freezero(ks->x25519_peer_public, X25519_KEY_LENGTH);
|
||||
|
||||
freezero(ks, sizeof(*ks));
|
||||
}
|
||||
|
||||
uint16_t
|
||||
tls13_key_share_group(struct tls13_key_share *ks)
|
||||
{
|
||||
return ks->group_id;
|
||||
}
|
||||
|
||||
int
|
||||
tls13_key_share_peer_pkey(struct tls13_key_share *ks, EVP_PKEY *pkey)
|
||||
{
|
||||
if (ks->nid == NID_X25519 && ks->x25519_peer_public != NULL) {
|
||||
if (!ssl_kex_dummy_ecdhe_x25519(pkey))
|
||||
return 0;
|
||||
} else if (ks->ecdhe_peer != NULL) {
|
||||
if (!EVP_PKEY_set1_EC_KEY(pkey, ks->ecdhe_peer))
|
||||
return 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_key_share_generate_ecdhe_ecp(struct tls13_key_share *ks)
|
||||
{
|
||||
EC_KEY *ecdhe = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (ks->ecdhe != NULL)
|
||||
goto err;
|
||||
|
||||
if ((ecdhe = EC_KEY_new()) == NULL)
|
||||
goto err;
|
||||
if (!ssl_kex_generate_ecdhe_ecp(ecdhe, ks->nid))
|
||||
goto err;
|
||||
|
||||
ks->ecdhe = ecdhe;
|
||||
ecdhe = NULL;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EC_KEY_free(ecdhe);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_key_share_generate_x25519(struct tls13_key_share *ks)
|
||||
{
|
||||
uint8_t *public = NULL, *private = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (ks->x25519_public != NULL || ks->x25519_private != NULL)
|
||||
goto err;
|
||||
|
||||
if ((public = calloc(1, X25519_KEY_LENGTH)) == NULL)
|
||||
goto err;
|
||||
if ((private = calloc(1, X25519_KEY_LENGTH)) == NULL)
|
||||
goto err;
|
||||
|
||||
X25519_keypair(public, private);
|
||||
|
||||
ks->x25519_public = public;
|
||||
ks->x25519_private = private;
|
||||
public = NULL;
|
||||
private = NULL;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
freezero(public, X25519_KEY_LENGTH);
|
||||
freezero(private, X25519_KEY_LENGTH);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
tls13_key_share_generate(struct tls13_key_share *ks)
|
||||
{
|
||||
if (ks->nid == NID_X25519)
|
||||
return tls13_key_share_generate_x25519(ks);
|
||||
|
||||
return tls13_key_share_generate_ecdhe_ecp(ks);
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_key_share_public_ecdhe_ecp(struct tls13_key_share *ks, CBB *cbb)
|
||||
{
|
||||
if (ks->ecdhe == NULL)
|
||||
return 0;
|
||||
|
||||
return ssl_kex_public_ecdhe_ecp(ks->ecdhe, cbb);
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_key_share_public_x25519(struct tls13_key_share *ks, CBB *cbb)
|
||||
{
|
||||
if (ks->x25519_public == NULL)
|
||||
return 0;
|
||||
|
||||
return CBB_add_bytes(cbb, ks->x25519_public, X25519_KEY_LENGTH);
|
||||
}
|
||||
|
||||
int
|
||||
tls13_key_share_public(struct tls13_key_share *ks, CBB *cbb)
|
||||
{
|
||||
CBB key_exchange;
|
||||
|
||||
if (!CBB_add_u16(cbb, ks->group_id))
|
||||
goto err;
|
||||
if (!CBB_add_u16_length_prefixed(cbb, &key_exchange))
|
||||
goto err;
|
||||
|
||||
if (ks->nid == NID_X25519) {
|
||||
if (!tls13_key_share_public_x25519(ks, &key_exchange))
|
||||
goto err;
|
||||
} else {
|
||||
if (!tls13_key_share_public_ecdhe_ecp(ks, &key_exchange))
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!CBB_flush(cbb))
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_key_share_peer_public_ecdhe_ecp(struct tls13_key_share *ks, CBS *cbs)
|
||||
{
|
||||
EC_KEY *ecdhe = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (ks->ecdhe_peer != NULL)
|
||||
goto err;
|
||||
|
||||
if ((ecdhe = EC_KEY_new()) == NULL)
|
||||
goto err;
|
||||
if (!ssl_kex_peer_public_ecdhe_ecp(ecdhe, ks->nid, cbs))
|
||||
goto err;
|
||||
|
||||
ks->ecdhe_peer = ecdhe;
|
||||
ecdhe = NULL;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EC_KEY_free(ecdhe);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_key_share_peer_public_x25519(struct tls13_key_share *ks, CBS *cbs)
|
||||
{
|
||||
size_t out_len;
|
||||
|
||||
if (ks->x25519_peer_public != NULL)
|
||||
return 0;
|
||||
|
||||
if (CBS_len(cbs) != X25519_KEY_LENGTH)
|
||||
return 0;
|
||||
|
||||
return CBS_stow(cbs, &ks->x25519_peer_public, &out_len);
|
||||
}
|
||||
|
||||
int
|
||||
tls13_key_share_peer_public(struct tls13_key_share *ks, uint16_t group,
|
||||
CBS *cbs)
|
||||
{
|
||||
if (ks->group_id != group)
|
||||
return 0;
|
||||
|
||||
if (ks->nid == NID_X25519) {
|
||||
if (!tls13_key_share_peer_public_x25519(ks, cbs))
|
||||
return 0;
|
||||
} else {
|
||||
if (!tls13_key_share_peer_public_ecdhe_ecp(ks, cbs))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_key_share_derive_ecdhe_ecp(struct tls13_key_share *ks,
|
||||
uint8_t **shared_key, size_t *shared_key_len)
|
||||
{
|
||||
if (ks->ecdhe == NULL || ks->ecdhe_peer == NULL)
|
||||
return 0;
|
||||
|
||||
return ssl_kex_derive_ecdhe_ecp(ks->ecdhe, ks->ecdhe_peer,
|
||||
shared_key, shared_key_len);
|
||||
}
|
||||
|
||||
static int
|
||||
tls13_key_share_derive_x25519(struct tls13_key_share *ks,
|
||||
uint8_t **shared_key, size_t *shared_key_len)
|
||||
{
|
||||
uint8_t *sk = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (ks->x25519_private == NULL || ks->x25519_peer_public == NULL)
|
||||
goto err;
|
||||
|
||||
if ((sk = calloc(1, X25519_KEY_LENGTH)) == NULL)
|
||||
goto err;
|
||||
if (!X25519(sk, ks->x25519_private, ks->x25519_peer_public))
|
||||
goto err;
|
||||
|
||||
*shared_key = sk;
|
||||
*shared_key_len = X25519_KEY_LENGTH;
|
||||
sk = NULL;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
freezero(sk, X25519_KEY_LENGTH);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
tls13_key_share_derive(struct tls13_key_share *ks, uint8_t **shared_key,
|
||||
size_t *shared_key_len)
|
||||
{
|
||||
if (*shared_key != NULL)
|
||||
return 0;
|
||||
|
||||
*shared_key_len = 0;
|
||||
|
||||
if (ks->nid == NID_X25519)
|
||||
return tls13_key_share_derive_x25519(ks, shared_key,
|
||||
shared_key_len);
|
||||
|
||||
return tls13_key_share_derive_ecdhe_ecp(ks, shared_key,
|
||||
shared_key_len);
|
||||
}
|
Reference in New Issue
Block a user