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