|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* Copyright (C) 2018 Red Hat, Inc.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Author: Daiki Ueno
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This file is part of GnuTLS.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* The GnuTLS is free software; you can redistribute it and/or
|
|
Packit |
aea12f |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit |
aea12f |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
aea12f |
* the License, or (at your option) any later version.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This library is distributed in the hope that it will be useful, but
|
|
Packit |
aea12f |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aea12f |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aea12f |
* Lesser General Public License for more details.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
aea12f |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This file contains the code for the Early Data TLS 1.3 extension.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include "gnutls_int.h"
|
|
Packit |
aea12f |
#include "errors.h"
|
|
Packit |
aea12f |
#include "num.h"
|
|
Packit |
aea12f |
#include "hello_ext_lib.h"
|
|
Packit |
aea12f |
#include <ext/early_data.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static int early_data_recv_params(gnutls_session_t session,
|
|
Packit |
aea12f |
const uint8_t * data,
|
|
Packit |
aea12f |
size_t data_size);
|
|
Packit |
aea12f |
static int early_data_send_params(gnutls_session_t session,
|
|
Packit |
aea12f |
gnutls_buffer_st * extdata);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
const hello_ext_entry_st ext_mod_early_data = {
|
|
Packit |
aea12f |
.name = "Early Data",
|
|
Packit |
aea12f |
.tls_id = 42,
|
|
Packit |
aea12f |
.gid = GNUTLS_EXTENSION_EARLY_DATA,
|
|
Packit |
aea12f |
.validity = GNUTLS_EXT_FLAG_TLS | GNUTLS_EXT_FLAG_CLIENT_HELLO | GNUTLS_EXT_FLAG_EE,
|
|
Packit Service |
991b93 |
.client_parse_point = GNUTLS_EXT_MANDATORY, /* force parsing prior to EXT_TLS extensions */
|
|
Packit Service |
991b93 |
.server_parse_point = GNUTLS_EXT_MANDATORY, /* force parsing prior to EXT_TLS extensions */
|
|
Packit |
aea12f |
.recv_func = early_data_recv_params,
|
|
Packit |
aea12f |
.send_func = early_data_send_params,
|
|
Packit |
aea12f |
.pack_func = NULL,
|
|
Packit |
aea12f |
.unpack_func = NULL,
|
|
Packit |
aea12f |
.deinit_func = _gnutls_hello_ext_default_deinit,
|
|
Packit |
aea12f |
.cannot_be_overriden = 0
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static int
|
|
Packit |
aea12f |
early_data_recv_params(gnutls_session_t session,
|
|
Packit |
aea12f |
const uint8_t * data, size_t _data_size)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
const version_entry_st *vers = get_version(session);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (!vers || !vers->tls13_sem)
|
|
Packit |
aea12f |
return gnutls_assert_val(0);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (session->security_parameters.entity == GNUTLS_SERVER) {
|
|
Packit |
aea12f |
/* The flag may be cleared by pre_shared_key
|
|
Packit |
aea12f |
* extension, when replay is detected. */
|
|
Packit |
aea12f |
if ((session->internals.flags & GNUTLS_ENABLE_EARLY_DATA) &&
|
|
Packit |
aea12f |
/* Refuse early data when this is a second CH after HRR */
|
|
Packit |
aea12f |
!(session->internals.hsk_flags & HSK_HRR_SENT))
|
|
Packit |
aea12f |
session->internals.hsk_flags |= HSK_EARLY_DATA_ACCEPTED;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
session->internals.hsk_flags |= HSK_EARLY_DATA_IN_FLIGHT;
|
|
Packit |
aea12f |
} else {
|
|
Packit |
aea12f |
if (_gnutls_ext_get_msg(session) == GNUTLS_EXT_FLAG_EE)
|
|
Packit |
aea12f |
session->internals.hsk_flags |= HSK_EARLY_DATA_ACCEPTED;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
return 0;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* returns data_size or a negative number on failure
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
static int
|
|
Packit |
aea12f |
early_data_send_params(gnutls_session_t session,
|
|
Packit |
aea12f |
gnutls_buffer_st * extdata)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
if (session->security_parameters.entity == GNUTLS_SERVER) {
|
|
Packit |
aea12f |
if (session->internals.hsk_flags & HSK_EARLY_DATA_ACCEPTED)
|
|
Packit |
aea12f |
return GNUTLS_E_INT_RET_0;
|
|
Packit |
aea12f |
} else {
|
|
Packit |
aea12f |
if (session->internals.early_data_presend_buffer.length > 0) {
|
|
Packit |
aea12f |
session->internals.hsk_flags |= HSK_EARLY_DATA_IN_FLIGHT;
|
|
Packit |
aea12f |
return GNUTLS_E_INT_RET_0;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
return 0;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/**
|
|
Packit |
aea12f |
* gnutls_record_get_max_early_data_size:
|
|
Packit |
aea12f |
* @session: is a #gnutls_session_t type.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This function returns the maximum early data size in this connection.
|
|
Packit |
aea12f |
* This property can only be set to servers. The client may be
|
|
Packit |
aea12f |
* provided with the maximum allowed size through the "early_data"
|
|
Packit |
aea12f |
* extension of the NewSessionTicket handshake message.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Returns: The maximum early data size in this connection.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Since: 3.6.5
|
|
Packit |
aea12f |
**/
|
|
Packit |
aea12f |
size_t
|
|
Packit |
aea12f |
gnutls_record_get_max_early_data_size(gnutls_session_t session)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
return session->security_parameters.max_early_data_size;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/**
|
|
Packit |
aea12f |
* gnutls_record_set_max_early_data_size:
|
|
Packit |
aea12f |
* @session: is a #gnutls_session_t type.
|
|
Packit |
aea12f |
* @size: is the new size
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This function sets the maximum early data size in this connection.
|
|
Packit |
aea12f |
* This property can only be set to servers. The client may be
|
|
Packit |
aea12f |
* provided with the maximum allowed size through the "early_data"
|
|
Packit |
aea12f |
* extension of the NewSessionTicket handshake message.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned,
|
|
Packit |
aea12f |
* otherwise a negative error code is returned.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Since: 3.6.4
|
|
Packit |
aea12f |
**/
|
|
Packit |
aea12f |
int
|
|
Packit |
aea12f |
gnutls_record_set_max_early_data_size(gnutls_session_t session,
|
|
Packit |
aea12f |
size_t size)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
if (session->security_parameters.entity == GNUTLS_CLIENT)
|
|
Packit |
aea12f |
return GNUTLS_E_INVALID_REQUEST;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Reject zero as well, as it is useless. */
|
|
Packit |
aea12f |
if (size == 0 || size > UINT32_MAX)
|
|
Packit |
aea12f |
return GNUTLS_E_INVALID_REQUEST;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
session->security_parameters.max_early_data_size = (uint32_t) size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
return 0;
|
|
Packit |
aea12f |
}
|