Coverage Report

Created: 2023-03-26 07:33

/src/gnutls/lib/gnutls_int.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2000-2016 Free Software Foundation, Inc.
3
 * Copyright (C) 2015-2018 Red Hat, Inc.
4
 *
5
 * Author: Nikos Mavrogiannopoulos
6
 *
7
 * This file is part of GnuTLS.
8
 *
9
 * The GnuTLS is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public License
11
 * as published by the Free Software Foundation; either version 2.1 of
12
 * the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful, but
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
21
 *
22
 */
23
24
#ifndef GNUTLS_LIB_GNUTLS_INT_H
25
# define GNUTLS_LIB_GNUTLS_INT_H
26
27
# ifdef HAVE_CONFIG_H
28
#  include <config.h>
29
# endif
30
31
# include <stddef.h>
32
# include <string.h>
33
# include <stdlib.h>
34
# include <stdio.h>
35
# include <ctype.h>
36
# include <limits.h>
37
# include <stdint.h>
38
# include <stdbool.h>
39
# include <assert.h>
40
41
# ifdef NO_SSIZE_T
42
#  define HAVE_SSIZE_T
43
typedef int ssize_t;
44
# endif
45
46
# include <sys/types.h>
47
# include <unistd.h>
48
# include <sys/stat.h>
49
# if HAVE_SYS_SOCKET_H
50
#  include <sys/socket.h>
51
# elif HAVE_WS2TCPIP_H
52
#  include <ws2tcpip.h>
53
# endif
54
# include <time.h>
55
56
# include "attribute.h"
57
58
# define ENABLE_ALIGN16
59
60
# ifdef __clang_major
61
#  define _GNUTLS_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
62
# else
63
#  define _GNUTLS_CLANG_VERSION 0
64
# endif
65
66
/* clang also defines __GNUC__. It promotes a GCC version of 4.2.1. */
67
# ifdef __GNUC__
68
#  define _GNUTLS_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
69
# endif
70
71
# if _GNUTLS_GCC_VERSION >= 30100
72
#  define likely(x)      __builtin_expect((x), 1)
73
0
#  define unlikely(x)    __builtin_expect((x), 0)
74
# else
75
#  define likely
76
#  define unlikely
77
# endif
78
79
# include <gnutls/gnutls.h>
80
# include <gnutls/dtls.h>
81
# include <gnutls/abstract.h>
82
# include <gnutls/socket.h>
83
# include <system.h>
84
85
/* in case we compile with system headers taking priority, we
86
 * make sure that some new attributes are still available.
87
 */
88
# ifndef __GNUTLS_CONST__
89
#  define __GNUTLS_CONST__
90
# endif
91
92
/* The size of a handshake message should not
93
 * be larger than this value.
94
 */
95
# define MAX_HANDSHAKE_PACKET_SIZE 128*1024
96
97
# define GNUTLS_DEF_SESSION_ID_SIZE 32
98
99
/* The maximum digest size of hash algorithms.
100
 */
101
# define MAX_FILENAME 512
102
0
# define MAX_HASH_SIZE 64
103
104
# define MAX_MAC_KEY_SIZE 64
105
106
# define MAX_CIPHER_BLOCK_SIZE 64 /* CHACHA20 */
107
0
# define MAX_CIPHER_KEY_SIZE 32
108
109
# define MAX_CIPHER_IV_SIZE 16
110
111
/* Maximum size of 2^16-1 has been chosen so that usernames can hold
112
 * PSK identities as defined in RFC 4279 section 2 and RFC 8446 section 4.2.11
113
 */
114
# define MAX_USERNAME_SIZE 65535
115
0
# define MAX_SERVER_NAME_SIZE 256
116
117
# define AEAD_EXPLICIT_DATA_SIZE 8
118
# define AEAD_IMPLICIT_DATA_SIZE 4
119
120
# define GNUTLS_MASTER_SIZE 48
121
# define GNUTLS_RANDOM_SIZE 32
122
123
/* Under TLS1.3 a hello retry request is sent as server hello */
124
# define REAL_HSK_TYPE(t) ((t)==GNUTLS_HANDSHAKE_HELLO_RETRY_REQUEST?GNUTLS_HANDSHAKE_SERVER_HELLO:t)
125
126
/* DTLS */
127
# define DTLS_RETRANS_TIMEOUT 1000
128
129
/* TLS Extensions */
130
/* we can receive up to MAX_EXT_TYPES extensions.
131
 */
132
# define MAX_EXT_TYPES 64
133
134
/* TLS-internal extension (will be parsed after a ciphersuite is selected).
135
 * This amends the gnutls_ext_parse_type_t. Not exported yet to allow more refining
136
 * prior to finalizing an API. */
137
# define _GNUTLS_EXT_TLS_POST_CS 177
138
139
/* expire time for resuming sessions */
140
# define DEFAULT_EXPIRE_TIME 21600
141
# define STEK_ROTATION_PERIOD_PRODUCT 3
142
# define DEFAULT_HANDSHAKE_TIMEOUT_MS 40*1000
143
144
/* The EC group to be used when the extension
145
 * supported groups/curves is not present */
146
# define DEFAULT_EC_GROUP GNUTLS_GROUP_SECP256R1
147
148
typedef enum transport_t {
149
  GNUTLS_STREAM,
150
  GNUTLS_DGRAM
151
} transport_t;
152
153
/* The TLS 1.3 stage of handshake */
154
typedef enum hs_stage_t {
155
  STAGE_HS,
156
  STAGE_APP,
157
  STAGE_UPD_OURS,
158
  STAGE_UPD_PEERS,
159
  STAGE_EARLY
160
} hs_stage_t;
161
162
typedef enum record_send_state_t {
163
  RECORD_SEND_NORMAL = 0,
164
  RECORD_SEND_CORKED, /* corked and transition to NORMAL afterwards */
165
  RECORD_SEND_CORKED_TO_KU, /* corked but must transition to RECORD_SEND_KEY_UPDATE_1 */
166
  RECORD_SEND_KEY_UPDATE_1,
167
  RECORD_SEND_KEY_UPDATE_2,
168
  RECORD_SEND_KEY_UPDATE_3
169
} record_send_state_t;
170
171
/* The mode check occurs a lot throughout GnuTLS and can be replaced by
172
 * the following shorter macro. Also easier to update one macro
173
 * in the future when the internal structure changes than all the conditionals
174
 * itself.
175
 */
176
# define IS_SERVER(session) (session->security_parameters.entity == GNUTLS_SERVER)
177
178
/* To check whether we have a DTLS session */
179
# define IS_DTLS(session) (session->internals.transport == GNUTLS_DGRAM)
180
181
/* To check whether we have a KTLS enabled */
182
# define IS_KTLS_ENABLED(session, interface) (session->internals.ktls_enabled & interface)
183
184
/* the maximum size of encrypted packets */
185
# define DEFAULT_MAX_RECORD_SIZE 16384
186
# define DEFAULT_MAX_EARLY_DATA_SIZE 16384
187
# define TLS_RECORD_HEADER_SIZE 5
188
# define DTLS_RECORD_HEADER_SIZE (TLS_RECORD_HEADER_SIZE+8)
189
# define RECORD_HEADER_SIZE(session) (IS_DTLS(session) ? DTLS_RECORD_HEADER_SIZE : TLS_RECORD_HEADER_SIZE)
190
# define MAX_RECORD_HEADER_SIZE DTLS_RECORD_HEADER_SIZE
191
192
# define MIN_RECORD_SIZE 512
193
# define MIN_RECORD_SIZE_SMALL 64
194
195
/* The following macro is used to calculate the overhead when sending.
196
 * when receiving we use a different way as there are implementations that
197
 * store more data than allowed.
198
 */
199
# define MAX_RECORD_SEND_OVERHEAD(session) (MAX_CIPHER_BLOCK_SIZE/*iv*/+MAX_PAD_SIZE+MAX_HASH_SIZE/*MAC*/)
200
# define MAX_PAD_SIZE 255
201
# define EXTRA_COMP_SIZE 2048
202
203
# define TLS_HANDSHAKE_HEADER_SIZE 4
204
# define DTLS_HANDSHAKE_HEADER_SIZE (TLS_HANDSHAKE_HEADER_SIZE+8)
205
# define HANDSHAKE_HEADER_SIZE(session) (IS_DTLS(session) ? DTLS_HANDSHAKE_HEADER_SIZE : TLS_HANDSHAKE_HEADER_SIZE)
206
# define MAX_HANDSHAKE_HEADER_SIZE DTLS_HANDSHAKE_HEADER_SIZE
207
208
/* Maximum seed size for provable parameters */
209
# define MAX_PVP_SEED_SIZE 256
210
211
/* This is the maximum handshake message size we send without
212
   fragmentation. This currently ignores record layer overhead. */
213
# define DTLS_DEFAULT_MTU 1200
214
215
/* the maximum size of the DTLS cookie */
216
# define DTLS_MAX_COOKIE_SIZE 32
217
218
/* The maximum number of HELLO_VERIFY_REQUEST messages the client
219
   processes before aborting. */
220
# define MAX_HANDSHAKE_HELLO_VERIFY_REQUESTS 5
221
222
# define MAX_PK_PARAM_SIZE 2048
223
224
/* defaults for verification functions
225
 */
226
0
# define DEFAULT_MAX_VERIFY_DEPTH 16
227
# define DEFAULT_MAX_VERIFY_BITS (MAX_PK_PARAM_SIZE*8)
228
0
# define MAX_VERIFY_DEPTH 4096
229
230
# include <mem.h>
231
232
# define MEMSUB(x,y) ((ssize_t)((ptrdiff_t)x-(ptrdiff_t)y))
233
234
# define DECR_LEN(len, x) DECR_LENGTH_RET(len, x, GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
235
# define DECR_LEN_FINAL(len, x) do { \
236
  if (len != x) \
237
    return gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET_LENGTH); \
238
  else \
239
    len = 0; \
240
  } while (0)
241
0
# define DECR_LENGTH_RET(len, x, RET) DECR_LENGTH_COM(len, x, return RET)
242
0
# define DECR_LENGTH_COM(len, x, COM) do { if (len<x) {gnutls_assert(); COM;} else len-=x; } while (0)
243
244
# define GNUTLS_POINTER_TO_INT(_) ((int) GNUTLS_POINTER_TO_INT_CAST (_))
245
# define GNUTLS_INT_TO_POINTER(_) ((void*) GNUTLS_POINTER_TO_INT_CAST (_))
246
247
# define GNUTLS_KX_INVALID (-1)
248
249
# include <mpi.h>
250
251
typedef enum handshake_state_t { STATE0 = 0, STATE1, STATE2,
252
  STATE3, STATE4, STATE5, STATE6, STATE7, STATE8,
253
  STATE9, STATE10, STATE11, STATE12, STATE13, STATE14,
254
  STATE15, STATE16, STATE17, STATE18, STATE19,
255
  STATE20 = 20, STATE21, STATE22,
256
  STATE30 = 30, STATE31, STATE40 = 40, STATE41, STATE50 = 50,
257
  STATE90 = 90, STATE91, STATE92, STATE93, STATE94, STATE99 = 99,
258
  STATE100 = 100, STATE101, STATE102, STATE103, STATE104,
259
  STATE105, STATE106, STATE107, STATE108, STATE109, STATE110,
260
  STATE111, STATE112, STATE113, STATE114, STATE115,
261
  STATE150    /* key update */
262
} handshake_state_t;
263
264
typedef enum bye_state_t {
265
  BYE_STATE0 = 0, BYE_STATE1, BYE_STATE2
266
} bye_state_t;
267
268
typedef enum send_ticket_state_t {
269
  TICKET_STATE0 = 0, TICKET_STATE1
270
} send_ticket_state_t;
271
272
typedef enum reauth_state_t {
273
  REAUTH_STATE0 = 0, REAUTH_STATE1, REAUTH_STATE2, REAUTH_STATE3,
274
  REAUTH_STATE4, REAUTH_STATE5
275
} reauth_state_t;
276
277
# define TICKET_STATE session->internals.ticket_state
278
# define BYE_STATE session->internals.bye_state
279
# define REAUTH_STATE session->internals.reauth_state
280
281
typedef enum heartbeat_state_t {
282
  SHB_SEND1 = 0,
283
  SHB_SEND2,
284
  SHB_RECV
285
} heartbeat_state_t;
286
287
typedef enum recv_state_t {
288
  RECV_STATE_0 = 0,
289
  RECV_STATE_DTLS_RETRANSMIT,
290
  /* client-side false start state */
291
  RECV_STATE_FALSE_START_HANDLING,  /* we are calling gnutls_handshake() within record_recv() */
292
  RECV_STATE_FALSE_START, /* gnutls_record_recv() should complete the handshake */
293
  /* async handshake msg state */
294
  RECV_STATE_ASYNC_HANDSHAKE, /* an incomplete async handshake message was seen */
295
  /* server-side early start under TLS1.3; enabled when no client cert is received */
296
  RECV_STATE_EARLY_START_HANDLING,  /* we are calling gnutls_handshake() within record_recv() */
297
  RECV_STATE_EARLY_START, /* gnutls_record_recv() should complete the handshake */
298
  RECV_STATE_REHANDSHAKE, /* gnutls_record_recv() should complete any incoming re-handshake requests */
299
  RECV_STATE_REAUTH /* gnutls_record_recv() should complete any incoming reauthentication requests */
300
} recv_state_t;
301
302
# include "str.h"
303
304
/* This is the maximum number of algorithms (ciphers or macs etc).
305
 * keep it synced with GNUTLS_MAX_ALGORITHM_NUM in gnutls.h
306
 */
307
# define MAX_ALGOS GNUTLS_MAX_ALGORITHM_NUM
308
309
/* IDs are allocated in a way that all values fit in 64-bit integer as (1<<val) */
310
typedef enum extensions_t {
311
  GNUTLS_EXTENSION_INVALID = 0xffff,
312
  GNUTLS_EXTENSION_STATUS_REQUEST = 0,
313
  GNUTLS_EXTENSION_CERT_TYPE,
314
  GNUTLS_EXTENSION_CLIENT_CERT_TYPE,
315
  GNUTLS_EXTENSION_SERVER_CERT_TYPE,
316
  GNUTLS_EXTENSION_SUPPORTED_GROUPS,
317
  GNUTLS_EXTENSION_SUPPORTED_EC_POINT_FORMATS,
318
  GNUTLS_EXTENSION_SRP,
319
  GNUTLS_EXTENSION_SIGNATURE_ALGORITHMS,
320
  GNUTLS_EXTENSION_SRTP,
321
  GNUTLS_EXTENSION_HEARTBEAT,
322
  GNUTLS_EXTENSION_ALPN,
323
  GNUTLS_EXTENSION_ETM,
324
  GNUTLS_EXTENSION_EXT_MASTER_SECRET,
325
  GNUTLS_EXTENSION_SESSION_TICKET,
326
  GNUTLS_EXTENSION_KEY_SHARE,
327
  GNUTLS_EXTENSION_SUPPORTED_VERSIONS,
328
  GNUTLS_EXTENSION_POST_HANDSHAKE,
329
  GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
330
  GNUTLS_EXTENSION_SERVER_NAME,
331
  GNUTLS_EXTENSION_COOKIE,
332
  GNUTLS_EXTENSION_EARLY_DATA,
333
  GNUTLS_EXTENSION_PSK_KE_MODES,
334
  GNUTLS_EXTENSION_RECORD_SIZE_LIMIT,
335
  GNUTLS_EXTENSION_MAX_RECORD_SIZE,
336
  GNUTLS_EXTENSION_COMPRESS_CERTIFICATE,
337
  /*
338
   * pre_shared_key and dumbfw must always be the last extensions,
339
   * in that order */
340
  GNUTLS_EXTENSION_DUMBFW,
341
  GNUTLS_EXTENSION_PRE_SHARED_KEY,
342
  GNUTLS_EXTENSION_MAX  /* not real extension - used for iterators */
343
} extensions_t;
344
345
# define GNUTLS_EXTENSION_MAX_VALUE 63
346
# define ext_track_t uint64_t
347
348
# include <verify.h>
349
350
verify(GNUTLS_EXTENSION_MAX < GNUTLS_EXTENSION_MAX_VALUE);
351
verify(GNUTLS_EXTENSION_MAX < MAX_EXT_TYPES);
352
353
/* we must provide at least 16 extensions for users to register;
354
 * increase GNUTLS_EXTENSION_MAX_VALUE, MAX_EXT_TYPES and used_exts
355
 * type if this fails
356
 */
357
verify(GNUTLS_EXTENSION_MAX_VALUE - GNUTLS_EXTENSION_MAX >= 16);
358
359
/* The 'verify' symbol from <verify.h> is used extensively in the
360
 * code; undef it to avoid clash
361
 */
362
# undef verify
363
364
typedef enum { CIPHER_STREAM, CIPHER_BLOCK, CIPHER_AEAD } cipher_type_t;
365
366
/* Record Protocol */
367
typedef enum content_type_t {
368
  GNUTLS_CHANGE_CIPHER_SPEC = 20, GNUTLS_ALERT,
369
  GNUTLS_HANDSHAKE, GNUTLS_APPLICATION_DATA,
370
  GNUTLS_HEARTBEAT
371
} content_type_t;
372
373
# define GNUTLS_PK_ANY (gnutls_pk_algorithm_t)-1
374
# define GNUTLS_PK_NONE (gnutls_pk_algorithm_t)-2
375
376
0
# define GNUTLS_PK_IS_RSA(pk) ((pk) == GNUTLS_PK_RSA || (pk) == GNUTLS_PK_RSA_PSS)
377
378
/* Message buffers (mbuffers) structures */
379
380
/* this is actually the maximum number of distinct handshake
381
 * messages that can arrive in a single flight
382
 */
383
# define MAX_HANDSHAKE_MSGS 6
384
typedef struct {
385
  /* Handshake layer type and sequence of message */
386
  gnutls_handshake_description_t htype;
387
388
  /* The "real" type received; that is, it does not distinguish
389
   * HRR from server hello, while htype does */
390
  gnutls_handshake_description_t rtype;
391
  uint32_t length;
392
393
  /* valid in DTLS */
394
  uint16_t sequence;
395
396
  /* indicate whether that message is complete.
397
   * complete means start_offset == 0 and end_offset == length
398
   */
399
  uint32_t start_offset;
400
  uint32_t end_offset;
401
402
  uint8_t header[MAX_HANDSHAKE_HEADER_SIZE];
403
  int header_size;
404
405
  gnutls_buffer_st data;
406
} handshake_buffer_st;
407
408
typedef struct mbuffer_st {
409
  /* when used in mbuffer_head_st */
410
  struct mbuffer_st *next;
411
  struct mbuffer_st *prev;
412
413
  /* msg->size - mark = number of bytes left to process in this
414
     message. Mark should only be non-zero when this buffer is the
415
     head of the queue. */
416
  size_t mark;
417
418
  /* the data */
419
  gnutls_datum_t msg;
420
  size_t maximum_size;
421
422
  /* used during fill in, to separate header from data
423
   * body. */
424
  unsigned int uhead_mark;
425
426
  /* Filled in by record layer on recv:
427
   * type, record_sequence
428
   */
429
430
  /* record layer content type */
431
  content_type_t type;
432
433
  /* record layer sequence */
434
  uint64_t record_sequence;
435
436
  /* Filled in by handshake layer on send:
437
   * type, epoch, htype, handshake_sequence
438
   */
439
440
  /* Record layer epoch of message */
441
  uint16_t epoch;
442
443
  /* Handshake layer type and sequence of message */
444
  gnutls_handshake_description_t htype;
445
  uint16_t handshake_sequence;
446
} mbuffer_st;
447
448
typedef struct mbuffer_head_st {
449
  mbuffer_st *head;
450
  mbuffer_st *tail;
451
452
  unsigned int length;
453
  size_t byte_length;
454
} mbuffer_head_st;
455
456
/* Store & Retrieve functions defines:
457
 */
458
459
typedef struct auth_cred_st {
460
  gnutls_credentials_type_t algorithm;
461
462
  /* the type of credentials depends on algorithm
463
   */
464
  void *credentials;
465
  struct auth_cred_st *next;
466
} auth_cred_st;
467
468
/* session ticket definitions */
469
# define TICKET_MASTER_KEY_SIZE (TICKET_KEY_NAME_SIZE+TICKET_CIPHER_KEY_SIZE+TICKET_MAC_SECRET_SIZE)
470
# define TICKET_KEY_NAME_SIZE 16
471
# define TICKET_CIPHER_KEY_SIZE 32
472
# define TICKET_MAC_SECRET_SIZE 16
473
474
/* These are restricted by TICKET_CIPHER_KEY_SIZE and TICKET_MAC_SECRET_SIZE */
475
# define TICKET_CIPHER GNUTLS_CIPHER_AES_256_CBC
476
# define TICKET_IV_SIZE 16
477
# define TICKET_BLOCK_SIZE 16
478
479
# define TICKET_MAC_ALGO GNUTLS_MAC_SHA1
480
# define TICKET_MAC_SIZE 20 /* HMAC-SHA1 */
481
482
struct ticket_st {
483
  uint8_t key_name[TICKET_KEY_NAME_SIZE];
484
  uint8_t IV[TICKET_IV_SIZE];
485
  uint8_t *encrypted_state;
486
  uint16_t encrypted_state_len;
487
  uint8_t mac[TICKET_MAC_SIZE];
488
};
489
490
struct binder_data_st {
491
  const struct mac_entry_st *prf; /* non-null if this struct is set */
492
  gnutls_datum_t psk;
493
494
  /* 0-based index of the selected PSK.
495
   * This only applies if the HSK_PSK_SELECTED flag is set in internals.hsk_flags,
496
   * which signals a PSK has indeed been selected. */
497
  uint8_t idx;
498
  uint8_t resumption; /* whether it is a resumption binder */
499
};
500
501
typedef void (*gnutls_stek_rotation_callback_t)(const gnutls_datum_t * prev_key,
502
            const gnutls_datum_t * new_key,
503
            uint64_t t);
504
505
struct gnutls_key_st {
506
  struct {    /* These are kept outside the TLS1.3 union as they are
507
         * negotiated via extension, even before protocol is negotiated */
508
    gnutls_pk_params_st ecdh_params;
509
    gnutls_pk_params_st ecdhx_params;
510
    gnutls_pk_params_st dh_params;
511
  } kshare;
512
513
  /* The union contents depend on the negotiated protocol.
514
   * It should not contain any values which are allocated
515
   * prior to protocol negotiation, as it would be impossible
516
   * to deinitialize.
517
   */
518
  union {
519
    struct {
520
      /* the current (depending on state) secret, can be
521
       * early_secret, client_early_traffic_secret, ... */
522
      uint8_t temp_secret[MAX_HASH_SIZE];
523
      unsigned temp_secret_size;  /* depends on negotiated PRF size */
524
      uint8_t e_ckey[MAX_HASH_SIZE];  /* client_early_traffic_secret */
525
      uint8_t hs_ckey[MAX_HASH_SIZE]; /* client_hs_traffic_secret */
526
      uint8_t hs_skey[MAX_HASH_SIZE]; /* server_hs_traffic_secret */
527
      uint8_t ap_ckey[MAX_HASH_SIZE]; /* client_ap_traffic_secret */
528
      uint8_t ap_skey[MAX_HASH_SIZE]; /* server_ap_traffic_secret */
529
      uint8_t ap_expkey[MAX_HASH_SIZE]; /* {early_,}exporter_master_secret */
530
      uint8_t ap_rms[MAX_HASH_SIZE];  /* resumption_master_secret */
531
    } tls13;  /* tls1.3 */
532
533
    /* Follow the SSL3.0 and TLS1.2 key exchanges */
534
    struct {
535
      /* For ECDH KX */
536
      struct {
537
        gnutls_pk_params_st params; /* private part */
538
        /* public part */
539
        bigint_t x;
540
        bigint_t y;
541
        gnutls_datum_t raw; /* public key used in ECDHX (point) */
542
      } ecdh;
543
544
      /* For DH KX */
545
      struct {
546
        gnutls_pk_params_st params;
547
        bigint_t client_Y;
548
      } dh;
549
550
      /* for SRP KX */
551
      struct {
552
        bigint_t srp_key;
553
        bigint_t srp_g;
554
        bigint_t srp_p;
555
        bigint_t A;
556
        bigint_t B;
557
        bigint_t u;
558
        bigint_t b;
559
        bigint_t a;
560
        bigint_t x;
561
      } srp;
562
    } tls12;  /* from ssl3.0 to tls12 */
563
  } proto;
564
565
  /* binders / pre-shared keys in use; temporary storage.
566
   * On client side it will hold data for the resumption and external
567
   * PSKs After server hello is received the selected binder is set on 0 position
568
   * and HSK_PSK_SELECTED is set.
569
   *
570
   * On server side the first value is populated with
571
   * the selected PSK data if HSK_PSK_SELECTED flag is set. */
572
  struct binder_data_st binders[2];
573
574
  /* TLS pre-master key; applies to 1.2 and 1.3 */
575
  gnutls_datum_t key;
576
577
   uint8_t
578
      /* The key to encrypt and decrypt session tickets */
579
   session_ticket_key[TICKET_MASTER_KEY_SIZE],
580
      /* Static buffer for the previous key, whenever we need it */
581
   previous_ticket_key[TICKET_MASTER_KEY_SIZE],
582
      /* Initial key supplied by the caller */
583
   initial_stek[TICKET_MASTER_KEY_SIZE];
584
585
  /* Whether the initial_stek is set through
586
   * gnutls_session_ticket_enable_server() */
587
  bool stek_initialized;
588
589
  /* this is used to hold the peers authentication data
590
   */
591
  /* auth_info_t structures SHOULD NOT contain malloced
592
   * elements. Check gnutls_session_pack.c, and gnutls_auth.c.
593
   * Remember that this should be calloced!
594
   */
595
  void *auth_info;
596
  gnutls_credentials_type_t auth_info_type;
597
  int auth_info_size; /* needed in order to store to db for restoring
598
         */
599
  auth_cred_st *cred; /* used to specify keys/certificates etc */
600
601
  struct {
602
    uint64_t last_result;
603
    uint8_t was_rotated;
604
    gnutls_stek_rotation_callback_t cb;
605
  } totp;
606
};
607
608
typedef struct gnutls_key_st gnutls_key_st;
609
610
struct pin_info_st {
611
  gnutls_pin_callback_t cb;
612
  void *data;
613
};
614
615
struct record_state_st;
616
typedef struct record_state_st record_state_st;
617
618
struct record_parameters_st;
619
typedef struct record_parameters_st record_parameters_st;
620
621
# define GNUTLS_CIPHER_FLAG_ONLY_AEAD (1 << 0)  /* When set, this cipher is only available through the new AEAD API */
622
# define GNUTLS_CIPHER_FLAG_XOR_NONCE (1 << 1)  /* In this TLS AEAD cipher xor the implicit_iv with the nonce */
623
# define GNUTLS_CIPHER_FLAG_NO_REKEY  (1 << 2)  /* whether this tls1.3 cipher doesn't need to rekey after 2^24 messages */
624
# define GNUTLS_CIPHER_FLAG_TAG_PREFIXED (1 << 3) /* When set, this cipher prefixes authentication tag */
625
626
/* cipher and mac parameters */
627
typedef struct cipher_entry_st {
628
  const char *name;
629
  gnutls_cipher_algorithm_t id;
630
  uint16_t blocksize;
631
  uint16_t keysize;
632
  cipher_type_t type;
633
  uint16_t implicit_iv; /* the size of implicit IV - the IV generated but not sent */
634
  uint16_t explicit_iv; /* the size of explicit IV - the IV stored in record */
635
  uint16_t cipher_iv; /* the size of IV needed by the cipher */
636
  uint16_t tagsize;
637
  unsigned flags;
638
} cipher_entry_st;
639
640
typedef struct gnutls_cipher_suite_entry_st {
641
  const char *name;
642
  const uint8_t id[2];
643
  const char *canonical_name;
644
  gnutls_cipher_algorithm_t block_algorithm;
645
  gnutls_kx_algorithm_t kx_algorithm;
646
  gnutls_mac_algorithm_t mac_algorithm;
647
  gnutls_protocol_t min_version;  /* this cipher suite is supported
648
           * from 'version' and above;
649
           */
650
  gnutls_protocol_t max_version;  /* this cipher suite is not supported
651
           * after 'version' and above;
652
           */
653
  gnutls_protocol_t min_dtls_version; /* DTLS min version */
654
  gnutls_protocol_t max_dtls_version; /* DTLS max version */
655
  gnutls_mac_algorithm_t prf;
656
} gnutls_cipher_suite_entry_st;
657
658
typedef struct gnutls_group_entry_st {
659
  const char *name;
660
  gnutls_group_t id;
661
  const gnutls_datum_t *prime;
662
  const gnutls_datum_t *q;
663
  const gnutls_datum_t *generator;
664
  const unsigned *q_bits;
665
  gnutls_ecc_curve_t curve;
666
  gnutls_pk_algorithm_t pk;
667
  unsigned tls_id;  /* The RFC4492 namedCurve ID or TLS 1.3 group ID */
668
} gnutls_group_entry_st;
669
670
# define GNUTLS_MAC_FLAG_PREIMAGE_INSECURE  1 /* if this algorithm should not be trusted for pre-image attacks */
671
# define GNUTLS_MAC_FLAG_CONTINUOUS_MAC   (1 << 1)  /* if this MAC should be used in a 'continuous' way in TLS */
672
# define GNUTLS_MAC_FLAG_PREIMAGE_INSECURE_REVERTIBLE (1 << 2)  /* if this algorithm should not be trusted for pre-image attacks, but can be enabled through API */
673
# define GNUTLS_MAC_FLAG_ALLOW_INSECURE_REVERTIBLE  (1 << 3)  /* when checking with _gnutls_digest_is_insecure2, don't treat revertible setting as fatal */
674
/* This structure is used both for MACs and digests
675
 */
676
typedef struct mac_entry_st {
677
  const char *name;
678
  const char *oid;  /* OID of the hash - if it is a hash */
679
  const char *mac_oid;  /* OID of the MAC algorithm - if it is a MAC */
680
  gnutls_mac_algorithm_t id;
681
  unsigned output_size;
682
  unsigned key_size;
683
  unsigned nonce_size;
684
  unsigned placeholder; /* if set, then not a real MAC */
685
  unsigned block_size;  /* internal block size for HMAC */
686
  unsigned flags;
687
} mac_entry_st;
688
689
typedef struct {
690
  const char *name;
691
  gnutls_protocol_t id; /* gnutls internal version number */
692
  unsigned age;   /* internal ordering by protocol age */
693
  uint8_t major;    /* defined by the protocol */
694
  uint8_t minor;    /* defined by the protocol */
695
  transport_t transport;  /* Type of transport, stream or datagram */
696
  bool supported;   /* 0 not supported, > 0 is supported */
697
  bool supported_revertible;
698
  bool explicit_iv;
699
  bool extensions;  /* whether it supports extensions */
700
  bool selectable_sighash;  /* whether signatures can be selected */
701
  bool selectable_prf;  /* whether the PRF is ciphersuite-defined */
702
703
  /* if SSL3 is disabled this flag indicates that this protocol is a placeholder,
704
   * otherwise it prevents this protocol from being set as record version */
705
  bool obsolete;
706
  bool tls13_sem;   /* The TLS 1.3 handshake semantics */
707
  bool false_start; /* That version can be used with false start */
708
  bool only_extension;  /* negotiated only with an extension */
709
  bool post_handshake_auth; /* Supports the TLS 1.3 post handshake auth */
710
  bool key_shares;  /* TLS 1.3 key share key exchange */
711
  bool multi_ocsp;  /* TLS 1.3 multiple OCSP responses */
712
  /*
713
   * TLS versions modify the semantics of signature algorithms. This number
714
   * is there to distinguish signature algorithms semantics between versions
715
   * (maps to sign_algorithm_st->tls_sem)
716
   */
717
  uint8_t tls_sig_sem;
718
} version_entry_st;
719
720
/* STATE (cont) */
721
722
# include <hash_int.h>
723
# include <cipher_int.h>
724
725
typedef struct {
726
  uint8_t id[2];    /* used to be (in TLS 1.2) hash algorithm , PK algorithm */
727
  uint8_t tls_sem;  /* should match the protocol version's tls_sig_sem. */
728
} sign_algorithm_st;
729
730
/* This structure holds parameters got from TLS extension
731
 * mechanism. (some extensions may hold parameters in auth_info_t
732
 * structures also - see SRP).
733
 */
734
735
# define MAX_VERIFY_DATA_SIZE 36/* in SSL 3.0, 12 in TLS 1.0 */
736
737
/* auth_info_t structures now MAY contain malloced
738
 * elements.
739
 */
740
741
/* This structure and auth_info_t, are stored in the resume database,
742
 * and are restored, in case of resume.
743
 * Holds all the required parameters to resume the current
744
 * session.
745
 */
746
747
/* Note that the security parameters structure is set up after the
748
 * handshake has finished. The only value you may depend on while
749
 * the handshake is in progress is the cipher suite value.
750
 */
751
typedef struct {
752
  unsigned int entity;  /* GNUTLS_SERVER or GNUTLS_CLIENT */
753
754
  /* The epoch used to read and write */
755
  uint16_t epoch_read;
756
  uint16_t epoch_write;
757
758
  /* The epoch that the next handshake will initialize. */
759
  uint16_t epoch_next;
760
761
  /* The epoch at index 0 of record_parameters. */
762
  uint16_t epoch_min;
763
764
  /* this is the ciphersuite we are going to use
765
   * moved here from internals in order to be restored
766
   * on resume;
767
   */
768
  const struct gnutls_cipher_suite_entry_st *cs;
769
770
  /* This is kept outside the ciphersuite entry as on certain
771
   * TLS versions we need a separate PRF MAC, i.e., MD5_SHA1. */
772
  const mac_entry_st *prf;
773
774
  uint8_t master_secret[GNUTLS_MASTER_SIZE];
775
  uint8_t client_random[GNUTLS_RANDOM_SIZE];
776
  uint8_t server_random[GNUTLS_RANDOM_SIZE];
777
  uint8_t session_id[GNUTLS_MAX_SESSION_ID_SIZE];
778
  uint8_t session_id_size;
779
  time_t timestamp;
780
781
  /* whether client has agreed in post handshake auth - only set on server side */
782
  uint8_t post_handshake_auth;
783
784
  /* The maximum amount of plaintext sent in a record,
785
   * negotiated with the peer.
786
   */
787
  uint16_t max_record_send_size;
788
  uint16_t max_record_recv_size;
789
790
  /* The maximum amount of plaintext sent in a record, set by
791
   * the programmer.
792
   */
793
  uint16_t max_user_record_send_size;
794
  uint16_t max_user_record_recv_size;
795
796
  /* The maximum amount of early data */
797
  uint32_t max_early_data_size;
798
799
  /* holds the negotiated certificate types */
800
  gnutls_certificate_type_t client_ctype;
801
  gnutls_certificate_type_t server_ctype;
802
803
  /* The selected (after server hello EC or DH group */
804
  const gnutls_group_entry_st *grp;
805
806
  /* Holds the signature algorithm that will be used in this session,
807
   * selected by the server at the time of Ciphersuite/certificate
808
   * selection - see select_sign_algorithm() */
809
  gnutls_sign_algorithm_t server_sign_algo;
810
811
  /* Holds the signature algorithm used in this session - If any */
812
  gnutls_sign_algorithm_t client_sign_algo;
813
814
  /* Whether the master secret negotiation will be according to
815
   * draft-ietf-tls-session-hash-01
816
   */
817
  uint8_t ext_master_secret;
818
  /* encrypt-then-mac -> rfc7366 */
819
  uint8_t etm;
820
821
  uint8_t client_auth_type; /* gnutls_credentials_type_t */
822
  uint8_t server_auth_type;
823
824
  /* Note: if you add anything in Security_Parameters struct, then
825
   * also modify CPY_COMMON in constate.c, and session_pack.c,
826
   * in order to save it in the session storage.
827
   */
828
829
  /* Used by extensions that enable supplemental data: Which ones
830
   * do that? Do they belong in security parameters?
831
   */
832
  int do_recv_supplemental, do_send_supplemental;
833
  const version_entry_st *pversion;
834
} security_parameters_st;
835
836
typedef struct api_aead_cipher_hd_st {
837
  cipher_hd_st ctx_enc;
838
} api_aead_cipher_hd_st;
839
840
struct record_state_st {
841
  /* mac keys can be as long as the hash size */
842
  uint8_t mac_key[MAX_HASH_SIZE];
843
  unsigned mac_key_size;
844
845
  uint8_t iv[MAX_CIPHER_IV_SIZE];
846
  unsigned iv_size;
847
848
  uint8_t key[MAX_CIPHER_KEY_SIZE];
849
  unsigned key_size;
850
851
  union {
852
    auth_cipher_hd_st tls12;
853
    api_aead_cipher_hd_st aead;
854
  } ctx;
855
  unsigned aead_tag_size;
856
  unsigned is_aead;
857
  uint64_t sequence_number;
858
  gnutls_record_encryption_level_t level;
859
};
860
861
/* These are used to resolve relative epochs. These values are just
862
   outside the 16 bit range to prevent off-by-one errors. An absolute
863
   epoch may be referred to by its numeric id in the range
864
   0x0000-0xffff. */
865
# define EPOCH_READ_CURRENT  70000
866
# define EPOCH_WRITE_CURRENT 70001
867
# define EPOCH_NEXT   70002
868
869
struct record_parameters_st {
870
  uint16_t epoch;
871
  int initialized;
872
873
  const cipher_entry_st *cipher;
874
  bool etm;
875
  const mac_entry_st *mac;
876
877
  /* for DTLS sliding window */
878
  uint64_t dtls_sw_next;  /* The end point (next expected packet) of the sliding window without epoch */
879
  uint64_t dtls_sw_bits;
880
  unsigned dtls_sw_have_recv; /* whether at least a packet has been received */
881
882
  record_state_st read;
883
  record_state_st write;
884
885
  /* Whether this state is in use, i.e., if there is
886
     a pending handshake message waiting to be encrypted
887
     under this epoch's parameters.
888
   */
889
  int usage_cnt;
890
};
891
892
typedef struct {
893
  unsigned int priorities[MAX_ALGOS];
894
  unsigned int num_priorities;
895
} priority_st;
896
897
typedef enum {
898
  SR_DISABLED,
899
  SR_UNSAFE,
900
  SR_PARTIAL,
901
  SR_SAFE
902
} safe_renegotiation_t;
903
904
# define MAX_CIPHERSUITE_SIZE 256
905
906
typedef struct ciphersuite_list_st {
907
  const gnutls_cipher_suite_entry_st *entry[MAX_CIPHERSUITE_SIZE];
908
  unsigned int size;
909
} ciphersuite_list_st;
910
911
typedef struct group_list_st {
912
  const gnutls_group_entry_st *entry[MAX_ALGOS];
913
  unsigned int size;
914
  bool have_ffdhe;
915
} group_list_st;
916
917
typedef struct sign_algo_list_st {
918
  const struct gnutls_sign_entry_st *entry[MAX_ALGOS];
919
  unsigned int size;
920
} sign_algo_list_st;
921
922
# include "atomic.h"
923
924
/* For the external api */
925
struct gnutls_priority_st {
926
  priority_st protocol;
927
  priority_st client_ctype;
928
  priority_st server_ctype;
929
930
  /* The following are not necessary to be stored in
931
   * the structure; however they are required by the
932
   * external APIs: gnutls_priority_*_list() */
933
  priority_st _cipher;
934
  priority_st _mac;
935
  priority_st _kx;
936
  priority_st _sign_algo;
937
  priority_st _supported_ecc;
938
939
  /* the supported groups */
940
  group_list_st groups;
941
942
  /* the supported signature algorithms */
943
  sign_algo_list_st sigalg;
944
945
  /* the supported ciphersuites */
946
  ciphersuite_list_st cs;
947
948
  /* to disable record padding */
949
  bool no_extensions;
950
951
  safe_renegotiation_t sr;
952
  bool min_record_version;
953
  bool server_precedence;
954
  bool allow_server_key_usage_violation;  /* for test suite purposes only */
955
  bool no_status_request;
956
  bool no_tickets;
957
  bool no_tickets_tls12;
958
  bool have_cbc;
959
  bool have_psk;
960
  bool force_etm;
961
  unsigned int additional_verify_flags;
962
  bool tls13_compat_mode;
963
  bool force_ext_master_secret;
964
965
  /* TLS_FALLBACK_SCSV */
966
  bool fallback;
967
968
  /* The session's expected security level.
969
   * Will be used to determine the minimum DH bits,
970
   * (or the acceptable certificate security level).
971
   */
972
  gnutls_sec_param_t level;
973
974
  /* these should be accessed from
975
   * session->internals.VAR names */
976
  bool _allow_large_records;
977
  bool _allow_small_records;
978
  bool _no_etm;
979
  bool _no_ext_master_secret;
980
  bool _allow_key_usage_violation;
981
  bool _allow_wrong_pms;
982
  bool _dumbfw;
983
  unsigned int _dh_prime_bits;  /* old (deprecated) variable */
984
985
   DEF_ATOMIC_INT(usage_cnt);
986
};
987
988
/* Allow around 50KB of length-hiding padding
989
 * when using legacy padding,
990
 * or around 3.2MB when using new padding. */
991
# define DEFAULT_MAX_EMPTY_RECORDS 200
992
993
# define ENABLE_COMPAT(x) \
994
        (x)->allow_large_records = 1; \
995
        (x)->allow_small_records = 1; \
996
        (x)->no_etm = 1; \
997
        (x)->no_ext_master_secret = 1; \
998
        (x)->allow_key_usage_violation = 1; \
999
        (x)->allow_wrong_pms = 1; \
1000
        (x)->dumbfw = 1
1001
1002
# define ENABLE_PRIO_COMPAT(x) \
1003
        (x)->_allow_large_records = 1; \
1004
        (x)->_allow_small_records = 1; \
1005
        (x)->_no_etm = 1; \
1006
        (x)->_no_ext_master_secret = 1; \
1007
        (x)->_allow_key_usage_violation = 1; \
1008
        (x)->_allow_wrong_pms = 1; \
1009
        (x)->_dumbfw = 1
1010
1011
/* DH and RSA parameters types.
1012
 */
1013
typedef struct gnutls_dh_params_int {
1014
  /* [0] is the prime, [1] is the generator, [2] is Q if available.
1015
   */
1016
  bigint_t params[3];
1017
  int q_bits;   /* length of q in bits. If zero then length is unknown.
1018
         */
1019
} dh_params_st;
1020
1021
/* TLS 1.3 session ticket
1022
 */
1023
typedef struct {
1024
  struct timespec arrival_time;
1025
  struct timespec creation_time;
1026
  uint32_t lifetime;
1027
  uint32_t age_add;
1028
  uint8_t nonce[255];
1029
  size_t nonce_size;
1030
  const mac_entry_st *prf;
1031
  uint8_t resumption_master_secret[MAX_HASH_SIZE];
1032
  gnutls_datum_t ticket;
1033
} tls13_ticket_st;
1034
1035
/* DTLS session state
1036
 */
1037
typedef struct {
1038
  /* HelloVerifyRequest DOS prevention cookie */
1039
  gnutls_datum_t dcookie;
1040
1041
  /* For DTLS handshake fragmentation and reassembly. */
1042
  uint16_t hsk_write_seq;
1043
  /* the sequence number of the expected packet */
1044
  unsigned int hsk_read_seq;
1045
  uint16_t mtu;
1046
1047
  /* a flight transmission is in process */
1048
  bool flight_init;
1049
  /* whether this is the last flight in the protocol  */
1050
  bool last_flight;
1051
1052
  /* the retransmission timeout in milliseconds */
1053
  unsigned int retrans_timeout_ms;
1054
1055
  unsigned int hsk_hello_verify_requests;
1056
1057
  /* The actual retrans_timeout for the next message (e.g. doubled or so)
1058
   */
1059
  unsigned int actual_retrans_timeout_ms;
1060
1061
  /* timers to handle async handshake after gnutls_handshake()
1062
   * has terminated. Required to handle retransmissions.
1063
   */
1064
  time_t async_term;
1065
1066
  /* last retransmission triggered by record layer */
1067
  struct timespec last_retransmit;
1068
  unsigned int packets_dropped;
1069
} dtls_st;
1070
1071
typedef struct tfo_st {
1072
  int fd;
1073
  int flags;
1074
  bool connect_only;  /* a previous sendmsg() failed, attempting connect() */
1075
  struct sockaddr_storage connect_addr;
1076
  socklen_t connect_addrlen;
1077
} tfo_st;
1078
1079
typedef struct {
1080
  /* holds all the parsed data received by the record layer */
1081
  mbuffer_head_st record_buffer;
1082
1083
  int handshake_hash_buffer_prev_len; /* keeps the length of handshake_hash_buffer, excluding
1084
             * the last received message */
1085
  unsigned handshake_hash_buffer_client_hello_len;  /* if non-zero it is the length of data until the client hello message */
1086
  unsigned handshake_hash_buffer_client_kx_len; /* if non-zero it is the length of data until the
1087
               * the client key exchange message */
1088
  unsigned handshake_hash_buffer_server_finished_len; /* if non-zero it is the length of data until the
1089
                 * the server finished message */
1090
  unsigned handshake_hash_buffer_client_finished_len; /* if non-zero it is the length of data until the
1091
                 * the client finished message */
1092
  gnutls_buffer_st handshake_hash_buffer; /* used to keep the last received handshake
1093
             * message */
1094
1095
  bool resumable;   /* if we can resume that session */
1096
1097
  send_ticket_state_t ticket_state; /* used by gnutls_session_ticket_send() */
1098
  bye_state_t bye_state;  /* used by gnutls_bye() */
1099
  reauth_state_t reauth_state;  /* used by gnutls_reauth() */
1100
1101
  handshake_state_t handshake_final_state;
1102
  handshake_state_t handshake_state;  /* holds
1103
             * a number which indicates where
1104
             * the handshake procedure has been
1105
             * interrupted. If it is 0 then
1106
             * no interruption has happened.
1107
             */
1108
1109
  bool invalid_connection;  /* if this session is valid */
1110
1111
  bool may_not_read;  /* if it's 0 then we can read/write, otherwise it's forbidden to read/write
1112
         */
1113
  bool may_not_write;
1114
  bool read_eof;    /* non-zero if we have received a closure alert. */
1115
1116
  int last_alert;   /* last alert received */
1117
1118
  /* The last handshake messages sent or received.
1119
   */
1120
  int last_handshake_in;
1121
  int last_handshake_out;
1122
1123
  /* priorities */
1124
  struct gnutls_priority_st *priorities;
1125
1126
  /* variables directly set when setting the priorities above, or
1127
   * when overriding them */
1128
  bool allow_large_records;
1129
  bool allow_small_records;
1130
  bool no_etm;
1131
  bool no_ext_master_secret;
1132
  bool allow_key_usage_violation;
1133
  bool allow_wrong_pms;
1134
  bool dumbfw;
1135
1136
  /* old (deprecated) variable. This is used for both srp_prime_bits
1137
   * and dh_prime_bits as they don't overlap */
1138
  /* For SRP: minimum bits to allow for SRP
1139
   * use gnutls_srp_set_prime_bits() to adjust it.
1140
   */
1141
  uint16_t dh_prime_bits; /* srp_prime_bits */
1142
1143
  /* resumed session */
1144
  bool resumed;   /* if we are resuming a session */
1145
1146
  /* server side: non-zero if resumption was requested by client
1147
   * client side: non-zero if we set resumption parameters */
1148
  bool resumption_requested;
1149
  security_parameters_st resumed_security_parameters;
1150
  gnutls_datum_t resumption_data; /* copy of input to gnutls_session_set_data() */
1151
1152
  /* These buffers are used in the handshake
1153
   * protocol only. freed using _gnutls_handshake_io_buffer_clear();
1154
   */
1155
  mbuffer_head_st handshake_send_buffer;
1156
  mbuffer_head_st handshake_header_recv_buffer;
1157
  handshake_buffer_st handshake_recv_buffer[MAX_HANDSHAKE_MSGS];
1158
  int handshake_recv_buffer_size;
1159
1160
  /* this buffer holds a record packet -mostly used for
1161
   * non blocking IO.
1162
   */
1163
  mbuffer_head_st record_recv_buffer; /* buffer holding the unparsed record that is currently
1164
             * being received */
1165
  mbuffer_head_st record_send_buffer; /* holds cached data
1166
             * for the gnutls_io_write_buffered()
1167
             * function.
1168
             */
1169
  size_t record_send_buffer_user_size;  /* holds the
1170
             * size of the user specified data to
1171
             * send.
1172
             */
1173
1174
  mbuffer_head_st early_data_recv_buffer;
1175
  gnutls_buffer_st early_data_presend_buffer;
1176
1177
  record_send_state_t rsend_state;
1178
  /* buffer used temporarily during key update */
1179
  gnutls_buffer_st record_key_update_buffer;
1180
  gnutls_buffer_st record_presend_buffer; /* holds cached data
1181
             * for the gnutls_record_send()
1182
             * function.
1183
             */
1184
1185
  /* buffer used temporarily during TLS1.3 reauthentication */
1186
  gnutls_buffer_st reauth_buffer;
1187
1188
  time_t expire_time; /* after expire_time seconds this session will expire */
1189
  const struct mod_auth_st_int *auth_struct;  /* used in handshake packets and KX algorithms */
1190
1191
  /* this is the highest version available
1192
   * to the peer. (advertized version).
1193
   * This is obtained by the Handshake Client Hello
1194
   * message. (some implementations read the Record version)
1195
   */
1196
  uint8_t adv_version_major;
1197
  uint8_t adv_version_minor;
1198
1199
  /* if this is non zero a certificate request message
1200
   * will be sent to the client. - only if the ciphersuite
1201
   * supports it. In server side it contains GNUTLS_CERT_REQUIRE
1202
   * or similar.
1203
   */
1204
  gnutls_certificate_request_t send_cert_req;
1205
1206
  /* callback to print the full path of certificate
1207
   * validation to the trusted root.
1208
   */
1209
  gnutls_verify_output_function *cert_output_callback;
1210
1211
  size_t max_handshake_data_buffer_size;
1212
1213
  /* PUSH & PULL functions.
1214
   */
1215
  gnutls_pull_timeout_func pull_timeout_func;
1216
  gnutls_pull_func pull_func;
1217
  gnutls_push_func push_func;
1218
  gnutls_vec_push_func vec_push_func;
1219
  gnutls_errno_func errno_func;
1220
  /* Holds the first argument of PUSH and PULL
1221
   * functions;
1222
   */
1223
  gnutls_transport_ptr_t transport_recv_ptr;
1224
  gnutls_transport_ptr_t transport_send_ptr;
1225
1226
  /* STORE & RETRIEVE functions. Only used if other
1227
   * backend than gdbm is used.
1228
   */
1229
  gnutls_db_store_func db_store_func;
1230
  gnutls_db_retr_func db_retrieve_func;
1231
  gnutls_db_remove_func db_remove_func;
1232
  void *db_ptr;
1233
1234
  /* post client hello callback (server side only)
1235
   */
1236
  gnutls_handshake_post_client_hello_func user_hello_func;
1237
  /* handshake hook function */
1238
  gnutls_handshake_hook_func h_hook;
1239
  unsigned int h_type;  /* the hooked type */
1240
  int16_t h_post;   /* whether post-generation/receive */
1241
  gnutls_handshake_read_func h_read_func;
1242
  gnutls_handshake_secret_func h_secret_func;
1243
  gnutls_alert_read_func alert_read_func;
1244
1245
  gnutls_keylog_func keylog_func;
1246
1247
  /* holds the selected certificate and key.
1248
   * use _gnutls_selected_certs_deinit() and _gnutls_selected_certs_set()
1249
   * to change them.
1250
   */
1251
  gnutls_pcert_st *selected_cert_list;
1252
  uint16_t selected_cert_list_length;
1253
  struct gnutls_privkey_st *selected_key;
1254
1255
  /* new callbacks such as gnutls_certificate_retrieve_function3
1256
   * set the selected_ocsp datum values. The older OCSP callback-based
1257
   * functions, set the ocsp_func. The former takes precedence when
1258
   * set.
1259
   */
1260
  gnutls_ocsp_data_st *selected_ocsp;
1261
  uint16_t selected_ocsp_length;
1262
  gnutls_status_request_ocsp_func selected_ocsp_func;
1263
  void *selected_ocsp_func_ptr;
1264
  bool selected_need_free;
1265
1266
  /* This holds the default version that our first
1267
   * record packet will have. */
1268
  uint8_t default_record_version[2];
1269
  uint8_t default_hello_version[2];
1270
1271
  void *user_ptr;
1272
1273
  /* Holds 0 if the last called function was interrupted while
1274
   * receiving, and non zero otherwise.
1275
   */
1276
  bool direction;
1277
1278
  /* If non zero the server will not advertise the CA's he
1279
   * trusts (do not send an RDN sequence).
1280
   */
1281
  bool ignore_rdn_sequence;
1282
1283
  /* This is used to set an arbitrary version in the RSA
1284
   * PMS secret. Can be used by clients to test whether the
1285
   * server checks that version. (** only used in gnutls-cli-debug)
1286
   */
1287
  uint8_t rsa_pms_version[2];
1288
1289
  /* To avoid using global variables, and especially on Windows where
1290
   * the application may use a different errno variable than GnuTLS,
1291
   * it is possible to use gnutls_transport_set_errno to set a
1292
   * session-specific errno variable in the user-replaceable push/pull
1293
   * functions.  This value is used by the send/recv functions.  (The
1294
   * strange name of this variable is because 'errno' is typically
1295
   * #define'd.)
1296
   */
1297
  int errnum;
1298
1299
  /* A handshake process has been completed */
1300
  bool initial_negotiation_completed;
1301
  void *post_negotiation_lock;  /* protects access to the variable above
1302
           * in the cases where negotiation is incomplete
1303
           * after gnutls_handshake() - early/false start */
1304
1305
  /* The type of transport protocol; stream or datagram */
1306
  transport_t transport;
1307
1308
  /* DTLS session state */
1309
  dtls_st dtls;
1310
  /* Protect from infinite loops due to GNUTLS_E_LARGE_PACKET non-handling
1311
   * or due to multiple alerts being received. */
1312
  unsigned handshake_suspicious_loops;
1313
  /* should be non-zero when a handshake is in progress */
1314
  bool handshake_in_progress;
1315
1316
  /* if set it means that the master key was set using
1317
   * gnutls_session_set_master() rather than being negotiated. */
1318
  bool premaster_set;
1319
1320
  unsigned int cb_tls_unique_len;
1321
  unsigned char cb_tls_unique[MAX_VERIFY_DATA_SIZE];
1322
1323
  /* starting time of current handshake */
1324
  struct timespec handshake_start_time;
1325
1326
  /* expected end time of current handshake (start+timeout);
1327
   * this is only filled if a handshake_time_ms is set. */
1328
  struct timespec handshake_abs_timeout;
1329
1330
  /* An estimation of round-trip time under TLS1.3; populated in client side only */
1331
  unsigned ertt;
1332
1333
  unsigned int handshake_timeout_ms;  /* timeout in milliseconds */
1334
  unsigned int record_timeout_ms; /* timeout in milliseconds */
1335
1336
  /* saved context of post handshake certificate request. In
1337
   * client side is what we received in server's certificate request;
1338
   * in server side is what we sent to client. */
1339
  gnutls_datum_t post_handshake_cr_context;
1340
  /* it is a copy of the handshake hash buffer if post handshake is used */
1341
  gnutls_buffer_st post_handshake_hash_buffer;
1342
1343
/* When either of PSK or DHE-PSK is received */
1344
# define HSK_PSK_KE_MODES_RECEIVED (HSK_PSK_KE_MODE_PSK|HSK_PSK_KE_MODE_DHE_PSK|HSK_PSK_KE_MODE_INVALID)
1345
1346
# define HSK_CRT_VRFY_EXPECTED 1
1347
# define HSK_CRT_ASKED (1<<2)
1348
# define HSK_HRR_SENT (1<<3)
1349
# define HSK_HRR_RECEIVED (1<<4)
1350
# define HSK_CRT_REQ_SENT (1<<5)
1351
# define HSK_COMP_CRT_REQ_SENT (1<<6) /* whether certificate compression has been requested */
1352
# define HSK_KEY_UPDATE_ASKED (1<<7)  /* flag is not used during handshake */
1353
# define HSK_FALSE_START_USED (1<<8)  /* TLS1.2 only */
1354
# define HSK_HAVE_FFDHE (1<<9)  /* whether the peer has advertized at least an FFDHE group */
1355
# define HSK_USED_FFDHE (1<<10) /* whether ffdhe was actually negotiated and used */
1356
# define HSK_PSK_KE_MODES_SENT (1<<11)
1357
# define HSK_PSK_KE_MODE_PSK (1<<12)  /* client: whether PSK without DH is allowed,
1358
           * server: whether PSK without DH is selected. */
1359
# define HSK_PSK_KE_MODE_INVALID (1<<13)/* server: no compatible PSK modes were seen */
1360
# define HSK_PSK_KE_MODE_DHE_PSK (1<<14)/* server: whether PSK with DH is selected
1361
           * client: whether PSK with DH is allowed
1362
           */
1363
# define HSK_PSK_SELECTED (1<<15) /* server: whether PSK was selected, either for resumption or not;
1364
           *         on resumption session->internals.resumed will be set as well.
1365
           * client: the same */
1366
# define HSK_KEY_SHARE_SENT (1<<16) /* server: key share was sent to client */
1367
# define HSK_KEY_SHARE_RECEIVED (1<<17) /* client: key share was received
1368
           * server: key share was received and accepted */
1369
# define HSK_TLS13_TICKET_SENT (1<<18)  /* client: sent a ticket under TLS1.3;
1370
           * server: a ticket was sent to client.
1371
           */
1372
# define HSK_TLS12_TICKET_SENT (1<<19)  /* client: sent a ticket under TLS1.2;
1373
           * server: a ticket was sent to client.
1374
           */
1375
# define HSK_TICKET_RECEIVED (1<<20)  /* client: a session ticket was received */
1376
# define HSK_EARLY_START_USED (1<<21)
1377
# define HSK_EARLY_DATA_IN_FLIGHT (1<<22) /* client: sent early_data extension in ClientHello
1378
             * server: early_data extension was seen in ClientHello
1379
             */
1380
# define HSK_EARLY_DATA_ACCEPTED (1<<23)/* client: early_data extension was seen in EncryptedExtensions
1381
           * server: intend to process early data
1382
           */
1383
# define HSK_RECORD_SIZE_LIMIT_NEGOTIATED (1<<24)
1384
# define HSK_RECORD_SIZE_LIMIT_SENT (1<<25) /* record_size_limit extension was sent */
1385
# define HSK_RECORD_SIZE_LIMIT_RECEIVED (1<<26) /* server: record_size_limit extension was seen but not accepted yet */
1386
# define HSK_OCSP_REQUESTED (1<<27) /* server: client requested OCSP stapling */
1387
# define HSK_CLIENT_OCSP_REQUESTED (1<<28)  /* client: server requested OCSP stapling */
1388
# define HSK_SERVER_HELLO_RECEIVED (1<<29)  /* client: Server Hello message has been received */
1389
1390
  /* The hsk_flags are for use within the ongoing handshake;
1391
   * they are reset to zero prior to handshake start by gnutls_handshake. */
1392
  unsigned hsk_flags;
1393
  struct timespec last_key_update;
1394
  unsigned key_update_count;
1395
  /* Read-only pointer to the full ClientHello message */
1396
  gnutls_buffer_st full_client_hello;
1397
  /* The offset at which extensions start in the ClientHello buffer */
1398
  int extensions_offset;
1399
1400
  gnutls_buffer_st hb_local_data;
1401
  gnutls_buffer_st hb_remote_data;
1402
  struct timespec hb_ping_start;  /* timestamp: when first HeartBeat ping was sent */
1403
  struct timespec hb_ping_sent; /* timestamp: when last HeartBeat ping was sent */
1404
  unsigned int hb_actual_retrans_timeout_ms;  /* current timeout, in milliseconds */
1405
  unsigned int hb_retrans_timeout_ms; /* the default timeout, in milliseconds */
1406
  unsigned int hb_total_timeout_ms; /* the total timeout, in milliseconds */
1407
1408
  bool ocsp_check_ok; /* will be zero if the OCSP response TLS extension
1409
         * check failed (OCSP was old/unrelated or so). */
1410
1411
  heartbeat_state_t hb_state; /* for ping */
1412
1413
  recv_state_t recv_state;  /* state of the receive function */
1414
1415
  /* if set, server and client random were set by the application */
1416
  bool sc_random_set;
1417
1418
# define INT_FLAG_NO_TLS13 (1LL<<60)
1419
  uint64_t flags;   /* the flags in gnutls_init() and GNUTLS_INT_FLAGS */
1420
1421
  /* a verify callback to override the verify callback from the credentials
1422
   * structure */
1423
  gnutls_certificate_verify_function *verify_callback;
1424
  gnutls_typed_vdata_st *vc_data;
1425
  gnutls_typed_vdata_st vc_sdata;
1426
  unsigned vc_elements;
1427
  unsigned vc_status;
1428
  unsigned int additional_verify_flags; /* may be set by priorities or the vc functions */
1429
1430
  /* we append the verify flags because these can be set,
1431
   * either by this function or by gnutls_session_set_verify_cert().
1432
   * However, we ensure that a single profile is set. */
1433
# define ADD_PROFILE_VFLAGS(session, vflags) do { \
1434
  if ((session->internals.additional_verify_flags & GNUTLS_VFLAGS_PROFILE_MASK) && \
1435
      (vflags & GNUTLS_VFLAGS_PROFILE_MASK)) \
1436
    session->internals.additional_verify_flags &= ~GNUTLS_VFLAGS_PROFILE_MASK; \
1437
  session->internals.additional_verify_flags |= vflags; \
1438
  } while(0)
1439
1440
  /* the SHA256 hash of the peer's certificate */
1441
  uint8_t cert_hash[32];
1442
  bool cert_hash_set;
1443
1444
  /* The saved username from PSK or SRP auth */
1445
  char *saved_username;
1446
  /* Length of the saved username without the NULL terminating byte.
1447
   * Must be set to -1 when saved username is NULL
1448
   */
1449
  int saved_username_size;
1450
1451
  /* Needed for TCP Fast Open (TFO), set by gnutls_transport_set_fastopen() */
1452
  tfo_st tfo;
1453
1454
  struct gnutls_supplemental_entry_st *rsup;
1455
  unsigned rsup_size;
1456
1457
  struct hello_ext_entry_st *rexts;
1458
  unsigned rexts_size;
1459
1460
  struct {    /* ext_data[id] contains data for extension_t id */
1461
    gnutls_ext_priv_data_t priv;
1462
    gnutls_ext_priv_data_t resumed_priv;
1463
    uint8_t set;
1464
    uint8_t resumed_set;
1465
  } ext_data[MAX_EXT_TYPES];
1466
1467
  /* In case of a client holds the extensions we sent to the peer;
1468
   * otherwise the extensions we received from the client. This is
1469
   * an OR of (1<<extensions_t values).
1470
   */
1471
  ext_track_t used_exts;
1472
1473
  gnutls_ext_flags_t ext_msg; /* accessed through _gnutls_ext_get/set_msg() */
1474
1475
  /* this is not the negotiated max_record_recv_size, but the actual maximum
1476
   * receive size */
1477
  unsigned max_recv_size;
1478
1479
  /* candidate groups to be selected for security params groups, they are
1480
   * prioritized in isolation under TLS1.2 */
1481
  const gnutls_group_entry_st *cand_ec_group;
1482
  const gnutls_group_entry_st *cand_dh_group;
1483
  /* used under TLS1.3+ */
1484
  const gnutls_group_entry_st *cand_group;
1485
1486
  /* the ciphersuite received in HRR */
1487
  uint8_t hrr_cs[2];
1488
1489
  /* this is only used under TLS1.2 or earlier */
1490
  int session_ticket_renew;
1491
1492
  tls13_ticket_st tls13_ticket;
1493
1494
  /* the amount of early data received so far */
1495
  uint32_t early_data_received;
1496
1497
  /* anti-replay measure for 0-RTT mode */
1498
  gnutls_anti_replay_t anti_replay;
1499
1500
  /* Protects _gnutls_epoch_gc() from _gnutls_epoch_get(); these may be
1501
   * called in parallel when false start is used and false start is used. */
1502
  void *epoch_lock;
1503
1504
  /* indicates whether or not was KTLS initialized properly. */
1505
  int ktls_enabled;
1506
1507
  /* Compression method for certificate compression */
1508
  gnutls_compression_method_t compress_certificate_method;
1509
1510
  /* If you add anything here, check _gnutls_handshake_internal_state_clear().
1511
   */
1512
} internals_st;
1513
1514
/* Maximum number of epochs we keep around. */
1515
# define MAX_EPOCH_INDEX 4
1516
1517
# define reset_cand_groups(session) \
1518
  session->internals.cand_ec_group = session->internals.cand_dh_group = \
1519
    session->internals.cand_group = NULL
1520
1521
struct gnutls_session_int {
1522
  security_parameters_st security_parameters;
1523
  record_parameters_st *record_parameters[MAX_EPOCH_INDEX];
1524
  internals_st internals;
1525
  gnutls_key_st key;
1526
};
1527
1528
/* functions
1529
 */
1530
void _gnutls_free_auth_info(gnutls_session_t session);
1531
1532
/* These two macros return the advertised TLS version of
1533
 * the peer.
1534
 */
1535
# define _gnutls_get_adv_version_major(session) \
1536
  session->internals.adv_version_major
1537
1538
# define _gnutls_get_adv_version_minor(session) \
1539
  session->internals.adv_version_minor
1540
1541
# define set_adv_version(session, major, minor) \
1542
  session->internals.adv_version_major = major; \
1543
  session->internals.adv_version_minor = minor
1544
1545
int _gnutls_is_secure_mem_null(const void *);
1546
1547
inline static const version_entry_st *get_version(gnutls_session_t session)
1548
0
{
1549
0
  return session->security_parameters.pversion;
1550
0
}
Unexecuted instantiation: common.c:get_version
Unexecuted instantiation: crl.c:get_version
Unexecuted instantiation: crq.c:get_version
Unexecuted instantiation: dn.c:get_version
Unexecuted instantiation: extensions.c:get_version
Unexecuted instantiation: hostname-verify.c:get_version
Unexecuted instantiation: key_decode.c:get_version
Unexecuted instantiation: key_encode.c:get_version
Unexecuted instantiation: mpi.c:get_version
Unexecuted instantiation: ocsp.c:get_version
Unexecuted instantiation: output.c:get_version
Unexecuted instantiation: pkcs12.c:get_version
Unexecuted instantiation: pkcs12_bag.c:get_version
Unexecuted instantiation: pkcs12_encr.c:get_version
Unexecuted instantiation: pkcs7-crypt.c:get_version
Unexecuted instantiation: privkey_openssl.c:get_version
Unexecuted instantiation: privkey_pkcs8.c:get_version
Unexecuted instantiation: privkey_pkcs8_pbes1.c:get_version
Unexecuted instantiation: prov-seed.c:get_version
Unexecuted instantiation: sign.c:get_version
Unexecuted instantiation: time.c:get_version
Unexecuted instantiation: tls_features.c:get_version
Unexecuted instantiation: verify-high.c:get_version
Unexecuted instantiation: verify-high2.c:get_version
Unexecuted instantiation: verify.c:get_version
Unexecuted instantiation: virt-san.c:get_version
Unexecuted instantiation: x509.c:get_version
Unexecuted instantiation: x509_dn.c:get_version
Unexecuted instantiation: x509_ext.c:get_version
Unexecuted instantiation: x509_write.c:get_version
Unexecuted instantiation: attributes.c:get_version
Unexecuted instantiation: email-verify.c:get_version
Unexecuted instantiation: ip.c:get_version
Unexecuted instantiation: krb5.c:get_version
Unexecuted instantiation: name_constraints.c:get_version
1551
1552
inline static unsigned get_num_version(gnutls_session_t session)
1553
0
{
1554
0
  if (likely(session->security_parameters.pversion != NULL))
1555
0
    return session->security_parameters.pversion->id;
1556
0
  else
1557
0
    return GNUTLS_VERSION_UNKNOWN;
1558
0
}
Unexecuted instantiation: common.c:get_num_version
Unexecuted instantiation: crl.c:get_num_version
Unexecuted instantiation: crq.c:get_num_version
Unexecuted instantiation: dn.c:get_num_version
Unexecuted instantiation: extensions.c:get_num_version
Unexecuted instantiation: hostname-verify.c:get_num_version
Unexecuted instantiation: key_decode.c:get_num_version
Unexecuted instantiation: key_encode.c:get_num_version
Unexecuted instantiation: mpi.c:get_num_version
Unexecuted instantiation: ocsp.c:get_num_version
Unexecuted instantiation: output.c:get_num_version
Unexecuted instantiation: pkcs12.c:get_num_version
Unexecuted instantiation: pkcs12_bag.c:get_num_version
Unexecuted instantiation: pkcs12_encr.c:get_num_version
Unexecuted instantiation: pkcs7-crypt.c:get_num_version
Unexecuted instantiation: privkey_openssl.c:get_num_version
Unexecuted instantiation: privkey_pkcs8.c:get_num_version
Unexecuted instantiation: privkey_pkcs8_pbes1.c:get_num_version
Unexecuted instantiation: prov-seed.c:get_num_version
Unexecuted instantiation: sign.c:get_num_version
Unexecuted instantiation: time.c:get_num_version
Unexecuted instantiation: tls_features.c:get_num_version
Unexecuted instantiation: verify-high.c:get_num_version
Unexecuted instantiation: verify-high2.c:get_num_version
Unexecuted instantiation: verify.c:get_num_version
Unexecuted instantiation: virt-san.c:get_num_version
Unexecuted instantiation: x509.c:get_num_version
Unexecuted instantiation: x509_dn.c:get_num_version
Unexecuted instantiation: x509_ext.c:get_num_version
Unexecuted instantiation: x509_write.c:get_num_version
Unexecuted instantiation: attributes.c:get_num_version
Unexecuted instantiation: email-verify.c:get_num_version
Unexecuted instantiation: ip.c:get_num_version
Unexecuted instantiation: krb5.c:get_num_version
Unexecuted instantiation: name_constraints.c:get_num_version
1559
1560
void _gnutls_priority_update_fips(void);
1561
void _gnutls_priority_update_non_aesni(void);
1562
extern unsigned _gnutls_disable_tls13;
1563
1564
# define timespec_sub_ms _gnutls_timespec_sub_ms
1565
unsigned int
1566
/* returns a-b in ms */
1567
 timespec_sub_ms(struct timespec *a, struct timespec *b);
1568
1569
inline static int _gnutls_timespec_cmp(struct timespec *a, struct timespec *b)
1570
0
{
1571
0
  if (a->tv_sec < b->tv_sec)
1572
0
    return -1;
1573
0
  if (a->tv_sec > b->tv_sec)
1574
0
    return 1;
1575
0
  if (a->tv_nsec < b->tv_nsec)
1576
0
    return -1;
1577
0
  if (a->tv_nsec > b->tv_nsec)
1578
0
    return 1;
1579
0
  return 0;
1580
0
}
Unexecuted instantiation: common.c:_gnutls_timespec_cmp
Unexecuted instantiation: crl.c:_gnutls_timespec_cmp
Unexecuted instantiation: crq.c:_gnutls_timespec_cmp
Unexecuted instantiation: dn.c:_gnutls_timespec_cmp
Unexecuted instantiation: extensions.c:_gnutls_timespec_cmp
Unexecuted instantiation: hostname-verify.c:_gnutls_timespec_cmp
Unexecuted instantiation: key_decode.c:_gnutls_timespec_cmp
Unexecuted instantiation: key_encode.c:_gnutls_timespec_cmp
Unexecuted instantiation: mpi.c:_gnutls_timespec_cmp
Unexecuted instantiation: ocsp.c:_gnutls_timespec_cmp
Unexecuted instantiation: output.c:_gnutls_timespec_cmp
Unexecuted instantiation: pkcs12.c:_gnutls_timespec_cmp
Unexecuted instantiation: pkcs12_bag.c:_gnutls_timespec_cmp
Unexecuted instantiation: pkcs12_encr.c:_gnutls_timespec_cmp
Unexecuted instantiation: pkcs7-crypt.c:_gnutls_timespec_cmp
Unexecuted instantiation: privkey_openssl.c:_gnutls_timespec_cmp
Unexecuted instantiation: privkey_pkcs8.c:_gnutls_timespec_cmp
Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_timespec_cmp
Unexecuted instantiation: prov-seed.c:_gnutls_timespec_cmp
Unexecuted instantiation: sign.c:_gnutls_timespec_cmp
Unexecuted instantiation: time.c:_gnutls_timespec_cmp
Unexecuted instantiation: tls_features.c:_gnutls_timespec_cmp
Unexecuted instantiation: verify-high.c:_gnutls_timespec_cmp
Unexecuted instantiation: verify-high2.c:_gnutls_timespec_cmp
Unexecuted instantiation: verify.c:_gnutls_timespec_cmp
Unexecuted instantiation: virt-san.c:_gnutls_timespec_cmp
Unexecuted instantiation: x509.c:_gnutls_timespec_cmp
Unexecuted instantiation: x509_dn.c:_gnutls_timespec_cmp
Unexecuted instantiation: x509_ext.c:_gnutls_timespec_cmp
Unexecuted instantiation: x509_write.c:_gnutls_timespec_cmp
Unexecuted instantiation: attributes.c:_gnutls_timespec_cmp
Unexecuted instantiation: email-verify.c:_gnutls_timespec_cmp
Unexecuted instantiation: ip.c:_gnutls_timespec_cmp
Unexecuted instantiation: krb5.c:_gnutls_timespec_cmp
Unexecuted instantiation: name_constraints.c:_gnutls_timespec_cmp
1581
1582
# include <algorithms.h>
1583
inline static int _gnutls_set_current_version(gnutls_session_t s, unsigned v)
1584
0
{
1585
0
  s->security_parameters.pversion = version_to_entry(v);
1586
0
  if (s->security_parameters.pversion == NULL) {
1587
0
    return GNUTLS_E_UNSUPPORTED_VERSION_PACKET;
1588
0
  }
1589
0
  return 0;
1590
0
}
Unexecuted instantiation: common.c:_gnutls_set_current_version
Unexecuted instantiation: crl.c:_gnutls_set_current_version
Unexecuted instantiation: crq.c:_gnutls_set_current_version
Unexecuted instantiation: dn.c:_gnutls_set_current_version
Unexecuted instantiation: extensions.c:_gnutls_set_current_version
Unexecuted instantiation: hostname-verify.c:_gnutls_set_current_version
Unexecuted instantiation: key_decode.c:_gnutls_set_current_version
Unexecuted instantiation: key_encode.c:_gnutls_set_current_version
Unexecuted instantiation: mpi.c:_gnutls_set_current_version
Unexecuted instantiation: ocsp.c:_gnutls_set_current_version
Unexecuted instantiation: output.c:_gnutls_set_current_version
Unexecuted instantiation: pkcs12.c:_gnutls_set_current_version
Unexecuted instantiation: pkcs12_bag.c:_gnutls_set_current_version
Unexecuted instantiation: pkcs12_encr.c:_gnutls_set_current_version
Unexecuted instantiation: pkcs7-crypt.c:_gnutls_set_current_version
Unexecuted instantiation: privkey_openssl.c:_gnutls_set_current_version
Unexecuted instantiation: privkey_pkcs8.c:_gnutls_set_current_version
Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_set_current_version
Unexecuted instantiation: prov-seed.c:_gnutls_set_current_version
Unexecuted instantiation: sign.c:_gnutls_set_current_version
Unexecuted instantiation: time.c:_gnutls_set_current_version
Unexecuted instantiation: tls_features.c:_gnutls_set_current_version
Unexecuted instantiation: verify-high.c:_gnutls_set_current_version
Unexecuted instantiation: verify-high2.c:_gnutls_set_current_version
Unexecuted instantiation: verify.c:_gnutls_set_current_version
Unexecuted instantiation: virt-san.c:_gnutls_set_current_version
Unexecuted instantiation: x509.c:_gnutls_set_current_version
Unexecuted instantiation: x509_dn.c:_gnutls_set_current_version
Unexecuted instantiation: x509_ext.c:_gnutls_set_current_version
Unexecuted instantiation: x509_write.c:_gnutls_set_current_version
Unexecuted instantiation: attributes.c:_gnutls_set_current_version
Unexecuted instantiation: email-verify.c:_gnutls_set_current_version
Unexecuted instantiation: ip.c:_gnutls_set_current_version
Unexecuted instantiation: krb5.c:_gnutls_set_current_version
Unexecuted instantiation: name_constraints.c:_gnutls_set_current_version
1591
1592
/* Returns the maximum amount of the plaintext to be sent, considering
1593
 * both user-specified/negotiated maximum values.
1594
 */
1595
inline static size_t max_record_send_size(gnutls_session_t session)
1596
0
{
1597
0
  size_t max;
1598
0
1599
0
  max = MIN(session->security_parameters.max_record_send_size,
1600
0
      session->security_parameters.max_user_record_send_size);
1601
0
1602
0
  if (IS_DTLS(session))
1603
0
    max = MIN(gnutls_dtls_get_data_mtu(session), max);
1604
0
1605
0
  return max;
1606
0
}
Unexecuted instantiation: common.c:max_record_send_size
Unexecuted instantiation: crl.c:max_record_send_size
Unexecuted instantiation: crq.c:max_record_send_size
Unexecuted instantiation: dn.c:max_record_send_size
Unexecuted instantiation: extensions.c:max_record_send_size
Unexecuted instantiation: hostname-verify.c:max_record_send_size
Unexecuted instantiation: key_decode.c:max_record_send_size
Unexecuted instantiation: key_encode.c:max_record_send_size
Unexecuted instantiation: mpi.c:max_record_send_size
Unexecuted instantiation: ocsp.c:max_record_send_size
Unexecuted instantiation: output.c:max_record_send_size
Unexecuted instantiation: pkcs12.c:max_record_send_size
Unexecuted instantiation: pkcs12_bag.c:max_record_send_size
Unexecuted instantiation: pkcs12_encr.c:max_record_send_size
Unexecuted instantiation: pkcs7-crypt.c:max_record_send_size
Unexecuted instantiation: privkey_openssl.c:max_record_send_size
Unexecuted instantiation: privkey_pkcs8.c:max_record_send_size
Unexecuted instantiation: privkey_pkcs8_pbes1.c:max_record_send_size
Unexecuted instantiation: prov-seed.c:max_record_send_size
Unexecuted instantiation: sign.c:max_record_send_size
Unexecuted instantiation: time.c:max_record_send_size
Unexecuted instantiation: tls_features.c:max_record_send_size
Unexecuted instantiation: verify-high.c:max_record_send_size
Unexecuted instantiation: verify-high2.c:max_record_send_size
Unexecuted instantiation: verify.c:max_record_send_size
Unexecuted instantiation: virt-san.c:max_record_send_size
Unexecuted instantiation: x509.c:max_record_send_size
Unexecuted instantiation: x509_dn.c:max_record_send_size
Unexecuted instantiation: x509_ext.c:max_record_send_size
Unexecuted instantiation: x509_write.c:max_record_send_size
Unexecuted instantiation: attributes.c:max_record_send_size
Unexecuted instantiation: email-verify.c:max_record_send_size
Unexecuted instantiation: ip.c:max_record_send_size
Unexecuted instantiation: krb5.c:max_record_send_size
Unexecuted instantiation: name_constraints.c:max_record_send_size
1607
1608
/* Returns the during the handshake negotiated certificate type(s).
1609
 * See state.c for the full function documentation.
1610
 *
1611
 * This function is made static inline for optimization reasons.
1612
 */
1613
inline static gnutls_certificate_type_t
1614
get_certificate_type(gnutls_session_t session, gnutls_ctype_target_t target)
1615
0
{
1616
0
  switch (target) {
1617
0
  case GNUTLS_CTYPE_CLIENT:
1618
0
    return session->security_parameters.client_ctype;
1619
0
    break;
1620
0
  case GNUTLS_CTYPE_SERVER:
1621
0
    return session->security_parameters.server_ctype;
1622
0
    break;
1623
0
  case GNUTLS_CTYPE_OURS:
1624
0
    if (IS_SERVER(session)) {
1625
0
      return session->security_parameters.server_ctype;
1626
0
    } else {
1627
0
      return session->security_parameters.client_ctype;
1628
0
    }
1629
0
    break;
1630
0
  case GNUTLS_CTYPE_PEERS:
1631
0
    if (IS_SERVER(session)) {
1632
0
      return session->security_parameters.client_ctype;
1633
0
    } else {
1634
0
      return session->security_parameters.server_ctype;
1635
0
    }
1636
0
    break;
1637
0
  default:    // Illegal parameter passed
1638
0
    return GNUTLS_CRT_UNKNOWN;
1639
0
  }
1640
0
}
Unexecuted instantiation: common.c:get_certificate_type
Unexecuted instantiation: crl.c:get_certificate_type
Unexecuted instantiation: crq.c:get_certificate_type
Unexecuted instantiation: dn.c:get_certificate_type
Unexecuted instantiation: extensions.c:get_certificate_type
Unexecuted instantiation: hostname-verify.c:get_certificate_type
Unexecuted instantiation: key_decode.c:get_certificate_type
Unexecuted instantiation: key_encode.c:get_certificate_type
Unexecuted instantiation: mpi.c:get_certificate_type
Unexecuted instantiation: ocsp.c:get_certificate_type
Unexecuted instantiation: output.c:get_certificate_type
Unexecuted instantiation: pkcs12.c:get_certificate_type
Unexecuted instantiation: pkcs12_bag.c:get_certificate_type
Unexecuted instantiation: pkcs12_encr.c:get_certificate_type
Unexecuted instantiation: pkcs7-crypt.c:get_certificate_type
Unexecuted instantiation: privkey_openssl.c:get_certificate_type
Unexecuted instantiation: privkey_pkcs8.c:get_certificate_type
Unexecuted instantiation: privkey_pkcs8_pbes1.c:get_certificate_type
Unexecuted instantiation: prov-seed.c:get_certificate_type
Unexecuted instantiation: sign.c:get_certificate_type
Unexecuted instantiation: time.c:get_certificate_type
Unexecuted instantiation: tls_features.c:get_certificate_type
Unexecuted instantiation: verify-high.c:get_certificate_type
Unexecuted instantiation: verify-high2.c:get_certificate_type
Unexecuted instantiation: verify.c:get_certificate_type
Unexecuted instantiation: virt-san.c:get_certificate_type
Unexecuted instantiation: x509.c:get_certificate_type
Unexecuted instantiation: x509_dn.c:get_certificate_type
Unexecuted instantiation: x509_ext.c:get_certificate_type
Unexecuted instantiation: x509_write.c:get_certificate_type
Unexecuted instantiation: attributes.c:get_certificate_type
Unexecuted instantiation: email-verify.c:get_certificate_type
Unexecuted instantiation: ip.c:get_certificate_type
Unexecuted instantiation: krb5.c:get_certificate_type
Unexecuted instantiation: name_constraints.c:get_certificate_type
1641
1642
/* Macros to aide constant time/mem checks */
1643
# define CONSTCHECK_NOT_EQUAL(a, b) ((-((uint32_t)(a) ^ (uint32_t)(b))) >> 31)
1644
# define CONSTCHECK_EQUAL(a, b) (1U - CONSTCHECK_NOT_EQUAL(a, b))
1645
1646
extern unsigned int _gnutls_global_version;
1647
1648
bool _gnutls_config_is_ktls_enabled(void);
1649
1650
#endif        /* GNUTLS_LIB_GNUTLS_INT_H */