|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* Copyright (C) 2000-2016 Free Software Foundation, Inc.
|
|
Packit |
aea12f |
* Copyright (C) 2015-2018 Red Hat, Inc.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Author: Nikos Mavrogiannopoulos
|
|
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 |
#ifndef GNUTLS_LIB_GNUTLS_INT_H
|
|
Packit |
aea12f |
#define GNUTLS_LIB_GNUTLS_INT_H
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#ifdef HAVE_CONFIG_H
|
|
Packit |
aea12f |
#include <config.h>
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <stddef.h>
|
|
Packit |
aea12f |
#include <string.h>
|
|
Packit |
aea12f |
#include <stdlib.h>
|
|
Packit |
aea12f |
#include <stdio.h>
|
|
Packit |
aea12f |
#include <ctype.h>
|
|
Packit |
aea12f |
#include <limits.h>
|
|
Packit |
aea12f |
#include <stdint.h>
|
|
Packit |
aea12f |
#include <stdbool.h>
|
|
Packit |
aea12f |
#include <assert.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#ifdef NO_SSIZE_T
|
|
Packit |
aea12f |
#define HAVE_SSIZE_T
|
|
Packit |
aea12f |
typedef int ssize_t;
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <sys/types.h>
|
|
Packit |
aea12f |
#include <unistd.h>
|
|
Packit |
aea12f |
#include <sys/stat.h>
|
|
Packit |
aea12f |
#if HAVE_SYS_SOCKET_H
|
|
Packit |
aea12f |
#include <sys/socket.h>
|
|
Packit |
aea12f |
#elif HAVE_WS2TCPIP_H
|
|
Packit |
aea12f |
#include <ws2tcpip.h>
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
#include <time.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <nettle/memxor.h>
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#include "attribute.h"
|
|
Packit Service |
991b93 |
|
|
Packit |
aea12f |
#define ENABLE_ALIGN16
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#ifdef __clang_major
|
|
Packit Service |
991b93 |
# define _GNUTLS_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
|
|
Packit Service |
991b93 |
#else
|
|
Packit Service |
991b93 |
# define _GNUTLS_CLANG_VERSION 0
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
/* clang also defines __GNUC__. It promotes a GCC version of 4.2.1. */
|
|
Packit Service |
991b93 |
#ifdef __GNUC__
|
|
Packit Service |
991b93 |
# define _GNUTLS_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#if _GNUTLS_GCC_VERSION >= 30100
|
|
Packit Service |
991b93 |
# define likely(x) __builtin_expect((x), 1)
|
|
Packit Service |
991b93 |
# define unlikely(x) __builtin_expect((x), 0)
|
|
Packit Service |
991b93 |
#else
|
|
Packit Service |
991b93 |
# define likely
|
|
Packit Service |
991b93 |
# define unlikely
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <gnutls/gnutls.h>
|
|
Packit |
aea12f |
#include <gnutls/dtls.h>
|
|
Packit |
aea12f |
#include <gnutls/abstract.h>
|
|
Packit |
aea12f |
#include <gnutls/socket.h>
|
|
Packit |
aea12f |
#include <system.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* in case we compile with system headers taking priority, we
|
|
Packit |
aea12f |
* make sure that some new attributes are still available.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#ifndef __GNUTLS_CONST__
|
|
Packit |
aea12f |
# define __GNUTLS_CONST__
|
|
Packit |
aea12f |
#endif
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The size of a handshake message should not
|
|
Packit |
aea12f |
* be larger than this value.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define MAX_HANDSHAKE_PACKET_SIZE 128*1024
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define GNUTLS_DEF_SESSION_ID_SIZE 32
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The maximum digest size of hash algorithms.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define MAX_FILENAME 512
|
|
Packit |
aea12f |
#define MAX_HASH_SIZE 64
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MAX_MAC_KEY_SIZE 64
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MAX_CIPHER_BLOCK_SIZE 64 /* CHACHA20 */
|
|
Packit |
aea12f |
#define MAX_CIPHER_KEY_SIZE 32
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MAX_CIPHER_IV_SIZE 16
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MAX_USERNAME_SIZE 128
|
|
Packit |
aea12f |
#define MAX_SERVER_NAME_SIZE 256
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define AEAD_EXPLICIT_DATA_SIZE 8
|
|
Packit |
aea12f |
#define AEAD_IMPLICIT_DATA_SIZE 4
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define GNUTLS_MASTER_SIZE 48
|
|
Packit |
aea12f |
#define GNUTLS_RANDOM_SIZE 32
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Under TLS1.3 a hello retry request is sent as server hello */
|
|
Packit |
aea12f |
#define REAL_HSK_TYPE(t) ((t)==GNUTLS_HANDSHAKE_HELLO_RETRY_REQUEST?GNUTLS_HANDSHAKE_SERVER_HELLO:t)
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* DTLS */
|
|
Packit |
aea12f |
#define DTLS_RETRANS_TIMEOUT 1000
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* TLS Extensions */
|
|
Packit |
aea12f |
/* we can receive up to MAX_EXT_TYPES extensions.
|
|
Packit |
aea12f |
*/
|
|
Packit Service |
991b93 |
#define MAX_EXT_TYPES 64
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* TLS-internal extension (will be parsed after a ciphersuite is selected).
|
|
Packit |
aea12f |
* This amends the gnutls_ext_parse_type_t. Not exported yet to allow more refining
|
|
Packit |
aea12f |
* prior to finalizing an API. */
|
|
Packit |
aea12f |
#define _GNUTLS_EXT_TLS_POST_CS 177
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* expire time for resuming sessions */
|
|
Packit |
aea12f |
#define DEFAULT_EXPIRE_TIME 21600
|
|
Packit |
aea12f |
#define STEK_ROTATION_PERIOD_PRODUCT 3
|
|
Packit |
aea12f |
#define DEFAULT_HANDSHAKE_TIMEOUT_MS 40*1000
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The EC group to be used when the extension
|
|
Packit |
aea12f |
* supported groups/curves is not present */
|
|
Packit |
aea12f |
#define DEFAULT_EC_GROUP GNUTLS_GROUP_SECP256R1
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum transport_t {
|
|
Packit |
aea12f |
GNUTLS_STREAM,
|
|
Packit |
aea12f |
GNUTLS_DGRAM
|
|
Packit |
aea12f |
} transport_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The TLS 1.3 stage of handshake */
|
|
Packit |
aea12f |
typedef enum hs_stage_t {
|
|
Packit |
aea12f |
STAGE_HS,
|
|
Packit |
aea12f |
STAGE_APP,
|
|
Packit |
aea12f |
STAGE_UPD_OURS,
|
|
Packit |
aea12f |
STAGE_UPD_PEERS,
|
|
Packit |
aea12f |
STAGE_EARLY
|
|
Packit |
aea12f |
} hs_stage_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum record_send_state_t {
|
|
Packit |
aea12f |
RECORD_SEND_NORMAL = 0,
|
|
Packit |
aea12f |
RECORD_SEND_CORKED, /* corked and transition to NORMAL afterwards */
|
|
Packit |
aea12f |
RECORD_SEND_CORKED_TO_KU, /* corked but must transition to RECORD_SEND_KEY_UPDATE_1 */
|
|
Packit |
aea12f |
RECORD_SEND_KEY_UPDATE_1,
|
|
Packit |
aea12f |
RECORD_SEND_KEY_UPDATE_2,
|
|
Packit |
aea12f |
RECORD_SEND_KEY_UPDATE_3
|
|
Packit |
aea12f |
} record_send_state_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The mode check occurs a lot throughout GnuTLS and can be replaced by
|
|
Packit |
aea12f |
* the following shorter macro. Also easier to update one macro
|
|
Packit |
aea12f |
* in the future when the internal structure changes than all the conditionals
|
|
Packit |
aea12f |
* itself.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define IS_SERVER(session) (session->security_parameters.entity == GNUTLS_SERVER)
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* To check whether we have a DTLS session */
|
|
Packit |
aea12f |
#define IS_DTLS(session) (session->internals.transport == GNUTLS_DGRAM)
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the maximum size of encrypted packets */
|
|
Packit |
aea12f |
#define DEFAULT_MAX_RECORD_SIZE 16384
|
|
Packit |
aea12f |
#define DEFAULT_MAX_EARLY_DATA_SIZE 16384
|
|
Packit |
aea12f |
#define TLS_RECORD_HEADER_SIZE 5
|
|
Packit |
aea12f |
#define DTLS_RECORD_HEADER_SIZE (TLS_RECORD_HEADER_SIZE+8)
|
|
Packit |
aea12f |
#define RECORD_HEADER_SIZE(session) (IS_DTLS(session) ? DTLS_RECORD_HEADER_SIZE : TLS_RECORD_HEADER_SIZE)
|
|
Packit |
aea12f |
#define MAX_RECORD_HEADER_SIZE DTLS_RECORD_HEADER_SIZE
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MIN_RECORD_SIZE 512
|
|
Packit |
aea12f |
#define MIN_RECORD_SIZE_SMALL 64
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The following macro is used to calculate the overhead when sending.
|
|
Packit |
aea12f |
* when receiving we use a different way as there are implementations that
|
|
Packit |
aea12f |
* store more data than allowed.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define MAX_RECORD_SEND_OVERHEAD(session) (MAX_CIPHER_BLOCK_SIZE/*iv*/+MAX_PAD_SIZE+MAX_HASH_SIZE/*MAC*/)
|
|
Packit |
aea12f |
#define MAX_RECORD_SEND_SIZE(session) (IS_DTLS(session)? \
|
|
Packit |
aea12f |
(MIN((size_t)gnutls_dtls_get_mtu(session), (size_t)session->security_parameters.max_record_send_size+MAX_RECORD_SEND_OVERHEAD(session))): \
|
|
Packit |
aea12f |
((size_t)session->security_parameters.max_record_send_size+MAX_RECORD_SEND_OVERHEAD(session)))
|
|
Packit |
aea12f |
#define MAX_PAD_SIZE 255
|
|
Packit |
aea12f |
#define EXTRA_COMP_SIZE 2048
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define TLS_HANDSHAKE_HEADER_SIZE 4
|
|
Packit |
aea12f |
#define DTLS_HANDSHAKE_HEADER_SIZE (TLS_HANDSHAKE_HEADER_SIZE+8)
|
|
Packit |
aea12f |
#define HANDSHAKE_HEADER_SIZE(session) (IS_DTLS(session) ? DTLS_HANDSHAKE_HEADER_SIZE : TLS_HANDSHAKE_HEADER_SIZE)
|
|
Packit |
aea12f |
#define MAX_HANDSHAKE_HEADER_SIZE DTLS_HANDSHAKE_HEADER_SIZE
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Maximum seed size for provable parameters */
|
|
Packit |
aea12f |
#define MAX_PVP_SEED_SIZE 256
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This is the maximum handshake message size we send without
|
|
Packit |
aea12f |
fragmentation. This currently ignores record layer overhead. */
|
|
Packit |
aea12f |
#define DTLS_DEFAULT_MTU 1200
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the maximum size of the DTLS cookie */
|
|
Packit |
aea12f |
#define DTLS_MAX_COOKIE_SIZE 32
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The maximum number of HELLO_VERIFY_REQUEST messages the client
|
|
Packit |
aea12f |
processes before aborting. */
|
|
Packit |
aea12f |
#define MAX_HANDSHAKE_HELLO_VERIFY_REQUESTS 5
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MAX_PK_PARAM_SIZE 2048
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* defaults for verification functions
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define DEFAULT_MAX_VERIFY_DEPTH 16
|
|
Packit |
aea12f |
#define DEFAULT_MAX_VERIFY_BITS (MAX_PK_PARAM_SIZE*8)
|
|
Packit |
aea12f |
#define MAX_VERIFY_DEPTH 4096
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <mem.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MEMSUB(x,y) ((ssize_t)((ptrdiff_t)x-(ptrdiff_t)y))
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#define DECR_LEN(len, x) DECR_LENGTH_RET(len, x, GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
|
|
Packit |
aea12f |
#define DECR_LEN_FINAL(len, x) do { \
|
|
Packit Service |
991b93 |
if (len != x) \
|
|
Packit |
aea12f |
return gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET_LENGTH); \
|
|
Packit Service |
991b93 |
else \
|
|
Packit Service |
991b93 |
len = 0; \
|
|
Packit |
aea12f |
} while (0)
|
|
Packit Service |
991b93 |
#define DECR_LENGTH_RET(len, x, RET) DECR_LENGTH_COM(len, x, return RET)
|
|
Packit Service |
991b93 |
#define DECR_LENGTH_COM(len, x, COM) do { if (len
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define GNUTLS_POINTER_TO_INT(_) ((int) GNUTLS_POINTER_TO_INT_CAST (_))
|
|
Packit |
aea12f |
#define GNUTLS_INT_TO_POINTER(_) ((void*) GNUTLS_POINTER_TO_INT_CAST (_))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define GNUTLS_KX_INVALID (-1)
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <mpi.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum handshake_state_t { STATE0 = 0, STATE1, STATE2,
|
|
Packit |
aea12f |
STATE3, STATE4, STATE5, STATE6, STATE7, STATE8,
|
|
Packit |
aea12f |
STATE9, STATE10, STATE11, STATE12, STATE13, STATE14,
|
|
Packit |
aea12f |
STATE15, STATE16, STATE17, STATE18, STATE19,
|
|
Packit |
aea12f |
STATE20 = 20, STATE21, STATE22,
|
|
Packit |
aea12f |
STATE30 = 30, STATE31, STATE40 = 40, STATE41, STATE50 = 50,
|
|
Packit |
aea12f |
STATE90=90, STATE91, STATE92, STATE93, STATE94, STATE99=99,
|
|
Packit |
aea12f |
STATE100=100, STATE101, STATE102, STATE103, STATE104,
|
|
Packit |
aea12f |
STATE105, STATE106, STATE107, STATE108, STATE109, STATE110,
|
|
Packit |
aea12f |
STATE111, STATE112, STATE113, STATE114, STATE115,
|
|
Packit |
aea12f |
STATE150 /* key update */
|
|
Packit |
aea12f |
} handshake_state_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum bye_state_t {
|
|
Packit |
aea12f |
BYE_STATE0 = 0, BYE_STATE1, BYE_STATE2
|
|
Packit |
aea12f |
} bye_state_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum send_ticket_state_t {
|
|
Packit |
aea12f |
TICKET_STATE0 = 0, TICKET_STATE1
|
|
Packit |
aea12f |
} send_ticket_state_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum reauth_state_t {
|
|
Packit |
aea12f |
REAUTH_STATE0 = 0, REAUTH_STATE1, REAUTH_STATE2, REAUTH_STATE3,
|
|
Packit |
aea12f |
REAUTH_STATE4, REAUTH_STATE5
|
|
Packit |
aea12f |
} reauth_state_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define TICKET_STATE session->internals.ticket_state
|
|
Packit |
aea12f |
#define BYE_STATE session->internals.bye_state
|
|
Packit |
aea12f |
#define REAUTH_STATE session->internals.reauth_state
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum heartbeat_state_t {
|
|
Packit |
aea12f |
SHB_SEND1 = 0,
|
|
Packit |
aea12f |
SHB_SEND2,
|
|
Packit |
aea12f |
SHB_RECV
|
|
Packit |
aea12f |
} heartbeat_state_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum recv_state_t {
|
|
Packit |
aea12f |
RECV_STATE_0 = 0,
|
|
Packit |
aea12f |
RECV_STATE_DTLS_RETRANSMIT,
|
|
Packit |
aea12f |
/* client-side false start state */
|
|
Packit |
aea12f |
RECV_STATE_FALSE_START_HANDLING, /* we are calling gnutls_handshake() within record_recv() */
|
|
Packit |
aea12f |
RECV_STATE_FALSE_START, /* gnutls_record_recv() should complete the handshake */
|
|
Packit |
aea12f |
/* async handshake msg state */
|
|
Packit |
aea12f |
RECV_STATE_ASYNC_HANDSHAKE, /* an incomplete async handshake message was seen */
|
|
Packit |
aea12f |
/* server-side early start under TLS1.3; enabled when no client cert is received */
|
|
Packit |
aea12f |
RECV_STATE_EARLY_START_HANDLING, /* we are calling gnutls_handshake() within record_recv() */
|
|
Packit |
aea12f |
RECV_STATE_EARLY_START, /* gnutls_record_recv() should complete the handshake */
|
|
Packit |
aea12f |
RECV_STATE_REHANDSHAKE, /* gnutls_record_recv() should complete any incoming re-handshake requests */
|
|
Packit |
aea12f |
RECV_STATE_REAUTH /* gnutls_record_recv() should complete any incoming reauthentication requests */
|
|
Packit |
aea12f |
} recv_state_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include "str.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This is the maximum number of algorithms (ciphers or macs etc).
|
|
Packit |
aea12f |
* keep it synced with GNUTLS_MAX_ALGORITHM_NUM in gnutls.h
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define MAX_ALGOS GNUTLS_MAX_ALGORITHM_NUM
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* IDs are allocated in a way that all values fit in 64-bit integer as (1<
|
|
Packit |
aea12f |
typedef enum extensions_t {
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_INVALID = 0xffff,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_STATUS_REQUEST = 0,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_CERT_TYPE,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_CLIENT_CERT_TYPE,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SERVER_CERT_TYPE,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SUPPORTED_GROUPS,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SUPPORTED_EC_POINT_FORMATS,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SRP,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SIGNATURE_ALGORITHMS,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SRTP,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_HEARTBEAT,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_ALPN,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_ETM,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_EXT_MASTER_SECRET,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SESSION_TICKET,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_KEY_SHARE,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SUPPORTED_VERSIONS,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_POST_HANDSHAKE,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_SERVER_NAME,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_COOKIE,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_EARLY_DATA,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_PSK_KE_MODES,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_RECORD_SIZE_LIMIT,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_MAX_RECORD_SIZE,
|
|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* pre_shared_key and dumbfw must always be the last extensions,
|
|
Packit |
aea12f |
* in that order */
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_DUMBFW,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_PRE_SHARED_KEY,
|
|
Packit |
aea12f |
GNUTLS_EXTENSION_MAX /* not real extension - used for iterators */
|
|
Packit |
aea12f |
} extensions_t;
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#define GNUTLS_EXTENSION_MAX_VALUE 63
|
|
Packit Service |
991b93 |
#define ext_track_t uint64_t
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#include <verify.h>
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
verify(GNUTLS_EXTENSION_MAX < GNUTLS_EXTENSION_MAX_VALUE);
|
|
Packit Service |
991b93 |
verify(GNUTLS_EXTENSION_MAX < MAX_EXT_TYPES);
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
/* we must provide at least 16 extensions for users to register;
|
|
Packit Service |
991b93 |
* increase GNUTLS_EXTENSION_MAX_VALUE, MAX_EXT_TYPES and used_exts
|
|
Packit Service |
991b93 |
* type if this fails
|
|
Packit Service |
991b93 |
*/
|
|
Packit Service |
991b93 |
verify(GNUTLS_EXTENSION_MAX_VALUE - GNUTLS_EXTENSION_MAX >= 16);
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
/* The 'verify' symbol from <verify.h> is used extensively in the
|
|
Packit Service |
991b93 |
* code; undef it to avoid clash
|
|
Packit Service |
991b93 |
*/
|
|
Packit Service |
991b93 |
#undef verify
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum { CIPHER_STREAM, CIPHER_BLOCK, CIPHER_AEAD } cipher_type_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define RESUME_TRUE 1
|
|
Packit |
aea12f |
#define RESUME_FALSE 0
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Record Protocol */
|
|
Packit |
aea12f |
typedef enum content_type_t {
|
|
Packit |
aea12f |
GNUTLS_CHANGE_CIPHER_SPEC = 20, GNUTLS_ALERT,
|
|
Packit |
aea12f |
GNUTLS_HANDSHAKE, GNUTLS_APPLICATION_DATA,
|
|
Packit |
aea12f |
GNUTLS_HEARTBEAT
|
|
Packit |
aea12f |
} content_type_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define GNUTLS_PK_ANY (gnutls_pk_algorithm_t)-1
|
|
Packit |
aea12f |
#define GNUTLS_PK_NONE (gnutls_pk_algorithm_t)-2
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define GNUTLS_PK_IS_RSA(pk) ((pk) == GNUTLS_PK_RSA || (pk) == GNUTLS_PK_RSA_PSS)
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Message buffers (mbuffers) structures */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* this is actually the maximum number of distinct handshake
|
|
Packit |
aea12f |
* messages that can arrive in a single flight
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define MAX_HANDSHAKE_MSGS 6
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
/* Handshake layer type and sequence of message */
|
|
Packit |
aea12f |
gnutls_handshake_description_t htype;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The "real" type received; that is, it does not distinguish
|
|
Packit |
aea12f |
* HRR from server hello, while htype does */
|
|
Packit |
aea12f |
gnutls_handshake_description_t rtype;
|
|
Packit |
aea12f |
uint32_t length;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* valid in DTLS */
|
|
Packit |
aea12f |
uint16_t sequence;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* indicate whether that message is complete.
|
|
Packit |
aea12f |
* complete means start_offset == 0 and end_offset == length
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
uint32_t start_offset;
|
|
Packit |
aea12f |
uint32_t end_offset;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
uint8_t header[MAX_HANDSHAKE_HEADER_SIZE];
|
|
Packit |
aea12f |
int header_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_buffer_st data;
|
|
Packit |
aea12f |
} handshake_buffer_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct mbuffer_st {
|
|
Packit |
aea12f |
/* when used in mbuffer_head_st */
|
|
Packit |
aea12f |
struct mbuffer_st *next;
|
|
Packit |
aea12f |
struct mbuffer_st *prev;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* msg->size - mark = number of bytes left to process in this
|
|
Packit |
aea12f |
message. Mark should only be non-zero when this buffer is the
|
|
Packit |
aea12f |
head of the queue. */
|
|
Packit |
aea12f |
size_t mark;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the data */
|
|
Packit |
aea12f |
gnutls_datum_t msg;
|
|
Packit |
aea12f |
size_t maximum_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* used during fill in, to separate header from data
|
|
Packit |
aea12f |
* body. */
|
|
Packit |
aea12f |
unsigned int uhead_mark;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Filled in by record layer on recv:
|
|
Packit |
aea12f |
* type, record_sequence
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* record layer content type */
|
|
Packit |
aea12f |
content_type_t type;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* record layer sequence */
|
|
Packit Service |
991b93 |
uint64_t record_sequence;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Filled in by handshake layer on send:
|
|
Packit |
aea12f |
* type, epoch, htype, handshake_sequence
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Record layer epoch of message */
|
|
Packit |
aea12f |
uint16_t epoch;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Handshake layer type and sequence of message */
|
|
Packit |
aea12f |
gnutls_handshake_description_t htype;
|
|
Packit |
aea12f |
uint16_t handshake_sequence;
|
|
Packit |
aea12f |
} mbuffer_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct mbuffer_head_st {
|
|
Packit |
aea12f |
mbuffer_st *head;
|
|
Packit |
aea12f |
mbuffer_st *tail;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
unsigned int length;
|
|
Packit |
aea12f |
size_t byte_length;
|
|
Packit |
aea12f |
} mbuffer_head_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Store & Retrieve functions defines:
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct auth_cred_st {
|
|
Packit |
aea12f |
gnutls_credentials_type_t algorithm;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the type of credentials depends on algorithm
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
void *credentials;
|
|
Packit |
aea12f |
struct auth_cred_st *next;
|
|
Packit |
aea12f |
} auth_cred_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* session ticket definitions */
|
|
Packit |
aea12f |
#define TICKET_MASTER_KEY_SIZE (TICKET_KEY_NAME_SIZE+TICKET_CIPHER_KEY_SIZE+TICKET_MAC_SECRET_SIZE)
|
|
Packit |
aea12f |
#define TICKET_KEY_NAME_SIZE 16
|
|
Packit |
aea12f |
#define TICKET_CIPHER_KEY_SIZE 32
|
|
Packit |
aea12f |
#define TICKET_MAC_SECRET_SIZE 16
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* These are restricted by TICKET_CIPHER_KEY_SIZE and TICKET_MAC_SECRET_SIZE */
|
|
Packit |
aea12f |
#define TICKET_CIPHER GNUTLS_CIPHER_AES_256_CBC
|
|
Packit |
aea12f |
#define TICKET_IV_SIZE 16
|
|
Packit |
aea12f |
#define TICKET_BLOCK_SIZE 16
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define TICKET_MAC_ALGO GNUTLS_MAC_SHA1
|
|
Packit |
aea12f |
#define TICKET_MAC_SIZE 20 /* HMAC-SHA1 */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct ticket_st {
|
|
Packit |
aea12f |
uint8_t key_name[TICKET_KEY_NAME_SIZE];
|
|
Packit |
aea12f |
uint8_t IV[TICKET_IV_SIZE];
|
|
Packit |
aea12f |
uint8_t *encrypted_state;
|
|
Packit |
aea12f |
uint16_t encrypted_state_len;
|
|
Packit |
aea12f |
uint8_t mac[TICKET_MAC_SIZE];
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct binder_data_st {
|
|
Packit |
aea12f |
const struct mac_entry_st *prf; /* non-null if this struct is set */
|
|
Packit |
aea12f |
gnutls_datum_t psk;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* 0-based index of the selected PSK.
|
|
Packit |
aea12f |
* This only applies if the HSK_PSK_SELECTED flag is set in internals.hsk_flags,
|
|
Packit |
aea12f |
* which signals a PSK has indeed been selected. */
|
|
Packit |
aea12f |
uint8_t idx;
|
|
Packit |
aea12f |
uint8_t resumption; /* whether it is a resumption binder */
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef void (* gnutls_stek_rotation_callback_t) (const gnutls_datum_t *prev_key,
|
|
Packit |
aea12f |
const gnutls_datum_t *new_key,
|
|
Packit |
aea12f |
uint64_t t);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct gnutls_key_st {
|
|
Packit |
aea12f |
struct { /* These are kept outside the TLS1.3 union as they are
|
|
Packit |
aea12f |
* negotiated via extension, even before protocol is negotiated */
|
|
Packit |
aea12f |
gnutls_pk_params_st ecdh_params;
|
|
Packit |
aea12f |
gnutls_pk_params_st ecdhx_params;
|
|
Packit |
aea12f |
gnutls_pk_params_st dh_params;
|
|
Packit |
aea12f |
} kshare;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The union contents depend on the negotiated protocol.
|
|
Packit |
aea12f |
* It should not contain any values which are allocated
|
|
Packit |
aea12f |
* prior to protocol negotiation, as it would be impossible
|
|
Packit |
aea12f |
* to deinitialize.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
union {
|
|
Packit |
aea12f |
struct {
|
|
Packit |
aea12f |
/* the current (depending on state) secret, can be
|
|
Packit |
aea12f |
* early_secret, client_early_traffic_secret, ... */
|
|
Packit |
aea12f |
uint8_t temp_secret[MAX_HASH_SIZE];
|
|
Packit |
aea12f |
unsigned temp_secret_size; /* depends on negotiated PRF size */
|
|
Packit |
aea12f |
uint8_t e_ckey[MAX_HASH_SIZE]; /* client_early_traffic_secret */
|
|
Packit |
aea12f |
uint8_t hs_ckey[MAX_HASH_SIZE]; /* client_hs_traffic_secret */
|
|
Packit |
aea12f |
uint8_t hs_skey[MAX_HASH_SIZE]; /* server_hs_traffic_secret */
|
|
Packit |
aea12f |
uint8_t ap_ckey[MAX_HASH_SIZE]; /* client_ap_traffic_secret */
|
|
Packit |
aea12f |
uint8_t ap_skey[MAX_HASH_SIZE]; /* server_ap_traffic_secret */
|
|
Packit |
aea12f |
uint8_t ap_expkey[MAX_HASH_SIZE]; /* {early_,}exporter_master_secret */
|
|
Packit |
aea12f |
uint8_t ap_rms[MAX_HASH_SIZE]; /* resumption_master_secret */
|
|
Packit |
aea12f |
} tls13; /* tls1.3 */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Folow the SSL3.0 and TLS1.2 key exchanges */
|
|
Packit |
aea12f |
struct {
|
|
Packit |
aea12f |
/* For ECDH KX */
|
|
Packit |
aea12f |
struct {
|
|
Packit |
aea12f |
gnutls_pk_params_st params; /* private part */
|
|
Packit |
aea12f |
/* public part */
|
|
Packit |
aea12f |
bigint_t x;
|
|
Packit |
aea12f |
bigint_t y;
|
|
Packit |
aea12f |
gnutls_datum_t raw; /* public key used in ECDHX (point) */
|
|
Packit |
aea12f |
} ecdh;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* For DH KX */
|
|
Packit |
aea12f |
struct {
|
|
Packit |
aea12f |
gnutls_pk_params_st params;
|
|
Packit |
aea12f |
bigint_t client_Y;
|
|
Packit |
aea12f |
} dh;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* for SRP KX */
|
|
Packit |
aea12f |
struct {
|
|
Packit |
aea12f |
bigint_t srp_key;
|
|
Packit |
aea12f |
bigint_t srp_g;
|
|
Packit |
aea12f |
bigint_t srp_p;
|
|
Packit |
aea12f |
bigint_t A;
|
|
Packit |
aea12f |
bigint_t B;
|
|
Packit |
aea12f |
bigint_t u;
|
|
Packit |
aea12f |
bigint_t b;
|
|
Packit |
aea12f |
bigint_t a;
|
|
Packit |
aea12f |
bigint_t x;
|
|
Packit |
aea12f |
} srp;
|
|
Packit |
aea12f |
} tls12; /* from ssl3.0 to tls12 */
|
|
Packit |
aea12f |
} proto;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* binders / pre-shared keys in use; temporary storage.
|
|
Packit |
aea12f |
* On client side it will hold data for the resumption and external
|
|
Packit |
aea12f |
* PSKs After server hello is received the selected binder is set on 0 position
|
|
Packit |
aea12f |
* and HSK_PSK_SELECTED is set.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* On server side the first value is populated with
|
|
Packit |
aea12f |
* the selected PSK data if HSK_PSK_SELECTED flag is set. */
|
|
Packit |
aea12f |
struct binder_data_st binders[2];
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* TLS pre-master key; applies to 1.2 and 1.3 */
|
|
Packit |
aea12f |
gnutls_datum_t key;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
uint8_t
|
|
Packit |
aea12f |
/* The key to encrypt and decrypt session tickets */
|
|
Packit |
aea12f |
session_ticket_key[TICKET_MASTER_KEY_SIZE],
|
|
Packit |
aea12f |
/* Static buffer for the previous key, whenever we need it */
|
|
Packit |
aea12f |
previous_ticket_key[TICKET_MASTER_KEY_SIZE],
|
|
Packit |
aea12f |
/* Initial key supplied by the caller */
|
|
Packit |
aea12f |
initial_stek[TICKET_MASTER_KEY_SIZE];
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* this is used to hold the peers authentication data
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
/* auth_info_t structures SHOULD NOT contain malloced
|
|
Packit |
aea12f |
* elements. Check gnutls_session_pack.c, and gnutls_auth.c.
|
|
Packit |
aea12f |
* Remember that this should be calloced!
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
void *auth_info;
|
|
Packit |
aea12f |
gnutls_credentials_type_t auth_info_type;
|
|
Packit |
aea12f |
int auth_info_size; /* needed in order to store to db for restoring
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
auth_cred_st *cred; /* used to specify keys/certificates etc */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct {
|
|
Packit |
aea12f |
uint64_t last_result;
|
|
Packit |
aea12f |
uint8_t was_rotated;
|
|
Packit |
aea12f |
gnutls_stek_rotation_callback_t cb;
|
|
Packit |
aea12f |
} totp;
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct gnutls_key_st gnutls_key_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct pin_info_st {
|
|
Packit |
aea12f |
gnutls_pin_callback_t cb;
|
|
Packit |
aea12f |
void *data;
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct record_state_st;
|
|
Packit |
aea12f |
typedef struct record_state_st record_state_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct record_parameters_st;
|
|
Packit |
aea12f |
typedef struct record_parameters_st record_parameters_st;
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#define GNUTLS_CIPHER_FLAG_ONLY_AEAD (1 << 0) /* When set, this cipher is only available through the new AEAD API */
|
|
Packit Service |
991b93 |
#define GNUTLS_CIPHER_FLAG_XOR_NONCE (1 << 1) /* In this TLS AEAD cipher xor the implicit_iv with the nonce */
|
|
Packit Service |
991b93 |
#define GNUTLS_CIPHER_FLAG_NO_REKEY (1 << 2) /* whether this tls1.3 cipher doesn't need to rekey after 2^24 messages */
|
|
Packit Service |
991b93 |
|
|
Packit |
aea12f |
/* cipher and mac parameters */
|
|
Packit |
aea12f |
typedef struct cipher_entry_st {
|
|
Packit |
aea12f |
const char *name;
|
|
Packit |
aea12f |
gnutls_cipher_algorithm_t id;
|
|
Packit |
aea12f |
uint16_t blocksize;
|
|
Packit |
aea12f |
uint16_t keysize;
|
|
Packit |
aea12f |
cipher_type_t type;
|
|
Packit |
aea12f |
uint16_t implicit_iv; /* the size of implicit IV - the IV generated but not sent */
|
|
Packit |
aea12f |
uint16_t explicit_iv; /* the size of explicit IV - the IV stored in record */
|
|
Packit |
aea12f |
uint16_t cipher_iv; /* the size of IV needed by the cipher */
|
|
Packit |
aea12f |
uint16_t tagsize;
|
|
Packit Service |
991b93 |
unsigned flags;
|
|
Packit |
aea12f |
} cipher_entry_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct gnutls_cipher_suite_entry_st {
|
|
Packit |
aea12f |
const char *name;
|
|
Packit |
aea12f |
const uint8_t id[2];
|
|
Packit |
aea12f |
gnutls_cipher_algorithm_t block_algorithm;
|
|
Packit |
aea12f |
gnutls_kx_algorithm_t kx_algorithm;
|
|
Packit |
aea12f |
gnutls_mac_algorithm_t mac_algorithm;
|
|
Packit |
aea12f |
gnutls_protocol_t min_version; /* this cipher suite is supported
|
|
Packit |
aea12f |
* from 'version' and above;
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_protocol_t max_version; /* this cipher suite is not supported
|
|
Packit |
aea12f |
* after 'version' and above;
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_protocol_t min_dtls_version; /* DTLS min version */
|
|
Packit |
aea12f |
gnutls_protocol_t max_dtls_version; /* DTLS max version */
|
|
Packit |
aea12f |
gnutls_mac_algorithm_t prf;
|
|
Packit |
aea12f |
} gnutls_cipher_suite_entry_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct gnutls_group_entry_st {
|
|
Packit |
aea12f |
const char *name;
|
|
Packit |
aea12f |
gnutls_group_t id;
|
|
Packit |
aea12f |
const gnutls_datum_t *prime;
|
|
Packit |
aea12f |
const gnutls_datum_t *q;
|
|
Packit |
aea12f |
const gnutls_datum_t *generator;
|
|
Packit |
aea12f |
const unsigned *q_bits;
|
|
Packit |
aea12f |
gnutls_ecc_curve_t curve;
|
|
Packit |
aea12f |
gnutls_pk_algorithm_t pk;
|
|
Packit |
aea12f |
unsigned tls_id; /* The RFC4492 namedCurve ID or TLS 1.3 group ID */
|
|
Packit |
aea12f |
} gnutls_group_entry_st;
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
#define GNUTLS_MAC_FLAG_PREIMAGE_INSECURE 1 /* if this algorithm should not be trusted for pre-image attacks */
|
|
Packit Service |
991b93 |
#define GNUTLS_MAC_FLAG_CONTINUOUS_MAC (1 << 1) /* if this MAC should be used in a 'continuous' way in TLS */
|
|
Packit |
aea12f |
/* This structure is used both for MACs and digests
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
typedef struct mac_entry_st {
|
|
Packit |
aea12f |
const char *name;
|
|
Packit |
aea12f |
const char *oid; /* OID of the hash - if it is a hash */
|
|
Packit |
aea12f |
const char *mac_oid; /* OID of the MAC algorithm - if it is a MAC */
|
|
Packit |
aea12f |
gnutls_mac_algorithm_t id;
|
|
Packit |
aea12f |
unsigned output_size;
|
|
Packit |
aea12f |
unsigned key_size;
|
|
Packit |
aea12f |
unsigned nonce_size;
|
|
Packit |
aea12f |
unsigned placeholder; /* if set, then not a real MAC */
|
|
Packit |
aea12f |
unsigned block_size; /* internal block size for HMAC */
|
|
Packit Service |
991b93 |
unsigned flags;
|
|
Packit |
aea12f |
} mac_entry_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
const char *name;
|
|
Packit |
aea12f |
gnutls_protocol_t id; /* gnutls internal version number */
|
|
Packit |
aea12f |
unsigned age; /* internal ordering by protocol age */
|
|
Packit |
aea12f |
uint8_t major; /* defined by the protocol */
|
|
Packit |
aea12f |
uint8_t minor; /* defined by the protocol */
|
|
Packit |
aea12f |
transport_t transport; /* Type of transport, stream or datagram */
|
|
Packit |
aea12f |
bool supported; /* 0 not supported, > 0 is supported */
|
|
Packit |
aea12f |
bool explicit_iv;
|
|
Packit |
aea12f |
bool extensions; /* whether it supports extensions */
|
|
Packit |
aea12f |
bool selectable_sighash; /* whether signatures can be selected */
|
|
Packit |
aea12f |
bool selectable_prf; /* whether the PRF is ciphersuite-defined */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* if SSL3 is disabled this flag indicates that this protocol is a placeholder,
|
|
Packit |
aea12f |
* otherwise it prevents this protocol from being set as record version */
|
|
Packit |
aea12f |
bool obsolete;
|
|
Packit |
aea12f |
bool tls13_sem; /* The TLS 1.3 handshake semantics */
|
|
Packit |
aea12f |
bool false_start; /* That version can be used with false start */
|
|
Packit |
aea12f |
bool only_extension; /* negotiated only with an extension */
|
|
Packit |
aea12f |
bool post_handshake_auth; /* Supports the TLS 1.3 post handshake auth */
|
|
Packit |
aea12f |
bool key_shares; /* TLS 1.3 key share key exchange */
|
|
Packit Service |
991b93 |
bool multi_ocsp; /* TLS 1.3 multiple OCSP responses */
|
|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* TLS versions modify the semantics of signature algorithms. This number
|
|
Packit |
aea12f |
* is there to distinguish signature algorithms semantics between versions
|
|
Packit |
aea12f |
* (maps to sign_algorithm_st->tls_sem)
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
uint8_t tls_sig_sem;
|
|
Packit |
aea12f |
} version_entry_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* STATE (cont) */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <hash_int.h>
|
|
Packit |
aea12f |
#include <cipher_int.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
uint8_t id[2]; /* used to be (in TLS 1.2) hash algorithm , PK algorithm */
|
|
Packit |
aea12f |
uint8_t tls_sem; /* should match the protocol version's tls_sig_sem. */
|
|
Packit |
aea12f |
} sign_algorithm_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This structure holds parameters got from TLS extension
|
|
Packit |
aea12f |
* mechanism. (some extensions may hold parameters in auth_info_t
|
|
Packit |
aea12f |
* structures also - see SRP).
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MAX_VERIFY_DATA_SIZE 36 /* in SSL 3.0, 12 in TLS 1.0 */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* auth_info_t structures now MAY contain malloced
|
|
Packit |
aea12f |
* elements.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This structure and auth_info_t, are stored in the resume database,
|
|
Packit |
aea12f |
* and are restored, in case of resume.
|
|
Packit |
aea12f |
* Holds all the required parameters to resume the current
|
|
Packit |
aea12f |
* session.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Note that the security parameters structure is set up after the
|
|
Packit |
aea12f |
* handshake has finished. The only value you may depend on while
|
|
Packit |
aea12f |
* the handshake is in progress is the cipher suite value.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
unsigned int entity; /* GNUTLS_SERVER or GNUTLS_CLIENT */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The epoch used to read and write */
|
|
Packit |
aea12f |
uint16_t epoch_read;
|
|
Packit |
aea12f |
uint16_t epoch_write;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The epoch that the next handshake will initialize. */
|
|
Packit |
aea12f |
uint16_t epoch_next;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The epoch at index 0 of record_parameters. */
|
|
Packit |
aea12f |
uint16_t epoch_min;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* this is the ciphersuite we are going to use
|
|
Packit |
aea12f |
* moved here from internals in order to be restored
|
|
Packit |
aea12f |
* on resume;
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
const struct gnutls_cipher_suite_entry_st *cs;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This is kept outside the ciphersuite entry as on certain
|
|
Packit |
aea12f |
* TLS versions we need a separate PRF MAC, i.e., MD5_SHA1. */
|
|
Packit |
aea12f |
const mac_entry_st *prf;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
uint8_t master_secret[GNUTLS_MASTER_SIZE];
|
|
Packit |
aea12f |
uint8_t client_random[GNUTLS_RANDOM_SIZE];
|
|
Packit |
aea12f |
uint8_t server_random[GNUTLS_RANDOM_SIZE];
|
|
Packit |
aea12f |
uint8_t session_id[GNUTLS_MAX_SESSION_ID_SIZE];
|
|
Packit |
aea12f |
uint8_t session_id_size;
|
|
Packit |
aea12f |
time_t timestamp;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* whether client has agreed in post handshake auth - only set on server side */
|
|
Packit |
aea12f |
uint8_t post_handshake_auth;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The maximum amount of plaintext sent in a record,
|
|
Packit |
aea12f |
* negotiated with the peer.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
uint16_t max_record_send_size;
|
|
Packit |
aea12f |
uint16_t max_record_recv_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The maximum amount of plaintext sent in a record, set by
|
|
Packit |
aea12f |
* the programmer.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
uint16_t max_user_record_send_size;
|
|
Packit |
aea12f |
uint16_t max_user_record_recv_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The maximum amount of early data */
|
|
Packit |
aea12f |
uint32_t max_early_data_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* holds the negotiated certificate types */
|
|
Packit |
aea12f |
gnutls_certificate_type_t client_ctype;
|
|
Packit |
aea12f |
gnutls_certificate_type_t server_ctype;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The selected (after server hello EC or DH group */
|
|
Packit |
aea12f |
const gnutls_group_entry_st *grp;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Holds the signature algorithm that will be used in this session,
|
|
Packit |
aea12f |
* selected by the server at the time of Ciphersuite/certificate
|
|
Packit |
aea12f |
* selection - see select_sign_algorithm() */
|
|
Packit |
aea12f |
gnutls_sign_algorithm_t server_sign_algo;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Holds the signature algorithm used in this session - If any */
|
|
Packit |
aea12f |
gnutls_sign_algorithm_t client_sign_algo;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Whether the master secret negotiation will be according to
|
|
Packit |
aea12f |
* draft-ietf-tls-session-hash-01
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
uint8_t ext_master_secret;
|
|
Packit |
aea12f |
/* encrypt-then-mac -> rfc7366 */
|
|
Packit |
aea12f |
uint8_t etm;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
uint8_t client_auth_type; /* gnutls_credentials_type_t */
|
|
Packit |
aea12f |
uint8_t server_auth_type;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Note: if you add anything in Security_Parameters struct, then
|
|
Packit |
aea12f |
* also modify CPY_COMMON in constate.c, and session_pack.c,
|
|
Packit |
aea12f |
* in order to save it in the session storage.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Used by extensions that enable supplemental data: Which ones
|
|
Packit |
aea12f |
* do that? Do they belong in security parameters?
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
int do_recv_supplemental, do_send_supplemental;
|
|
Packit |
aea12f |
const version_entry_st *pversion;
|
|
Packit |
aea12f |
} security_parameters_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct api_aead_cipher_hd_st {
|
|
Packit |
aea12f |
cipher_hd_st ctx_enc;
|
|
Packit |
aea12f |
} api_aead_cipher_hd_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct record_state_st {
|
|
Packit |
aea12f |
/* mac keys can be as long as the hash size */
|
|
Packit |
aea12f |
uint8_t mac_key[MAX_HASH_SIZE];
|
|
Packit |
aea12f |
unsigned mac_key_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
uint8_t iv[MAX_CIPHER_IV_SIZE];
|
|
Packit |
aea12f |
unsigned iv_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
uint8_t key[MAX_CIPHER_KEY_SIZE];
|
|
Packit |
aea12f |
unsigned key_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
union {
|
|
Packit |
aea12f |
auth_cipher_hd_st tls12;
|
|
Packit |
aea12f |
api_aead_cipher_hd_st aead;
|
|
Packit |
aea12f |
} ctx;
|
|
Packit |
aea12f |
unsigned aead_tag_size;
|
|
Packit |
aea12f |
unsigned is_aead;
|
|
Packit Service |
991b93 |
uint64_t sequence_number;
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* These are used to resolve relative epochs. These values are just
|
|
Packit |
aea12f |
outside the 16 bit range to prevent off-by-one errors. An absolute
|
|
Packit |
aea12f |
epoch may be referred to by its numeric id in the range
|
|
Packit |
aea12f |
0x0000-0xffff. */
|
|
Packit |
aea12f |
#define EPOCH_READ_CURRENT 70000
|
|
Packit |
aea12f |
#define EPOCH_WRITE_CURRENT 70001
|
|
Packit |
aea12f |
#define EPOCH_NEXT 70002
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct record_parameters_st {
|
|
Packit |
aea12f |
uint16_t epoch;
|
|
Packit |
aea12f |
int initialized;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
const cipher_entry_st *cipher;
|
|
Packit |
aea12f |
bool etm;
|
|
Packit |
aea12f |
const mac_entry_st *mac;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* for DTLS sliding window */
|
|
Packit |
aea12f |
uint64_t dtls_sw_next; /* The end point (next expected packet) of the sliding window without epoch */
|
|
Packit |
aea12f |
uint64_t dtls_sw_bits;
|
|
Packit |
aea12f |
unsigned dtls_sw_have_recv; /* whether at least a packet has been received */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
record_state_st read;
|
|
Packit |
aea12f |
record_state_st write;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Whether this state is in use, i.e., if there is
|
|
Packit |
aea12f |
a pending handshake message waiting to be encrypted
|
|
Packit |
aea12f |
under this epoch's parameters.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
int usage_cnt;
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
unsigned int priorities[MAX_ALGOS];
|
|
Packit |
aea12f |
unsigned int num_priorities;
|
|
Packit |
aea12f |
} priority_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef enum {
|
|
Packit |
aea12f |
SR_DISABLED,
|
|
Packit |
aea12f |
SR_UNSAFE,
|
|
Packit |
aea12f |
SR_PARTIAL,
|
|
Packit |
aea12f |
SR_SAFE
|
|
Packit |
aea12f |
} safe_renegotiation_t;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define MAX_CIPHERSUITE_SIZE 256
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct ciphersuite_list_st {
|
|
Packit |
aea12f |
const gnutls_cipher_suite_entry_st *entry[MAX_CIPHERSUITE_SIZE];
|
|
Packit |
aea12f |
unsigned int size;
|
|
Packit |
aea12f |
} ciphersuite_list_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct group_list_st {
|
|
Packit |
aea12f |
const gnutls_group_entry_st *entry[MAX_ALGOS];
|
|
Packit |
aea12f |
unsigned int size;
|
|
Packit |
aea12f |
bool have_ffdhe;
|
|
Packit |
aea12f |
} group_list_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct sign_algo_list_st {
|
|
Packit |
aea12f |
const struct gnutls_sign_entry_st *entry[MAX_ALGOS];
|
|
Packit |
aea12f |
unsigned int size;
|
|
Packit |
aea12f |
} sign_algo_list_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include "atomic.h"
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* For the external api */
|
|
Packit |
aea12f |
struct gnutls_priority_st {
|
|
Packit |
aea12f |
priority_st protocol;
|
|
Packit |
aea12f |
priority_st client_ctype;
|
|
Packit |
aea12f |
priority_st server_ctype;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The following are not necessary to be stored in
|
|
Packit |
aea12f |
* the structure; however they are required by the
|
|
Packit |
aea12f |
* external APIs: gnutls_priority_*_list() */
|
|
Packit |
aea12f |
priority_st _cipher;
|
|
Packit |
aea12f |
priority_st _mac;
|
|
Packit |
aea12f |
priority_st _kx;
|
|
Packit |
aea12f |
priority_st _sign_algo;
|
|
Packit |
aea12f |
priority_st _supported_ecc;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the supported groups */
|
|
Packit |
aea12f |
group_list_st groups;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the supported signature algorithms */
|
|
Packit |
aea12f |
sign_algo_list_st sigalg;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the supported ciphersuites */
|
|
Packit |
aea12f |
ciphersuite_list_st cs;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* to disable record padding */
|
|
Packit |
aea12f |
bool no_extensions;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
safe_renegotiation_t sr;
|
|
Packit |
aea12f |
bool min_record_version;
|
|
Packit |
aea12f |
bool server_precedence;
|
|
Packit |
aea12f |
bool allow_server_key_usage_violation; /* for test suite purposes only */
|
|
Packit |
aea12f |
bool no_tickets;
|
|
Packit |
aea12f |
bool have_cbc;
|
|
Packit |
aea12f |
bool have_psk;
|
|
Packit |
aea12f |
bool force_etm;
|
|
Packit |
aea12f |
unsigned int additional_verify_flags;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* TLS_FALLBACK_SCSV */
|
|
Packit |
aea12f |
bool fallback;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The session's expected security level.
|
|
Packit |
aea12f |
* Will be used to determine the minimum DH bits,
|
|
Packit |
aea12f |
* (or the acceptable certificate security level).
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_sec_param_t level;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* these should be accessed from
|
|
Packit |
aea12f |
* session->internals.VAR names */
|
|
Packit |
aea12f |
bool _allow_large_records;
|
|
Packit |
aea12f |
bool _allow_small_records;
|
|
Packit |
aea12f |
bool _no_etm;
|
|
Packit |
aea12f |
bool _no_ext_master_secret;
|
|
Packit |
aea12f |
bool _allow_key_usage_violation;
|
|
Packit |
aea12f |
bool _allow_wrong_pms;
|
|
Packit |
aea12f |
bool _dumbfw;
|
|
Packit |
aea12f |
unsigned int _dh_prime_bits; /* old (deprecated) variable */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
DEF_ATOMIC_INT(usage_cnt);
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Allow around 50KB of length-hiding padding
|
|
Packit |
aea12f |
* when using legacy padding,
|
|
Packit |
aea12f |
* or around 3.2MB when using new padding. */
|
|
Packit |
aea12f |
#define DEFAULT_MAX_EMPTY_RECORDS 200
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define ENABLE_COMPAT(x) \
|
|
Packit |
aea12f |
(x)->allow_large_records = 1; \
|
|
Packit |
aea12f |
(x)->allow_small_records = 1; \
|
|
Packit |
aea12f |
(x)->no_etm = 1; \
|
|
Packit |
aea12f |
(x)->no_ext_master_secret = 1; \
|
|
Packit |
aea12f |
(x)->allow_key_usage_violation = 1; \
|
|
Packit |
aea12f |
(x)->allow_wrong_pms = 1; \
|
|
Packit |
aea12f |
(x)->dumbfw = 1
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define ENABLE_PRIO_COMPAT(x) \
|
|
Packit |
aea12f |
(x)->_allow_large_records = 1; \
|
|
Packit |
aea12f |
(x)->_allow_small_records = 1; \
|
|
Packit |
aea12f |
(x)->_no_etm = 1; \
|
|
Packit |
aea12f |
(x)->_no_ext_master_secret = 1; \
|
|
Packit |
aea12f |
(x)->_allow_key_usage_violation = 1; \
|
|
Packit |
aea12f |
(x)->_allow_wrong_pms = 1; \
|
|
Packit |
aea12f |
(x)->_dumbfw = 1
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* DH and RSA parameters types.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
typedef struct gnutls_dh_params_int {
|
|
Packit |
aea12f |
/* [0] is the prime, [1] is the generator, [2] is Q if available.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
bigint_t params[3];
|
|
Packit |
aea12f |
int q_bits; /* length of q in bits. If zero then length is unknown.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
} dh_params_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* TLS 1.3 session ticket
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
struct timespec arrival_time;
|
|
Packit |
aea12f |
struct timespec creation_time;
|
|
Packit |
aea12f |
uint32_t lifetime;
|
|
Packit |
aea12f |
uint32_t age_add;
|
|
Packit |
aea12f |
uint8_t nonce[255];
|
|
Packit |
aea12f |
size_t nonce_size;
|
|
Packit |
aea12f |
const mac_entry_st *prf;
|
|
Packit |
aea12f |
uint8_t resumption_master_secret[MAX_HASH_SIZE];
|
|
Packit |
aea12f |
gnutls_datum_t ticket;
|
|
Packit |
aea12f |
} tls13_ticket_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* DTLS session state
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
/* HelloVerifyRequest DOS prevention cookie */
|
|
Packit |
aea12f |
gnutls_datum_t dcookie;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* For DTLS handshake fragmentation and reassembly. */
|
|
Packit |
aea12f |
uint16_t hsk_write_seq;
|
|
Packit |
aea12f |
/* the sequence number of the expected packet */
|
|
Packit |
aea12f |
unsigned int hsk_read_seq;
|
|
Packit |
aea12f |
uint16_t mtu;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* a flight transmission is in process */
|
|
Packit |
aea12f |
bool flight_init;
|
|
Packit |
aea12f |
/* whether this is the last flight in the protocol */
|
|
Packit |
aea12f |
bool last_flight;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the retransmission timeout in milliseconds */
|
|
Packit |
aea12f |
unsigned int retrans_timeout_ms;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
unsigned int hsk_hello_verify_requests;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The actual retrans_timeout for the next message (e.g. doubled or so)
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
unsigned int actual_retrans_timeout_ms;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* timers to handle async handshake after gnutls_handshake()
|
|
Packit |
aea12f |
* has terminated. Required to handle retransmissions.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
time_t async_term;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* last retransmission triggered by record layer */
|
|
Packit |
aea12f |
struct timespec last_retransmit;
|
|
Packit |
aea12f |
unsigned int packets_dropped;
|
|
Packit |
aea12f |
} dtls_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct tfo_st {
|
|
Packit |
aea12f |
int fd;
|
|
Packit |
aea12f |
int flags;
|
|
Packit |
aea12f |
bool connect_only; /* a previous sendmsg() failed, attempting connect() */
|
|
Packit |
aea12f |
struct sockaddr_storage connect_addr;
|
|
Packit |
aea12f |
socklen_t connect_addrlen;
|
|
Packit |
aea12f |
} tfo_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
typedef struct {
|
|
Packit |
aea12f |
/* holds all the parsed data received by the record layer */
|
|
Packit |
aea12f |
mbuffer_head_st record_buffer;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
int handshake_hash_buffer_prev_len; /* keeps the length of handshake_hash_buffer, excluding
|
|
Packit |
aea12f |
* the last received message */
|
|
Packit |
aea12f |
unsigned handshake_hash_buffer_client_hello_len; /* if non-zero it is the length of data until the client hello message */
|
|
Packit |
aea12f |
unsigned handshake_hash_buffer_client_kx_len;/* if non-zero it is the length of data until the
|
|
Packit |
aea12f |
* the client key exchange message */
|
|
Packit |
aea12f |
unsigned handshake_hash_buffer_server_finished_len;/* if non-zero it is the length of data until the
|
|
Packit |
aea12f |
* the server finished message */
|
|
Packit |
aea12f |
unsigned handshake_hash_buffer_client_finished_len;/* if non-zero it is the length of data until the
|
|
Packit |
aea12f |
* the client finished message */
|
|
Packit |
aea12f |
gnutls_buffer_st handshake_hash_buffer; /* used to keep the last received handshake
|
|
Packit |
aea12f |
* message */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
bool resumable; /* TRUE or FALSE - if we can resume that session */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
send_ticket_state_t ticket_state; /* used by gnutls_session_ticket_send() */
|
|
Packit |
aea12f |
bye_state_t bye_state; /* used by gnutls_bye() */
|
|
Packit |
aea12f |
reauth_state_t reauth_state; /* used by gnutls_reauth() */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
handshake_state_t handshake_final_state;
|
|
Packit |
aea12f |
handshake_state_t handshake_state; /* holds
|
|
Packit |
aea12f |
* a number which indicates where
|
|
Packit |
aea12f |
* the handshake procedure has been
|
|
Packit |
aea12f |
* interrupted. If it is 0 then
|
|
Packit |
aea12f |
* no interruption has happened.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
bool invalid_connection; /* true or FALSE - if this session is valid */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
bool may_not_read; /* if it's 0 then we can read/write, otherwise it's forbidden to read/write
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
bool may_not_write;
|
|
Packit |
aea12f |
bool read_eof; /* non-zero if we have received a closure alert. */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
int last_alert; /* last alert received */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The last handshake messages sent or received.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
int last_handshake_in;
|
|
Packit |
aea12f |
int last_handshake_out;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* priorities */
|
|
Packit |
aea12f |
struct gnutls_priority_st *priorities;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* variables directly set when setting the priorities above, or
|
|
Packit |
aea12f |
* when overriding them */
|
|
Packit |
aea12f |
bool allow_large_records;
|
|
Packit |
aea12f |
bool allow_small_records;
|
|
Packit |
aea12f |
bool no_etm;
|
|
Packit |
aea12f |
bool no_ext_master_secret;
|
|
Packit |
aea12f |
bool allow_key_usage_violation;
|
|
Packit |
aea12f |
bool allow_wrong_pms;
|
|
Packit |
aea12f |
bool dumbfw;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* old (deprecated) variable. This is used for both srp_prime_bits
|
|
Packit |
aea12f |
* and dh_prime_bits as they don't overlap */
|
|
Packit |
aea12f |
/* For SRP: minimum bits to allow for SRP
|
|
Packit |
aea12f |
* use gnutls_srp_set_prime_bits() to adjust it.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
uint16_t dh_prime_bits; /* srp_prime_bits */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* resumed session */
|
|
Packit |
aea12f |
bool resumed; /* RESUME_TRUE or FALSE - if we are resuming a session */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* server side: non-zero if resumption was requested by client
|
|
Packit |
aea12f |
* client side: non-zero if we set resumption parameters */
|
|
Packit |
aea12f |
bool resumption_requested;
|
|
Packit |
aea12f |
security_parameters_st resumed_security_parameters;
|
|
Packit |
aea12f |
gnutls_datum_t resumption_data; /* copy of input to gnutls_session_set_data() */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* These buffers are used in the handshake
|
|
Packit |
aea12f |
* protocol only. freed using _gnutls_handshake_io_buffer_clear();
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
mbuffer_head_st handshake_send_buffer;
|
|
Packit |
aea12f |
mbuffer_head_st handshake_header_recv_buffer;
|
|
Packit |
aea12f |
handshake_buffer_st handshake_recv_buffer[MAX_HANDSHAKE_MSGS];
|
|
Packit |
aea12f |
int handshake_recv_buffer_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* this buffer holds a record packet -mostly used for
|
|
Packit |
aea12f |
* non blocking IO.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
mbuffer_head_st record_recv_buffer; /* buffer holding the unparsed record that is currently
|
|
Packit |
aea12f |
* being received */
|
|
Packit |
aea12f |
mbuffer_head_st record_send_buffer; /* holds cached data
|
|
Packit |
aea12f |
* for the gnutls_io_write_buffered()
|
|
Packit |
aea12f |
* function.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
size_t record_send_buffer_user_size; /* holds the
|
|
Packit |
aea12f |
* size of the user specified data to
|
|
Packit |
aea12f |
* send.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
mbuffer_head_st early_data_recv_buffer;
|
|
Packit |
aea12f |
gnutls_buffer_st early_data_presend_buffer;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
record_send_state_t rsend_state;
|
|
Packit |
aea12f |
/* buffer used temporarily during key update */
|
|
Packit |
aea12f |
gnutls_buffer_st record_key_update_buffer;
|
|
Packit |
aea12f |
gnutls_buffer_st record_presend_buffer; /* holds cached data
|
|
Packit |
aea12f |
* for the gnutls_record_send()
|
|
Packit |
aea12f |
* function.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* buffer used temporarily during TLS1.3 reauthentication */
|
|
Packit |
aea12f |
gnutls_buffer_st reauth_buffer;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
time_t expire_time; /* after expire_time seconds this session will expire */
|
|
Packit |
aea12f |
const struct mod_auth_st_int *auth_struct; /* used in handshake packets and KX algorithms */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* this is the highest version available
|
|
Packit |
aea12f |
* to the peer. (advertized version).
|
|
Packit |
aea12f |
* This is obtained by the Handshake Client Hello
|
|
Packit |
aea12f |
* message. (some implementations read the Record version)
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
uint8_t adv_version_major;
|
|
Packit |
aea12f |
uint8_t adv_version_minor;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* if this is non zero a certificate request message
|
|
Packit |
aea12f |
* will be sent to the client. - only if the ciphersuite
|
|
Packit |
aea12f |
* supports it. In server side it contains GNUTLS_CERT_REQUIRE
|
|
Packit |
aea12f |
* or similar.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_certificate_request_t send_cert_req;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
size_t max_handshake_data_buffer_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* PUSH & PULL functions.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_pull_timeout_func pull_timeout_func;
|
|
Packit |
aea12f |
gnutls_pull_func pull_func;
|
|
Packit |
aea12f |
gnutls_push_func push_func;
|
|
Packit |
aea12f |
gnutls_vec_push_func vec_push_func;
|
|
Packit |
aea12f |
gnutls_errno_func errno_func;
|
|
Packit |
aea12f |
/* Holds the first argument of PUSH and PULL
|
|
Packit |
aea12f |
* functions;
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_transport_ptr_t transport_recv_ptr;
|
|
Packit |
aea12f |
gnutls_transport_ptr_t transport_send_ptr;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* STORE & RETRIEVE functions. Only used if other
|
|
Packit |
aea12f |
* backend than gdbm is used.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_db_store_func db_store_func;
|
|
Packit |
aea12f |
gnutls_db_retr_func db_retrieve_func;
|
|
Packit |
aea12f |
gnutls_db_remove_func db_remove_func;
|
|
Packit |
aea12f |
void *db_ptr;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* post client hello callback (server side only)
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_handshake_post_client_hello_func user_hello_func;
|
|
Packit |
aea12f |
/* handshake hook function */
|
|
Packit |
aea12f |
gnutls_handshake_hook_func h_hook;
|
|
Packit |
aea12f |
unsigned int h_type; /* the hooked type */
|
|
Packit |
aea12f |
int16_t h_post; /* whether post-generation/receive */
|
|
Packit |
aea12f |
|
|
Packit Service |
991b93 |
gnutls_keylog_func keylog_func;
|
|
Packit Service |
991b93 |
|
|
Packit |
aea12f |
/* holds the selected certificate and key.
|
|
Packit |
aea12f |
* use _gnutls_selected_certs_deinit() and _gnutls_selected_certs_set()
|
|
Packit |
aea12f |
* to change them.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_pcert_st *selected_cert_list;
|
|
Packit |
aea12f |
uint16_t selected_cert_list_length;
|
|
Packit |
aea12f |
struct gnutls_privkey_st *selected_key;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* new callbacks such as gnutls_certificate_retrieve_function3
|
|
Packit |
aea12f |
* set the selected_ocsp datum values. The older OCSP callback-based
|
|
Packit |
aea12f |
* functions, set the ocsp_func. The former takes precedence when
|
|
Packit |
aea12f |
* set.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
gnutls_ocsp_data_st *selected_ocsp;
|
|
Packit |
aea12f |
uint16_t selected_ocsp_length;
|
|
Packit |
aea12f |
gnutls_status_request_ocsp_func selected_ocsp_func;
|
|
Packit |
aea12f |
void *selected_ocsp_func_ptr;
|
|
Packit |
aea12f |
bool selected_need_free;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This holds the default version that our first
|
|
Packit |
aea12f |
* record packet will have. */
|
|
Packit |
aea12f |
uint8_t default_record_version[2];
|
|
Packit |
aea12f |
uint8_t default_hello_version[2];
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
void *user_ptr;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Holds 0 if the last called function was interrupted while
|
|
Packit |
aea12f |
* receiving, and non zero otherwise.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
bool direction;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* If non zero the server will not advertise the CA's he
|
|
Packit |
aea12f |
* trusts (do not send an RDN sequence).
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
bool ignore_rdn_sequence;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* This is used to set an arbitrary version in the RSA
|
|
Packit |
aea12f |
* PMS secret. Can be used by clients to test whether the
|
|
Packit |
aea12f |
* server checks that version. (** only used in gnutls-cli-debug)
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
uint8_t rsa_pms_version[2];
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* To avoid using global variables, and especially on Windows where
|
|
Packit |
aea12f |
* the application may use a different errno variable than GnuTLS,
|
|
Packit |
aea12f |
* it is possible to use gnutls_transport_set_errno to set a
|
|
Packit |
aea12f |
* session-specific errno variable in the user-replaceable push/pull
|
|
Packit |
aea12f |
* functions. This value is used by the send/recv functions. (The
|
|
Packit |
aea12f |
* strange name of this variable is because 'errno' is typically
|
|
Packit |
aea12f |
* #define'd.)
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
int errnum;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* A handshake process has been completed */
|
|
Packit |
aea12f |
bool initial_negotiation_completed;
|
|
Packit |
aea12f |
void *post_negotiation_lock; /* protects access to the variable above
|
|
Packit |
aea12f |
* in the cases where negotiation is incomplete
|
|
Packit |
aea12f |
* after gnutls_handshake() - early/false start */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The type of transport protocol; stream or datagram */
|
|
Packit |
aea12f |
transport_t transport;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* DTLS session state */
|
|
Packit |
aea12f |
dtls_st dtls;
|
|
Packit |
aea12f |
/* Protect from infinite loops due to GNUTLS_E_LARGE_PACKET non-handling
|
|
Packit |
aea12f |
* or due to multiple alerts being received. */
|
|
Packit |
aea12f |
unsigned handshake_suspicious_loops;
|
|
Packit |
aea12f |
/* should be non-zero when a handshake is in progress */
|
|
Packit |
aea12f |
bool handshake_in_progress;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* if set it means that the master key was set using
|
|
Packit |
aea12f |
* gnutls_session_set_master() rather than being negotiated. */
|
|
Packit |
aea12f |
bool premaster_set;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
unsigned int cb_tls_unique_len;
|
|
Packit |
aea12f |
unsigned char cb_tls_unique[MAX_VERIFY_DATA_SIZE];
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* starting time of current handshake */
|
|
Packit |
aea12f |
struct timespec handshake_start_time;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* expected end time of current handshake (start+timeout);
|
|
Packit |
aea12f |
* this is only filled if a handshake_time_ms is set. */
|
|
Packit |
aea12f |
struct timespec handshake_abs_timeout;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* An estimation of round-trip time under TLS1.3; populated in client side only */
|
|
Packit |
aea12f |
unsigned ertt;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
unsigned int handshake_timeout_ms; /* timeout in milliseconds */
|
|
Packit |
aea12f |
unsigned int record_timeout_ms; /* timeout in milliseconds */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* saved context of post handshake certificate request. In
|
|
Packit |
aea12f |
* client side is what we received in server's certificate request;
|
|
Packit |
aea12f |
* in server side is what we sent to client. */
|
|
Packit |
aea12f |
gnutls_datum_t post_handshake_cr_context;
|
|
Packit |
aea12f |
/* it is a copy of the handshake hash buffer if post handshake is used */
|
|
Packit |
aea12f |
gnutls_buffer_st post_handshake_hash_buffer;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* When either of PSK or DHE-PSK is received */
|
|
Packit |
aea12f |
#define HSK_PSK_KE_MODES_RECEIVED (HSK_PSK_KE_MODE_PSK|HSK_PSK_KE_MODE_DHE_PSK|HSK_PSK_KE_MODE_INVALID)
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define HSK_CRT_VRFY_EXPECTED 1
|
|
Packit |
aea12f |
#define HSK_CRT_ASKED (1<<2)
|
|
Packit |
aea12f |
#define HSK_HRR_SENT (1<<3)
|
|
Packit |
aea12f |
#define HSK_HRR_RECEIVED (1<<4)
|
|
Packit |
aea12f |
#define HSK_CRT_REQ_SENT (1<<5)
|
|
Packit |
aea12f |
#define HSK_KEY_UPDATE_ASKED (1<<7) /* flag is not used during handshake */
|
|
Packit |
aea12f |
#define HSK_FALSE_START_USED (1<<8) /* TLS1.2 only */
|
|
Packit |
aea12f |
#define HSK_HAVE_FFDHE (1<<9) /* whether the peer has advertized at least an FFDHE group */
|
|
Packit |
aea12f |
#define HSK_USED_FFDHE (1<<10) /* whether ffdhe was actually negotiated and used */
|
|
Packit |
aea12f |
#define HSK_PSK_KE_MODES_SENT (1<<11)
|
|
Packit |
aea12f |
#define HSK_PSK_KE_MODE_PSK (1<<12) /* client: whether PSK without DH is allowed,
|
|
Packit |
aea12f |
* server: whether PSK without DH is selected. */
|
|
Packit |
aea12f |
#define HSK_PSK_KE_MODE_INVALID (1<<13) /* server: no compatible PSK modes were seen */
|
|
Packit |
aea12f |
#define HSK_PSK_KE_MODE_DHE_PSK (1<<14) /* server: whether PSK with DH is selected
|
|
Packit |
aea12f |
* client: whether PSK with DH is allowed
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define HSK_PSK_SELECTED (1<<15) /* server: whether PSK was selected, either for resumption or not;
|
|
Packit |
aea12f |
* on resumption session->internals.resumed will be set as well.
|
|
Packit |
aea12f |
* client: the same */
|
|
Packit |
aea12f |
#define HSK_KEY_SHARE_SENT (1<<16) /* server: key share was sent to client */
|
|
Packit |
aea12f |
#define HSK_KEY_SHARE_RECEIVED (1<<17) /* client: key share was received
|
|
Packit |
aea12f |
* server: key share was received and accepted */
|
|
Packit |
aea12f |
#define HSK_TLS13_TICKET_SENT (1<<18) /* client: sent a ticket under TLS1.3;
|
|
Packit |
aea12f |
* server: a ticket was sent to client.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define HSK_TLS12_TICKET_SENT (1<<19) /* client: sent a ticket under TLS1.2;
|
|
Packit |
aea12f |
* server: a ticket was sent to client.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define HSK_TICKET_RECEIVED (1<<20) /* client: a session ticket was received */
|
|
Packit |
aea12f |
#define HSK_EARLY_START_USED (1<<21)
|
|
Packit |
aea12f |
#define HSK_EARLY_DATA_IN_FLIGHT (1<<22) /* client: sent early_data extension in ClientHello
|
|
Packit |
aea12f |
* server: early_data extension was seen in ClientHello
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define HSK_EARLY_DATA_ACCEPTED (1<<23) /* client: early_data extension was seen in EncryptedExtensions
|
|
Packit |
aea12f |
* server: intend to process early data
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define HSK_RECORD_SIZE_LIMIT_NEGOTIATED (1<<24)
|
|
Packit |
aea12f |
#define HSK_RECORD_SIZE_LIMIT_SENT (1<<25) /* record_size_limit extension was sent */
|
|
Packit |
aea12f |
#define HSK_RECORD_SIZE_LIMIT_RECEIVED (1<<26) /* server: record_size_limit extension was seen but not accepted yet */
|
|
Packit Service |
991b93 |
#define HSK_OCSP_REQUESTED (1<<27) /* server: client requested OCSP stapling */
|
|
Packit Service |
991b93 |
#define HSK_CLIENT_OCSP_REQUESTED (1<<28) /* client: server requested OCSP stapling */
|
|
Packit Service |
129507 |
#define HSK_SERVER_HELLO_RECEIVED (1<<29) /* client: Server Hello message has been received */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The hsk_flags are for use within the ongoing handshake;
|
|
Packit |
aea12f |
* they are reset to zero prior to handshake start by gnutls_handshake. */
|
|
Packit |
aea12f |
unsigned hsk_flags;
|
|
Packit |
aea12f |
struct timespec last_key_update;
|
|
Packit |
aea12f |
unsigned key_update_count;
|
|
Packit |
aea12f |
/* Read-only pointer to the full ClientHello message */
|
|
Packit |
aea12f |
gnutls_buffer_st full_client_hello;
|
|
Packit |
aea12f |
/* The offset at which extensions start in the ClientHello buffer */
|
|
Packit |
aea12f |
int extensions_offset;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_buffer_st hb_local_data;
|
|
Packit |
aea12f |
gnutls_buffer_st hb_remote_data;
|
|
Packit |
aea12f |
struct timespec hb_ping_start; /* timestamp: when first HeartBeat ping was sent */
|
|
Packit |
aea12f |
struct timespec hb_ping_sent; /* timestamp: when last HeartBeat ping was sent */
|
|
Packit |
aea12f |
unsigned int hb_actual_retrans_timeout_ms; /* current timeout, in milliseconds */
|
|
Packit |
aea12f |
unsigned int hb_retrans_timeout_ms; /* the default timeout, in milliseconds */
|
|
Packit |
aea12f |
unsigned int hb_total_timeout_ms; /* the total timeout, in milliseconds */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
bool ocsp_check_ok; /* will be zero if the OCSP response TLS extension
|
|
Packit |
aea12f |
* check failed (OCSP was old/unrelated or so). */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
heartbeat_state_t hb_state; /* for ping */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
recv_state_t recv_state; /* state of the receive function */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* if set, server and client random were set by the application */
|
|
Packit |
aea12f |
bool sc_random_set;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define INT_FLAG_NO_TLS13 (1LL<<60)
|
|
Packit |
aea12f |
uint64_t flags; /* the flags in gnutls_init() and GNUTLS_INT_FLAGS */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* a verify callback to override the verify callback from the credentials
|
|
Packit |
aea12f |
* structure */
|
|
Packit |
aea12f |
gnutls_certificate_verify_function *verify_callback;
|
|
Packit |
aea12f |
gnutls_typed_vdata_st *vc_data;
|
|
Packit |
aea12f |
gnutls_typed_vdata_st vc_sdata;
|
|
Packit |
aea12f |
unsigned vc_elements;
|
|
Packit |
aea12f |
unsigned vc_status;
|
|
Packit |
aea12f |
unsigned int additional_verify_flags; /* may be set by priorities or the vc functions */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* we append the verify flags because these can be set,
|
|
Packit |
aea12f |
* either by this function or by gnutls_session_set_verify_cert().
|
|
Packit |
aea12f |
* However, we ensure that a single profile is set. */
|
|
Packit |
aea12f |
#define ADD_PROFILE_VFLAGS(session, vflags) do { \
|
|
Packit |
aea12f |
if ((session->internals.additional_verify_flags & GNUTLS_VFLAGS_PROFILE_MASK) && \
|
|
Packit |
aea12f |
(vflags & GNUTLS_VFLAGS_PROFILE_MASK)) \
|
|
Packit |
aea12f |
session->internals.additional_verify_flags &= ~GNUTLS_VFLAGS_PROFILE_MASK; \
|
|
Packit |
aea12f |
session->internals.additional_verify_flags |= vflags; \
|
|
Packit |
aea12f |
} while(0)
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the SHA256 hash of the peer's certificate */
|
|
Packit |
aea12f |
uint8_t cert_hash[32];
|
|
Packit |
aea12f |
bool cert_hash_set;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* The saved username from PSK or SRP auth */
|
|
Packit |
aea12f |
char saved_username[MAX_USERNAME_SIZE+1];
|
|
Packit Service |
991b93 |
int saved_username_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Needed for TCP Fast Open (TFO), set by gnutls_transport_set_fastopen() */
|
|
Packit |
aea12f |
tfo_st tfo;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct gnutls_supplemental_entry_st *rsup;
|
|
Packit |
aea12f |
unsigned rsup_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct hello_ext_entry_st *rexts;
|
|
Packit |
aea12f |
unsigned rexts_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct { /* ext_data[id] contains data for extension_t id */
|
|
Packit |
aea12f |
gnutls_ext_priv_data_t priv;
|
|
Packit |
aea12f |
gnutls_ext_priv_data_t resumed_priv;
|
|
Packit |
aea12f |
uint8_t set;
|
|
Packit |
aea12f |
uint8_t resumed_set;
|
|
Packit |
aea12f |
} ext_data[MAX_EXT_TYPES];
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* In case of a client holds the extensions we sent to the peer;
|
|
Packit |
aea12f |
* otherwise the extensions we received from the client. This is
|
|
Packit |
aea12f |
* an OR of (1<
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
ext_track_t used_exts;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
gnutls_ext_flags_t ext_msg; /* accessed through _gnutls_ext_get/set_msg() */
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* this is not the negotiated max_record_recv_size, but the actual maximum
|
|
Packit |
aea12f |
* receive size */
|
|
Packit |
aea12f |
unsigned max_recv_size;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* candidate groups to be selected for security params groups, they are
|
|
Packit |
aea12f |
* prioritized in isolation under TLS1.2 */
|
|
Packit |
aea12f |
const gnutls_group_entry_st *cand_ec_group;
|
|
Packit |
aea12f |
const gnutls_group_entry_st *cand_dh_group;
|
|
Packit |
aea12f |
/* used under TLS1.3+ */
|
|
Packit |
aea12f |
const gnutls_group_entry_st *cand_group;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the ciphersuite received in HRR */
|
|
Packit |
aea12f |
uint8_t hrr_cs[2];
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* this is only used under TLS1.2 or earlier */
|
|
Packit |
aea12f |
int session_ticket_renew;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
tls13_ticket_st tls13_ticket;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* the amount of early data received so far */
|
|
Packit |
aea12f |
uint32_t early_data_received;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* anti-replay measure for 0-RTT mode */
|
|
Packit |
aea12f |
gnutls_anti_replay_t anti_replay;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Protects _gnutls_epoch_gc() from _gnutls_epoch_get(); these may be
|
|
Packit |
aea12f |
* called in parallel when false start is used and false start is used. */
|
|
Packit |
aea12f |
void *epoch_lock;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* If you add anything here, check _gnutls_handshake_internal_state_clear().
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
} internals_st;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Maximum number of epochs we keep around. */
|
|
Packit |
aea12f |
#define MAX_EPOCH_INDEX 4
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define reset_cand_groups(session) \
|
|
Packit |
aea12f |
session->internals.cand_ec_group = session->internals.cand_dh_group = \
|
|
Packit |
aea12f |
session->internals.cand_group = NULL
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct gnutls_session_int {
|
|
Packit |
aea12f |
security_parameters_st security_parameters;
|
|
Packit |
aea12f |
record_parameters_st *record_parameters[MAX_EPOCH_INDEX];
|
|
Packit |
aea12f |
internals_st internals;
|
|
Packit |
aea12f |
gnutls_key_st key;
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* functions
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
void _gnutls_free_auth_info(gnutls_session_t session);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* These two macros return the advertised TLS version of
|
|
Packit |
aea12f |
* the peer.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
#define _gnutls_get_adv_version_major(session) \
|
|
Packit |
aea12f |
session->internals.adv_version_major
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define _gnutls_get_adv_version_minor(session) \
|
|
Packit |
aea12f |
session->internals.adv_version_minor
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define set_adv_version(session, major, minor) \
|
|
Packit |
aea12f |
session->internals.adv_version_major = major; \
|
|
Packit |
aea12f |
session->internals.adv_version_minor = minor
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
int _gnutls_is_secure_mem_null(const void *);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
inline static const version_entry_st *get_version(gnutls_session_t session)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
return session->security_parameters.pversion;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
inline static unsigned get_num_version(gnutls_session_t session)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
if (likely(session->security_parameters.pversion != NULL))
|
|
Packit |
aea12f |
return session->security_parameters.pversion->id;
|
|
Packit |
aea12f |
else
|
|
Packit |
aea12f |
return GNUTLS_VERSION_UNKNOWN;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
void _gnutls_priority_update_fips(void);
|
|
Packit |
aea12f |
void _gnutls_priority_update_non_aesni(void);
|
|
Packit |
aea12f |
extern unsigned _gnutls_disable_tls13;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define timespec_sub_ms _gnutls_timespec_sub_ms
|
|
Packit |
aea12f |
unsigned int
|
|
Packit |
aea12f |
/* returns a-b in ms */
|
|
Packit |
aea12f |
timespec_sub_ms(struct timespec *a, struct timespec *b);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
inline static int _gnutls_timespec_cmp(struct timespec *a, struct timespec *b) {
|
|
Packit |
aea12f |
if (a->tv_sec < b->tv_sec)
|
|
Packit |
aea12f |
return -1;
|
|
Packit |
aea12f |
if (a->tv_sec > b->tv_sec)
|
|
Packit |
aea12f |
return 1;
|
|
Packit |
aea12f |
if (a->tv_nsec < b->tv_nsec)
|
|
Packit |
aea12f |
return -1;
|
|
Packit |
aea12f |
if (a->tv_nsec > b->tv_nsec)
|
|
Packit |
aea12f |
return 1;
|
|
Packit |
aea12f |
return 0;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <algorithms.h>
|
|
Packit |
aea12f |
inline static int _gnutls_set_current_version(gnutls_session_t s, unsigned v)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
s->security_parameters.pversion = version_to_entry(v);
|
|
Packit |
aea12f |
if (s->security_parameters.pversion == NULL) {
|
|
Packit |
aea12f |
return GNUTLS_E_UNSUPPORTED_VERSION_PACKET;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
return 0;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Returns the maximum amount of the plaintext to be sent, considering
|
|
Packit |
aea12f |
* both user-specified/negotiated maximum values.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
inline static size_t max_record_send_size(gnutls_session_t session,
|
|
Packit |
aea12f |
record_parameters_st *
|
|
Packit |
aea12f |
record_params)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
size_t max;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
max = MIN(session->security_parameters.max_record_send_size,
|
|
Packit |
aea12f |
session->security_parameters.max_user_record_send_size);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
if (IS_DTLS(session))
|
|
Packit |
aea12f |
max = MIN(gnutls_dtls_get_data_mtu(session), max);
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
return max;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Returns the during the handshake negotiated certificate type(s).
|
|
Packit |
aea12f |
* See state.c for the full function documentation.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This function is made static inline for optimization reasons.
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
inline static gnutls_certificate_type_t
|
|
Packit |
aea12f |
get_certificate_type(gnutls_session_t session,
|
|
Packit |
aea12f |
gnutls_ctype_target_t target)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
switch (target) {
|
|
Packit |
aea12f |
case GNUTLS_CTYPE_CLIENT:
|
|
Packit |
aea12f |
return session->security_parameters.client_ctype;
|
|
Packit |
aea12f |
break;
|
|
Packit |
aea12f |
case GNUTLS_CTYPE_SERVER:
|
|
Packit |
aea12f |
return session->security_parameters.server_ctype;
|
|
Packit |
aea12f |
break;
|
|
Packit |
aea12f |
case GNUTLS_CTYPE_OURS:
|
|
Packit |
aea12f |
if (IS_SERVER(session)) {
|
|
Packit |
aea12f |
return session->security_parameters.server_ctype;
|
|
Packit |
aea12f |
} else {
|
|
Packit |
aea12f |
return session->security_parameters.client_ctype;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
break;
|
|
Packit |
aea12f |
case GNUTLS_CTYPE_PEERS:
|
|
Packit |
aea12f |
if (IS_SERVER(session)) {
|
|
Packit |
aea12f |
return session->security_parameters.client_ctype;
|
|
Packit |
aea12f |
} else {
|
|
Packit |
aea12f |
return session->security_parameters.server_ctype;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
break;
|
|
Packit |
aea12f |
default: // Illegal parameter passed
|
|
Packit |
aea12f |
return GNUTLS_CRT_UNKNOWN;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* Macros to aide constant time/mem checks */
|
|
Packit |
aea12f |
#define CONSTCHECK_NOT_EQUAL(a, b) ((-((uint32_t)(a) ^ (uint32_t)(b))) >> 31)
|
|
Packit |
aea12f |
#define CONSTCHECK_EQUAL(a, b) (1U - CONSTCHECK_NOT_EQUAL(a, b))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
extern unsigned int _gnutls_global_version;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#endif /* GNUTLS_LIB_GNUTLS_INT_H */
|