documented update
[gnutls.git] / lib / gnutls_int.h
blob77705a304f361aa521c0c2db77899ae09924c0b4
1 /*
2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #ifndef GNUTLS_INT_H
24 #define GNUTLS_INT_H
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
30 #include <stddef.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <ctype.h>
35 #include <limits.h>
36 #include <stdint.h>
38 #ifdef NO_SSIZE_T
39 #define HAVE_SSIZE_T
40 typedef int ssize_t;
41 #endif
43 #include <sys/types.h>
44 #include <unistd.h>
45 #include <sys/stat.h>
46 #if HAVE_SYS_SOCKET_H
47 # include <sys/socket.h>
48 #elif HAVE_WS2TCPIP_H
49 # include <ws2tcpip.h>
50 #endif
51 #include <time.h>
52 #include <u64.h> /* gnulib for uint64_t */
54 #ifdef HAVE_LIBNETTLE
55 # include <nettle/memxor.h>
56 #else
57 # include <gl/memxor.h>
58 # define memxor gl_memxor
59 #endif
61 #ifdef __GNUC__
62 # ifndef _GNUTLS_GCC_VERSION
63 # define _GNUTLS_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
64 # endif
65 # if _GNUTLS_GCC_VERSION >= 30100
66 # define likely(x) __builtin_expect((x), 1)
67 # define unlikely(x) __builtin_expect((x), 0)
68 # endif
69 #endif
71 #ifndef likely
72 # define likely
73 # define unlikely
74 #endif
76 /* some systems had problems with long long int, thus,
77 * it is not used.
79 typedef struct
81 unsigned char i[8];
82 } uint64;
84 #include <gnutls/gnutls.h>
85 #include <gnutls/dtls.h>
86 #include <gnutls/abstract.h>
87 #include <system.h>
90 * They are not needed any more. You can simply enable
91 * the gnutls_log callback to get error descriptions.
93 #define BUFFERS_DEBUG
94 #define WRITE_DEBUG
95 #define READ_DEBUG
96 #define HANDSHAKE_DEBUG // Prints some information on handshake
97 #define COMPRESSION_DEBUG
98 #define DEBUG
101 /* The size of a handshake message should not
102 * be larger than this value.
104 #define MAX_HANDSHAKE_PACKET_SIZE 48*1024
106 #define TLS_MAX_SESSION_ID_SIZE 32
108 /* The maximum digest size of hash algorithms.
110 #define MAX_HASH_SIZE 64
111 #define MAX_CIPHER_BLOCK_SIZE 16
112 #define MAX_CIPHER_KEY_SIZE 32
114 #define MAX_USERNAME_SIZE 128
115 #define MAX_SERVER_NAME_SIZE 128
117 #define SESSION_TICKET_KEY_NAME_SIZE 16
118 #define SESSION_TICKET_KEY_SIZE 16
119 #define SESSION_TICKET_IV_SIZE 16
120 #define SESSION_TICKET_MAC_SECRET_SIZE 32
122 #define AEAD_EXPLICIT_DATA_SIZE 8
123 #define AEAD_IMPLICIT_DATA_SIZE 4
125 #define GNUTLS_MASTER_SIZE 48
126 #define GNUTLS_RANDOM_SIZE 32
128 /* DTLS */
129 #define DTLS_RECORD_WINDOW_SIZE 64
131 /* TLS Extensions */
132 /* we can receive up to MAX_EXT_TYPES extensions.
134 #define MAX_EXT_TYPES 32
137 * gnutls_ext_parse_type_t:
138 * @GNUTLS_EXT_NONE: Never parsed
139 * @GNUTLS_EXT_ANY: Any extension type.
140 * @GNUTLS_EXT_APPLICATION: Application extension.
141 * @GNUTLS_EXT_TLS: TLS-internal extension.
142 * @GNUTLS_EXT_MANDATORY: Extension parsed even if resuming (or extensions are disabled).
144 * Enumeration of different TLS extension types. This flag
145 * indicates for an extension whether it is useful to application
146 * level or TLS level only. This is (only) used to parse the
147 * application level extensions before the "client_hello" callback
148 * is called.
150 typedef enum
152 GNUTLS_EXT_ANY = 0,
153 GNUTLS_EXT_APPLICATION = 1,
154 GNUTLS_EXT_TLS = 2,
155 GNUTLS_EXT_MANDATORY = 3,
156 GNUTLS_EXT_NONE = 4
157 } gnutls_ext_parse_type_t;
160 /* expire time for resuming sessions */
161 #define DEFAULT_EXPIRE_TIME 3600
163 typedef enum transport_t
165 GNUTLS_STREAM,
166 GNUTLS_DGRAM
167 } transport_t;
169 /* the maximum size of encrypted packets */
170 #define IS_DTLS(session) (session->internals.transport == GNUTLS_DGRAM)
172 #define DEFAULT_MAX_RECORD_SIZE 16384
173 #define TLS_RECORD_HEADER_SIZE 5
174 #define DTLS_RECORD_HEADER_SIZE (TLS_RECORD_HEADER_SIZE+8)
175 #define RECORD_HEADER_SIZE(session) (IS_DTLS(session) ? DTLS_RECORD_HEADER_SIZE : TLS_RECORD_HEADER_SIZE)
176 #define MAX_RECORD_HEADER_SIZE DTLS_RECORD_HEADER_SIZE
178 #define MAX_RECORD_SEND_SIZE(session) (IS_DTLS(session)?((size_t)gnutls_dtls_get_data_mtu(session)):(size_t)session->security_parameters.max_record_send_size)
179 #define MAX_RECORD_RECV_SIZE(session) ((size_t)session->security_parameters.max_record_recv_size)
180 #define MAX_PAD_SIZE 255
181 #define EXTRA_COMP_SIZE 2048
182 #define MAX_RECORD_OVERHEAD (MAX_CIPHER_BLOCK_SIZE/*iv*/+MAX_PAD_SIZE+EXTRA_COMP_SIZE+MAX_HASH_SIZE/*MAC*/)
183 #define MAX_RECV_SIZE(session) (MAX_RECORD_OVERHEAD+MAX_RECORD_RECV_SIZE(session)+RECORD_HEADER_SIZE(session))
185 #define TLS_HANDSHAKE_HEADER_SIZE 4
186 #define DTLS_HANDSHAKE_HEADER_SIZE (TLS_HANDSHAKE_HEADER_SIZE+8)
187 #define HANDSHAKE_HEADER_SIZE(session) (IS_DTLS(session) ? DTLS_HANDSHAKE_HEADER_SIZE : TLS_HANDSHAKE_HEADER_SIZE)
188 #define MAX_HANDSHAKE_HEADER_SIZE DTLS_HANDSHAKE_HEADER_SIZE
190 /* This is the maximum handshake message size we send without
191 fragmentation. This currently ignores record layer overhead. */
192 #define DTLS_DEFAULT_MTU 1200
194 /* the maximum size of the DTLS cookie */
195 #define DTLS_MAX_COOKIE_SIZE 32
197 /* The maximum number of HELLO_VERIFY_REQUEST messages the client
198 processes before aborting. */
199 #define MAX_HANDSHAKE_HELLO_VERIFY_REQUESTS 5
201 /* defaults for verification functions
203 #define DEFAULT_VERIFY_DEPTH 32
204 #define DEFAULT_VERIFY_BITS 16*1024
206 #include <gnutls_mem.h>
208 #define MEMSUB(x,y) ((ssize_t)((ptrdiff_t)x-(ptrdiff_t)y))
210 #define DECR_LEN(len, x) do { len-=x; if (len<0) {gnutls_assert(); return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;} } while (0)
211 #define DECR_LENGTH_RET(len, x, RET) do { len-=x; if (len<0) {gnutls_assert(); return RET;} } while (0)
212 #define DECR_LENGTH_COM(len, x, COM) do { len-=x; if (len<0) {gnutls_assert(); COM;} } while (0)
214 #define GNUTLS_POINTER_TO_INT(_) ((int) GNUTLS_POINTER_TO_INT_CAST (_))
215 #define GNUTLS_INT_TO_POINTER(_) ((void*) GNUTLS_POINTER_TO_INT_CAST (_))
217 typedef struct
219 uint8_t pint[3];
220 } uint24;
222 #include <gnutls_mpi.h>
224 typedef enum handshake_state_t
225 { STATE0 = 0, STATE1, STATE2,
226 STATE3, STATE4, STATE5,
227 STATE6, STATE7, STATE8, STATE9, STATE11 = 11,
228 STATE20 = 20, STATE21, STATE22,
229 STATE30 = 30, STATE31, STATE40 = 40, STATE41, STATE50 = 50,
230 STATE60 = 60, STATE61, STATE62, STATE70, STATE71
231 } handshake_state_t;
233 #include <gnutls_str.h>
235 /* This is the maximum number of algorithms (ciphers or macs etc).
236 * keep it synced with GNUTLS_MAX_ALGORITHM_NUM in gnutls.h
238 #define MAX_ALGOS GNUTLS_MAX_ALGORITHM_NUM
240 typedef enum extensions_t
242 GNUTLS_EXTENSION_SERVER_NAME = 0,
243 GNUTLS_EXTENSION_MAX_RECORD_SIZE = 1,
244 GNUTLS_EXTENSION_CERT_TYPE = 9,
245 GNUTLS_EXTENSION_SUPPORTED_ECC = 10,
246 GNUTLS_EXTENSION_SUPPORTED_ECC_PF = 11,
247 GNUTLS_EXTENSION_SRP = 12,
248 GNUTLS_EXTENSION_SIGNATURE_ALGORITHMS = 13,
249 GNUTLS_EXTENSION_SESSION_TICKET = 35,
250 GNUTLS_EXTENSION_SAFE_RENEGOTIATION = 65281 /* aka: 0xff01 */
251 } extensions_t;
253 typedef enum
254 { CIPHER_STREAM, CIPHER_BLOCK } cipher_type_t;
256 #define RESUME_TRUE 1
257 #define RESUME_FALSE 0
259 /* Record Protocol */
260 typedef enum content_type_t
262 GNUTLS_CHANGE_CIPHER_SPEC = 20, GNUTLS_ALERT,
263 GNUTLS_HANDSHAKE, GNUTLS_APPLICATION_DATA,
264 } content_type_t;
267 #define GNUTLS_PK_ANY (gnutls_pk_algorithm_t)-1
268 #define GNUTLS_PK_NONE (gnutls_pk_algorithm_t)-2
270 /* Message buffers (mbuffers) structures */
272 /* this is actually the maximum number of distinct handshake
273 * messages that can arrive in a single flight
275 #define MAX_HANDSHAKE_MSGS 6
276 typedef struct
278 /* Handshake layer type and sequence of message */
279 gnutls_handshake_description_t htype;
280 uint32_t length;
282 /* valid in DTLS */
283 uint16_t sequence;
285 /* indicate whether that message is complete.
286 * complete means start_offset == 0 and end_offset == length
288 uint32_t start_offset;
289 uint32_t end_offset;
291 uint8_t header[MAX_HANDSHAKE_HEADER_SIZE];
292 int header_size;
294 gnutls_buffer_st data;
295 } handshake_buffer_st;
297 typedef struct mbuffer_st
299 /* when used in mbuffer_head_st */
300 struct mbuffer_st *next;
301 struct mbuffer_st *prev;
303 /* msg->size - mark = number of bytes left to process in this
304 message. Mark should only be non-zero when this buffer is the
305 head of the queue. */
306 size_t mark;
309 /* the data */
310 gnutls_datum_t msg;
311 size_t maximum_size;
313 /* used during fill in, to separate header from data
314 * body. */
315 unsigned int user_mark;
317 /* Filled in by record layer on recv:
318 * type, record_sequence
321 /* record layer content type */
322 content_type_t type;
324 /* record layer sequence */
325 uint64 record_sequence;
327 /* Filled in by handshake layer on send:
328 * type, epoch, htype, handshake_sequence
331 /* Record layer epoch of message */
332 uint16_t epoch;
334 /* Handshake layer type and sequence of message */
335 gnutls_handshake_description_t htype;
336 uint16_t handshake_sequence;
337 } mbuffer_st;
339 typedef struct mbuffer_head_st
341 mbuffer_st *head;
342 mbuffer_st *tail;
344 unsigned int length;
345 size_t byte_length;
346 } mbuffer_head_st;
348 /* Store & Retrieve functions defines:
351 typedef struct auth_cred_st
353 gnutls_credentials_type_t algorithm;
355 /* the type of credentials depends on algorithm
357 void *credentials;
358 struct auth_cred_st *next;
359 } auth_cred_st;
361 struct gnutls_key_st
363 /* For ECDH KX */
364 gnutls_pk_params_st ecdh_params;
365 bigint_t ecdh_x;
366 bigint_t ecdh_y;
368 /* For DH KX */
369 gnutls_datum_t key;
370 bigint_t KEY;
371 bigint_t client_Y;
372 bigint_t client_g;
373 bigint_t client_p;
374 bigint_t dh_secret;
375 /* for SRP */
376 bigint_t A;
377 bigint_t B;
378 bigint_t u;
379 bigint_t b;
380 bigint_t a;
381 bigint_t x;
382 /* RSA: e, m
384 bigint_t rsa[2];
386 /* this is used to hold the peers authentication data
388 /* auth_info_t structures SHOULD NOT contain malloced
389 * elements. Check gnutls_session_pack.c, and gnutls_auth.c.
390 * Remember that this should be calloced!
392 void *auth_info;
393 gnutls_credentials_type_t auth_info_type;
394 int auth_info_size; /* needed in order to store to db for restoring
396 uint8_t crypt_algo;
398 auth_cred_st *cred; /* used to specify keys/certificates etc */
400 int crt_requested;
401 /* some ciphersuites use this
402 * to provide client authentication.
403 * 1 if client auth was requested
404 * by the peer, 0 otherwise
405 *** In case of a server this
406 * holds 1 if we should wait
407 * for a client certificate verify
410 typedef struct gnutls_key_st *gnutls_key_st;
413 struct record_state_st;
414 typedef struct record_state_st record_state_st;
416 struct record_parameters_st;
417 typedef struct record_parameters_st record_parameters_st;
419 /* STATE (cont) */
421 #include <gnutls_hash_int.h>
422 #include <gnutls_cipher_int.h>
423 #include <gnutls_compress.h>
425 typedef struct
427 uint8_t hash_algorithm;
428 uint8_t sign_algorithm; /* pk algorithm actually */
429 } sign_algorithm_st;
431 /* This structure holds parameters got from TLS extension
432 * mechanism. (some extensions may hold parameters in auth_info_t
433 * structures also - see SRP).
436 #define MAX_SIGNATURE_ALGORITHMS 16
437 #define MAX_SIGN_ALGO_SIZE (2 + MAX_SIGNATURE_ALGORITHMS * 2)
439 #define MAX_VERIFY_DATA_SIZE 36 /* in SSL 3.0, 12 in TLS 1.0 */
441 /* auth_info_t structures now MAY contain malloced
442 * elements.
445 /* This structure and auth_info_t, are stored in the resume database,
446 * and are restored, in case of resume.
447 * Holds all the required parameters to resume the current
448 * session.
451 /* if you add anything in Security_Parameters struct, then
452 * also modify CPY_COMMON in gnutls_constate.c.
455 /* Note that the security parameters structure is set up after the
456 * handshake has finished. The only value you may depend on while
457 * the handshake is in progress is the cipher suite value.
459 typedef struct
461 unsigned int entity; /* GNUTLS_SERVER or GNUTLS_CLIENT */
462 gnutls_kx_algorithm_t kx_algorithm;
464 /* The epoch used to read and write */
465 uint16_t epoch_read;
466 uint16_t epoch_write;
468 /* The epoch that the next handshake will initialize. */
469 uint16_t epoch_next;
471 /* The epoch at index 0 of record_parameters. */
472 uint16_t epoch_min;
474 /* this is the ciphersuite we are going to use
475 * moved here from internals in order to be restored
476 * on resume;
478 uint8_t cipher_suite[2];
479 gnutls_compression_method_t compression_method;
480 uint8_t master_secret[GNUTLS_MASTER_SIZE];
481 uint8_t client_random[GNUTLS_RANDOM_SIZE];
482 uint8_t server_random[GNUTLS_RANDOM_SIZE];
483 uint8_t session_id[TLS_MAX_SESSION_ID_SIZE];
484 uint8_t session_id_size;
485 time_t timestamp;
487 /* The send size is the one requested by the programmer.
488 * The recv size is the one negotiated with the peer.
490 uint16_t max_record_send_size;
491 uint16_t max_record_recv_size;
492 /* holds the negotiated certificate type */
493 gnutls_certificate_type_t cert_type;
494 gnutls_ecc_curve_t ecc_curve; /* holds the first supported ECC curve requested by client */
495 gnutls_protocol_t version; /* moved here */
497 /* FIXME: The following are not saved in the session storage
498 * for session resumption.
501 /* Used by extensions that enable supplemental data: Which ones
502 * do that? Do they belong in security parameters?
504 int do_recv_supplemental, do_send_supplemental;
505 } security_parameters_st;
507 struct record_state_st
509 gnutls_datum_t mac_secret;
510 gnutls_datum_t IV;
511 gnutls_datum_t key;
512 auth_cipher_hd_st cipher_state;
513 comp_hd_st compression_state;
514 uint64 sequence_number;
517 /* These are used to resolve relative epochs. These values are just
518 outside the 16 bit range to prevent off-by-one errors. An absolute
519 epoch may be referred to by its numeric id in the range
520 0x0000-0xffff. */
521 #define EPOCH_READ_CURRENT 70000
522 #define EPOCH_WRITE_CURRENT 70001
523 #define EPOCH_NEXT 70002
525 struct record_parameters_st
527 uint16_t epoch;
528 int initialized;
530 gnutls_cipher_algorithm_t cipher_algorithm;
531 gnutls_mac_algorithm_t mac_algorithm;
532 gnutls_compression_method_t compression_algorithm;
534 /* for DTLS */
535 uint64_t record_sw[DTLS_RECORD_WINDOW_SIZE];
536 unsigned int record_sw_size;
538 record_state_st read;
539 record_state_st write;
541 /* Whether this state is in use, i.e., if there is
542 a pending handshake message waiting to be encrypted
543 under this epoch's parameters.
545 int usage_cnt;
548 typedef struct
550 unsigned int priority[MAX_ALGOS];
551 unsigned int algorithms;
552 } priority_st;
554 typedef enum
556 SR_DISABLED,
557 SR_UNSAFE,
558 SR_PARTIAL,
559 SR_SAFE
560 } safe_renegotiation_t;
562 /* For the external api */
563 struct gnutls_priority_st
565 priority_st cipher;
566 priority_st mac;
567 priority_st kx;
568 priority_st compression;
569 priority_st protocol;
570 priority_st cert_type;
571 priority_st sign_algo;
572 priority_st supported_ecc;
574 /* to disable record padding */
575 unsigned int no_extensions:1;
576 unsigned int no_padding:1;
577 unsigned int allow_large_records:1;
578 safe_renegotiation_t sr;
579 unsigned int ssl3_record_version:1;
580 unsigned int server_precedence:1;
581 unsigned int additional_verify_flags;
585 /* DH and RSA parameters types.
587 typedef struct gnutls_dh_params_int
589 /* [0] is the prime, [1] is the generator.
591 bigint_t params[2];
592 int q_bits; /* length of q in bits. If zero then length is unknown.
594 } dh_params_st;
596 typedef struct
598 gnutls_dh_params_t dh_params;
599 int free_dh_params;
600 gnutls_rsa_params_t rsa_params;
601 int free_rsa_params;
602 } internal_params_st;
604 /* DTLS session state
606 typedef struct
608 /* HelloVerifyRequest DOS prevention cookie */
609 uint8_t cookie[DTLS_MAX_COOKIE_SIZE];
610 uint8_t cookie_len;
612 /* For DTLS handshake fragmentation and reassembly. */
613 uint16_t hsk_write_seq;
614 /* the sequence number of the expected packet */
615 unsigned int hsk_read_seq;
616 uint16_t mtu;
618 /* a flight transmission is in process */
619 unsigned int flight_init:1;
620 /* whether this is the last flight in the protocol */
621 unsigned int last_flight:1;
623 /* the retransmission timeout in milliseconds */
624 unsigned int retrans_timeout_ms;
625 /* the connection timeout in milliseconds */
626 unsigned int total_timeout_ms;
628 unsigned int hsk_hello_verify_requests;
630 /* non blocking stuff variables */
631 unsigned int blocking:1;
632 /* starting time of current handshake */
633 struct timespec handshake_start_time;
635 /* The actual retrans_timeout for the next message (e.g. doubled or so)
637 unsigned int actual_retrans_timeout_ms;
639 /* timers to handle async handshake after gnutls_handshake()
640 * has terminated. Required to handle retransmissions.
642 time_t async_term;
644 /* last retransmission triggered by record layer */
645 struct timespec last_retransmit;
646 unsigned int packets_dropped;
647 } dtls_st;
650 typedef union
652 void *ptr;
653 uint32_t num;
654 } extension_priv_data_t;
656 typedef struct
658 /* holds all the parsed data received by the record layer */
659 mbuffer_head_st record_buffer;
661 int handshake_hash_buffer_prev_len; /* keeps the length of handshake_hash_buffer, excluding
662 * the last received message */
663 gnutls_buffer_st handshake_hash_buffer; /* used to keep the last received handshake
664 * message */
665 unsigned int resumable:1; /* TRUE or FALSE - if we can resume that session */
666 unsigned int ticket_sent:1; /* whether a session ticket was sent */
667 handshake_state_t handshake_state; /* holds
668 * a number which indicates where
669 * the handshake procedure has been
670 * interrupted. If it is 0 then
671 * no interruption has happened.
674 int invalid_connection:1; /* true or FALSE - if this session is valid */
676 int may_not_read:1; /* if it's 0 then we can read/write, otherwise it's forbiden to read/write
678 int may_not_write:1;
679 int read_eof:1; /* non-zero if we have received a closure alert. */
681 int last_alert; /* last alert received */
683 /* The last handshake messages sent or received.
685 int last_handshake_in;
686 int last_handshake_out;
688 /* priorities */
689 struct gnutls_priority_st priorities;
691 /* resumed session */
692 unsigned int resumed:1; /* RESUME_TRUE or FALSE - if we are resuming a session */
693 unsigned int resumption_requested:1; /* non-zero if resumption was requested by client */
694 security_parameters_st resumed_security_parameters;
696 /* These buffers are used in the handshake
697 * protocol only. freed using _gnutls_handshake_io_buffer_clear();
699 mbuffer_head_st handshake_send_buffer;
700 handshake_buffer_st handshake_recv_buffer[MAX_HANDSHAKE_MSGS];
701 int handshake_recv_buffer_size;
703 /* this buffer holds a record packet -mostly used for
704 * non blocking IO.
706 mbuffer_head_st record_recv_buffer; /* buffer holding the unparsed record that is currently
707 * being received */
708 mbuffer_head_st record_send_buffer; /* holds cached data
709 * for the gnutls_io_write_buffered()
710 * function.
712 size_t record_send_buffer_user_size; /* holds the
713 * size of the user specified data to
714 * send.
717 int expire_time; /* after expire_time seconds this session will expire */
718 struct mod_auth_st_int *auth_struct; /* used in handshake packets and KX algorithms */
720 /* this is the highest version available
721 * to the peer. (advertized version).
722 * This is obtained by the Handshake Client Hello
723 * message. (some implementations read the Record version)
725 uint8_t adv_version_major;
726 uint8_t adv_version_minor;
728 /* if this is non zero a certificate request message
729 * will be sent to the client. - only if the ciphersuite
730 * supports it.
732 int send_cert_req;
734 /* bits to use for DHE and DHA
735 * use _gnutls_dh_get_prime_bits() and gnutls_dh_set_prime_bits()
736 * to access it.
738 uint16_t dh_prime_bits;
740 size_t max_handshake_data_buffer_size;
742 /* PUSH & PULL functions.
744 gnutls_pull_timeout_func pull_timeout_func;
745 gnutls_pull_func pull_func;
746 gnutls_push_func push_func;
747 gnutls_vec_push_func vec_push_func;
748 gnutls_errno_func errno_func;
749 /* Holds the first argument of PUSH and PULL
750 * functions;
752 gnutls_transport_ptr_t transport_recv_ptr;
753 gnutls_transport_ptr_t transport_send_ptr;
755 /* STORE & RETRIEVE functions. Only used if other
756 * backend than gdbm is used.
758 gnutls_db_store_func db_store_func;
759 gnutls_db_retr_func db_retrieve_func;
760 gnutls_db_remove_func db_remove_func;
761 void *db_ptr;
763 /* post client hello callback (server side only)
765 gnutls_handshake_post_client_hello_func user_hello_func;
767 /* holds the selected certificate and key.
768 * use _gnutls_selected_certs_deinit() and _gnutls_selected_certs_set()
769 * to change them.
771 gnutls_pcert_st *selected_cert_list;
772 int selected_cert_list_length;
773 struct gnutls_privkey_st *selected_key;
774 int selected_need_free:1;
776 /* holds the extensions we sent to the peer
777 * (in case of a client)
779 uint16_t extensions_sent[MAX_EXT_TYPES];
780 uint16_t extensions_sent_size;
782 /* is 0 if we are to send the whole PGP key, or non zero
783 * if the fingerprint is to be sent.
785 int pgp_fingerprint;
787 /* This holds the default version that our first
788 * record packet will have. */
789 uint8_t default_record_version[2];
791 void *user_ptr;
793 int enable_private; /* non zero to
794 * enable cipher suites
795 * which have 0xFF status.
798 /* Holds 0 if the last called function was interrupted while
799 * receiving, and non zero otherwise.
801 int direction;
803 /* This callback will be used (if set) to receive an
804 * openpgp key. (if the peer sends a fingerprint)
806 gnutls_openpgp_recv_key_func openpgp_recv_key_func;
808 /* If non zero the server will not advertise the CA's he
809 * trusts (do not send an RDN sequence).
811 int ignore_rdn_sequence;
813 /* This is used to set an arbitary version in the RSA
814 * PMS secret. Can be used by clients to test whether the
815 * server checks that version. (** only used in gnutls-cli-debug)
817 uint8_t rsa_pms_version[2];
819 /* Here we cache the DH or RSA parameters got from the
820 * credentials structure, or from a callback. That is to
821 * minimize external calls.
823 internal_params_st params;
825 /* To avoid using global variables, and especially on Windows where
826 * the application may use a different errno variable than GnuTLS,
827 * it is possible to use gnutls_transport_set_errno to set a
828 * session-specific errno variable in the user-replaceable push/pull
829 * functions. This value is used by the send/recv functions. (The
830 * strange name of this variable is because 'errno' is typically
831 * #define'd.)
833 int errnum;
835 /* Function used to perform public-key signing operation during
836 handshake. Used by gnutls_sig.c:_gnutls_tls_sign(), see also
837 gnutls_sign_callback_set(). */
838 gnutls_sign_func sign_func;
839 void *sign_func_userdata;
841 /* minimum bits to allow for SRP
842 * use gnutls_srp_set_prime_bits() to adjust it.
844 uint16_t srp_prime_bits;
846 /* A handshake process has been completed */
847 unsigned int initial_negotiation_completed:1;
849 struct
851 uint16_t type;
852 extension_priv_data_t priv;
853 int set:1;
854 } extension_int_data[MAX_EXT_TYPES];
856 struct
858 uint16_t type;
859 extension_priv_data_t priv;
860 int set:1;
861 } resumed_extension_int_data[MAX_EXT_TYPES];
862 /* The type of transport protocol; stream or datagram */
863 transport_t transport;
865 /* DTLS session state */
866 dtls_st dtls;
868 /* if set it means that the master key was set using
869 * gnutls_session_set_master() rather than being negotiated. */
870 unsigned int premaster_set:1;
872 unsigned int cb_tls_unique_len;
873 unsigned char cb_tls_unique[MAX_VERIFY_DATA_SIZE];
875 /* If you add anything here, check _gnutls_handshake_internal_state_clear().
877 } internals_st;
879 /* Maximum number of epochs we keep around. */
880 #define MAX_EPOCH_INDEX 16
882 struct gnutls_session_int
884 security_parameters_st security_parameters;
885 record_parameters_st *record_parameters[MAX_EPOCH_INDEX];
886 internals_st internals;
887 gnutls_key_st key;
891 /* functions
893 void _gnutls_free_auth_info (gnutls_session_t session);
895 /* These two macros return the advertised TLS version of
896 * the peer.
898 #define _gnutls_get_adv_version_major( session) \
899 session->internals.adv_version_major
901 #define _gnutls_get_adv_version_minor( session) \
902 session->internals.adv_version_minor
904 #define set_adv_version( session, major, minor) \
905 session->internals.adv_version_major = major; \
906 session->internals.adv_version_minor = minor
908 void _gnutls_set_adv_version (gnutls_session_t, gnutls_protocol_t);
909 gnutls_protocol_t _gnutls_get_adv_version (gnutls_session_t);
911 int _gnutls_is_secure_mem_null (const void *);
913 inline static gnutls_protocol_t
914 _gnutls_protocol_get_version (gnutls_session_t session)
916 return session->security_parameters.version;
919 #define gnutls_protocol_get_version _gnutls_protocol_get_version
921 inline static void
922 _gnutls_set_current_version (gnutls_session_t session,
923 gnutls_protocol_t version)
925 session->security_parameters.version = version;
928 #endif /* GNUTLS_INT_H */