|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2000-2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
* Copyright (C) 2015-2018 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The GnuTLS is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
4684c1 |
* the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This library is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifndef GNUTLS_LIB_HELLO_EXT_H
|
|
Packit Service |
4684c1 |
#define GNUTLS_LIB_HELLO_EXT_H
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "gnutls_int.h"
|
|
Packit Service |
4684c1 |
#include <gnutls/gnutls.h>
|
|
Packit Service |
4684c1 |
#include "str.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Functions for hello extension parsing.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
int _gnutls_parse_hello_extensions(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
gnutls_ext_flags_t msg,
|
|
Packit Service |
4684c1 |
gnutls_ext_parse_type_t parse_type,
|
|
Packit Service |
4684c1 |
const uint8_t * data, int data_size);
|
|
Packit Service |
4684c1 |
int _gnutls_gen_hello_extensions(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
gnutls_buffer_st * extdata,
|
|
Packit Service |
4684c1 |
gnutls_ext_flags_t msg,
|
|
Packit Service |
4684c1 |
gnutls_ext_parse_type_t);
|
|
Packit Service |
4684c1 |
int _gnutls_hello_ext_init(void);
|
|
Packit Service |
4684c1 |
void _gnutls_hello_ext_deinit(void);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void _gnutls_hello_ext_priv_deinit(gnutls_session_t session);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* functions to be used by extensions internally
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
void _gnutls_hello_ext_unset_priv(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
extensions_t ext);
|
|
Packit Service |
4684c1 |
void _gnutls_hello_ext_set_priv(gnutls_session_t session, extensions_t ext,
|
|
Packit Service |
4684c1 |
gnutls_ext_priv_data_t);
|
|
Packit Service |
4684c1 |
int _gnutls_hello_ext_get_priv(gnutls_session_t session, extensions_t ext,
|
|
Packit Service |
4684c1 |
gnutls_ext_priv_data_t *);
|
|
Packit Service |
4684c1 |
int _gnutls_hello_ext_get_resumed_priv(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
extensions_t ext,
|
|
Packit Service |
4684c1 |
gnutls_ext_priv_data_t * data);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define GNUTLS_EXT_FLAG_MSG_MASK (GNUTLS_EXT_FLAG_CLIENT_HELLO | GNUTLS_EXT_FLAG_TLS12_SERVER_HELLO| \
|
|
Packit Service |
4684c1 |
GNUTLS_EXT_FLAG_TLS13_SERVER_HELLO | GNUTLS_EXT_FLAG_EE | GNUTLS_EXT_FLAG_HRR)
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* these flags can only be set in the extensions, but cannot be requested;
|
|
Packit Service |
4684c1 |
* they are handled internally by the hello parsing/generating functions. */
|
|
Packit Service |
4684c1 |
#define GNUTLS_EXT_FLAG_SET_ONLY_FLAGS_MASK ~(GNUTLS_EXT_FLAG_DTLS | GNUTLS_EXT_FLAG_TLS)
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* obtain the message this extension was received at */
|
|
Packit Service |
4684c1 |
inline static gnutls_ext_flags_t _gnutls_ext_get_msg(gnutls_session_t session)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
return session->internals.ext_msg & GNUTLS_EXT_FLAG_MSG_MASK;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static void _gnutls_ext_set_msg(gnutls_session_t session, gnutls_ext_flags_t msg)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
session->internals.ext_msg = msg;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static void _gnutls_ext_set_extensions_offset(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
int offset)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
session->internals.extensions_offset = offset;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static int _gnutls_ext_get_extensions_offset(gnutls_session_t session)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
return session->internals.extensions_offset;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int _gnutls_ext_set_full_client_hello(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
handshake_buffer_st *recv_buf);
|
|
Packit Service |
4684c1 |
unsigned _gnutls_ext_get_full_client_hello(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
gnutls_datum_t *datum);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* for session packing */
|
|
Packit Service |
4684c1 |
int _gnutls_hello_ext_pack(gnutls_session_t session, gnutls_buffer_st * packed);
|
|
Packit Service |
4684c1 |
int _gnutls_hello_ext_unpack(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
gnutls_buffer_st * packed);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static const char *ext_msg_validity_to_str(gnutls_ext_flags_t msg)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
msg &= GNUTLS_EXT_FLAG_MSG_MASK;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
switch(msg) {
|
|
Packit Service |
4684c1 |
case GNUTLS_EXT_FLAG_CLIENT_HELLO:
|
|
Packit Service |
4684c1 |
return "client hello";
|
|
Packit Service |
4684c1 |
case GNUTLS_EXT_FLAG_TLS12_SERVER_HELLO:
|
|
Packit Service |
4684c1 |
return "TLS 1.2 server hello";
|
|
Packit Service |
4684c1 |
case GNUTLS_EXT_FLAG_TLS13_SERVER_HELLO:
|
|
Packit Service |
4684c1 |
return "TLS 1.3 server hello";
|
|
Packit Service |
4684c1 |
case GNUTLS_EXT_FLAG_EE:
|
|
Packit Service |
4684c1 |
return "encrypted extensions";
|
|
Packit Service |
4684c1 |
case GNUTLS_EXT_FLAG_HRR:
|
|
Packit Service |
4684c1 |
return "hello retry request";
|
|
Packit Service |
4684c1 |
default:
|
|
Packit Service |
4684c1 |
return "(unknown)";
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef struct hello_ext_entry_st {
|
|
Packit Service |
4684c1 |
const char *name; /* const overridden when free_struct is set */
|
|
Packit Service |
4684c1 |
unsigned free_struct;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
uint16_t tls_id;
|
|
Packit Service |
4684c1 |
unsigned gid; /* gnutls internal ID */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_ext_parse_type_t client_parse_point;
|
|
Packit Service |
4684c1 |
gnutls_ext_parse_type_t server_parse_point;
|
|
Packit Service |
4684c1 |
unsigned validity; /* multiple items of gnutls_ext_flags_t */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* this function must return 0 when Not Applicable
|
|
Packit Service |
4684c1 |
* size of extension data if ok
|
|
Packit Service |
4684c1 |
* < 0 on other error.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
gnutls_ext_recv_func recv_func;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* this function must return 0 when Not Applicable
|
|
Packit Service |
4684c1 |
* size of extension data if ok
|
|
Packit Service |
4684c1 |
* GNUTLS_E_INT_RET_0 if extension data size is zero
|
|
Packit Service |
4684c1 |
* < 0 on other error.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
gnutls_ext_send_func send_func;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_ext_deinit_data_func deinit_func; /* this will be called to deinitialize
|
|
Packit Service |
4684c1 |
* internal data
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
gnutls_ext_pack_func pack_func; /* packs internal data to machine independent format */
|
|
Packit Service |
4684c1 |
gnutls_ext_unpack_func unpack_func; /* unpacks internal data */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* non-zero if that extension cannot be overridden by the applications.
|
|
Packit Service |
4684c1 |
* That should be set to extensions which allocate data early, e.g., on
|
|
Packit Service |
4684c1 |
* gnutls_init(), or modify the TLS protocol in a way that the application
|
|
Packit Service |
4684c1 |
* cannot control. */
|
|
Packit Service |
4684c1 |
unsigned cannot_be_overriden;
|
|
Packit Service |
4684c1 |
} hello_ext_entry_st;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Checks if the extension @id provided has been requested
|
|
Packit Service |
4684c1 |
* by us (in client side).In server side it checks whether this
|
|
Packit Service |
4684c1 |
* extension was advertized by the client.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* It returns non-zero for true, otherwise zero.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
inline static unsigned
|
|
Packit Service |
4684c1 |
_gnutls_hello_ext_is_present(gnutls_session_t session, extensions_t id)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (session->internals.used_exts & ((ext_track_t)1 << id))
|
|
Packit Service |
4684c1 |
return 1;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Adds the extension we want to send in the extensions list.
|
|
Packit Service |
4684c1 |
* This list is used in client side to check whether the (later) received
|
|
Packit Service |
4684c1 |
* extensions are the ones we requested.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* In server side, this list is used to ensure we don't send
|
|
Packit Service |
4684c1 |
* extensions that we didn't receive a corresponding value.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Returns zero if failed, non-zero on success.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
inline static
|
|
Packit Service |
4684c1 |
unsigned _gnutls_hello_ext_save(gnutls_session_t session,
|
|
Packit Service |
4684c1 |
extensions_t id,
|
|
Packit Service |
4684c1 |
unsigned check_dup)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
if (check_dup && _gnutls_hello_ext_is_present(session, id)) {
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
session->internals.used_exts |= ((ext_track_t)1 << id);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 1;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static
|
|
Packit Service |
4684c1 |
void _gnutls_hello_ext_save_sr(gnutls_session_t session)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
_gnutls_hello_ext_save(session, GNUTLS_EXTENSION_SAFE_RENEGOTIATION, 1);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif /* GNUTLS_LIB_HELLO_EXT_H */
|