summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_local.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/ssl_local.h')
-rw-r--r--src/lib/libssl/ssl_local.h1531
1 files changed, 0 insertions, 1531 deletions
diff --git a/src/lib/libssl/ssl_local.h b/src/lib/libssl/ssl_local.h
deleted file mode 100644
index 9666f3882a..0000000000
--- a/src/lib/libssl/ssl_local.h
+++ /dev/null
@@ -1,1531 +0,0 @@
1/* $OpenBSD: ssl_local.h,v 1.7 2023/07/06 07:56:32 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#ifndef HEADER_SSL_LOCL_H
144#define HEADER_SSL_LOCL_H
145
146#include <sys/types.h>
147
148#include <errno.h>
149#include <stdlib.h>
150#include <string.h>
151#include <time.h>
152#include <unistd.h>
153
154#include <openssl/opensslconf.h>
155
156#include <openssl/bio.h>
157#include <openssl/buffer.h>
158#include <openssl/dsa.h>
159#include <openssl/err.h>
160#include <openssl/rsa.h>
161#include <openssl/ssl.h>
162#include <openssl/stack.h>
163
164#include "bytestring.h"
165#include "tls_content.h"
166#include "tls13_internal.h"
167
168__BEGIN_HIDDEN_DECLS
169
170#define CTASSERT(x) extern char _ctassert[(x) ? 1 : -1 ] \
171 __attribute__((__unused__))
172
173#ifndef LIBRESSL_HAS_DTLS1_2
174#define LIBRESSL_HAS_DTLS1_2
175#endif
176
177/* LOCAL STUFF */
178
179#define SSL_DECRYPT 0
180#define SSL_ENCRYPT 1
181
182/*
183 * Define the Bitmasks for SSL_CIPHER.algorithms.
184 * This bits are used packed as dense as possible. If new methods/ciphers
185 * etc will be added, the bits a likely to change, so this information
186 * is for internal library use only, even though SSL_CIPHER.algorithms
187 * can be publicly accessed.
188 * Use the according functions for cipher management instead.
189 *
190 * The bit mask handling in the selection and sorting scheme in
191 * ssl_create_cipher_list() has only limited capabilities, reflecting
192 * that the different entities within are mutually exclusive:
193 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
194 */
195
196/* Bits for algorithm_mkey (key exchange algorithm) */
197#define SSL_kRSA 0x00000001L /* RSA key exchange */
198#define SSL_kDHE 0x00000008L /* tmp DH key no DH cert */
199#define SSL_kECDHE 0x00000080L /* ephemeral ECDH */
200#define SSL_kGOST 0x00000200L /* GOST key exchange */
201#define SSL_kTLS1_3 0x00000400L /* TLSv1.3 key exchange */
202
203/* Bits for algorithm_auth (server authentication) */
204#define SSL_aRSA 0x00000001L /* RSA auth */
205#define SSL_aDSS 0x00000002L /* DSS auth */
206#define SSL_aNULL 0x00000004L /* no auth (i.e. use ADH or AECDH) */
207#define SSL_aECDSA 0x00000040L /* ECDSA auth*/
208#define SSL_aGOST01 0x00000200L /* GOST R 34.10-2001 signature auth */
209#define SSL_aTLS1_3 0x00000400L /* TLSv1.3 authentication */
210
211/* Bits for algorithm_enc (symmetric encryption) */
212#define SSL_DES 0x00000001L
213#define SSL_3DES 0x00000002L
214#define SSL_RC4 0x00000004L
215#define SSL_IDEA 0x00000008L
216#define SSL_eNULL 0x00000010L
217#define SSL_AES128 0x00000020L
218#define SSL_AES256 0x00000040L
219#define SSL_CAMELLIA128 0x00000080L
220#define SSL_CAMELLIA256 0x00000100L
221#define SSL_eGOST2814789CNT 0x00000200L
222#define SSL_AES128GCM 0x00000400L
223#define SSL_AES256GCM 0x00000800L
224#define SSL_CHACHA20POLY1305 0x00001000L
225
226#define SSL_AES (SSL_AES128|SSL_AES256|SSL_AES128GCM|SSL_AES256GCM)
227#define SSL_CAMELLIA (SSL_CAMELLIA128|SSL_CAMELLIA256)
228
229
230/* Bits for algorithm_mac (symmetric authentication) */
231
232#define SSL_MD5 0x00000001L
233#define SSL_SHA1 0x00000002L
234#define SSL_GOST94 0x00000004L
235#define SSL_GOST89MAC 0x00000008L
236#define SSL_SHA256 0x00000010L
237#define SSL_SHA384 0x00000020L
238/* Not a real MAC, just an indication it is part of cipher */
239#define SSL_AEAD 0x00000040L
240#define SSL_STREEBOG256 0x00000080L
241
242/* Bits for algorithm_ssl (protocol version) */
243#define SSL_SSLV3 0x00000002L
244#define SSL_TLSV1 SSL_SSLV3 /* for now */
245#define SSL_TLSV1_2 0x00000004L
246#define SSL_TLSV1_3 0x00000008L
247
248
249/* Bits for algorithm2 (handshake digests and other extra flags) */
250
251#define SSL_HANDSHAKE_MAC_MASK 0xff0
252#define SSL_HANDSHAKE_MAC_MD5 0x010
253#define SSL_HANDSHAKE_MAC_SHA 0x020
254#define SSL_HANDSHAKE_MAC_GOST94 0x040
255#define SSL_HANDSHAKE_MAC_SHA256 0x080
256#define SSL_HANDSHAKE_MAC_SHA384 0x100
257#define SSL_HANDSHAKE_MAC_STREEBOG256 0x200
258#define SSL_HANDSHAKE_MAC_DEFAULT (SSL_HANDSHAKE_MAC_MD5 | SSL_HANDSHAKE_MAC_SHA)
259
260#define SSL3_CK_ID 0x03000000
261#define SSL3_CK_VALUE_MASK 0x0000ffff
262
263#define TLS1_PRF_DGST_MASK (0xff << TLS1_PRF_DGST_SHIFT)
264
265#define TLS1_PRF_DGST_SHIFT 10
266#define TLS1_PRF_MD5 (SSL_HANDSHAKE_MAC_MD5 << TLS1_PRF_DGST_SHIFT)
267#define TLS1_PRF_SHA1 (SSL_HANDSHAKE_MAC_SHA << TLS1_PRF_DGST_SHIFT)
268#define TLS1_PRF_SHA256 (SSL_HANDSHAKE_MAC_SHA256 << TLS1_PRF_DGST_SHIFT)
269#define TLS1_PRF_SHA384 (SSL_HANDSHAKE_MAC_SHA384 << TLS1_PRF_DGST_SHIFT)
270#define TLS1_PRF_GOST94 (SSL_HANDSHAKE_MAC_GOST94 << TLS1_PRF_DGST_SHIFT)
271#define TLS1_PRF_STREEBOG256 (SSL_HANDSHAKE_MAC_STREEBOG256 << TLS1_PRF_DGST_SHIFT)
272#define TLS1_PRF (TLS1_PRF_MD5 | TLS1_PRF_SHA1)
273
274/*
275 * Stream MAC for GOST ciphersuites from cryptopro draft
276 * (currently this also goes into algorithm2).
277 */
278#define TLS1_STREAM_MAC 0x04
279
280/*
281 * SSL_CIPHER_ALGORITHM2_VARIABLE_NONCE_IN_RECORD is an algorithm2 flag that
282 * indicates that the variable part of the nonce is included as a prefix of
283 * the record (AES-GCM, for example, does this with an 8-byte variable nonce.)
284 */
285#define SSL_CIPHER_ALGORITHM2_VARIABLE_NONCE_IN_RECORD (1 << 22)
286
287/*
288 * SSL_CIPHER_AEAD_FIXED_NONCE_LEN returns the number of bytes of fixed nonce
289 * for an SSL_CIPHER with an algorithm_mac of SSL_AEAD.
290 */
291#define SSL_CIPHER_AEAD_FIXED_NONCE_LEN(ssl_cipher) \
292 (((ssl_cipher->algorithm2 >> 24) & 0xf) * 2)
293
294/*
295 * Cipher strength information.
296 */
297#define SSL_STRONG_MASK 0x000001fcL
298#define SSL_STRONG_NONE 0x00000004L
299#define SSL_LOW 0x00000020L
300#define SSL_MEDIUM 0x00000040L
301#define SSL_HIGH 0x00000080L
302
303/*
304 * The keylength (measured in RSA key bits, I guess) for temporary keys.
305 * Cipher argument is so that this can be variable in the future.
306 */
307#define SSL_C_PKEYLENGTH(c) 1024
308
309/* See if we use signature algorithms extension. */
310#define SSL_USE_SIGALGS(s) \
311 (s->method->enc_flags & SSL_ENC_FLAG_SIGALGS)
312
313/* See if we use SHA256 default PRF. */
314#define SSL_USE_SHA256_PRF(s) \
315 (s->method->enc_flags & SSL_ENC_FLAG_SHA256_PRF)
316
317/* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
318#define SSL_USE_TLS1_2_CIPHERS(s) \
319 (s->method->enc_flags & SSL_ENC_FLAG_TLS1_2_CIPHERS)
320
321/* Allow TLS 1.3 ciphersuites only. */
322#define SSL_USE_TLS1_3_CIPHERS(s) \
323 (s->method->enc_flags & SSL_ENC_FLAG_TLS1_3_CIPHERS)
324
325#define SSL_PKEY_RSA 0
326#define SSL_PKEY_ECC 1
327#define SSL_PKEY_GOST01 2
328#define SSL_PKEY_NUM 3
329
330#define SSL_MAX_EMPTY_RECORDS 32
331
332/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
333 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
334 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
335 * SSL_kDHE <- RSA_ENC | RSA_SIGN | DSA_SIGN
336 * SSL_aRSA <- RSA_ENC | RSA_SIGN
337 * SSL_aDSS <- DSA_SIGN
338 */
339
340/* From ECC-TLS draft, used in encoding the curve type in
341 * ECParameters
342 */
343#define EXPLICIT_PRIME_CURVE_TYPE 1
344#define EXPLICIT_CHAR2_CURVE_TYPE 2
345#define NAMED_CURVE_TYPE 3
346
347typedef struct ssl_cert_pkey_st {
348 X509 *x509;
349 EVP_PKEY *privatekey;
350 STACK_OF(X509) *chain;
351} SSL_CERT_PKEY;
352
353typedef struct ssl_cert_st {
354 /* Current active set */
355 /* ALWAYS points to an element of the pkeys array
356 * Probably it would make more sense to store
357 * an index, not a pointer. */
358 SSL_CERT_PKEY *key;
359
360 SSL_CERT_PKEY pkeys[SSL_PKEY_NUM];
361
362 /* The following masks are for the key and auth
363 * algorithms that are supported by the certs below */
364 int valid;
365 unsigned long mask_k;
366 unsigned long mask_a;
367
368 DH *dhe_params;
369 DH *(*dhe_params_cb)(SSL *ssl, int is_export, int keysize);
370 int dhe_params_auto;
371
372 int (*security_cb)(const SSL *s, const SSL_CTX *ctx, int op, int bits,
373 int nid, void *other, void *ex_data); /* Not exposed in API. */
374 int security_level;
375 void *security_ex_data; /* Not exposed in API. */
376
377 int references; /* >1 only if SSL_copy_session_id is used */
378} SSL_CERT;
379
380struct ssl_comp_st {
381 int id;
382 const char *name;
383};
384
385struct ssl_cipher_st {
386 int valid;
387 const char *name; /* text name */
388 unsigned long id; /* id, 4 bytes, first is version */
389
390 unsigned long algorithm_mkey; /* key exchange algorithm */
391 unsigned long algorithm_auth; /* server authentication */
392 unsigned long algorithm_enc; /* symmetric encryption */
393 unsigned long algorithm_mac; /* symmetric authentication */
394 unsigned long algorithm_ssl; /* (major) protocol version */
395
396 unsigned long algo_strength; /* strength and export flags */
397 unsigned long algorithm2; /* Extra flags */
398 int strength_bits; /* Number of bits really used */
399 int alg_bits; /* Number of bits for algorithm */
400};
401
402struct ssl_method_st {
403 int dtls;
404 int server;
405 int version;
406
407 uint16_t min_tls_version;
408 uint16_t max_tls_version;
409
410 int (*ssl_new)(SSL *s);
411 void (*ssl_clear)(SSL *s);
412 void (*ssl_free)(SSL *s);
413
414 int (*ssl_accept)(SSL *s);
415 int (*ssl_connect)(SSL *s);
416 int (*ssl_shutdown)(SSL *s);
417
418 int (*ssl_renegotiate)(SSL *s);
419 int (*ssl_renegotiate_check)(SSL *s);
420
421 int (*ssl_pending)(const SSL *s);
422 int (*ssl_read_bytes)(SSL *s, int type, unsigned char *buf, int len,
423 int peek);
424 int (*ssl_write_bytes)(SSL *s, int type, const void *buf_, int len);
425
426 const SSL_CIPHER *(*get_cipher)(unsigned int ncipher);
427
428 unsigned int enc_flags; /* SSL_ENC_FLAG_* */
429};
430
431/*
432 * Let's make this into an ASN.1 type structure as follows
433 * SSL_SESSION_ID ::= SEQUENCE {
434 * version INTEGER, -- structure version number
435 * SSLversion INTEGER, -- SSL version number
436 * Cipher OCTET STRING, -- the 2 byte cipher ID
437 * Session_ID OCTET STRING, -- the Session ID
438 * Master_key OCTET STRING, -- the master key
439 * KRB5_principal OCTET STRING -- optional Kerberos principal
440 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
441 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
442 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
443 * Session_ID_context [ 4 ] EXPLICIT OCTET STRING, -- the Session ID context
444 * Verify_result [ 5 ] EXPLICIT INTEGER, -- X509_V_... code for `Peer'
445 * HostName [ 6 ] EXPLICIT OCTET STRING, -- optional HostName from servername TLS extension
446 * PSK_identity_hint [ 7 ] EXPLICIT OCTET STRING, -- optional PSK identity hint
447 * PSK_identity [ 8 ] EXPLICIT OCTET STRING, -- optional PSK identity
448 * Ticket_lifetime_hint [9] EXPLICIT INTEGER, -- server's lifetime hint for session ticket
449 * Ticket [10] EXPLICIT OCTET STRING, -- session ticket (clients only)
450 * Compression_meth [11] EXPLICIT OCTET STRING, -- optional compression method
451 * SRP_username [ 12 ] EXPLICIT OCTET STRING -- optional SRP username
452 * }
453 * Look in ssl/ssl_asn1.c for more details
454 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
455 */
456struct ssl_session_st {
457 int ssl_version; /* what ssl version session info is
458 * being kept in here? */
459
460 size_t master_key_length;
461 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
462
463 /* session_id - valid? */
464 size_t session_id_length;
465 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
466
467 /* this is used to determine whether the session is being reused in
468 * the appropriate context. It is up to the application to set this,
469 * via SSL_new */
470 size_t sid_ctx_length;
471 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
472
473 /* Peer provided leaf (end-entity) certificate. */
474 X509 *peer_cert;
475 int peer_cert_type;
476
477 /* when app_verify_callback accepts a session where the peer's certificate
478 * is not ok, we must remember the error for session reuse: */
479 long verify_result; /* only for servers */
480
481 long timeout;
482 time_t time;
483 int references;
484
485 const SSL_CIPHER *cipher;
486 unsigned long cipher_id; /* when ASN.1 loaded, this
487 * needs to be used to load
488 * the 'cipher' structure */
489
490 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
491
492 char *tlsext_hostname;
493
494 /* Session resumption - RFC 5077 and RFC 8446. */
495 unsigned char *tlsext_tick; /* Session ticket */
496 size_t tlsext_ticklen; /* Session ticket length */
497 uint32_t tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */
498 uint32_t tlsext_tick_age_add; /* TLSv1.3 ticket age obfuscation (in ms) */
499 struct tls13_secret resumption_master_secret;
500
501 CRYPTO_EX_DATA ex_data; /* application specific data */
502
503 /* These are used to make removal of session-ids more
504 * efficient and to implement a maximum cache size. */
505 struct ssl_session_st *prev, *next;
506
507 /* Used to indicate that session resumption is not allowed.
508 * Applications can also set this bit for a new session via
509 * not_resumable_session_cb to disable session caching and tickets. */
510 int not_resumable;
511
512 size_t tlsext_ecpointformatlist_length;
513 uint8_t *tlsext_ecpointformatlist; /* peer's list */
514 size_t tlsext_supportedgroups_length;
515 uint16_t *tlsext_supportedgroups; /* peer's list */
516};
517
518struct ssl_sigalg;
519
520typedef struct ssl_handshake_tls12_st {
521 /* Used when SSL_ST_FLUSH_DATA is entered. */
522 int next_state;
523
524 /* Handshake message type and size. */
525 int message_type;
526 unsigned long message_size;
527
528 /* Reuse current handshake message. */
529 int reuse_message;
530
531 /* Client certificate requests. */
532 int cert_request;
533 STACK_OF(X509_NAME) *ca_names;
534
535 /* Record-layer key block for TLS 1.2 and earlier. */
536 struct tls12_key_block *key_block;
537
538 /* Transcript hash prior to sending certificate verify message. */
539 uint8_t cert_verify[EVP_MAX_MD_SIZE];
540} SSL_HANDSHAKE_TLS12;
541
542typedef struct ssl_handshake_tls13_st {
543 int use_legacy;
544 int hrr;
545
546 /* Client indicates psk_dhe_ke support in PskKeyExchangeMode. */
547 int use_psk_dhe_ke;
548
549 /* Certificate selected for use (static pointer). */
550 const SSL_CERT_PKEY *cpk;
551
552 /* Version proposed by peer server. */
553 uint16_t server_version;
554
555 uint16_t server_group;
556 struct tls13_secrets *secrets;
557
558 uint8_t *cookie;
559 size_t cookie_len;
560
561 /* Preserved transcript hash. */
562 uint8_t transcript_hash[EVP_MAX_MD_SIZE];
563 size_t transcript_hash_len;
564
565 /* Legacy session ID. */
566 uint8_t legacy_session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
567 size_t legacy_session_id_len;
568
569 /* ClientHello hash, used to validate following HelloRetryRequest */
570 EVP_MD_CTX *clienthello_md_ctx;
571 unsigned char *clienthello_hash;
572 unsigned int clienthello_hash_len;
573
574 /* QUIC read buffer and read/write encryption levels. */
575 struct tls_buffer *quic_read_buffer;
576 enum ssl_encryption_level_t quic_read_level;
577 enum ssl_encryption_level_t quic_write_level;
578} SSL_HANDSHAKE_TLS13;
579
580typedef struct ssl_handshake_st {
581 /*
582 * Minimum and maximum versions supported for this handshake. These are
583 * initialised at the start of a handshake based on the method in use
584 * and the current protocol version configuration.
585 */
586 uint16_t our_min_tls_version;
587 uint16_t our_max_tls_version;
588
589 /*
590 * Version negotiated for this session. For a client this is set once
591 * the server selected version is parsed from the ServerHello (either
592 * from the legacy version or supported versions extension). For a
593 * server this is set once we select the version we will use with the
594 * client.
595 */
596 uint16_t negotiated_tls_version;
597
598 /*
599 * Legacy version advertised by our peer. For a server this is the
600 * version specified by the client in the ClientHello message. For a
601 * client, this is the version provided in the ServerHello message.
602 */
603 uint16_t peer_legacy_version;
604
605 /*
606 * Current handshake state - contains one of the SSL3_ST_* values and
607 * is used by the TLSv1.2 state machine, as well as being updated by
608 * the TLSv1.3 stack due to it being exposed externally.
609 */
610 int state;
611
612 /* Cipher being negotiated in this handshake. */
613 const SSL_CIPHER *cipher;
614
615 /* Extensions seen in this handshake. */
616 uint32_t extensions_seen;
617
618 /* Signature algorithms selected for use (static pointers). */
619 const struct ssl_sigalg *our_sigalg;
620 const struct ssl_sigalg *peer_sigalg;
621
622 /* sigalgs offered in this handshake in wire form */
623 uint8_t *sigalgs;
624 size_t sigalgs_len;
625
626 /* Key share for ephemeral key exchange. */
627 struct tls_key_share *key_share;
628
629 /*
630 * Copies of the verify data sent in our finished message and the
631 * verify data received in the finished message sent by our peer.
632 */
633 uint8_t finished[EVP_MAX_MD_SIZE];
634 size_t finished_len;
635 uint8_t peer_finished[EVP_MAX_MD_SIZE];
636 size_t peer_finished_len;
637
638 /* List of certificates received from our peer. */
639 STACK_OF(X509) *peer_certs;
640 STACK_OF(X509) *peer_certs_no_leaf;
641
642 /* Certificate chain resulting from X.509 verification. */
643 STACK_OF(X509) *verified_chain;
644
645 SSL_HANDSHAKE_TLS12 tls12;
646 SSL_HANDSHAKE_TLS13 tls13;
647} SSL_HANDSHAKE;
648
649typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
650
651/* TLS Session Ticket extension struct. */
652struct tls_session_ticket_ext_st {
653 unsigned short length;
654 void *data;
655};
656
657struct tls12_key_block;
658
659struct tls12_key_block *tls12_key_block_new(void);
660void tls12_key_block_free(struct tls12_key_block *kb);
661void tls12_key_block_client_write(struct tls12_key_block *kb, CBS *mac_key,
662 CBS *key, CBS *iv);
663void tls12_key_block_server_write(struct tls12_key_block *kb, CBS *mac_key,
664 CBS *key, CBS *iv);
665int tls12_key_block_generate(struct tls12_key_block *kb, SSL *s,
666 const EVP_AEAD *aead, const EVP_CIPHER *cipher, const EVP_MD *mac_hash);
667
668struct tls12_record_layer;
669
670struct tls12_record_layer *tls12_record_layer_new(void);
671void tls12_record_layer_free(struct tls12_record_layer *rl);
672void tls12_record_layer_alert(struct tls12_record_layer *rl,
673 uint8_t *alert_desc);
674int tls12_record_layer_write_overhead(struct tls12_record_layer *rl,
675 size_t *overhead);
676int tls12_record_layer_read_protected(struct tls12_record_layer *rl);
677int tls12_record_layer_write_protected(struct tls12_record_layer *rl);
678void tls12_record_layer_set_aead(struct tls12_record_layer *rl,
679 const EVP_AEAD *aead);
680void tls12_record_layer_set_cipher_hash(struct tls12_record_layer *rl,
681 const EVP_CIPHER *cipher, const EVP_MD *handshake_hash,
682 const EVP_MD *mac_hash);
683void tls12_record_layer_set_version(struct tls12_record_layer *rl,
684 uint16_t version);
685void tls12_record_layer_set_initial_epoch(struct tls12_record_layer *rl,
686 uint16_t epoch);
687uint16_t tls12_record_layer_read_epoch(struct tls12_record_layer *rl);
688uint16_t tls12_record_layer_write_epoch(struct tls12_record_layer *rl);
689int tls12_record_layer_use_write_epoch(struct tls12_record_layer *rl,
690 uint16_t epoch);
691void tls12_record_layer_write_epoch_done(struct tls12_record_layer *rl,
692 uint16_t epoch);
693void tls12_record_layer_clear_read_state(struct tls12_record_layer *rl);
694void tls12_record_layer_clear_write_state(struct tls12_record_layer *rl);
695void tls12_record_layer_reflect_seq_num(struct tls12_record_layer *rl);
696int tls12_record_layer_change_read_cipher_state(struct tls12_record_layer *rl,
697 CBS *mac_key, CBS *key, CBS *iv);
698int tls12_record_layer_change_write_cipher_state(struct tls12_record_layer *rl,
699 CBS *mac_key, CBS *key, CBS *iv);
700int tls12_record_layer_open_record(struct tls12_record_layer *rl,
701 uint8_t *buf, size_t buf_len, struct tls_content *out);
702int tls12_record_layer_seal_record(struct tls12_record_layer *rl,
703 uint8_t content_type, const uint8_t *content, size_t content_len,
704 CBB *out);
705
706typedef void (ssl_info_callback_fn)(const SSL *s, int type, int val);
707typedef void (ssl_msg_callback_fn)(int is_write, int version, int content_type,
708 const void *buf, size_t len, SSL *ssl, void *arg);
709
710struct ssl_ctx_st {
711 const SSL_METHOD *method;
712 const SSL_QUIC_METHOD *quic_method;
713
714 STACK_OF(SSL_CIPHER) *cipher_list;
715
716 struct x509_store_st /* X509_STORE */ *cert_store;
717
718 /* If timeout is not 0, it is the default timeout value set
719 * when SSL_new() is called. This has been put in to make
720 * life easier to set things up */
721 long session_timeout;
722
723 int references;
724
725 /* Default values to use in SSL structures follow (these are copied by SSL_new) */
726
727 STACK_OF(X509) *extra_certs;
728
729 int verify_mode;
730 size_t sid_ctx_length;
731 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
732
733 X509_VERIFY_PARAM *param;
734
735 /*
736 * XXX
737 * default_passwd_cb used by python and openvpn, need to keep it until we
738 * add an accessor
739 */
740 /* Default password callback. */
741 pem_password_cb *default_passwd_callback;
742
743 /* Default password callback user data. */
744 void *default_passwd_callback_userdata;
745
746 uint16_t min_tls_version;
747 uint16_t max_tls_version;
748
749 /*
750 * These may be zero to imply minimum or maximum version supported by
751 * the method.
752 */
753 uint16_t min_proto_version;
754 uint16_t max_proto_version;
755
756 unsigned long options;
757 unsigned long mode;
758
759 /* If this callback is not null, it will be called each
760 * time a session id is added to the cache. If this function
761 * returns 1, it means that the callback will do a
762 * SSL_SESSION_free() when it has finished using it. Otherwise,
763 * on 0, it means the callback has finished with it.
764 * If remove_session_cb is not null, it will be called when
765 * a session-id is removed from the cache. After the call,
766 * OpenSSL will SSL_SESSION_free() it. */
767 int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
768 void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
769 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
770 const unsigned char *data, int len, int *copy);
771
772 /* if defined, these override the X509_verify_cert() calls */
773 int (*app_verify_callback)(X509_STORE_CTX *, void *);
774 void *app_verify_arg;
775
776 /* get client cert callback */
777 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
778
779 /* cookie generate callback */
780 int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie,
781 unsigned int *cookie_len);
782
783 /* verify cookie callback */
784 int (*app_verify_cookie_cb)(SSL *ssl, const unsigned char *cookie,
785 unsigned int cookie_len);
786
787 ssl_info_callback_fn *info_callback;
788
789 /* callback that allows applications to peek at protocol messages */
790 ssl_msg_callback_fn *msg_callback;
791 void *msg_callback_arg;
792
793 int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */
794
795 /* Default generate session ID callback. */
796 GEN_SESSION_CB generate_session_id;
797
798 /* TLS extensions servername callback */
799 int (*tlsext_servername_callback)(SSL*, int *, void *);
800 void *tlsext_servername_arg;
801
802 /* Callback to support customisation of ticket key setting */
803 int (*tlsext_ticket_key_cb)(SSL *ssl, unsigned char *name,
804 unsigned char *iv, EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
805
806 /* certificate status request info */
807 /* Callback for status request */
808 int (*tlsext_status_cb)(SSL *ssl, void *arg);
809 void *tlsext_status_arg;
810
811 struct lhash_st_SSL_SESSION *sessions;
812
813 /* Most session-ids that will be cached, default is
814 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
815 unsigned long session_cache_size;
816 struct ssl_session_st *session_cache_head;
817 struct ssl_session_st *session_cache_tail;
818
819 /* This can have one of 2 values, ored together,
820 * SSL_SESS_CACHE_CLIENT,
821 * SSL_SESS_CACHE_SERVER,
822 * Default is SSL_SESSION_CACHE_SERVER, which means only
823 * SSL_accept which cache SSL_SESSIONS. */
824 int session_cache_mode;
825
826 struct {
827 int sess_connect; /* SSL new conn - started */
828 int sess_connect_renegotiate;/* SSL reneg - requested */
829 int sess_connect_good; /* SSL new conne/reneg - finished */
830 int sess_accept; /* SSL new accept - started */
831 int sess_accept_renegotiate;/* SSL reneg - requested */
832 int sess_accept_good; /* SSL accept/reneg - finished */
833 int sess_miss; /* session lookup misses */
834 int sess_timeout; /* reuse attempt on timeouted session */
835 int sess_cache_full; /* session removed due to full cache */
836 int sess_hit; /* session reuse actually done */
837 int sess_cb_hit; /* session-id that was not
838 * in the cache was
839 * passed back via the callback. This
840 * indicates that the application is
841 * supplying session-id's from other
842 * processes - spooky :-) */
843 } stats;
844
845 CRYPTO_EX_DATA ex_data;
846
847 STACK_OF(SSL_CIPHER) *cipher_list_tls13;
848
849 SSL_CERT *cert;
850
851 /* Default values used when no per-SSL value is defined follow */
852
853 /* what we put in client cert requests */
854 STACK_OF(X509_NAME) *client_CA;
855
856 long max_cert_list;
857
858 int read_ahead;
859
860 int quiet_shutdown;
861
862 /* Maximum amount of data to send in one fragment.
863 * actual record size can be more than this due to
864 * padding and MAC overheads.
865 */
866 unsigned int max_send_fragment;
867
868#ifndef OPENSSL_NO_ENGINE
869 /* Engine to pass requests for client certs to
870 */
871 ENGINE *client_cert_engine;
872#endif
873
874 /* RFC 4507 session ticket keys */
875 unsigned char tlsext_tick_key_name[16];
876 unsigned char tlsext_tick_hmac_key[16];
877 unsigned char tlsext_tick_aes_key[16];
878
879 /* SRTP profiles we are willing to do from RFC 5764 */
880 STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
881
882 /*
883 * ALPN information.
884 */
885
886 /*
887 * Server callback function that allows the server to select the
888 * protocol for the connection.
889 * out: on successful return, this must point to the raw protocol
890 * name (without the length prefix).
891 * outlen: on successful return, this contains the length of out.
892 * in: points to the client's list of supported protocols in
893 * wire-format.
894 * inlen: the length of in.
895 */
896 int (*alpn_select_cb)(SSL *s, const unsigned char **out,
897 unsigned char *outlen, const unsigned char *in, unsigned int inlen,
898 void *arg);
899 void *alpn_select_cb_arg;
900
901 /* Client list of supported protocols in wire format. */
902 uint8_t *alpn_client_proto_list;
903 size_t alpn_client_proto_list_len;
904
905 size_t tlsext_ecpointformatlist_length;
906 uint8_t *tlsext_ecpointformatlist; /* our list */
907 size_t tlsext_supportedgroups_length;
908 uint16_t *tlsext_supportedgroups; /* our list */
909 SSL_CTX_keylog_cb_func keylog_callback; /* Unused. For OpenSSL compatibility. */
910 size_t num_tickets; /* Unused, for OpenSSL compatibility */
911};
912
913struct ssl_st {
914 /* protocol version
915 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, DTLS1_VERSION)
916 */
917 int version;
918
919 const SSL_METHOD *method;
920 const SSL_QUIC_METHOD *quic_method;
921
922 /* There are 2 BIO's even though they are normally both the
923 * same. This is so data can be read and written to different
924 * handlers */
925
926 BIO *rbio; /* used by SSL_read */
927 BIO *wbio; /* used by SSL_write */
928 BIO *bbio; /* used during session-id reuse to concatenate
929 * messages */
930 int server; /* are we the server side? - mostly used by SSL_clear*/
931
932 struct ssl3_state_st *s3; /* SSLv3 variables */
933 struct dtls1_state_st *d1; /* DTLSv1 variables */
934
935 X509_VERIFY_PARAM *param;
936
937 /* crypto */
938 STACK_OF(SSL_CIPHER) *cipher_list;
939
940 /* This is used to hold the server certificate used */
941 SSL_CERT *cert;
942
943 /* the session_id_context is used to ensure sessions are only reused
944 * in the appropriate context */
945 size_t sid_ctx_length;
946 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
947
948 /* This can also be in the session once a session is established */
949 SSL_SESSION *session;
950
951 /* Used in SSL2 and SSL3 */
952 int verify_mode; /* 0 don't care about verify failure.
953 * 1 fail if verify fails */
954 int error; /* error bytes to be written */
955 int error_code; /* actual code */
956
957 SSL_CTX *ctx;
958
959 long verify_result;
960
961 int references;
962
963 int client_version; /* what was passed, used for
964 * SSLv3/TLS rollback check */
965
966 unsigned int max_send_fragment;
967
968 const struct tls_extension **tlsext_build_order;
969 size_t tlsext_build_order_len;
970
971 char *tlsext_hostname;
972
973 /* certificate status request info */
974 /* Status type or -1 if no status type */
975 int tlsext_status_type;
976
977 SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
978#define session_ctx initial_ctx
979
980 struct tls13_ctx *tls13;
981
982 uint16_t min_tls_version;
983 uint16_t max_tls_version;
984
985 /*
986 * These may be zero to imply minimum or maximum version supported by
987 * the method.
988 */
989 uint16_t min_proto_version;
990 uint16_t max_proto_version;
991
992 unsigned long options; /* protocol behaviour */
993 unsigned long mode; /* API behaviour */
994
995 /* Client list of supported protocols in wire format. */
996 uint8_t *alpn_client_proto_list;
997 size_t alpn_client_proto_list_len;
998
999 /* QUIC transport params we will send */
1000 uint8_t *quic_transport_params;
1001 size_t quic_transport_params_len;
1002
1003 /* XXX Callbacks */
1004
1005 /* true when we are actually in SSL_accept() or SSL_connect() */
1006 int in_handshake;
1007 int (*handshake_func)(SSL *);
1008
1009 ssl_info_callback_fn *info_callback;
1010
1011 /* callback that allows applications to peek at protocol messages */
1012 ssl_msg_callback_fn *msg_callback;
1013 void *msg_callback_arg;
1014
1015 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
1016
1017 /* Default generate session ID callback. */
1018 GEN_SESSION_CB generate_session_id;
1019
1020 /* TLS extension debug callback */
1021 void (*tlsext_debug_cb)(SSL *s, int client_server, int type,
1022 unsigned char *data, int len, void *arg);
1023 void *tlsext_debug_arg;
1024
1025 /* TLS Session Ticket extension callback */
1026 tls_session_ticket_ext_cb_fn tls_session_ticket_ext_cb;
1027 void *tls_session_ticket_ext_cb_arg;
1028
1029 /* TLS pre-shared secret session resumption */
1030 tls_session_secret_cb_fn tls_session_secret_cb;
1031 void *tls_session_secret_cb_arg;
1032
1033 /* XXX non-callback */
1034
1035 /* This holds a variable that indicates what we were doing
1036 * when a 0 or -1 is returned. This is needed for
1037 * non-blocking IO so we know what request needs re-doing when
1038 * in SSL_accept or SSL_connect */
1039 int rwstate;
1040
1041 /* Imagine that here's a boolean member "init" that is
1042 * switched as soon as SSL_set_{accept/connect}_state
1043 * is called for the first time, so that "state" and
1044 * "handshake_func" are properly initialized. But as
1045 * handshake_func is == 0 until then, we use this
1046 * test instead of an "init" member.
1047 */
1048
1049 int new_session;/* Generate a new session or reuse an old one.
1050 * NB: For servers, the 'new' session may actually be a previously
1051 * cached session or even the previous session unless
1052 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */
1053 int quiet_shutdown;/* don't send shutdown packets */
1054 int shutdown; /* we have shut things down, 0x01 sent, 0x02
1055 * for received */
1056 BUF_MEM *init_buf; /* buffer used during init */
1057 void *init_msg; /* pointer to handshake message body, set by ssl3_get_message() */
1058 int init_num; /* amount read/written */
1059 int init_off; /* amount read/written */
1060
1061 /* used internally to point at a raw packet */
1062 unsigned char *packet;
1063 unsigned int packet_length;
1064
1065 int read_ahead; /* Read as many input bytes as possible
1066 * (for non-blocking reads) */
1067
1068 int hit; /* reusing a previous session */
1069
1070 STACK_OF(SSL_CIPHER) *cipher_list_tls13;
1071
1072 struct tls12_record_layer *rl;
1073
1074 /* session info */
1075
1076 /* extra application data */
1077 CRYPTO_EX_DATA ex_data;
1078
1079 /* client cert? */
1080 /* for server side, keep the list of CA_dn we can use */
1081 STACK_OF(X509_NAME) *client_CA;
1082
1083 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
1084 * and SSL_write() calls, good for nbio debugging :-) */
1085 int debug;
1086 long max_cert_list;
1087 int first_packet;
1088
1089 /* Expect OCSP CertificateStatus message */
1090 int tlsext_status_expected;
1091 /* OCSP status request only */
1092 STACK_OF(OCSP_RESPID) *tlsext_ocsp_ids;
1093 X509_EXTENSIONS *tlsext_ocsp_exts;
1094
1095 /* OCSP response received or to be sent */
1096 unsigned char *tlsext_ocsp_resp;
1097 size_t tlsext_ocsp_resp_len;
1098
1099 /* RFC4507 session ticket expected to be received or sent */
1100 int tlsext_ticket_expected;
1101
1102 size_t tlsext_ecpointformatlist_length;
1103 uint8_t *tlsext_ecpointformatlist; /* our list */
1104 size_t tlsext_supportedgroups_length;
1105 uint16_t *tlsext_supportedgroups; /* our list */
1106
1107 /* TLS Session Ticket extension override */
1108 TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
1109
1110 STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles; /* What we'll do */
1111 const SRTP_PROTECTION_PROFILE *srtp_profile; /* What's been chosen */
1112
1113 int renegotiate;/* 1 if we are renegotiating.
1114 * 2 if we are a server and are inside a handshake
1115 * (i.e. not just sending a HelloRequest) */
1116
1117 int rstate; /* where we are when reading */
1118
1119 int mac_packet;
1120
1121 int empty_record_count;
1122
1123 size_t num_tickets; /* Unused, for OpenSSL compatibility */
1124};
1125
1126typedef struct ssl3_record_internal_st {
1127 int type; /* type of record */
1128 unsigned int length; /* How many bytes available */
1129 unsigned int padding_length; /* Number of padding bytes. */
1130 unsigned int off; /* read/write offset into 'buf' */
1131 unsigned char *data; /* pointer to the record data */
1132 unsigned char *input; /* where the decode bytes are */
1133 uint16_t epoch; /* epoch number, needed by DTLS1 */
1134 unsigned char seq_num[8]; /* sequence number, needed by DTLS1 */
1135} SSL3_RECORD_INTERNAL;
1136
1137typedef struct ssl3_buffer_internal_st {
1138 unsigned char *buf; /* at least SSL3_RT_MAX_PACKET_SIZE bytes,
1139 * see ssl3_setup_buffers() */
1140 size_t len; /* buffer size */
1141 int offset; /* where to 'copy from' */
1142 int left; /* how many bytes left */
1143} SSL3_BUFFER_INTERNAL;
1144
1145typedef struct ssl3_state_st {
1146 long flags;
1147
1148 unsigned char server_random[SSL3_RANDOM_SIZE];
1149 unsigned char client_random[SSL3_RANDOM_SIZE];
1150
1151 SSL3_BUFFER_INTERNAL rbuf; /* read IO goes into here */
1152 SSL3_BUFFER_INTERNAL wbuf; /* write IO goes into here */
1153
1154 SSL3_RECORD_INTERNAL rrec; /* each decoded record goes in here */
1155
1156 struct tls_content *rcontent; /* Content from opened TLS records. */
1157
1158 /* we allow one fatal and one warning alert to be outstanding,
1159 * send close alert via the warning alert */
1160 int alert_dispatch;
1161 unsigned char send_alert[2];
1162
1163 /* flags for countermeasure against known-IV weakness */
1164 int need_empty_fragments;
1165 int empty_fragment_done;
1166
1167 /* Unprocessed Alert/Handshake protocol data. */
1168 struct tls_buffer *alert_fragment;
1169 struct tls_buffer *handshake_fragment;
1170
1171 /* partial write - check the numbers match */
1172 unsigned int wnum; /* number of bytes sent so far */
1173 int wpend_tot; /* number bytes written */
1174 int wpend_type;
1175 int wpend_ret; /* number of bytes submitted */
1176 const unsigned char *wpend_buf;
1177
1178 /* Transcript of handshake messages that have been sent and received. */
1179 struct tls_buffer *handshake_transcript;
1180
1181 /* Rolling hash of handshake messages. */
1182 EVP_MD_CTX *handshake_hash;
1183
1184 /* this is set whenerver we see a change_cipher_spec message
1185 * come in when we are not looking for one */
1186 int change_cipher_spec;
1187
1188 int warn_alert;
1189 int fatal_alert;
1190
1191 /* This flag is set when we should renegotiate ASAP, basically when
1192 * there is no more data in the read or write buffers */
1193 int renegotiate;
1194 int total_renegotiations;
1195 int num_renegotiations;
1196
1197 int in_read_app_data;
1198
1199 SSL_HANDSHAKE hs;
1200
1201 /* Connection binding to prevent renegotiation attacks */
1202 unsigned char previous_client_finished[EVP_MAX_MD_SIZE];
1203 unsigned char previous_client_finished_len;
1204 unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
1205 unsigned char previous_server_finished_len;
1206 int send_connection_binding; /* TODOEKR */
1207
1208 /* Set if we saw a Renegotiation Indication extension from our peer. */
1209 int renegotiate_seen;
1210
1211 /*
1212 * ALPN information.
1213 *
1214 * In a server these point to the selected ALPN protocol after the
1215 * ClientHello has been processed. In a client these contain the
1216 * protocol that the server selected once the ServerHello has been
1217 * processed.
1218 */
1219 uint8_t *alpn_selected;
1220 size_t alpn_selected_len;
1221
1222 /* Contains the QUIC transport params received from our peer. */
1223 uint8_t *peer_quic_transport_params;
1224 size_t peer_quic_transport_params_len;
1225} SSL3_STATE;
1226
1227/*
1228 * Flag values for enc_flags.
1229 */
1230
1231/* Uses signature algorithms extension. */
1232#define SSL_ENC_FLAG_SIGALGS (1 << 1)
1233
1234/* Uses SHA256 default PRF. */
1235#define SSL_ENC_FLAG_SHA256_PRF (1 << 2)
1236
1237/* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
1238#define SSL_ENC_FLAG_TLS1_2_CIPHERS (1 << 4)
1239
1240/* Allow TLS 1.3 ciphersuites only. */
1241#define SSL_ENC_FLAG_TLS1_3_CIPHERS (1 << 5)
1242
1243#define TLSV1_ENC_FLAGS 0
1244#define TLSV1_1_ENC_FLAGS 0
1245#define TLSV1_2_ENC_FLAGS (SSL_ENC_FLAG_SIGALGS | \
1246 SSL_ENC_FLAG_SHA256_PRF | \
1247 SSL_ENC_FLAG_TLS1_2_CIPHERS)
1248#define TLSV1_3_ENC_FLAGS (SSL_ENC_FLAG_SIGALGS | \
1249 SSL_ENC_FLAG_TLS1_3_CIPHERS)
1250
1251extern const SSL_CIPHER ssl3_ciphers[];
1252
1253const char *ssl_version_string(int ver);
1254int ssl_version_set_min(const SSL_METHOD *meth, uint16_t proto_ver,
1255 uint16_t max_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver);
1256int ssl_version_set_max(const SSL_METHOD *meth, uint16_t proto_ver,
1257 uint16_t min_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver);
1258int ssl_enabled_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
1259int ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
1260uint16_t ssl_tls_version(uint16_t version);
1261uint16_t ssl_effective_tls_version(SSL *s);
1262int ssl_max_supported_version(SSL *s, uint16_t *max_ver);
1263int ssl_max_legacy_version(SSL *s, uint16_t *max_ver);
1264int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver);
1265int ssl_check_version_from_server(SSL *s, uint16_t server_version);
1266int ssl_legacy_stack_version(SSL *s, uint16_t version);
1267int ssl_cipher_in_list(STACK_OF(SSL_CIPHER) *ciphers, const SSL_CIPHER *cipher);
1268int ssl_cipher_allowed_in_tls_version_range(const SSL_CIPHER *cipher,
1269 uint16_t min_ver, uint16_t max_ver);
1270
1271const SSL_METHOD *tls_legacy_method(void);
1272const SSL_METHOD *ssl_get_method(uint16_t version);
1273
1274void ssl_clear_cipher_state(SSL *s);
1275int ssl_clear_bad_session(SSL *s);
1276
1277void ssl_info_callback(const SSL *s, int type, int value);
1278void ssl_msg_callback(SSL *s, int is_write, int content_type,
1279 const void *msg_buf, size_t msg_len);
1280void ssl_msg_callback_cbs(SSL *s, int is_write, int content_type, CBS *cbs);
1281
1282SSL_CERT *ssl_cert_new(void);
1283SSL_CERT *ssl_cert_dup(SSL_CERT *cert);
1284void ssl_cert_free(SSL_CERT *c);
1285SSL_CERT *ssl_get0_cert(SSL_CTX *ctx, SSL *ssl);
1286int ssl_cert_set0_chain(SSL_CTX *ctx, SSL *ssl, STACK_OF(X509) *chain);
1287int ssl_cert_set1_chain(SSL_CTX *ctx, SSL *ssl, STACK_OF(X509) *chain);
1288int ssl_cert_add0_chain_cert(SSL_CTX *ctx, SSL *ssl, X509 *cert);
1289int ssl_cert_add1_chain_cert(SSL_CTX *ctx, SSL *ssl, X509 *cert);
1290
1291int ssl_security_default_cb(const SSL *ssl, const SSL_CTX *ctx, int op,
1292 int bits, int nid, void *other, void *ex_data);
1293
1294int ssl_security_cipher_check(const SSL *ssl, SSL_CIPHER *cipher);
1295int ssl_security_shared_cipher(const SSL *ssl, SSL_CIPHER *cipher);
1296int ssl_security_supported_cipher(const SSL *ssl, SSL_CIPHER *cipher);
1297int ssl_ctx_security_dh(const SSL_CTX *ctx, DH *dh);
1298int ssl_security_dh(const SSL *ssl, DH *dh);
1299int ssl_security_sigalg_check(const SSL *ssl, const EVP_PKEY *pkey);
1300int ssl_security_tickets(const SSL *ssl);
1301int ssl_security_version(const SSL *ssl, int version);
1302int ssl_security_cert(const SSL_CTX *ctx, const SSL *ssl, X509 *x509,
1303 int is_peer, int *out_error);
1304int ssl_security_cert_chain(const SSL *ssl, STACK_OF(X509) *sk,
1305 X509 *x509, int *out_error);
1306int ssl_security_shared_group(const SSL *ssl, uint16_t group_id);
1307int ssl_security_supported_group(const SSL *ssl, uint16_t group_id);
1308
1309SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int include_ticket);
1310int ssl_get_new_session(SSL *s, int session);
1311int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block,
1312 int *alert);
1313int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
1314SSL_CIPHER *OBJ_bsearch_ssl_cipher_id(SSL_CIPHER *key, SSL_CIPHER const *base,
1315 int num);
1316int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *ciphers, CBB *cbb);
1317STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, CBS *cbs);
1318STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
1319 STACK_OF(SSL_CIPHER) **pref, STACK_OF(SSL_CIPHER) *tls13,
1320 const char *rule_str, SSL_CERT *cert);
1321int ssl_parse_ciphersuites(STACK_OF(SSL_CIPHER) **out_ciphers, const char *str);
1322int ssl_merge_cipherlists(STACK_OF(SSL_CIPHER) *cipherlist,
1323 STACK_OF(SSL_CIPHER) *cipherlist_tls13,
1324 STACK_OF(SSL_CIPHER) **out_cipherlist);
1325void ssl_update_cache(SSL *s, int mode);
1326int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
1327 const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size);
1328int ssl_cipher_get_evp_aead(const SSL_SESSION *s, const EVP_AEAD **aead);
1329int ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md);
1330
1331int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk);
1332int ssl_undefined_function(SSL *s);
1333int ssl_undefined_void_function(void);
1334int ssl_undefined_const_function(const SSL *s);
1335SSL_CERT_PKEY *ssl_get_server_send_pkey(const SSL *s);
1336EVP_PKEY *ssl_get_sign_pkey(SSL *s, const SSL_CIPHER *c, const EVP_MD **pmd,
1337 const struct ssl_sigalg **sap);
1338size_t ssl_dhe_params_auto_key_bits(SSL *s);
1339int ssl_cert_type(EVP_PKEY *pkey);
1340void ssl_set_cert_masks(SSL_CERT *c, const SSL_CIPHER *cipher);
1341STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
1342int ssl_has_ecc_ciphers(SSL *s);
1343int ssl_verify_alarm_type(long type);
1344
1345int SSL_SESSION_ticket(SSL_SESSION *ss, unsigned char **out, size_t *out_len);
1346
1347const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
1348int ssl3_do_write(SSL *s, int type);
1349int ssl3_send_alert(SSL *s, int level, int desc);
1350int ssl3_get_req_cert_types(SSL *s, CBB *cbb);
1351int ssl3_get_message(SSL *s, int st1, int stn, int mt, long max);
1352int ssl3_num_ciphers(void);
1353const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
1354const SSL_CIPHER *ssl3_get_cipher_by_id(unsigned int id);
1355const SSL_CIPHER *ssl3_get_cipher_by_value(uint16_t value);
1356uint16_t ssl3_cipher_get_value(const SSL_CIPHER *c);
1357int ssl3_renegotiate(SSL *ssl);
1358
1359int ssl3_renegotiate_check(SSL *ssl);
1360
1361void ssl_force_want_read(SSL *s);
1362
1363int ssl3_dispatch_alert(SSL *s);
1364int ssl3_read_alert(SSL *s);
1365int ssl3_read_change_cipher_spec(SSL *s);
1366int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
1367int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
1368int ssl3_output_cert_chain(SSL *s, CBB *cbb, SSL_CERT_PKEY *cpk);
1369SSL_CIPHER *ssl3_choose_cipher(SSL *ssl, STACK_OF(SSL_CIPHER) *clnt,
1370 STACK_OF(SSL_CIPHER) *srvr);
1371int ssl3_setup_buffers(SSL *s);
1372int ssl3_setup_init_buffer(SSL *s);
1373void ssl3_release_init_buffer(SSL *s);
1374int ssl3_setup_read_buffer(SSL *s);
1375int ssl3_setup_write_buffer(SSL *s);
1376void ssl3_release_buffer(SSL3_BUFFER_INTERNAL *b);
1377void ssl3_release_read_buffer(SSL *s);
1378void ssl3_release_write_buffer(SSL *s);
1379int ssl3_new(SSL *s);
1380void ssl3_free(SSL *s);
1381int ssl3_accept(SSL *s);
1382int ssl3_connect(SSL *s);
1383int ssl3_read(SSL *s, void *buf, int len);
1384int ssl3_peek(SSL *s, void *buf, int len);
1385int ssl3_write(SSL *s, const void *buf, int len);
1386int ssl3_shutdown(SSL *s);
1387void ssl3_clear(SSL *s);
1388long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg);
1389long ssl3_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg);
1390long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
1391long ssl3_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp)(void));
1392int ssl3_pending(const SSL *s);
1393
1394int ssl3_handshake_msg_hdr_len(SSL *s);
1395int ssl3_handshake_msg_start(SSL *s, CBB *handshake, CBB *body,
1396 uint8_t msg_type);
1397int ssl3_handshake_msg_finish(SSL *s, CBB *handshake);
1398int ssl3_handshake_write(SSL *s);
1399int ssl3_record_write(SSL *s, int type);
1400
1401int ssl3_do_change_cipher_spec(SSL *ssl);
1402
1403int ssl3_packet_read(SSL *s, int plen);
1404int ssl3_packet_extend(SSL *s, int plen);
1405int ssl_server_legacy_first_packet(SSL *s);
1406int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
1407 unsigned int len);
1408
1409int ssl_kex_generate_dhe(DH *dh, DH *dh_params);
1410int ssl_kex_generate_dhe_params_auto(DH *dh, size_t key_len);
1411int ssl_kex_params_dhe(DH *dh, CBB *cbb);
1412int ssl_kex_public_dhe(DH *dh, CBB *cbb);
1413int ssl_kex_peer_params_dhe(DH *dh, CBS *cbs, int *decode_error,
1414 int *invalid_params);
1415int ssl_kex_peer_public_dhe(DH *dh, CBS *cbs, int *decode_error,
1416 int *invalid_key);
1417int ssl_kex_derive_dhe(DH *dh, DH *dh_peer,
1418 uint8_t **shared_key, size_t *shared_key_len);
1419
1420int ssl_kex_dummy_ecdhe_x25519(EVP_PKEY *pkey);
1421int ssl_kex_generate_ecdhe_ecp(EC_KEY *ecdh, int nid);
1422int ssl_kex_public_ecdhe_ecp(EC_KEY *ecdh, CBB *cbb);
1423int ssl_kex_peer_public_ecdhe_ecp(EC_KEY *ecdh, int nid, CBS *cbs);
1424int ssl_kex_derive_ecdhe_ecp(EC_KEY *ecdh, EC_KEY *ecdh_peer,
1425 uint8_t **shared_key, size_t *shared_key_len);
1426
1427int tls1_new(SSL *s);
1428void tls1_free(SSL *s);
1429void tls1_clear(SSL *s);
1430
1431int ssl_init_wbio_buffer(SSL *s, int push);
1432void ssl_free_wbio_buffer(SSL *s);
1433
1434int tls1_transcript_hash_init(SSL *s);
1435int tls1_transcript_hash_update(SSL *s, const unsigned char *buf, size_t len);
1436int tls1_transcript_hash_value(SSL *s, unsigned char *out, size_t len,
1437 size_t *outlen);
1438void tls1_transcript_hash_free(SSL *s);
1439
1440int tls1_transcript_init(SSL *s);
1441void tls1_transcript_free(SSL *s);
1442void tls1_transcript_reset(SSL *s);
1443int tls1_transcript_append(SSL *s, const unsigned char *buf, size_t len);
1444int tls1_transcript_data(SSL *s, const unsigned char **data, size_t *len);
1445void tls1_transcript_freeze(SSL *s);
1446void tls1_transcript_unfreeze(SSL *s);
1447int tls1_transcript_record(SSL *s, const unsigned char *buf, size_t len);
1448
1449int tls1_PRF(SSL *s, const unsigned char *secret, size_t secret_len,
1450 const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len,
1451 const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len,
1452 const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len);
1453
1454void tls1_cleanup_key_block(SSL *s);
1455int tls1_change_read_cipher_state(SSL *s);
1456int tls1_change_write_cipher_state(SSL *s);
1457int tls1_setup_key_block(SSL *s);
1458int tls1_generate_key_block(SSL *s, uint8_t *key_block, size_t key_block_len);
1459int ssl_ok(SSL *s);
1460
1461int tls12_derive_finished(SSL *s);
1462int tls12_derive_peer_finished(SSL *s);
1463int tls12_derive_master_secret(SSL *s, uint8_t *premaster_secret,
1464 size_t premaster_secret_len);
1465
1466int ssl_using_ecc_cipher(SSL *s);
1467int ssl_check_srvr_ecc_cert_and_alg(SSL *s, X509 *x);
1468
1469void tls1_get_formatlist(const SSL *s, int client_formats,
1470 const uint8_t **pformats, size_t *pformatslen);
1471void tls1_get_group_list(const SSL *s, int client_groups,
1472 const uint16_t **pgroups, size_t *pgroupslen);
1473
1474int tls1_set_groups(uint16_t **out_group_ids, size_t *out_group_ids_len,
1475 const int *groups, size_t ngroups);
1476int tls1_set_group_list(uint16_t **out_group_ids, size_t *out_group_ids_len,
1477 const char *groups);
1478
1479int tls1_ec_group_id2nid(uint16_t group_id, int *out_nid);
1480int tls1_ec_group_id2bits(uint16_t group_id, int *out_bits);
1481int tls1_ec_nid2group_id(int nid, uint16_t *out_group_id);
1482int tls1_check_group(SSL *s, uint16_t group_id);
1483int tls1_count_shared_groups(const SSL *ssl, size_t *out_count);
1484int tls1_get_shared_group_by_index(const SSL *ssl, size_t index, int *out_nid);
1485int tls1_get_supported_group(const SSL *s, int *out_nid);
1486
1487int ssl_check_clienthello_tlsext_early(SSL *s);
1488int ssl_check_clienthello_tlsext_late(SSL *s);
1489int ssl_check_serverhello_tlsext(SSL *s);
1490
1491#define TLS1_TICKET_FATAL_ERROR -1
1492#define TLS1_TICKET_NONE 0
1493#define TLS1_TICKET_EMPTY 1
1494#define TLS1_TICKET_NOT_DECRYPTED 2
1495#define TLS1_TICKET_DECRYPTED 3
1496
1497int tls1_process_ticket(SSL *s, CBS *ext_block, int *alert, SSL_SESSION **ret);
1498
1499int tls1_check_ec_server_key(SSL *s);
1500
1501/* s3_cbc.c */
1502void ssl3_cbc_copy_mac(unsigned char *out, const SSL3_RECORD_INTERNAL *rec,
1503 unsigned int md_size, unsigned int orig_len);
1504int ssl3_cbc_remove_padding(SSL3_RECORD_INTERNAL *rec, unsigned int eiv_len,
1505 unsigned int mac_size);
1506char ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx);
1507int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx, unsigned char *md_out,
1508 size_t *md_out_size, const unsigned char header[13],
1509 const unsigned char *data, size_t data_plus_mac_size,
1510 size_t data_plus_mac_plus_padding_size, const unsigned char *mac_secret,
1511 unsigned int mac_secret_length);
1512int SSL_state_func_code(int _state);
1513
1514#define SSLerror(s, r) SSL_error_internal(s, r, __FILE__, __LINE__)
1515#define SSLerrorx(r) ERR_PUT_error(ERR_LIB_SSL,(0xfff),(r),__FILE__,__LINE__)
1516void SSL_error_internal(const SSL *s, int r, char *f, int l);
1517
1518#ifndef OPENSSL_NO_SRTP
1519
1520int srtp_find_profile_by_name(const char *profile_name,
1521 const SRTP_PROTECTION_PROFILE **pptr, unsigned int len);
1522int srtp_find_profile_by_num(unsigned int profile_num,
1523 const SRTP_PROTECTION_PROFILE **pptr);
1524
1525#endif /* OPENSSL_NO_SRTP */
1526
1527int tls_process_peer_certs(SSL *s, STACK_OF(X509) *peer_certs);
1528
1529__END_HIDDEN_DECLS
1530
1531#endif /* !HEADER_SSL_LOCL_H */