2016-11-25 06:54:59 +08:00
|
|
|
/*
|
2021-01-28 03:23:33 +08:00
|
|
|
* Copyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved.
|
2016-11-25 06:54:59 +08:00
|
|
|
*
|
2018-12-06 20:08:51 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-11-25 06:54:59 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <openssl/ocsp.h>
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "../ssl_local.h"
|
|
|
|
#include "statem_local.h"
|
2017-09-11 22:43:56 +08:00
|
|
|
#include "internal/cryptlib.h"
|
|
|
|
|
2022-08-16 09:05:02 +08:00
|
|
|
#define COOKIE_STATE_FORMAT_VERSION 1
|
2017-09-11 22:43:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 2 bytes for packet length, 2 bytes for format version, 2 bytes for
|
|
|
|
* protocol version, 2 bytes for group id, 2 bytes for cipher id, 1 byte for
|
2022-08-16 09:05:02 +08:00
|
|
|
* key_share present flag, 8 bytes for timestamp, 2 bytes for the hashlen,
|
2018-01-17 22:29:22 +08:00
|
|
|
* EVP_MAX_MD_SIZE for transcript hash, 1 byte for app cookie length, app cookie
|
|
|
|
* length bytes, SHA256_DIGEST_LENGTH bytes for the HMAC of the whole thing.
|
2017-09-11 22:43:56 +08:00
|
|
|
*/
|
2022-08-16 09:05:02 +08:00
|
|
|
#define MAX_COOKIE_SIZE (2 + 2 + 2 + 2 + 2 + 1 + 8 + 2 + EVP_MAX_MD_SIZE + 1 \
|
2017-09-11 22:43:56 +08:00
|
|
|
+ SSL_COOKIE_LENGTH + SHA256_DIGEST_LENGTH)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Message header + 2 bytes for protocol version + number of random bytes +
|
2018-01-23 20:23:23 +08:00
|
|
|
* + 1 byte for legacy session id length + number of bytes in legacy session id
|
|
|
|
* + 2 bytes for ciphersuite + 1 byte for legacy compression
|
|
|
|
* + 2 bytes for extension block length + 6 bytes for key_share extension
|
|
|
|
* + 4 bytes for cookie extension header + the number of bytes in the cookie
|
2017-09-11 22:43:56 +08:00
|
|
|
*/
|
2018-01-23 20:23:23 +08:00
|
|
|
#define MAX_HRR_SIZE (SSL3_HM_HEADER_LENGTH + 2 + SSL3_RANDOM_SIZE + 1 \
|
2017-09-11 22:43:56 +08:00
|
|
|
+ SSL_MAX_SSL_SESSION_ID_LENGTH + 2 + 1 + 2 + 6 + 4 \
|
|
|
|
+ MAX_COOKIE_SIZE)
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse the client's renegotiation binding and abort if it's not right
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_renegotiate(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
unsigned int ilen;
|
|
|
|
const unsigned char *data;
|
2023-01-25 22:43:50 +08:00
|
|
|
int ok;
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
/* Parse the length byte */
|
|
|
|
if (!PACKET_get_1(pkt, &ilen)
|
|
|
|
|| !PACKET_get_bytes(pkt, &data, ilen)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_RENEGOTIATION_ENCODING_ERR);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the extension matches */
|
2018-12-13 02:09:50 +08:00
|
|
|
if (ilen != s->s3.previous_client_finished_len) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_R_RENEGOTIATION_MISMATCH);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-25 22:43:50 +08:00
|
|
|
ok = memcmp(data, s->s3.previous_client_finished,
|
|
|
|
s->s3.previous_client_finished_len);
|
|
|
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
|
|
|
if (ok) {
|
2023-02-09 22:21:59 +08:00
|
|
|
if ((data[0] ^ s->s3.previous_client_finished[0]) != 0xFF) {
|
2023-01-25 22:43:50 +08:00
|
|
|
ok = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (ok) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, SSL_R_RENEGOTIATION_MISMATCH);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
s->s3.send_connection_binding = 1;
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
/*-
|
|
|
|
* The servername extension is treated as follows:
|
|
|
|
*
|
|
|
|
* - Only the hostname type is supported with a maximum length of 255.
|
|
|
|
* - The servername is rejected if too long or if it contains zeros,
|
|
|
|
* in which case an fatal alert is generated.
|
|
|
|
* - The servername field is maintained together with the session cache.
|
|
|
|
* - When a session is resumed, the servername call back invoked in order
|
|
|
|
* to allow the application to position itself to the right context.
|
|
|
|
* - The servername is acknowledged if it is new for a session or when
|
|
|
|
* it is identical to a previously used for the same session.
|
|
|
|
* Applications can control the behaviour. They can at any time
|
|
|
|
* set a 'desirable' servername for a new SSL object. This can be the
|
|
|
|
* case for example with HTTPS when a Host: header field is received and
|
|
|
|
* a renegotiation is requested. In this case, a possible servername
|
|
|
|
* presented in the new client hello is only acknowledged if it matches
|
|
|
|
* the value of the Host: field.
|
|
|
|
* - Applications must use SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
|
|
|
|
* if they provide for changing an explicit servername context for the
|
|
|
|
* session, i.e. when the session has been established with a servername
|
|
|
|
* extension.
|
|
|
|
* - On session reconnect, the servername extension may be absent.
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_server_name(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context, X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
unsigned int servname_type;
|
|
|
|
PACKET sni, hostname;
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_2(pkt, &sni)
|
|
|
|
/* ServerNameList must be at least 1 byte long. */
|
|
|
|
|| PACKET_remaining(&sni) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-08-11 22:15:22 +08:00
|
|
|
* Although the intent was for server_name to be extensible, RFC 4366
|
|
|
|
* was not clear about it; and so OpenSSL among other implementations,
|
|
|
|
* always and only allows a 'host_name' name types.
|
2016-11-25 06:54:59 +08:00
|
|
|
* RFC 6066 corrected the mistake but adding new name types
|
|
|
|
* is nevertheless no longer feasible, so act as if no other
|
|
|
|
* SNI types can exist, to simplify parsing.
|
|
|
|
*
|
|
|
|
* Also note that the RFC permits only one SNI value per type,
|
|
|
|
* i.e., we can only have a single hostname.
|
|
|
|
*/
|
|
|
|
if (!PACKET_get_1(&sni, &servname_type)
|
|
|
|
|| servname_type != TLSEXT_NAMETYPE_host_name
|
|
|
|
|| !PACKET_as_length_prefixed_2(&sni, &hostname)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-26 00:06:06 +08:00
|
|
|
/*
|
|
|
|
* In TLSv1.2 and below the SNI is associated with the session. In TLSv1.3
|
|
|
|
* we always use the SNI value from the handshake.
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
if (!s->hit || SSL_CONNECTION_IS_TLS13(s)) {
|
2016-11-25 06:54:59 +08:00
|
|
|
if (PACKET_remaining(&hostname) > TLSEXT_MAXLEN_host_name) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_UNRECOGNIZED_NAME, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PACKET_contains_zero_byte(&hostname)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_UNRECOGNIZED_NAME, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Normalize SNI hostname handling for SSL and SSL_SESSION
In particular, adhere to the rule that we must not modify any
property of an SSL_SESSION object once it is (or might be) in
a session cache. Such modifications are thread-unsafe and have
been observed to cause crashes at runtime.
To effect this change, standardize on the property that
SSL_SESSION->ext.hostname is set only when that SNI value
has been negotiated by both parties for use with that session.
For session resumption this is trivially the case, so only new
handshakes are affected.
On the client, the new semantics are that the SSL->ext.hostname is
for storing the value configured by the caller, and this value is
used when constructing the ClientHello. On the server, SSL->ext.hostname
is used to hold the value received from the client. Only if the
SNI negotiation is successful will the hostname be stored into the
session object; the server can do this after it sends the ServerHello,
and the client after it has received and processed the ServerHello.
This obviates the need to remove the hostname from the session object
in case of failed negotiation (a change that was introduced in commit
9fb6cb810b769abbd60f11ef6e936a4e4456b19d in order to allow TLS 1.3
early data when SNI was present in the ClientHello but not the session
being resumed), which was modifying cached sessions in certain cases.
(In TLS 1.3 we always produce a new SSL_SESSION object for new
connections, even in the case of resumption, so no TLS 1.3 handshakes
were affected.)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6378)
2018-05-30 22:49:29 +08:00
|
|
|
/*
|
|
|
|
* Store the requested SNI in the SSL as temporary storage.
|
|
|
|
* If we accept it, it will get stored in the SSL_SESSION as well.
|
|
|
|
*/
|
|
|
|
OPENSSL_free(s->ext.hostname);
|
|
|
|
s->ext.hostname = NULL;
|
|
|
|
if (!PACKET_strndup(&hostname, &s->ext.hostname)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->servername_done = 1;
|
2019-09-26 00:06:06 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* In TLSv1.2 and below we should check if the SNI is consistent between
|
|
|
|
* the initial handshake and the resumption. In TLSv1.3 SNI is not
|
|
|
|
* associated with the session.
|
|
|
|
*/
|
Normalize SNI hostname handling for SSL and SSL_SESSION
In particular, adhere to the rule that we must not modify any
property of an SSL_SESSION object once it is (or might be) in
a session cache. Such modifications are thread-unsafe and have
been observed to cause crashes at runtime.
To effect this change, standardize on the property that
SSL_SESSION->ext.hostname is set only when that SNI value
has been negotiated by both parties for use with that session.
For session resumption this is trivially the case, so only new
handshakes are affected.
On the client, the new semantics are that the SSL->ext.hostname is
for storing the value configured by the caller, and this value is
used when constructing the ClientHello. On the server, SSL->ext.hostname
is used to hold the value received from the client. Only if the
SNI negotiation is successful will the hostname be stored into the
session object; the server can do this after it sends the ServerHello,
and the client after it has received and processed the ServerHello.
This obviates the need to remove the hostname from the session object
in case of failed negotiation (a change that was introduced in commit
9fb6cb810b769abbd60f11ef6e936a4e4456b19d in order to allow TLS 1.3
early data when SNI was present in the ClientHello but not the session
being resumed), which was modifying cached sessions in certain cases.
(In TLS 1.3 we always produce a new SSL_SESSION object for new
connections, even in the case of resumption, so no TLS 1.3 handshakes
were affected.)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6378)
2018-05-30 22:49:29 +08:00
|
|
|
s->servername_done = (s->session->ext.hostname != NULL)
|
2016-12-09 03:18:40 +08:00
|
|
|
&& PACKET_equal(&hostname, s->session->ext.hostname,
|
|
|
|
strlen(s->session->ext.hostname));
|
2016-11-25 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_maxfragmentlen(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2017-11-06 00:46:48 +08:00
|
|
|
{
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
if (PACKET_remaining(pkt) != 1 || !PACKET_get_1(pkt, &value)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-11-06 00:46:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Received |value| should be a valid max-fragment-length code. */
|
|
|
|
if (!IS_MAX_FRAGMENT_LENGTH_EXT_VALID(value)) {
|
2017-11-22 01:18:43 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,
|
|
|
|
SSL_R_SSL3_EXT_INVALID_MAX_FRAGMENT_LENGTH);
|
2017-11-06 00:46:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RFC 6066: The negotiated length applies for the duration of the session
|
|
|
|
* including session resumptions.
|
|
|
|
* We should receive the same code as in resumed session !
|
|
|
|
*/
|
|
|
|
if (s->hit && s->session->ext.max_fragment_len_mode != value) {
|
2017-11-22 01:18:43 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,
|
|
|
|
SSL_R_SSL3_EXT_INVALID_MAX_FRAGMENT_LENGTH);
|
2017-11-06 00:46:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store it in session, so it'll become binding for us
|
|
|
|
* and we'll include it in a next Server Hello.
|
|
|
|
*/
|
|
|
|
s->session->ext.max_fragment_len_mode = value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-25 06:54:59 +08:00
|
|
|
#ifndef OPENSSL_NO_SRP
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_srp(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
PACKET srp_I;
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_1(pkt, &srp_I)
|
|
|
|
|| PACKET_contains_zero_byte(&srp_I)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PACKET_strndup(&srp_I, &s->srp_ctx.login)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_ec_pt_formats(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
PACKET ec_point_format_list;
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_1(pkt, &ec_point_format_list)
|
|
|
|
|| PACKET_remaining(&ec_point_format_list) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s->hit) {
|
|
|
|
if (!PACKET_memdup(&ec_point_format_list,
|
2019-06-18 18:45:26 +08:00
|
|
|
&s->ext.peer_ecpointformats,
|
|
|
|
&s->ext.peer_ecpointformats_len)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_session_ticket(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
2016-12-09 03:18:40 +08:00
|
|
|
if (s->ext.session_ticket_cb &&
|
2022-06-20 23:11:28 +08:00
|
|
|
!s->ext.session_ticket_cb(SSL_CONNECTION_GET_SSL(s),
|
|
|
|
PACKET_data(pkt), PACKET_remaining(pkt),
|
|
|
|
s->ext.session_ticket_cb_arg)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_sig_algs_cert(SSL_CONNECTION *s, PACKET *pkt,
|
2020-12-01 09:30:10 +08:00
|
|
|
ossl_unused unsigned int context,
|
|
|
|
ossl_unused X509 *x,
|
|
|
|
ossl_unused size_t chainidx)
|
Add support for the TLS 1.3 signature_algorithms_cert extension
The new extension is like signature_algorithms, but only for the
signature *on* the certificate we will present to the peer (the
old signature_algorithms extension is still used for signatures that
we *generate*, i.e., those over TLS data structures).
We do not need to generate this extension, since we are the same
implementation as our X.509 stack and can handle the same types
of signatures, but we need to be prepared to receive it, and use the received
information when selecting what certificate to present.
There is a lot of interplay between signature_algorithms_cert and
signature_algorithms, since both affect what certificate we can
use, and thus the resulting signature algorithm used for TLS messages.
So, apply signature_algorithms_cert (if present) as a filter on what
certificates we can consider when choosing a certificate+sigalg
pair.
As part of this addition, we also remove the fallback code that let
keys of type EVP_PKEY_RSA be used to generate RSA-PSS signatures -- the
new rsa_pss_pss_* and rsa_pss_rsae_* signature schemes have pulled
the key type into what is covered by the signature algorithm, so
we should not apply this sort of compatibility workaround.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5068)
2018-01-12 01:47:12 +08:00
|
|
|
{
|
|
|
|
PACKET supported_sig_algs;
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_2(pkt, &supported_sig_algs)
|
|
|
|
|| PACKET_remaining(&supported_sig_algs) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
Add support for the TLS 1.3 signature_algorithms_cert extension
The new extension is like signature_algorithms, but only for the
signature *on* the certificate we will present to the peer (the
old signature_algorithms extension is still used for signatures that
we *generate*, i.e., those over TLS data structures).
We do not need to generate this extension, since we are the same
implementation as our X.509 stack and can handle the same types
of signatures, but we need to be prepared to receive it, and use the received
information when selecting what certificate to present.
There is a lot of interplay between signature_algorithms_cert and
signature_algorithms, since both affect what certificate we can
use, and thus the resulting signature algorithm used for TLS messages.
So, apply signature_algorithms_cert (if present) as a filter on what
certificates we can consider when choosing a certificate+sigalg
pair.
As part of this addition, we also remove the fallback code that let
keys of type EVP_PKEY_RSA be used to generate RSA-PSS signatures -- the
new rsa_pss_pss_* and rsa_pss_rsae_* signature schemes have pulled
the key type into what is covered by the signature algorithm, so
we should not apply this sort of compatibility workaround.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5068)
2018-01-12 01:47:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s->hit && !tls1_save_sigalgs(s, &supported_sig_algs, 1)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
Add support for the TLS 1.3 signature_algorithms_cert extension
The new extension is like signature_algorithms, but only for the
signature *on* the certificate we will present to the peer (the
old signature_algorithms extension is still used for signatures that
we *generate*, i.e., those over TLS data structures).
We do not need to generate this extension, since we are the same
implementation as our X.509 stack and can handle the same types
of signatures, but we need to be prepared to receive it, and use the received
information when selecting what certificate to present.
There is a lot of interplay between signature_algorithms_cert and
signature_algorithms, since both affect what certificate we can
use, and thus the resulting signature algorithm used for TLS messages.
So, apply signature_algorithms_cert (if present) as a filter on what
certificates we can consider when choosing a certificate+sigalg
pair.
As part of this addition, we also remove the fallback code that let
keys of type EVP_PKEY_RSA be used to generate RSA-PSS signatures -- the
new rsa_pss_pss_* and rsa_pss_rsae_* signature schemes have pulled
the key type into what is covered by the signature algorithm, so
we should not apply this sort of compatibility workaround.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5068)
2018-01-12 01:47:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_sig_algs(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context, X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
PACKET supported_sig_algs;
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_2(pkt, &supported_sig_algs)
|
|
|
|
|| PACKET_remaining(&supported_sig_algs) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Add support for the TLS 1.3 signature_algorithms_cert extension
The new extension is like signature_algorithms, but only for the
signature *on* the certificate we will present to the peer (the
old signature_algorithms extension is still used for signatures that
we *generate*, i.e., those over TLS data structures).
We do not need to generate this extension, since we are the same
implementation as our X.509 stack and can handle the same types
of signatures, but we need to be prepared to receive it, and use the received
information when selecting what certificate to present.
There is a lot of interplay between signature_algorithms_cert and
signature_algorithms, since both affect what certificate we can
use, and thus the resulting signature algorithm used for TLS messages.
So, apply signature_algorithms_cert (if present) as a filter on what
certificates we can consider when choosing a certificate+sigalg
pair.
As part of this addition, we also remove the fallback code that let
keys of type EVP_PKEY_RSA be used to generate RSA-PSS signatures -- the
new rsa_pss_pss_* and rsa_pss_rsae_* signature schemes have pulled
the key type into what is covered by the signature algorithm, so
we should not apply this sort of compatibility workaround.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5068)
2018-01-12 01:47:12 +08:00
|
|
|
if (!s->hit && !tls1_save_sigalgs(s, &supported_sig_algs, 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-26 00:28:02 +08:00
|
|
|
#ifndef OPENSSL_NO_OCSP
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_status_request(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
2016-12-08 01:04:46 +08:00
|
|
|
PACKET responder_id_list, exts;
|
|
|
|
|
2018-04-06 21:53:05 +08:00
|
|
|
/* We ignore this in a resumption handshake */
|
|
|
|
if (s->hit)
|
|
|
|
return 1;
|
|
|
|
|
2016-12-02 17:14:15 +08:00
|
|
|
/* Not defined if we get one of these in a client Certificate */
|
|
|
|
if (x != NULL)
|
|
|
|
return 1;
|
|
|
|
|
2016-12-09 03:18:40 +08:00
|
|
|
if (!PACKET_get_1(pkt, (unsigned int *)&s->ext.status_type)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-11-26 00:28:02 +08:00
|
|
|
|
2016-12-09 03:18:40 +08:00
|
|
|
if (s->ext.status_type != TLSEXT_STATUSTYPE_ocsp) {
|
2016-11-25 06:54:59 +08:00
|
|
|
/*
|
2016-12-08 01:04:46 +08:00
|
|
|
* We don't know what to do with any other type so ignore it.
|
2016-11-25 06:54:59 +08:00
|
|
|
*/
|
2016-12-09 03:18:40 +08:00
|
|
|
s->ext.status_type = TLSEXT_STATUSTYPE_nothing;
|
2016-12-08 01:04:46 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2016-11-25 06:54:59 +08:00
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
if (!PACKET_get_length_prefixed_2 (pkt, &responder_id_list)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-12-08 01:04:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-11-25 06:54:59 +08:00
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
/*
|
|
|
|
* We remove any OCSP_RESPIDs from a previous handshake
|
|
|
|
* to prevent unbounded memory growth - CVE-2016-6304
|
|
|
|
*/
|
2016-12-09 03:18:40 +08:00
|
|
|
sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);
|
2016-12-08 01:04:46 +08:00
|
|
|
if (PACKET_remaining(&responder_id_list) > 0) {
|
2016-12-09 03:18:40 +08:00
|
|
|
s->ext.ocsp.ids = sk_OCSP_RESPID_new_null();
|
|
|
|
if (s->ext.ocsp.ids == NULL) {
|
2022-09-29 19:57:34 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_CRYPTO_LIB);
|
2016-12-08 01:04:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
2016-12-09 03:18:40 +08:00
|
|
|
s->ext.ocsp.ids = NULL;
|
2016-12-08 01:04:46 +08:00
|
|
|
}
|
2016-11-25 06:54:59 +08:00
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
while (PACKET_remaining(&responder_id_list) > 0) {
|
|
|
|
OCSP_RESPID *id;
|
|
|
|
PACKET responder_id;
|
|
|
|
const unsigned char *id_data;
|
2016-11-25 06:54:59 +08:00
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
if (!PACKET_get_length_prefixed_2(&responder_id_list, &responder_id)
|
|
|
|
|| PACKET_remaining(&responder_id) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-12-08 01:04:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-11-25 06:54:59 +08:00
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
id_data = PACKET_data(&responder_id);
|
|
|
|
id = d2i_OCSP_RESPID(NULL, &id_data,
|
|
|
|
(int)PACKET_remaining(&responder_id));
|
|
|
|
if (id == NULL) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-12-08 01:04:46 +08:00
|
|
|
return 0;
|
2016-11-25 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
if (id_data != PACKET_end(&responder_id)) {
|
|
|
|
OCSP_RESPID_free(id);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-11-22 01:18:43 +08:00
|
|
|
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:18:40 +08:00
|
|
|
if (!sk_OCSP_RESPID_push(s->ext.ocsp.ids, id)) {
|
2016-12-08 01:04:46 +08:00
|
|
|
OCSP_RESPID_free(id);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-11-22 01:18:43 +08:00
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in request_extensions */
|
|
|
|
if (!PACKET_as_length_prefixed_2(pkt, &exts)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-12-08 01:04:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PACKET_remaining(&exts) > 0) {
|
|
|
|
const unsigned char *ext_data = PACKET_data(&exts);
|
|
|
|
|
2016-12-09 03:18:40 +08:00
|
|
|
sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts,
|
2016-12-08 01:04:46 +08:00
|
|
|
X509_EXTENSION_free);
|
2016-12-09 03:18:40 +08:00
|
|
|
s->ext.ocsp.exts =
|
2016-12-08 01:04:46 +08:00
|
|
|
d2i_X509_EXTENSIONS(NULL, &ext_data, (int)PACKET_remaining(&exts));
|
2016-12-09 03:18:40 +08:00
|
|
|
if (s->ext.ocsp.exts == NULL || ext_data != PACKET_end(&exts)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-12-08 01:04:46 +08:00
|
|
|
return 0;
|
2016-11-25 06:54:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2016-11-26 00:28:02 +08:00
|
|
|
#endif
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_NEXTPROTONEG
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_npn(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
2016-12-08 01:04:46 +08:00
|
|
|
/*
|
|
|
|
* We shouldn't accept this extension on a
|
|
|
|
* renegotiation.
|
|
|
|
*/
|
2017-01-11 07:02:28 +08:00
|
|
|
if (SSL_IS_FIRST_HANDSHAKE(s))
|
2018-12-13 02:09:50 +08:00
|
|
|
s->s3.npn_seen = 1;
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2016-12-08 01:04:46 +08:00
|
|
|
* Save the ALPN extension in a ClientHello.|pkt| holds the contents of the ALPN
|
2017-11-23 21:11:42 +08:00
|
|
|
* extension, not including type and length. Returns: 1 on success, 0 on error.
|
2016-11-25 06:54:59 +08:00
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_alpn(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
PACKET protocol_list, save_protocol_list, protocol;
|
|
|
|
|
2017-01-11 07:02:28 +08:00
|
|
|
if (!SSL_IS_FIRST_HANDSHAKE(s))
|
2016-11-25 06:54:59 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_2(pkt, &protocol_list)
|
|
|
|
|| PACKET_remaining(&protocol_list) < 2) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
save_protocol_list = protocol_list;
|
|
|
|
do {
|
|
|
|
/* Protocol names can't be empty. */
|
|
|
|
if (!PACKET_get_length_prefixed_1(&protocol_list, &protocol)
|
|
|
|
|| PACKET_remaining(&protocol) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} while (PACKET_remaining(&protocol_list) != 0);
|
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
OPENSSL_free(s->s3.alpn_proposed);
|
|
|
|
s->s3.alpn_proposed = NULL;
|
|
|
|
s->s3.alpn_proposed_len = 0;
|
2016-11-25 06:54:59 +08:00
|
|
|
if (!PACKET_memdup(&save_protocol_list,
|
2018-12-13 02:09:50 +08:00
|
|
|
&s->s3.alpn_proposed, &s->s3.alpn_proposed_len)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_SRTP
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_use_srtp(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context, X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
STACK_OF(SRTP_PROTECTION_PROFILE) *srvr;
|
|
|
|
unsigned int ct, mki_len, id;
|
|
|
|
int i, srtp_pref;
|
|
|
|
PACKET subpkt;
|
2022-06-20 23:11:28 +08:00
|
|
|
SSL *ssl = SSL_CONNECTION_GET_SSL(s);
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
/* Ignore this if we have no SRTP profiles */
|
2022-06-20 23:11:28 +08:00
|
|
|
if (SSL_get_srtp_profiles(ssl) == NULL)
|
2016-11-25 06:54:59 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Pull off the length of the cipher suite list and check it is even */
|
2016-12-08 01:04:46 +08:00
|
|
|
if (!PACKET_get_net_2(pkt, &ct) || (ct & 1) != 0
|
|
|
|
|| !PACKET_get_sub_packet(pkt, &subpkt, ct)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR,
|
2016-11-25 06:54:59 +08:00
|
|
|
SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
srvr = SSL_get_srtp_profiles(ssl);
|
2016-11-25 06:54:59 +08:00
|
|
|
s->srtp_profile = NULL;
|
|
|
|
/* Search all profiles for a match initially */
|
|
|
|
srtp_pref = sk_SRTP_PROTECTION_PROFILE_num(srvr);
|
|
|
|
|
|
|
|
while (PACKET_remaining(&subpkt)) {
|
|
|
|
if (!PACKET_get_net_2(&subpkt, &id)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR,
|
2017-11-22 01:18:43 +08:00
|
|
|
SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only look for match in profiles of higher preference than
|
|
|
|
* current match.
|
|
|
|
* If no profiles have been have been configured then this
|
|
|
|
* does nothing.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < srtp_pref; i++) {
|
2016-12-08 01:21:48 +08:00
|
|
|
SRTP_PROTECTION_PROFILE *sprof =
|
2016-12-08 01:04:46 +08:00
|
|
|
sk_SRTP_PROTECTION_PROFILE_value(srvr, i);
|
|
|
|
|
2016-11-25 06:54:59 +08:00
|
|
|
if (sprof->id == id) {
|
|
|
|
s->srtp_profile = sprof;
|
|
|
|
srtp_pref = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
/* Now extract the MKI value as a sanity check, but discard it for now */
|
2016-11-25 06:54:59 +08:00
|
|
|
if (!PACKET_get_1(pkt, &mki_len)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR,
|
2017-11-22 01:18:43 +08:00
|
|
|
SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PACKET_forward(pkt, mki_len)
|
|
|
|
|| PACKET_remaining(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_SRTP_MKI_VALUE);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_etm(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
if (!(s->options & SSL_OP_NO_ENCRYPT_THEN_MAC))
|
2017-02-03 22:06:20 +08:00
|
|
|
s->ext.use_etm = 1;
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-01-12 23:28:48 +08:00
|
|
|
/*
|
|
|
|
* Process a psk_kex_modes extension received in the ClientHello. |pkt| contains
|
|
|
|
* the raw PACKET data for the extension. Returns 1 on success or 0 on failure.
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_psk_kex_modes(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2017-01-12 23:28:48 +08:00
|
|
|
{
|
|
|
|
#ifndef OPENSSL_NO_TLS1_3
|
|
|
|
PACKET psk_kex_modes;
|
|
|
|
unsigned int mode;
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_1(pkt, &psk_kex_modes)
|
|
|
|
|| PACKET_remaining(&psk_kex_modes) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-01-12 23:28:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (PACKET_get_1(&psk_kex_modes, &mode)) {
|
|
|
|
if (mode == TLSEXT_KEX_MODE_KE_DHE)
|
|
|
|
s->ext.psk_kex_mode |= TLSEXT_KEX_MODE_FLAG_KE_DHE;
|
2017-06-30 16:41:03 +08:00
|
|
|
else if (mode == TLSEXT_KEX_MODE_KE
|
|
|
|
&& (s->options & SSL_OP_ALLOW_NO_DHE_KEX) != 0)
|
2017-01-12 23:28:48 +08:00
|
|
|
s->ext.psk_kex_mode |= TLSEXT_KEX_MODE_FLAG_KE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-25 06:54:59 +08:00
|
|
|
/*
|
|
|
|
* Process a key_share extension received in the ClientHello. |pkt| contains
|
|
|
|
* the raw PACKET data for the extension. Returns 1 on success or 0 on failure.
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_key_share(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context, X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
2016-12-28 23:32:39 +08:00
|
|
|
#ifndef OPENSSL_NO_TLS1_3
|
2016-11-25 06:54:59 +08:00
|
|
|
unsigned int group_id;
|
|
|
|
PACKET key_share_list, encoded_pt;
|
2017-09-26 22:41:34 +08:00
|
|
|
const uint16_t *clntgroups, *srvrgroups;
|
|
|
|
size_t clnt_num_groups, srvr_num_groups;
|
2017-09-23 07:15:34 +08:00
|
|
|
int found = 0;
|
2016-11-25 06:54:59 +08:00
|
|
|
|
2017-01-18 19:31:37 +08:00
|
|
|
if (s->hit && (s->ext.psk_kex_mode & TLSEXT_KEX_MODE_FLAG_KE_DHE) == 0)
|
2016-11-25 06:54:59 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Sanity check */
|
2018-12-13 02:09:50 +08:00
|
|
|
if (s->s3.peer_tmp != NULL) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_2(pkt, &key_share_list)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-26 22:41:34 +08:00
|
|
|
/* Get our list of supported groups */
|
|
|
|
tls1_get_supported_groups(s, &srvrgroups, &srvr_num_groups);
|
|
|
|
/* Get the clients list of supported groups. */
|
|
|
|
tls1_get_peer_groups(s, &clntgroups, &clnt_num_groups);
|
|
|
|
if (clnt_num_groups == 0) {
|
2017-05-11 17:55:54 +08:00
|
|
|
/*
|
|
|
|
* This can only happen if the supported_groups extension was not sent,
|
|
|
|
* because we verify that the length is non-zero when we process that
|
|
|
|
* extension.
|
|
|
|
*/
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_MISSING_EXTENSION,
|
2017-11-22 01:18:43 +08:00
|
|
|
SSL_R_MISSING_SUPPORTED_GROUPS_EXTENSION);
|
2017-05-11 17:55:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-11-25 06:54:59 +08:00
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
if (s->s3.group_id != 0 && PACKET_remaining(&key_share_list) == 0) {
|
2017-09-11 22:43:56 +08:00
|
|
|
/*
|
|
|
|
* If we set a group_id already, then we must have sent an HRR
|
|
|
|
* requesting a new key_share. If we haven't got one then that is an
|
|
|
|
* error
|
|
|
|
*/
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_KEY_SHARE);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-25 06:54:59 +08:00
|
|
|
while (PACKET_remaining(&key_share_list) > 0) {
|
|
|
|
if (!PACKET_get_net_2(&key_share_list, &group_id)
|
|
|
|
|| !PACKET_get_length_prefixed_2(&key_share_list, &encoded_pt)
|
|
|
|
|| PACKET_remaining(&encoded_pt) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we already found a suitable key_share we loop through the
|
|
|
|
* rest to verify the structure, but don't process them.
|
|
|
|
*/
|
|
|
|
if (found)
|
|
|
|
continue;
|
|
|
|
|
2017-09-11 22:43:56 +08:00
|
|
|
/*
|
|
|
|
* If we sent an HRR then the key_share sent back MUST be for the group
|
|
|
|
* we requested, and must be the only key_share sent.
|
|
|
|
*/
|
2018-12-13 02:09:50 +08:00
|
|
|
if (s->s3.group_id != 0
|
2022-09-30 17:50:53 +08:00
|
|
|
&& (group_id != s->s3.group_id
|
2017-09-11 22:43:56 +08:00
|
|
|
|| PACKET_remaining(&key_share_list) != 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_KEY_SHARE);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-25 06:54:59 +08:00
|
|
|
/* Check if this share is in supported_groups sent from client */
|
2017-09-26 22:41:34 +08:00
|
|
|
if (!check_in_list(s, group_id, clntgroups, clnt_num_groups, 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_KEY_SHARE);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this share is for a group we can use */
|
2022-09-30 21:21:50 +08:00
|
|
|
if (!check_in_list(s, group_id, srvrgroups, srvr_num_groups, 1)
|
|
|
|
|| !tls_group_allowed(s, group_id, SSL_SECOP_CURVE_SUPPORTED)
|
|
|
|
/*
|
|
|
|
* We tolerate but ignore a group id that we don't think is
|
|
|
|
* suitable for TLSv1.3
|
|
|
|
*/
|
|
|
|
|| !tls_valid_group(s, group_id, TLS1_3_VERSION, TLS1_3_VERSION,
|
|
|
|
0, NULL)) {
|
2016-11-25 06:54:59 +08:00
|
|
|
/* Share not suitable */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-10-25 05:10:38 +08:00
|
|
|
s->s3.group_id = group_id;
|
|
|
|
/* Cache the selected group ID in the SSL_SESSION */
|
|
|
|
s->session->kex_group = group_id;
|
|
|
|
|
2020-02-03 17:05:31 +08:00
|
|
|
if ((s->s3.peer_tmp = ssl_generate_param_group(s, group_id)) == NULL) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR,
|
2016-11-25 06:54:59 +08:00
|
|
|
SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-02-10 18:49:37 +08:00
|
|
|
if (tls13_set_encoded_pub_key(s->s3.peer_tmp,
|
|
|
|
PACKET_data(&encoded_pt),
|
|
|
|
PACKET_remaining(&encoded_pt)) <= 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_ECPOINT);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = 1;
|
|
|
|
}
|
2016-12-28 23:32:39 +08:00
|
|
|
#endif
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_cookie(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
2017-09-11 22:43:56 +08:00
|
|
|
{
|
2018-05-21 19:20:18 +08:00
|
|
|
#ifndef OPENSSL_NO_TLS1_3
|
2017-09-28 20:25:23 +08:00
|
|
|
unsigned int format, version, key_share, group_id;
|
2017-09-11 22:43:56 +08:00
|
|
|
EVP_MD_CTX *hctx;
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
PACKET cookie, raw, chhash, appcookie;
|
|
|
|
WPACKET hrrpkt;
|
|
|
|
const unsigned char *data, *mdin, *ciphdata;
|
|
|
|
unsigned char hmac[SHA256_DIGEST_LENGTH];
|
|
|
|
unsigned char hrr[MAX_HRR_SIZE];
|
|
|
|
size_t rawlen, hmaclen, hrrlen, ciphlen;
|
2022-08-16 09:05:02 +08:00
|
|
|
uint64_t tm, now;
|
2022-06-20 23:11:28 +08:00
|
|
|
SSL *ssl = SSL_CONNECTION_GET_SSL(s);
|
|
|
|
SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
|
2017-09-11 22:43:56 +08:00
|
|
|
|
|
|
|
/* Ignore any cookie if we're not set up to verify it */
|
2022-06-20 23:11:28 +08:00
|
|
|
if (sctx->verify_stateless_cookie_cb == NULL
|
2018-12-13 02:09:50 +08:00
|
|
|
|| (s->s3.flags & TLS1_FLAGS_STATELESS) == 0)
|
2017-09-11 22:43:56 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_2(pkt, &cookie)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
raw = cookie;
|
|
|
|
data = PACKET_data(&raw);
|
|
|
|
rawlen = PACKET_remaining(&raw);
|
|
|
|
if (rawlen < SHA256_DIGEST_LENGTH
|
|
|
|
|| !PACKET_forward(&raw, rawlen - SHA256_DIGEST_LENGTH)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
mdin = PACKET_data(&raw);
|
|
|
|
|
|
|
|
/* Verify the HMAC of the cookie */
|
|
|
|
hctx = EVP_MD_CTX_create();
|
2022-06-20 23:11:28 +08:00
|
|
|
pkey = EVP_PKEY_new_raw_private_key_ex(sctx->libctx, "HMAC",
|
|
|
|
sctx->propq,
|
2020-09-24 17:42:23 +08:00
|
|
|
s->session_ctx->ext.cookie_hmac_key,
|
|
|
|
sizeof(s->session_ctx->ext.cookie_hmac_key));
|
2017-09-11 22:43:56 +08:00
|
|
|
if (hctx == NULL || pkey == NULL) {
|
|
|
|
EVP_MD_CTX_free(hctx);
|
|
|
|
EVP_PKEY_free(pkey);
|
2022-09-29 19:57:34 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-23 20:23:23 +08:00
|
|
|
hmaclen = SHA256_DIGEST_LENGTH;
|
2022-06-20 23:11:28 +08:00
|
|
|
if (EVP_DigestSignInit_ex(hctx, NULL, "SHA2-256", sctx->libctx,
|
|
|
|
sctx->propq, pkey, NULL) <= 0
|
2018-01-23 20:23:23 +08:00
|
|
|
|| EVP_DigestSign(hctx, hmac, &hmaclen, data,
|
|
|
|
rawlen - SHA256_DIGEST_LENGTH) <= 0
|
2017-09-11 22:43:56 +08:00
|
|
|
|| hmaclen != SHA256_DIGEST_LENGTH) {
|
|
|
|
EVP_MD_CTX_free(hctx);
|
|
|
|
EVP_PKEY_free(pkey);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EVP_MD_CTX_free(hctx);
|
|
|
|
EVP_PKEY_free(pkey);
|
|
|
|
|
|
|
|
if (CRYPTO_memcmp(hmac, mdin, SHA256_DIGEST_LENGTH) != 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_COOKIE_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PACKET_get_net_2(&cookie, &format)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Check the cookie format is something we recognise. Ignore it if not */
|
|
|
|
if (format != COOKIE_STATE_FORMAT_VERSION)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The rest of these checks really shouldn't fail since we have verified the
|
|
|
|
* HMAC above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Check the version number is sane */
|
|
|
|
if (!PACKET_get_net_2(&cookie, &version)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (version != TLS1_3_VERSION) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER,
|
2017-09-11 22:43:56 +08:00
|
|
|
SSL_R_BAD_PROTOCOL_VERSION_NUMBER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-28 20:25:23 +08:00
|
|
|
if (!PACKET_get_net_2(&cookie, &group_id)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-09-28 20:25:23 +08:00
|
|
|
|
2017-09-11 22:43:56 +08:00
|
|
|
ciphdata = PACKET_data(&cookie);
|
|
|
|
if (!PACKET_forward(&cookie, 2)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-12-13 02:09:50 +08:00
|
|
|
if (group_id != s->s3.group_id
|
|
|
|
|| s->s3.tmp.new_cipher
|
2017-09-28 20:25:23 +08:00
|
|
|
!= ssl_get_cipher_by_char(s, ciphdata, 0)) {
|
|
|
|
/*
|
|
|
|
* We chose a different cipher or group id this time around to what is
|
|
|
|
* in the cookie. Something must have changed.
|
|
|
|
*/
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_CIPHER);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PACKET_get_1(&cookie, &key_share)
|
2022-08-16 09:05:02 +08:00
|
|
|
|| !PACKET_get_net_8(&cookie, &tm)
|
2017-09-11 22:43:56 +08:00
|
|
|
|| !PACKET_get_length_prefixed_2(&cookie, &chhash)
|
|
|
|
|| !PACKET_get_length_prefixed_1(&cookie, &appcookie)
|
|
|
|
|| PACKET_remaining(&cookie) != SHA256_DIGEST_LENGTH) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-17 22:29:22 +08:00
|
|
|
/* We tolerate a cookie age of up to 10 minutes (= 60 * 10 seconds) */
|
2022-08-16 09:05:02 +08:00
|
|
|
now = time(NULL);
|
2018-01-17 22:29:22 +08:00
|
|
|
if (tm > now || (now - tm) > 600) {
|
|
|
|
/* Cookie is stale. Ignore it */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-09-11 22:43:56 +08:00
|
|
|
/* Verify the app cookie */
|
2022-06-20 23:11:28 +08:00
|
|
|
if (sctx->verify_stateless_cookie_cb(ssl,
|
|
|
|
PACKET_data(&appcookie),
|
|
|
|
PACKET_remaining(&appcookie)) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_COOKIE_MISMATCH);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconstruct the HRR that we would have sent in response to the original
|
|
|
|
* ClientHello so we can add it to the transcript hash.
|
|
|
|
* Note: This won't work with custom HRR extensions
|
|
|
|
*/
|
|
|
|
if (!WPACKET_init_static_len(&hrrpkt, hrr, sizeof(hrr), 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!WPACKET_put_bytes_u8(&hrrpkt, SSL3_MT_SERVER_HELLO)
|
|
|
|
|| !WPACKET_start_sub_packet_u24(&hrrpkt)
|
|
|
|
|| !WPACKET_put_bytes_u16(&hrrpkt, TLS1_2_VERSION)
|
|
|
|
|| !WPACKET_memcpy(&hrrpkt, hrrrandom, SSL3_RANDOM_SIZE)
|
|
|
|
|| !WPACKET_sub_memcpy_u8(&hrrpkt, s->tmp_session_id,
|
|
|
|
s->tmp_session_id_len)
|
2022-06-20 23:11:28 +08:00
|
|
|
|| !ssl->method->put_cipher_by_char(s->s3.tmp.new_cipher, &hrrpkt,
|
|
|
|
&ciphlen)
|
2017-09-11 22:43:56 +08:00
|
|
|
|| !WPACKET_put_bytes_u8(&hrrpkt, 0)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(&hrrpkt)) {
|
|
|
|
WPACKET_cleanup(&hrrpkt);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!WPACKET_put_bytes_u16(&hrrpkt, TLSEXT_TYPE_supported_versions)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(&hrrpkt)
|
2018-07-18 23:05:49 +08:00
|
|
|
|| !WPACKET_put_bytes_u16(&hrrpkt, s->version)
|
2017-09-11 22:43:56 +08:00
|
|
|
|| !WPACKET_close(&hrrpkt)) {
|
|
|
|
WPACKET_cleanup(&hrrpkt);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (key_share) {
|
|
|
|
if (!WPACKET_put_bytes_u16(&hrrpkt, TLSEXT_TYPE_key_share)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(&hrrpkt)
|
2018-12-13 02:09:50 +08:00
|
|
|
|| !WPACKET_put_bytes_u16(&hrrpkt, s->s3.group_id)
|
2017-09-11 22:43:56 +08:00
|
|
|
|| !WPACKET_close(&hrrpkt)) {
|
|
|
|
WPACKET_cleanup(&hrrpkt);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!WPACKET_put_bytes_u16(&hrrpkt, TLSEXT_TYPE_cookie)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(&hrrpkt)
|
|
|
|
|| !WPACKET_sub_memcpy_u16(&hrrpkt, data, rawlen)
|
|
|
|
|| !WPACKET_close(&hrrpkt) /* cookie extension */
|
|
|
|
|| !WPACKET_close(&hrrpkt) /* extension block */
|
|
|
|
|| !WPACKET_close(&hrrpkt) /* message */
|
|
|
|
|| !WPACKET_get_total_written(&hrrpkt, &hrrlen)
|
|
|
|
|| !WPACKET_finish(&hrrpkt)) {
|
|
|
|
WPACKET_cleanup(&hrrpkt);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reconstruct the transcript hash */
|
|
|
|
if (!create_synthetic_message_hash(s, PACKET_data(&chhash),
|
|
|
|
PACKET_remaining(&chhash), hrr,
|
|
|
|
hrrlen)) {
|
|
|
|
/* SSLfatal() already called */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Act as if this ClientHello came after a HelloRetryRequest */
|
|
|
|
s->hello_retry_request = 1;
|
|
|
|
|
2017-09-13 21:50:49 +08:00
|
|
|
s->ext.cookieok = 1;
|
2018-05-21 19:20:18 +08:00
|
|
|
#endif
|
2017-09-13 21:50:49 +08:00
|
|
|
|
2017-09-11 22:43:56 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_supported_groups(SSL_CONNECTION *s, PACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
PACKET supported_groups_list;
|
|
|
|
|
|
|
|
/* Each group is 2 bytes and we must have at least 1. */
|
|
|
|
if (!PACKET_as_length_prefixed_2(pkt, &supported_groups_list)
|
|
|
|
|| PACKET_remaining(&supported_groups_list) == 0
|
|
|
|
|| (PACKET_remaining(&supported_groups_list) % 2) != 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
if (!s->hit || SSL_CONNECTION_IS_TLS13(s)) {
|
2019-06-14 19:46:13 +08:00
|
|
|
OPENSSL_free(s->ext.peer_supportedgroups);
|
|
|
|
s->ext.peer_supportedgroups = NULL;
|
|
|
|
s->ext.peer_supportedgroups_len = 0;
|
2017-09-22 23:06:52 +08:00
|
|
|
if (!tls1_save_u16(&supported_groups_list,
|
2019-06-14 19:46:13 +08:00
|
|
|
&s->ext.peer_supportedgroups,
|
|
|
|
&s->ext.peer_supportedgroups_len)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
Don't modify resumed session objects
If s->hit is set, s->session corresponds to a session created on
a previous connection, and is a data structure that is potentially
shared across other SSL objects. As such, there are thread-safety
issues with modifying the structure without taking its lock (and
of course all corresponding read accesses would also need to take
the lock as well), which have been observed to cause double-frees.
Regardless of thread-safety, the resumed session object is intended
to reflect parameters of the connection that created the session,
and modifying it to reflect the parameters from the current connection
is confusing. So, modifications to the session object during
ClientHello processing should only be performed on new connections,
i.e., those where s->hit is not set.
The code mostly got this right, providing such checks when processing
SNI and EC point formats, but the supported groups (formerly
supported curves) extension was missing it, which is fixed by this commit.
However, TLS 1.3 makes the suppported_groups extension mandatory
(when using (EC)DHE, which is the normal case), checking for the group
list in the key_share extension processing. But, TLS 1.3 only [0] supports
session tickets for session resumption, so the session object in question
is the output of d2i_SSL_SESSION(), and will not be shared across SSL
objects. Thus, it is safe to modify s->session for TLS 1.3 connections.
[0] A psk_find_session callback can also be used, but the restriction that
each callback execution must produce a distinct SSL_SESSION structure
can be documented when the psk_find_session callback documentation is
completed.
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4123)
2017-08-09 21:14:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-11-25 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_ems(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 06:54:59 +08:00
|
|
|
{
|
|
|
|
/* The extension must always be empty */
|
|
|
|
if (PACKET_remaining(pkt) != 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2016-11-25 06:54:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-11 01:28:35 +08:00
|
|
|
if (s->options & SSL_OP_NO_EXTENDED_MASTER_SECRET)
|
|
|
|
return 1;
|
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
s->s3.flags |= TLS1_FLAGS_RECEIVED_EXTMS;
|
2016-11-25 06:54:59 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2016-11-25 18:22:02 +08:00
|
|
|
|
2017-02-24 19:13:25 +08:00
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_early_data(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2017-02-24 19:13:25 +08:00
|
|
|
{
|
|
|
|
if (PACKET_remaining(pkt) != 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-02-24 19:13:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-13 19:24:51 +08:00
|
|
|
if (s->hello_retry_request != SSL_HRR_NONE) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_EXTENSION);
|
2017-07-14 21:50:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-24 19:13:25 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
static SSL_TICKET_STATUS tls_get_stateful_ticket(SSL_CONNECTION *s, PACKET *tick,
|
2018-06-13 22:57:39 +08:00
|
|
|
SSL_SESSION **sess)
|
|
|
|
{
|
|
|
|
SSL_SESSION *tmpsess = NULL;
|
|
|
|
|
2018-07-16 23:57:36 +08:00
|
|
|
s->ext.ticket_expected = 1;
|
|
|
|
|
2018-06-13 22:57:39 +08:00
|
|
|
switch (PACKET_remaining(tick)) {
|
|
|
|
case 0:
|
|
|
|
return SSL_TICKET_EMPTY;
|
|
|
|
|
|
|
|
case SSL_MAX_SSL_SESSION_ID_LENGTH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return SSL_TICKET_NO_DECRYPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpsess = lookup_sess_in_cache(s, PACKET_data(tick),
|
|
|
|
SSL_MAX_SSL_SESSION_ID_LENGTH);
|
|
|
|
|
|
|
|
if (tmpsess == NULL)
|
|
|
|
return SSL_TICKET_NO_DECRYPT;
|
|
|
|
|
|
|
|
*sess = tmpsess;
|
|
|
|
return SSL_TICKET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_psk(SSL_CONNECTION *s, PACKET *pkt, unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
2017-01-19 00:28:23 +08:00
|
|
|
{
|
|
|
|
PACKET identities, binders, binder;
|
|
|
|
size_t binderoffset, hashsize;
|
|
|
|
SSL_SESSION *sess = NULL;
|
2017-06-12 16:18:24 +08:00
|
|
|
unsigned int id, i, ext = 0;
|
2017-01-19 00:28:23 +08:00
|
|
|
const EVP_MD *md = NULL;
|
2022-06-20 23:11:28 +08:00
|
|
|
SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
|
|
|
|
SSL *ssl = SSL_CONNECTION_GET_SSL(s);
|
2017-01-19 00:28:23 +08:00
|
|
|
|
2017-01-25 19:56:23 +08:00
|
|
|
/*
|
|
|
|
* If we have no PSK kex mode that we recognise then we can't resume so
|
|
|
|
* ignore this extension
|
|
|
|
*/
|
|
|
|
if ((s->ext.psk_kex_mode
|
|
|
|
& (TLSEXT_KEX_MODE_FLAG_KE | TLSEXT_KEX_MODE_FLAG_KE_DHE)) == 0)
|
|
|
|
return 1;
|
|
|
|
|
2017-01-19 00:28:23 +08:00
|
|
|
if (!PACKET_get_length_prefixed_2(pkt, &identities)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-01-19 00:28:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-10 01:22:36 +08:00
|
|
|
s->ext.ticket_expected = 0;
|
2017-01-19 00:28:23 +08:00
|
|
|
for (id = 0; PACKET_remaining(&identities) != 0; id++) {
|
|
|
|
PACKET identity;
|
2017-02-24 17:30:54 +08:00
|
|
|
unsigned long ticket_agel;
|
2018-03-07 00:41:51 +08:00
|
|
|
size_t idlen;
|
2017-01-19 00:28:23 +08:00
|
|
|
|
|
|
|
if (!PACKET_get_length_prefixed_2(&identities, &identity)
|
2017-02-24 17:30:54 +08:00
|
|
|
|| !PACKET_get_net_4(&identities, &ticket_agel)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-01-19 00:28:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-07 00:41:51 +08:00
|
|
|
idlen = PACKET_remaining(&identity);
|
2017-06-12 16:18:24 +08:00
|
|
|
if (s->psk_find_session_cb != NULL
|
2022-06-20 23:11:28 +08:00
|
|
|
&& !s->psk_find_session_cb(ssl, PACKET_data(&identity), idlen,
|
2017-06-20 21:25:38 +08:00
|
|
|
&sess)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_EXTENSION);
|
2017-06-20 21:25:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 20:58:05 +08:00
|
|
|
#ifndef OPENSSL_NO_PSK
|
2021-10-26 15:16:18 +08:00
|
|
|
if (sess == NULL
|
2018-03-07 00:41:51 +08:00
|
|
|
&& s->psk_server_callback != NULL
|
|
|
|
&& idlen <= PSK_MAX_IDENTITY_LEN) {
|
|
|
|
char *pskid = NULL;
|
|
|
|
unsigned char pskdata[PSK_MAX_PSK_LEN];
|
|
|
|
unsigned int pskdatalen;
|
|
|
|
|
|
|
|
if (!PACKET_strndup(&identity, &pskid)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2018-03-07 00:41:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-06-20 23:11:28 +08:00
|
|
|
pskdatalen = s->psk_server_callback(ssl, pskid, pskdata,
|
2018-03-07 00:41:51 +08:00
|
|
|
sizeof(pskdata));
|
|
|
|
OPENSSL_free(pskid);
|
|
|
|
if (pskdatalen > PSK_MAX_PSK_LEN) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2018-03-07 00:41:51 +08:00
|
|
|
return 0;
|
|
|
|
} else if (pskdatalen > 0) {
|
|
|
|
const SSL_CIPHER *cipher;
|
|
|
|
const unsigned char tls13_aes128gcmsha256_id[] = { 0x13, 0x01 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We found a PSK using an old style callback. We don't know
|
|
|
|
* the digest so we default to SHA256 as per the TLSv1.3 spec
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
cipher = SSL_CIPHER_find(ssl, tls13_aes128gcmsha256_id);
|
2018-03-07 00:41:51 +08:00
|
|
|
if (cipher == NULL) {
|
|
|
|
OPENSSL_cleanse(pskdata, pskdatalen);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2018-03-07 00:41:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sess = SSL_SESSION_new();
|
|
|
|
if (sess == NULL
|
|
|
|
|| !SSL_SESSION_set1_master_key(sess, pskdata,
|
|
|
|
pskdatalen)
|
|
|
|
|| !SSL_SESSION_set_cipher(sess, cipher)
|
|
|
|
|| !SSL_SESSION_set_protocol_version(sess,
|
|
|
|
TLS1_3_VERSION)) {
|
|
|
|
OPENSSL_cleanse(pskdata, pskdatalen);
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2018-03-07 00:41:51 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
OPENSSL_cleanse(pskdata, pskdatalen);
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 20:58:05 +08:00
|
|
|
#endif /* OPENSSL_NO_PSK */
|
2018-03-07 00:41:51 +08:00
|
|
|
|
2017-06-20 21:25:38 +08:00
|
|
|
if (sess != NULL) {
|
|
|
|
/* We found a PSK */
|
2017-06-12 16:18:24 +08:00
|
|
|
SSL_SESSION *sesstmp = ssl_session_dup(sess, 0);
|
2017-01-27 23:18:51 +08:00
|
|
|
|
2017-06-12 16:18:24 +08:00
|
|
|
if (sesstmp == NULL) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-06-12 16:18:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SSL_SESSION_free(sess);
|
|
|
|
sess = sesstmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We've just been told to use this session for this context so
|
|
|
|
* make sure the sid_ctx matches up.
|
|
|
|
*/
|
|
|
|
memcpy(sess->sid_ctx, s->sid_ctx, s->sid_ctx_length);
|
|
|
|
sess->sid_ctx_length = s->sid_ctx_length;
|
|
|
|
ext = 1;
|
2017-08-01 22:45:29 +08:00
|
|
|
if (id == 0)
|
|
|
|
s->ext.early_data_ok = 1;
|
2018-08-24 23:16:28 +08:00
|
|
|
s->ext.ticket_expected = 1;
|
2017-06-12 16:18:24 +08:00
|
|
|
} else {
|
2022-08-29 12:17:25 +08:00
|
|
|
OSSL_TIME t, age, expire;
|
2018-05-10 01:22:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-06-21 23:54:55 +08:00
|
|
|
/*
|
|
|
|
* If we are using anti-replay protection then we behave as if
|
|
|
|
* SSL_OP_NO_TICKET is set - we are caching tickets anyway so there
|
|
|
|
* is no point in using full stateless tickets.
|
|
|
|
*/
|
|
|
|
if ((s->options & SSL_OP_NO_TICKET) != 0
|
2018-06-07 16:11:05 +08:00
|
|
|
|| (s->max_early_data > 0
|
|
|
|
&& (s->options & SSL_OP_NO_ANTI_REPLAY) == 0))
|
2018-06-13 22:57:39 +08:00
|
|
|
ret = tls_get_stateful_ticket(s, &identity, &sess);
|
|
|
|
else
|
|
|
|
ret = tls_decrypt_ticket(s, PACKET_data(&identity),
|
|
|
|
PACKET_remaining(&identity), NULL, 0,
|
|
|
|
&sess);
|
2018-05-10 01:22:36 +08:00
|
|
|
|
|
|
|
if (ret == SSL_TICKET_EMPTY) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2018-05-10 01:22:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-06-12 16:18:24 +08:00
|
|
|
|
2017-03-16 01:25:55 +08:00
|
|
|
if (ret == SSL_TICKET_FATAL_ERR_MALLOC
|
|
|
|
|| ret == SSL_TICKET_FATAL_ERR_OTHER) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-06-12 16:18:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-05-10 01:22:36 +08:00
|
|
|
if (ret == SSL_TICKET_NONE || ret == SSL_TICKET_NO_DECRYPT)
|
2017-06-12 16:18:24 +08:00
|
|
|
continue;
|
|
|
|
|
2018-03-16 17:25:34 +08:00
|
|
|
/* Check for replay */
|
|
|
|
if (s->max_early_data > 0
|
2018-06-07 16:11:05 +08:00
|
|
|
&& (s->options & SSL_OP_NO_ANTI_REPLAY) == 0
|
2018-03-16 17:25:34 +08:00
|
|
|
&& !SSL_CTX_remove_session(s->session_ctx, sess)) {
|
|
|
|
SSL_SESSION_free(sess);
|
|
|
|
sess = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-27 19:18:26 +08:00
|
|
|
age = ossl_time_subtract(ossl_ms2time(ticket_agel),
|
|
|
|
ossl_ms2time(sess->ext.tick_age_add));
|
2022-08-29 12:17:25 +08:00
|
|
|
t = ossl_time_subtract(ossl_time_now(), sess->time);
|
2017-06-12 16:18:24 +08:00
|
|
|
|
|
|
|
/*
|
2023-02-27 19:18:26 +08:00
|
|
|
* Although internally we use OSS_TIME which has ns granularity,
|
|
|
|
* when SSL_SESSION structures are serialised/deserialised we use
|
|
|
|
* second granularity for the sess->time field. Therefore it could
|
|
|
|
* appear that the client's ticket age is longer than ours (our
|
|
|
|
* ticket age calculation should always be slightly longer than the
|
|
|
|
* client's due to the network latency). Therefore we add 1000ms to
|
|
|
|
* our age calculation to adjust for rounding errors.
|
2017-06-12 16:18:24 +08:00
|
|
|
*/
|
2022-08-29 12:17:25 +08:00
|
|
|
expire = ossl_time_add(t, ossl_ms2time(1000));
|
|
|
|
|
2017-08-01 22:45:29 +08:00
|
|
|
if (id == 0
|
2022-08-29 12:17:25 +08:00
|
|
|
&& ossl_time_compare(sess->timeout, t) >= 0
|
|
|
|
&& ossl_time_compare(age, expire) <= 0
|
|
|
|
&& ossl_time_compare(ossl_time_add(age, TICKET_AGE_ALLOWANCE),
|
|
|
|
expire) >= 0) {
|
2017-06-12 16:18:24 +08:00
|
|
|
/*
|
|
|
|
* Ticket age is within tolerance and not expired. We allow it
|
|
|
|
* for early data
|
|
|
|
*/
|
|
|
|
s->ext.early_data_ok = 1;
|
|
|
|
}
|
2017-01-19 00:28:23 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
md = ssl_md(sctx, sess->cipher->algorithm2);
|
2022-07-12 12:28:37 +08:00
|
|
|
if (md == NULL) {
|
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
|
|
|
goto err;
|
|
|
|
}
|
2020-01-16 20:14:27 +08:00
|
|
|
if (!EVP_MD_is_a(md,
|
2022-06-20 23:11:28 +08:00
|
|
|
EVP_MD_get0_name(ssl_md(sctx,
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
s->s3.tmp.new_cipher->algorithm2)))) {
|
2017-06-07 00:19:32 +08:00
|
|
|
/* The ciphersuite is not compatible with this session. */
|
2017-01-19 00:28:23 +08:00
|
|
|
SSL_SESSION_free(sess);
|
|
|
|
sess = NULL;
|
2017-08-01 22:45:29 +08:00
|
|
|
s->ext.early_data_ok = 0;
|
2018-08-24 23:16:28 +08:00
|
|
|
s->ext.ticket_expected = 0;
|
2017-01-19 00:28:23 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sess == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
binderoffset = PACKET_data(pkt) - (const unsigned char *)s->init_buf->data;
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
hashsize = EVP_MD_get_size(md);
|
2017-01-19 00:28:23 +08:00
|
|
|
|
|
|
|
if (!PACKET_get_length_prefixed_2(pkt, &binders)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-01-19 00:28:23 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= id; i++) {
|
|
|
|
if (!PACKET_get_length_prefixed_1(&binders, &binder)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-01-19 00:28:23 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 21:36:13 +08:00
|
|
|
if (PACKET_remaining(&binder) != hashsize) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
2017-12-05 21:36:13 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (tls_psk_do_binder(s, md, (const unsigned char *)s->init_buf->data,
|
|
|
|
binderoffset, PACKET_data(&binder), NULL, sess, 0,
|
|
|
|
ext) != 1) {
|
2017-11-23 19:41:40 +08:00
|
|
|
/* SSLfatal() already called */
|
2017-01-19 00:28:23 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2019-03-01 23:40:20 +08:00
|
|
|
s->ext.tick_identity = id;
|
2017-02-24 17:30:54 +08:00
|
|
|
|
2017-01-19 00:28:23 +08:00
|
|
|
SSL_SESSION_free(s->session);
|
|
|
|
s->session = sess;
|
|
|
|
return 1;
|
|
|
|
err:
|
2017-03-04 23:45:40 +08:00
|
|
|
SSL_SESSION_free(sess);
|
2017-01-19 00:28:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
int tls_parse_ctos_post_handshake_auth(SSL_CONNECTION *s, PACKET *pkt,
|
2020-12-01 09:30:10 +08:00
|
|
|
ossl_unused unsigned int context,
|
|
|
|
ossl_unused X509 *x,
|
|
|
|
ossl_unused size_t chainidx)
|
Add TLSv1.3 post-handshake authentication (PHA)
Add SSL_verify_client_post_handshake() for servers to initiate PHA
Add SSL_force_post_handshake_auth() for clients that don't have certificates
initially configured, but use a certificate callback.
Update SSL_CTX_set_verify()/SSL_set_verify() mode:
* Add SSL_VERIFY_POST_HANDSHAKE to postpone client authentication until after
the initial handshake.
* Update SSL_VERIFY_CLIENT_ONCE now only sends out one CertRequest regardless
of when the certificate authentication takes place; either initial handshake,
re-negotiation, or post-handshake authentication.
Add 'RequestPostHandshake' and 'RequirePostHandshake' SSL_CONF options that
add the SSL_VERIFY_POST_HANDSHAKE to the 'Request' and 'Require' options
Add support to s_client:
* Enabled automatically when cert is configured
* Can be forced enabled via -force_pha
Add support to s_server:
* Use 'c' to invoke PHA in s_server
* Remove some dead code
Update documentation
Update unit tests:
* Illegal use of PHA extension
* TLSv1.3 certificate tests
DTLS and TLS behave ever-so-slightly differently. So, when DTLS1.3 is
implemented, it's PHA support state machine may need to be different.
Add a TODO and a #error
Update handshake context to deal with PHA.
The handshake context for TLSv1.3 post-handshake auth is up through the
ClientFinish message, plus the CertificateRequest message. Subsequent
Certificate, CertificateVerify, and Finish messages are based on this
handshake context (not the Certificate message per se, but it's included
after the hash). KeyUpdate, NewSessionTicket, and prior Certificate
Request messages are not included in post-handshake authentication.
After the ClientFinished message is processed, save off the digest state
for future post-handshake authentication. When post-handshake auth occurs,
copy over the saved handshake context into the "main" handshake digest.
This effectively discards the any KeyUpdate or NewSessionTicket messages
and any prior post-handshake authentication.
This, of course, assumes that the ID-22 did not mean to include any
previous post-handshake authentication into the new handshake transcript.
This is implied by section 4.4.1 that lists messages only up to the
first ClientFinished.
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4964)
2017-12-19 05:52:28 +08:00
|
|
|
{
|
|
|
|
if (PACKET_remaining(pkt) != 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_DECODE_ERROR,
|
Add TLSv1.3 post-handshake authentication (PHA)
Add SSL_verify_client_post_handshake() for servers to initiate PHA
Add SSL_force_post_handshake_auth() for clients that don't have certificates
initially configured, but use a certificate callback.
Update SSL_CTX_set_verify()/SSL_set_verify() mode:
* Add SSL_VERIFY_POST_HANDSHAKE to postpone client authentication until after
the initial handshake.
* Update SSL_VERIFY_CLIENT_ONCE now only sends out one CertRequest regardless
of when the certificate authentication takes place; either initial handshake,
re-negotiation, or post-handshake authentication.
Add 'RequestPostHandshake' and 'RequirePostHandshake' SSL_CONF options that
add the SSL_VERIFY_POST_HANDSHAKE to the 'Request' and 'Require' options
Add support to s_client:
* Enabled automatically when cert is configured
* Can be forced enabled via -force_pha
Add support to s_server:
* Use 'c' to invoke PHA in s_server
* Remove some dead code
Update documentation
Update unit tests:
* Illegal use of PHA extension
* TLSv1.3 certificate tests
DTLS and TLS behave ever-so-slightly differently. So, when DTLS1.3 is
implemented, it's PHA support state machine may need to be different.
Add a TODO and a #error
Update handshake context to deal with PHA.
The handshake context for TLSv1.3 post-handshake auth is up through the
ClientFinish message, plus the CertificateRequest message. Subsequent
Certificate, CertificateVerify, and Finish messages are based on this
handshake context (not the Certificate message per se, but it's included
after the hash). KeyUpdate, NewSessionTicket, and prior Certificate
Request messages are not included in post-handshake authentication.
After the ClientFinished message is processed, save off the digest state
for future post-handshake authentication. When post-handshake auth occurs,
copy over the saved handshake context into the "main" handshake digest.
This effectively discards the any KeyUpdate or NewSessionTicket messages
and any prior post-handshake authentication.
This, of course, assumes that the ID-22 did not mean to include any
previous post-handshake authentication into the new handshake transcript.
This is implied by section 4.4.1 that lists messages only up to the
first ClientFinished.
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4964)
2017-12-19 05:52:28 +08:00
|
|
|
SSL_R_POST_HANDSHAKE_AUTH_ENCODING_ERR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->post_handshake_auth = SSL_PHA_EXT_RECEIVED;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-12-08 01:04:46 +08:00
|
|
|
/*
|
|
|
|
* Add the server's renegotiation binding
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_renegotiate(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2018-12-13 02:09:50 +08:00
|
|
|
if (!s->s3.send_connection_binding)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
2017-05-11 04:46:14 +08:00
|
|
|
/* Still add this even if SSL_OP_NO_RENEGOTIATION is set */
|
2016-11-25 18:22:02 +08:00
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_renegotiate)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_start_sub_packet_u8(pkt)
|
2018-12-13 02:09:50 +08:00
|
|
|
|| !WPACKET_memcpy(pkt, s->s3.previous_client_finished,
|
|
|
|
s->s3.previous_client_finished_len)
|
|
|
|
|| !WPACKET_memcpy(pkt, s->s3.previous_server_finished,
|
|
|
|
s->s3.previous_server_finished_len)
|
2016-11-25 18:22:02 +08:00
|
|
|
|| !WPACKET_close(pkt)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_server_name(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2019-09-26 00:06:06 +08:00
|
|
|
if (s->servername_done != 1)
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prior to TLSv1.3 we ignore any SNI in the current handshake if resuming.
|
|
|
|
* We just use the servername from the initial handshake.
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
if (s->hit && !SSL_CONNECTION_IS_TLS13(s))
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_server_name)
|
|
|
|
|| !WPACKET_put_bytes_u16(pkt, 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-11-06 00:46:48 +08:00
|
|
|
/* Add/include the server's max fragment len extension into ServerHello */
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_maxfragmentlen(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-11-06 00:46:48 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2017-11-06 00:46:48 +08:00
|
|
|
{
|
|
|
|
if (!USE_MAX_FRAGMENT_LENGTH_EXT(s->session))
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* 4 bytes for this extension type and extension length
|
|
|
|
* 1 byte for the Max Fragment Length code value.
|
|
|
|
*/
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_max_fragment_length)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_put_bytes_u8(pkt, s->session->ext.max_fragment_len_mode)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-11-06 00:46:48 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXT_RETURN_SENT;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_ec_pt_formats(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2018-12-13 02:09:50 +08:00
|
|
|
unsigned long alg_k = s->s3.tmp.new_cipher->algorithm_mkey;
|
|
|
|
unsigned long alg_a = s->s3.tmp.new_cipher->algorithm_auth;
|
2016-12-07 20:30:52 +08:00
|
|
|
int using_ecc = ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA))
|
2019-06-18 18:45:26 +08:00
|
|
|
&& (s->ext.peer_ecpointformats != NULL);
|
2016-11-25 18:22:02 +08:00
|
|
|
const unsigned char *plist;
|
|
|
|
size_t plistlen;
|
|
|
|
|
|
|
|
if (!using_ecc)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
|
|
|
tls1_get_formatlist(s, &plist, &plistlen);
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_sub_memcpy_u8(pkt, plist, plistlen)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_supported_groups(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2017-05-05 17:27:14 +08:00
|
|
|
{
|
2017-09-22 23:06:52 +08:00
|
|
|
const uint16_t *groups;
|
2017-05-05 17:27:14 +08:00
|
|
|
size_t numgroups, i, first = 1;
|
2020-05-19 06:37:18 +08:00
|
|
|
int version;
|
2017-05-05 17:27:14 +08:00
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
/* s->s3.group_id is non zero if we accepted a key_share */
|
|
|
|
if (s->s3.group_id == 0)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2017-05-05 17:27:14 +08:00
|
|
|
|
|
|
|
/* Get our list of supported groups */
|
2017-09-26 22:28:16 +08:00
|
|
|
tls1_get_supported_groups(s, &groups, &numgroups);
|
2017-09-24 10:26:26 +08:00
|
|
|
if (numgroups == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-05-05 17:27:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy group ID if supported */
|
2022-06-20 23:11:28 +08:00
|
|
|
version = SSL_version(SSL_CONNECTION_GET_SSL(s));
|
2017-09-22 23:06:52 +08:00
|
|
|
for (i = 0; i < numgroups; i++) {
|
|
|
|
uint16_t group = groups[i];
|
|
|
|
|
2021-01-14 01:27:10 +08:00
|
|
|
if (tls_valid_group(s, group, version, version, 0, NULL)
|
2019-06-13 18:06:12 +08:00
|
|
|
&& tls_group_allowed(s, group, SSL_SECOP_CURVE_SUPPORTED)) {
|
2017-05-05 17:27:14 +08:00
|
|
|
if (first) {
|
|
|
|
/*
|
|
|
|
* Check if the client is already using our preferred group. If
|
|
|
|
* so we don't need to add this extension
|
|
|
|
*/
|
2018-12-13 02:09:50 +08:00
|
|
|
if (s->s3.group_id == group)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2017-05-05 17:27:14 +08:00
|
|
|
|
|
|
|
/* Add extension header */
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_supported_groups)
|
|
|
|
/* Sub-packet for supported_groups extension */
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-05-05 17:27:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
first = 0;
|
|
|
|
}
|
2017-09-22 23:06:52 +08:00
|
|
|
if (!WPACKET_put_bytes_u16(pkt, group)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-05-05 17:27:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-05-05 17:27:14 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2017-05-05 17:27:14 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_session_ticket(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2016-12-09 03:18:40 +08:00
|
|
|
if (!s->ext.ticket_expected || !tls_use_ticket(s)) {
|
|
|
|
s->ext.ticket_expected = 0;
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_session_ticket)
|
|
|
|
|| !WPACKET_put_bytes_u16(pkt, 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2016-11-26 00:28:02 +08:00
|
|
|
#ifndef OPENSSL_NO_OCSP
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_status_request(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2019-09-05 23:43:57 +08:00
|
|
|
/* We don't currently support this extension inside a CertificateRequest */
|
|
|
|
if (context == SSL_EXT_TLS1_3_CERTIFICATE_REQUEST)
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
|
2016-12-09 03:18:40 +08:00
|
|
|
if (!s->ext.status_expected)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
if (SSL_CONNECTION_IS_TLS13(s) && chainidx != 0)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-12-02 17:14:15 +08:00
|
|
|
|
2016-11-25 18:22:02 +08:00
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)
|
2016-12-02 22:46:54 +08:00
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-12-02 22:46:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In TLSv1.3 we include the certificate status itself. In <= TLSv1.2 we
|
|
|
|
* send back an empty extension, with the certificate status appearing as a
|
|
|
|
* separate message
|
|
|
|
*/
|
2022-06-20 23:11:28 +08:00
|
|
|
if (SSL_CONNECTION_IS_TLS13(s) && !tls_construct_cert_status_body(s, pkt)) {
|
2017-11-23 01:43:20 +08:00
|
|
|
/* SSLfatal() already called */
|
2017-12-15 15:01:20 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-11-23 01:43:20 +08:00
|
|
|
}
|
|
|
|
if (!WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
2016-11-26 00:28:02 +08:00
|
|
|
#endif
|
2016-11-25 18:22:02 +08:00
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_NEXTPROTONEG
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_next_proto_neg(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
|
|
|
const unsigned char *npa;
|
|
|
|
unsigned int npalen;
|
|
|
|
int ret;
|
2018-12-13 02:09:50 +08:00
|
|
|
int npn_seen = s->s3.npn_seen;
|
2022-06-20 23:11:28 +08:00
|
|
|
SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
|
2016-11-25 18:22:02 +08:00
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
s->s3.npn_seen = 0;
|
2022-06-20 23:11:28 +08:00
|
|
|
if (!npn_seen || sctx->ext.npn_advertised_cb == NULL)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
ret = sctx->ext.npn_advertised_cb(SSL_CONNECTION_GET_SSL(s), &npa, &npalen,
|
|
|
|
sctx->ext.npn_advertised_cb_arg);
|
2016-11-25 18:22:02 +08:00
|
|
|
if (ret == SSL_TLSEXT_ERR_OK) {
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_next_proto_neg)
|
|
|
|
|| !WPACKET_sub_memcpy_u16(pkt, npa, npalen)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
2018-12-13 02:09:50 +08:00
|
|
|
s->s3.npn_seen = 1;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_alpn(SSL_CONNECTION *s, WPACKET *pkt, unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2018-12-13 02:09:50 +08:00
|
|
|
if (s->s3.alpn_selected == NULL)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt,
|
|
|
|
TLSEXT_TYPE_application_layer_protocol_negotiation)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
2018-12-13 02:09:50 +08:00
|
|
|
|| !WPACKET_sub_memcpy_u8(pkt, s->s3.alpn_selected,
|
|
|
|
s->s3.alpn_selected_len)
|
2016-11-25 18:22:02 +08:00
|
|
|
|| !WPACKET_close(pkt)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_SRTP
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_use_srtp(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
|
|
|
if (s->srtp_profile == NULL)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-30 21:46:11 +08:00
|
|
|
|
2016-11-25 18:22:02 +08:00
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_use_srtp)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_put_bytes_u16(pkt, 2)
|
|
|
|
|| !WPACKET_put_bytes_u16(pkt, s->srtp_profile->id)
|
|
|
|
|| !WPACKET_put_bytes_u8(pkt, 0)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_etm(SSL_CONNECTION *s, WPACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2017-02-03 22:06:20 +08:00
|
|
|
if (!s->ext.use_etm)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't use encrypt_then_mac if AEAD or RC4 might want to disable
|
|
|
|
* for other cases too.
|
|
|
|
*/
|
2018-12-13 02:09:50 +08:00
|
|
|
if (s->s3.tmp.new_cipher->algorithm_mac == SSL_AEAD
|
|
|
|
|| s->s3.tmp.new_cipher->algorithm_enc == SSL_RC4
|
|
|
|
|| s->s3.tmp.new_cipher->algorithm_enc == SSL_eGOST2814789CNT
|
2020-03-30 23:09:24 +08:00
|
|
|
|| s->s3.tmp.new_cipher->algorithm_enc == SSL_eGOST2814789CNT12
|
|
|
|
|| s->s3.tmp.new_cipher->algorithm_enc == SSL_MAGMA
|
|
|
|
|| s->s3.tmp.new_cipher->algorithm_enc == SSL_KUZNYECHIK) {
|
2017-02-03 22:06:20 +08:00
|
|
|
s->ext.use_etm = 0;
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_encrypt_then_mac)
|
|
|
|
|| !WPACKET_put_bytes_u16(pkt, 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_ems(SSL_CONNECTION *s, WPACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2018-12-13 02:09:50 +08:00
|
|
|
if ((s->s3.flags & TLS1_FLAGS_RECEIVED_EXTMS) == 0)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret)
|
|
|
|
|| !WPACKET_put_bytes_u16(pkt, 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_supported_versions(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-11-04 00:38:48 +08:00
|
|
|
unsigned int context, X509 *x,
|
|
|
|
size_t chainidx)
|
|
|
|
{
|
2022-06-20 23:11:28 +08:00
|
|
|
if (!ossl_assert(SSL_CONNECTION_IS_TLS13(s))) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2018-03-13 18:36:03 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
2017-11-04 00:38:48 +08:00
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_supported_versions)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
2018-07-18 23:05:49 +08:00
|
|
|
|| !WPACKET_put_bytes_u16(pkt, s->version)
|
2017-11-04 00:38:48 +08:00
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-11-04 00:38:48 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXT_RETURN_SENT;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_key_share(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
2016-12-28 23:32:39 +08:00
|
|
|
#ifndef OPENSSL_NO_TLS1_3
|
2016-11-25 18:22:02 +08:00
|
|
|
unsigned char *encodedPoint;
|
|
|
|
size_t encoded_pt_len = 0;
|
2018-12-13 02:09:50 +08:00
|
|
|
EVP_PKEY *ckey = s->s3.peer_tmp, *skey = NULL;
|
2020-09-28 09:32:03 +08:00
|
|
|
const TLS_GROUP_INFO *ginf = NULL;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
2017-09-28 20:25:23 +08:00
|
|
|
if (s->hello_retry_request == SSL_HRR_PENDING) {
|
|
|
|
if (ckey != NULL) {
|
|
|
|
/* Original key_share was acceptable so don't ask for another one */
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
}
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_key_share)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
2022-09-30 17:50:53 +08:00
|
|
|
|| !WPACKET_put_bytes_u16(pkt, s->s3.group_id)
|
2017-09-28 20:25:23 +08:00
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-28 20:25:23 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-01-31 00:16:28 +08:00
|
|
|
}
|
|
|
|
|
2017-09-28 20:25:23 +08:00
|
|
|
return EXT_RETURN_SENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ckey == NULL) {
|
|
|
|
/* No key_share received from client - must be resuming */
|
2017-01-19 01:22:18 +08:00
|
|
|
if (!s->hit || !tls13_generate_handshake_secret(s, NULL, 0)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-01-19 01:22:18 +08:00
|
|
|
}
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
2021-03-30 12:27:49 +08:00
|
|
|
if (s->hit && (s->ext.psk_kex_mode & TLSEXT_KEX_MODE_FLAG_KE_DHE) == 0) {
|
|
|
|
/*
|
|
|
|
* PSK ('hit') and explicitly not doing DHE (if the client sent the
|
|
|
|
* DHE option we always take it); don't send key share.
|
|
|
|
*/
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
}
|
2016-11-25 18:22:02 +08:00
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_key_share)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
2018-12-13 02:09:50 +08:00
|
|
|
|| !WPACKET_put_bytes_u16(pkt, s->s3.group_id)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
if ((ginf = tls1_group_id_lookup(SSL_CONNECTION_GET_CTX(s),
|
|
|
|
s->s3.group_id)) == NULL) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:32:03 +08:00
|
|
|
if (!ginf->is_kem) {
|
|
|
|
/* Regular KEX */
|
|
|
|
skey = ssl_generate_pkey(s, ckey);
|
|
|
|
if (skey == NULL) {
|
2022-09-29 19:57:34 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_SSL_LIB);
|
2020-09-28 09:32:03 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
2016-11-25 18:22:02 +08:00
|
|
|
|
2020-09-28 09:32:03 +08:00
|
|
|
/* Generate encoding of server key */
|
2020-10-09 21:19:42 +08:00
|
|
|
encoded_pt_len = EVP_PKEY_get1_encoded_public_key(skey, &encodedPoint);
|
2020-09-28 09:32:03 +08:00
|
|
|
if (encoded_pt_len == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EC_LIB);
|
2020-09-28 09:32:03 +08:00
|
|
|
EVP_PKEY_free(skey);
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_sub_memcpy_u16(pkt, encodedPoint, encoded_pt_len)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2020-09-28 09:32:03 +08:00
|
|
|
EVP_PKEY_free(skey);
|
|
|
|
OPENSSL_free(encodedPoint);
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
2016-11-25 18:22:02 +08:00
|
|
|
OPENSSL_free(encodedPoint);
|
|
|
|
|
2020-09-28 09:32:03 +08:00
|
|
|
/*
|
|
|
|
* This causes the crypto state to be updated based on the derived keys
|
|
|
|
*/
|
|
|
|
s->s3.tmp.pkey = skey;
|
|
|
|
if (ssl_derive(s, skey, ckey, 1) == 0) {
|
|
|
|
/* SSLfatal() already called */
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* KEM mode */
|
|
|
|
unsigned char *ct = NULL;
|
|
|
|
size_t ctlen = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This does not update the crypto state.
|
|
|
|
*
|
|
|
|
* The generated pms is stored in `s->s3.tmp.pms` to be later used via
|
|
|
|
* ssl_gensecret().
|
|
|
|
*/
|
|
|
|
if (ssl_encapsulate(s, ckey, &ct, &ctlen, 0) == 0) {
|
|
|
|
/* SSLfatal() already called */
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctlen == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2020-09-28 09:32:03 +08:00
|
|
|
OPENSSL_free(ct);
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_sub_memcpy_u16(pkt, ct, ctlen)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2020-09-28 09:32:03 +08:00
|
|
|
OPENSSL_free(ct);
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
OPENSSL_free(ct);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This causes the crypto state to be updated based on the generated pms
|
|
|
|
*/
|
|
|
|
if (ssl_gensecret(s, s->s3.tmp.pms, s->s3.tmp.pmslen) == 0) {
|
|
|
|
/* SSLfatal() already called */
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
2021-03-16 22:47:09 +08:00
|
|
|
s->s3.did_kex = 1;
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2018-05-21 19:20:18 +08:00
|
|
|
#else
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
#endif
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_cookie(SSL_CONNECTION *s, WPACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-09-11 22:43:56 +08:00
|
|
|
X509 *x, size_t chainidx)
|
|
|
|
{
|
2018-05-21 19:20:18 +08:00
|
|
|
#ifndef OPENSSL_NO_TLS1_3
|
2017-09-11 22:43:56 +08:00
|
|
|
unsigned char *hashval1, *hashval2, *appcookie1, *appcookie2, *cookie;
|
|
|
|
unsigned char *hmac, *hmac2;
|
2018-02-26 10:39:11 +08:00
|
|
|
size_t startlen, ciphlen, totcookielen, hashlen, hmaclen, appcookielen;
|
2017-09-11 22:43:56 +08:00
|
|
|
EVP_MD_CTX *hctx;
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
int ret = EXT_RETURN_FAIL;
|
2022-06-20 23:11:28 +08:00
|
|
|
SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
|
|
|
|
SSL *ssl = SSL_CONNECTION_GET_SSL(s);
|
2017-09-11 22:43:56 +08:00
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
if ((s->s3.flags & TLS1_FLAGS_STATELESS) == 0)
|
2017-09-11 22:43:56 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
if (sctx->gen_stateless_cookie_cb == NULL) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_NO_COOKIE_CALLBACK_SET);
|
2018-03-09 01:44:12 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
2017-09-11 22:43:56 +08:00
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_cookie)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_get_total_written(pkt, &startlen)
|
|
|
|
|| !WPACKET_reserve_bytes(pkt, MAX_COOKIE_SIZE, &cookie)
|
|
|
|
|| !WPACKET_put_bytes_u16(pkt, COOKIE_STATE_FORMAT_VERSION)
|
|
|
|
|| !WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION)
|
2018-12-13 02:09:50 +08:00
|
|
|
|| !WPACKET_put_bytes_u16(pkt, s->s3.group_id)
|
2022-06-20 23:11:28 +08:00
|
|
|
|| !ssl->method->put_cipher_by_char(s->s3.tmp.new_cipher, pkt,
|
|
|
|
&ciphlen)
|
2017-09-11 22:43:56 +08:00
|
|
|
/* Is there a key_share extension present in this HRR? */
|
2018-12-13 02:09:50 +08:00
|
|
|
|| !WPACKET_put_bytes_u8(pkt, s->s3.peer_tmp == NULL)
|
2022-08-16 09:05:02 +08:00
|
|
|
|| !WPACKET_put_bytes_u64(pkt, time(NULL))
|
2017-09-11 22:43:56 +08:00
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_reserve_bytes(pkt, EVP_MAX_MD_SIZE, &hashval1)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the hash of the initial ClientHello. ssl_handshake_hash() operates
|
|
|
|
* on raw buffers, so we first reserve sufficient bytes (above) and then
|
|
|
|
* subsequently allocate them (below)
|
|
|
|
*/
|
|
|
|
if (!ssl3_digest_cached_records(s, 0)
|
|
|
|
|| !ssl_handshake_hash(s, hashval1, EVP_MAX_MD_SIZE, &hashlen)) {
|
|
|
|
/* SSLfatal() already called */
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_allocate_bytes(pkt, hashlen, &hashval2)
|
|
|
|
|| !ossl_assert(hashval1 == hashval2)
|
|
|
|
|| !WPACKET_close(pkt)
|
|
|
|
|| !WPACKET_start_sub_packet_u8(pkt)
|
|
|
|
|| !WPACKET_reserve_bytes(pkt, SSL_COOKIE_LENGTH, &appcookie1)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate the application cookie */
|
2022-06-20 23:11:28 +08:00
|
|
|
if (sctx->gen_stateless_cookie_cb(ssl, appcookie1,
|
|
|
|
&appcookielen) == 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_COOKIE_GEN_CALLBACK_FAILURE);
|
2017-09-11 22:43:56 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_allocate_bytes(pkt, appcookielen, &appcookie2)
|
|
|
|
|| !ossl_assert(appcookie1 == appcookie2)
|
|
|
|
|| !WPACKET_close(pkt)
|
|
|
|
|| !WPACKET_get_total_written(pkt, &totcookielen)
|
|
|
|
|| !WPACKET_reserve_bytes(pkt, SHA256_DIGEST_LENGTH, &hmac)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
hmaclen = SHA256_DIGEST_LENGTH;
|
|
|
|
|
|
|
|
totcookielen -= startlen;
|
|
|
|
if (!ossl_assert(totcookielen <= MAX_COOKIE_SIZE - SHA256_DIGEST_LENGTH)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HMAC the cookie */
|
|
|
|
hctx = EVP_MD_CTX_create();
|
2022-06-20 23:11:28 +08:00
|
|
|
pkey = EVP_PKEY_new_raw_private_key_ex(sctx->libctx, "HMAC",
|
|
|
|
sctx->propq,
|
2020-09-24 17:42:23 +08:00
|
|
|
s->session_ctx->ext.cookie_hmac_key,
|
|
|
|
sizeof(s->session_ctx->ext.cookie_hmac_key));
|
2017-09-11 22:43:56 +08:00
|
|
|
if (hctx == NULL || pkey == NULL) {
|
2022-09-29 19:57:34 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB);
|
2017-09-11 22:43:56 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
if (EVP_DigestSignInit_ex(hctx, NULL, "SHA2-256", sctx->libctx,
|
|
|
|
sctx->propq, pkey, NULL) <= 0
|
2017-09-11 22:43:56 +08:00
|
|
|
|| EVP_DigestSign(hctx, hmac, &hmaclen, cookie,
|
|
|
|
totcookielen) <= 0) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ossl_assert(totcookielen + hmaclen <= MAX_COOKIE_SIZE)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_allocate_bytes(pkt, hmaclen, &hmac2)
|
|
|
|
|| !ossl_assert(hmac == hmac2)
|
|
|
|
|| !ossl_assert(cookie == hmac - totcookielen)
|
|
|
|
|| !WPACKET_close(pkt)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-09-11 22:43:56 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = EXT_RETURN_SENT;
|
|
|
|
|
|
|
|
err:
|
|
|
|
EVP_MD_CTX_free(hctx);
|
|
|
|
EVP_PKEY_free(pkey);
|
|
|
|
return ret;
|
2018-05-21 19:20:18 +08:00
|
|
|
#else
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
#endif
|
2017-09-11 22:43:56 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_cryptopro_bug(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2016-11-25 18:22:02 +08:00
|
|
|
{
|
|
|
|
const unsigned char cryptopro_ext[36] = {
|
|
|
|
0xfd, 0xe8, /* 65000 */
|
|
|
|
0x00, 0x20, /* 32 bytes length */
|
|
|
|
0x30, 0x1e, 0x30, 0x08, 0x06, 0x06, 0x2a, 0x85,
|
|
|
|
0x03, 0x02, 0x02, 0x09, 0x30, 0x08, 0x06, 0x06,
|
|
|
|
0x2a, 0x85, 0x03, 0x02, 0x02, 0x16, 0x30, 0x08,
|
|
|
|
0x06, 0x06, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x17
|
|
|
|
};
|
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
if (((s->s3.tmp.new_cipher->id & 0xFFFF) != 0x80
|
|
|
|
&& (s->s3.tmp.new_cipher->id & 0xFFFF) != 0x81)
|
2022-06-20 23:11:28 +08:00
|
|
|
|| (SSL_get_options(SSL_CONNECTION_GET_SSL(s))
|
|
|
|
& SSL_OP_CRYPTOPRO_TLSEXT_BUG) == 0)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
|
|
|
|
if (!WPACKET_memcpy(pkt, cryptopro_ext, sizeof(cryptopro_ext))) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2016-11-25 18:22:02 +08:00
|
|
|
}
|
2017-01-19 01:22:18 +08:00
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_early_data(SSL_CONNECTION *s, WPACKET *pkt,
|
2017-05-09 20:44:25 +08:00
|
|
|
unsigned int context, X509 *x,
|
2017-11-22 01:18:43 +08:00
|
|
|
size_t chainidx)
|
2017-02-24 19:13:25 +08:00
|
|
|
{
|
2017-04-04 18:40:02 +08:00
|
|
|
if (context == SSL_EXT_TLS1_3_NEW_SESSION_TICKET) {
|
2017-03-09 23:31:55 +08:00
|
|
|
if (s->max_early_data == 0)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2017-03-09 23:31:55 +08:00
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_early_data)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_put_bytes_u32(pkt, s->max_early_data)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-03-09 23:31:55 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2017-03-09 23:31:55 +08:00
|
|
|
}
|
|
|
|
|
2017-02-24 19:13:25 +08:00
|
|
|
if (s->ext.early_data != SSL_EARLY_DATA_ACCEPTED)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2017-02-24 19:13:25 +08:00
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_early_data)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-02-24 19:13:25 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2017-02-24 19:13:25 +08:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:11:28 +08:00
|
|
|
EXT_RETURN tls_construct_stoc_psk(SSL_CONNECTION *s, WPACKET *pkt,
|
|
|
|
unsigned int context,
|
2017-11-22 01:18:43 +08:00
|
|
|
X509 *x, size_t chainidx)
|
2017-01-19 01:22:18 +08:00
|
|
|
{
|
|
|
|
if (!s->hit)
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_NOT_SENT;
|
2017-01-19 01:22:18 +08:00
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_psk)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
2019-03-01 23:40:20 +08:00
|
|
|
|| !WPACKET_put_bytes_u16(pkt, s->ext.tick_identity)
|
2017-01-19 01:22:18 +08:00
|
|
|
|| !WPACKET_close(pkt)) {
|
2020-11-04 21:39:57 +08:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_FAIL;
|
2017-01-19 01:22:18 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:44:25 +08:00
|
|
|
return EXT_RETURN_SENT;
|
2017-01-19 01:22:18 +08:00
|
|
|
}
|
2021-01-28 03:23:33 +08:00
|
|
|
|
|
|
|
EXT_RETURN tls_construct_stoc_client_cert_type(SSL_CONNECTION *sc, WPACKET *pkt,
|
|
|
|
unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
|
|
|
{
|
|
|
|
if (sc->ext.client_cert_type_ctos == OSSL_CERT_TYPE_CTOS_ERROR
|
|
|
|
&& (send_certificate_request(sc)
|
|
|
|
|| sc->post_handshake_auth == SSL_PHA_EXT_RECEIVED)) {
|
|
|
|
/* Did not receive an acceptable cert type - and doing client auth */
|
|
|
|
SSLfatal(sc, SSL_AD_UNSUPPORTED_CERTIFICATE, SSL_R_BAD_EXTENSION);
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->ext.client_cert_type == TLSEXT_cert_type_x509) {
|
|
|
|
sc->ext.client_cert_type_ctos = OSSL_CERT_TYPE_CTOS_NONE;
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: only supposed to send this if we are going to do a cert request,
|
|
|
|
* but TLSv1.3 could do a PHA request if the client supports it
|
|
|
|
*/
|
|
|
|
if ((!send_certificate_request(sc) && sc->post_handshake_auth != SSL_PHA_EXT_RECEIVED)
|
|
|
|
|| sc->ext.client_cert_type_ctos != OSSL_CERT_TYPE_CTOS_GOOD
|
|
|
|
|| sc->client_cert_type == NULL) {
|
|
|
|
/* if we don't send it, reset to TLSEXT_cert_type_x509 */
|
|
|
|
sc->ext.client_cert_type_ctos = OSSL_CERT_TYPE_CTOS_NONE;
|
|
|
|
sc->ext.client_cert_type = TLSEXT_cert_type_x509;
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_client_cert_type)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_put_bytes_u8(pkt, sc->ext.client_cert_type)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
|
|
|
SSLfatal(sc, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
return EXT_RETURN_SENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* One of |pref|, |other| is configured and the values are sanitized */
|
|
|
|
static int reconcile_cert_type(const unsigned char *pref, size_t pref_len,
|
|
|
|
const unsigned char *other, size_t other_len,
|
|
|
|
uint8_t *chosen_cert_type)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < pref_len; i++) {
|
|
|
|
if (memchr(other, pref[i], other_len) != NULL) {
|
|
|
|
*chosen_cert_type = pref[i];
|
|
|
|
return OSSL_CERT_TYPE_CTOS_GOOD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OSSL_CERT_TYPE_CTOS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tls_parse_ctos_client_cert_type(SSL_CONNECTION *sc, PACKET *pkt,
|
|
|
|
unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
|
|
|
{
|
|
|
|
PACKET supported_cert_types;
|
|
|
|
const unsigned char *data;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
/* Ignore the extension */
|
|
|
|
if (sc->client_cert_type == NULL) {
|
|
|
|
sc->ext.client_cert_type_ctos = OSSL_CERT_TYPE_CTOS_NONE;
|
|
|
|
sc->ext.client_cert_type = TLSEXT_cert_type_x509;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_1(pkt, &supported_cert_types)) {
|
|
|
|
sc->ext.client_cert_type_ctos = OSSL_CERT_TYPE_CTOS_ERROR;
|
|
|
|
SSLfatal(sc, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((len = PACKET_remaining(&supported_cert_types)) == 0) {
|
|
|
|
sc->ext.client_cert_type_ctos = OSSL_CERT_TYPE_CTOS_ERROR;
|
|
|
|
SSLfatal(sc, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!PACKET_get_bytes(&supported_cert_types, &data, len)) {
|
|
|
|
sc->ext.client_cert_type_ctos = OSSL_CERT_TYPE_CTOS_ERROR;
|
|
|
|
SSLfatal(sc, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* client_cert_type: client (peer) has priority */
|
|
|
|
sc->ext.client_cert_type_ctos = reconcile_cert_type(data, len,
|
|
|
|
sc->client_cert_type, sc->client_cert_type_len,
|
|
|
|
&sc->ext.client_cert_type);
|
|
|
|
|
|
|
|
/* Ignore the error until sending - so we can check cert auth*/
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXT_RETURN tls_construct_stoc_server_cert_type(SSL_CONNECTION *sc, WPACKET *pkt,
|
|
|
|
unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
|
|
|
{
|
|
|
|
if (sc->ext.server_cert_type == TLSEXT_cert_type_x509) {
|
|
|
|
sc->ext.server_cert_type_ctos = OSSL_CERT_TYPE_CTOS_NONE;
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
}
|
|
|
|
if (sc->ext.server_cert_type_ctos != OSSL_CERT_TYPE_CTOS_GOOD
|
|
|
|
|| sc->server_cert_type == NULL) {
|
|
|
|
/* if we don't send it, reset to TLSEXT_cert_type_x509 */
|
|
|
|
sc->ext.server_cert_type_ctos = OSSL_CERT_TYPE_CTOS_NONE;
|
|
|
|
sc->ext.server_cert_type = TLSEXT_cert_type_x509;
|
|
|
|
return EXT_RETURN_NOT_SENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_server_cert_type)
|
|
|
|
|| !WPACKET_start_sub_packet_u16(pkt)
|
|
|
|
|| !WPACKET_put_bytes_u8(pkt, sc->ext.server_cert_type)
|
|
|
|
|| !WPACKET_close(pkt)) {
|
|
|
|
SSLfatal(sc, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
|
|
|
|
return EXT_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
return EXT_RETURN_SENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tls_parse_ctos_server_cert_type(SSL_CONNECTION *sc, PACKET *pkt,
|
|
|
|
unsigned int context,
|
|
|
|
X509 *x, size_t chainidx)
|
|
|
|
{
|
|
|
|
PACKET supported_cert_types;
|
|
|
|
const unsigned char *data;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
/* Ignore the extension */
|
|
|
|
if (sc->server_cert_type == NULL) {
|
|
|
|
sc->ext.server_cert_type_ctos = OSSL_CERT_TYPE_CTOS_NONE;
|
|
|
|
sc->ext.server_cert_type = TLSEXT_cert_type_x509;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PACKET_as_length_prefixed_1(pkt, &supported_cert_types)) {
|
|
|
|
SSLfatal(sc, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((len = PACKET_remaining(&supported_cert_types)) == 0) {
|
|
|
|
SSLfatal(sc, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!PACKET_get_bytes(&supported_cert_types, &data, len)) {
|
|
|
|
SSLfatal(sc, SSL_AD_DECODE_ERROR, SSL_R_BAD_EXTENSION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* server_cert_type: server (this) has priority */
|
|
|
|
sc->ext.server_cert_type_ctos = reconcile_cert_type(sc->server_cert_type, sc->server_cert_type_len,
|
|
|
|
data, len,
|
|
|
|
&sc->ext.server_cert_type);
|
|
|
|
if (sc->ext.server_cert_type_ctos == OSSL_CERT_TYPE_CTOS_GOOD)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Did not receive an acceptable cert type */
|
|
|
|
SSLfatal(sc, SSL_AD_UNSUPPORTED_CERTIFICATE, SSL_R_BAD_EXTENSION);
|
|
|
|
return 0;
|
|
|
|
}
|