summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_locl.h
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2021-08-18 16:06:57 +0000
committercvs2svn <admin@example.com>2021-08-18 16:06:57 +0000
commitd56c8fa8260d226f98b26f017b45b9c2b135f38d (patch)
tree348178b41617813cc93787187984a734ef8379ca /src/lib/libssl/ssl_locl.h
parent18b9c1bcab7c37d8c5bd05b8e0d14d0c59d96650 (diff)
downloadopenbsd-tb_20210818.tar.gz
openbsd-tb_20210818.tar.bz2
openbsd-tb_20210818.zip
This commit was manufactured by cvs2git to create tag 'tb_20210818'.tb_20210818
Diffstat (limited to 'src/lib/libssl/ssl_locl.h')
-rw-r--r--src/lib/libssl/ssl_locl.h1429
1 files changed, 0 insertions, 1429 deletions
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
deleted file mode 100644
index f3650f238e..0000000000
--- a/src/lib/libssl/ssl_locl.h
+++ /dev/null
@@ -1,1429 +0,0 @@
1/* $OpenBSD: ssl_locl.h,v 1.356 2021/07/26 03:17:38 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/*
352#define CERT_INVALID 0
353#define CERT_PUBLIC_KEY 1
354#define CERT_PRIVATE_KEY 2
355*/
356
357/* From ECC-TLS draft, used in encoding the curve type in
358 * ECParameters
359 */
360#define EXPLICIT_PRIME_CURVE_TYPE 1
361#define EXPLICIT_CHAR2_CURVE_TYPE 2
362#define NAMED_CURVE_TYPE 3
363
364struct ssl_cipher_st {
365 int valid;
366 const char *name; /* text name */
367 unsigned long id; /* id, 4 bytes, first is version */
368
369 unsigned long algorithm_mkey; /* key exchange algorithm */
370 unsigned long algorithm_auth; /* server authentication */
371 unsigned long algorithm_enc; /* symmetric encryption */
372 unsigned long algorithm_mac; /* symmetric authentication */
373 unsigned long algorithm_ssl; /* (major) protocol version */
374
375 unsigned long algo_strength; /* strength and export flags */
376 unsigned long algorithm2; /* Extra flags */
377 int strength_bits; /* Number of bits really used */
378 int alg_bits; /* Number of bits for algorithm */
379};
380
381struct ssl_method_st {
382 int dtls;
383 int server;
384 int version;
385
386 uint16_t min_tls_version;
387 uint16_t max_tls_version;
388
389 int (*ssl_new)(SSL *s);
390 void (*ssl_clear)(SSL *s);
391 void (*ssl_free)(SSL *s);
392
393 int (*ssl_accept)(SSL *s);
394 int (*ssl_connect)(SSL *s);
395 int (*ssl_shutdown)(SSL *s);
396
397 int (*ssl_renegotiate)(SSL *s);
398 int (*ssl_renegotiate_check)(SSL *s);
399
400 int (*ssl_pending)(const SSL *s);
401 int (*ssl_read_bytes)(SSL *s, int type, unsigned char *buf, int len,
402 int peek);
403 int (*ssl_write_bytes)(SSL *s, int type, const void *buf_, int len);
404
405 const SSL_CIPHER *(*get_cipher)(unsigned int ncipher);
406
407 unsigned int enc_flags; /* SSL_ENC_FLAG_* */
408};
409
410typedef struct ssl_session_internal_st {
411 CRYPTO_EX_DATA ex_data; /* application specific data */
412
413 /* These are used to make removal of session-ids more
414 * efficient and to implement a maximum cache size. */
415 struct ssl_session_st *prev, *next;
416
417 /* Used to indicate that session resumption is not allowed.
418 * Applications can also set this bit for a new session via
419 * not_resumable_session_cb to disable session caching and tickets. */
420 int not_resumable;
421
422 /* The cert is the certificate used to establish this connection */
423 struct sess_cert_st /* SESS_CERT */ *sess_cert;
424
425 size_t tlsext_ecpointformatlist_length;
426 uint8_t *tlsext_ecpointformatlist; /* peer's list */
427 size_t tlsext_supportedgroups_length;
428 uint16_t *tlsext_supportedgroups; /* peer's list */
429} SSL_SESSION_INTERNAL;
430#define SSI(s) (s->session->internal)
431
432/* Lets 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 3 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 int master_key_length;
461 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
462
463 /* session_id - valid? */
464 unsigned int 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 unsigned int sid_ctx_length;
471 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
472
473 /* This is the cert for the other end. */
474 X509 *peer;
475
476 /* when app_verify_callback accepts a session where the peer's certificate
477 * is not ok, we must remember the error for session reuse: */
478 long verify_result; /* only for servers */
479
480 long timeout;
481 time_t time;
482 int references;
483
484 const SSL_CIPHER *cipher;
485 unsigned long cipher_id; /* when ASN.1 loaded, this
486 * needs to be used to load
487 * the 'cipher' structure */
488
489 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
490
491 char *tlsext_hostname;
492
493 /* RFC4507 info */
494 unsigned char *tlsext_tick; /* Session ticket */
495 size_t tlsext_ticklen; /* Session ticket length */
496 long tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */
497
498 struct ssl_session_internal_st *internal;
499};
500
501typedef struct cert_pkey_st {
502 X509 *x509;
503 EVP_PKEY *privatekey;
504 STACK_OF(X509) *chain;
505} CERT_PKEY;
506
507struct ssl_sigalg;
508
509typedef struct ssl_handshake_tls12_st {
510 /* Used when SSL_ST_FLUSH_DATA is entered. */
511 int next_state;
512
513 /* Handshake message type and size. */
514 int message_type;
515 unsigned long message_size;
516
517 /* Reuse current handshake message. */
518 int reuse_message;
519
520 /* Client certificate requests. */
521 int cert_request;
522 STACK_OF(X509_NAME) *ca_names;
523
524 /* Record-layer key block for TLS 1.2 and earlier. */
525 struct tls12_key_block *key_block;
526
527 /* Transcript hash prior to sending certificate verify message. */
528 uint8_t cert_verify[EVP_MAX_MD_SIZE];
529} SSL_HANDSHAKE_TLS12;
530
531typedef struct ssl_handshake_tls13_st {
532 int use_legacy;
533 int hrr;
534
535 /* Certificate selected for use (static pointer). */
536 const CERT_PKEY *cpk;
537
538 /* Version proposed by peer server. */
539 uint16_t server_version;
540
541 uint16_t server_group;
542 struct tls13_key_share *key_share;
543 struct tls13_secrets *secrets;
544
545 uint8_t *cookie;
546 size_t cookie_len;
547
548 /* Preserved transcript hash. */
549 uint8_t transcript_hash[EVP_MAX_MD_SIZE];
550 size_t transcript_hash_len;
551
552 /* Legacy session ID. */
553 uint8_t legacy_session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
554 size_t legacy_session_id_len;
555
556 /* ClientHello hash, used to validate following HelloRetryRequest */
557 EVP_MD_CTX *clienthello_md_ctx;
558 unsigned char *clienthello_hash;
559 unsigned int clienthello_hash_len;
560} SSL_HANDSHAKE_TLS13;
561
562typedef struct ssl_handshake_st {
563 /*
564 * Minimum and maximum versions supported for this handshake. These are
565 * initialised at the start of a handshake based on the method in use
566 * and the current protocol version configuration.
567 */
568 uint16_t our_min_tls_version;
569 uint16_t our_max_tls_version;
570
571 /*
572 * Version negotiated for this session. For a client this is set once
573 * the server selected version is parsed from the ServerHello (either
574 * from the legacy version or supported versions extension). For a
575 * server this is set once we select the version we will use with the
576 * client.
577 */
578 uint16_t negotiated_tls_version;
579
580 /*
581 * Current handshake state - contains one of the SSL3_ST_* values and
582 * is used by the TLSv1.2 state machine, as well as being updated by
583 * the TLSv1.3 stack due to it being exposed externally.
584 */
585 int state;
586
587 /* Cipher being negotiated in this handshake. */
588 const SSL_CIPHER *cipher;
589
590 /* Extensions seen in this handshake. */
591 uint32_t extensions_seen;
592
593 /* Signature algorithms selected for use (static pointers). */
594 const struct ssl_sigalg *our_sigalg;
595 const struct ssl_sigalg *peer_sigalg;
596
597 /* sigalgs offered in this handshake in wire form */
598 uint8_t *sigalgs;
599 size_t sigalgs_len;
600
601 /*
602 * Copies of the verify data sent in our finished message and the
603 * verify data received in the finished message sent by our peer.
604 */
605 uint8_t finished[EVP_MAX_MD_SIZE];
606 size_t finished_len;
607 uint8_t peer_finished[EVP_MAX_MD_SIZE];
608 size_t peer_finished_len;
609
610 SSL_HANDSHAKE_TLS12 tls12;
611 SSL_HANDSHAKE_TLS13 tls13;
612} SSL_HANDSHAKE;
613
614struct tls12_key_block;
615
616struct tls12_key_block *tls12_key_block_new(void);
617void tls12_key_block_free(struct tls12_key_block *kb);
618void tls12_key_block_client_write(struct tls12_key_block *kb, CBS *mac_key,
619 CBS *key, CBS *iv);
620void tls12_key_block_server_write(struct tls12_key_block *kb, CBS *mac_key,
621 CBS *key, CBS *iv);
622int tls12_key_block_generate(struct tls12_key_block *kb, SSL *s,
623 const EVP_AEAD *aead, const EVP_CIPHER *cipher, const EVP_MD *mac_hash);
624
625struct tls12_record_layer;
626
627struct tls12_record_layer *tls12_record_layer_new(void);
628void tls12_record_layer_free(struct tls12_record_layer *rl);
629void tls12_record_layer_alert(struct tls12_record_layer *rl,
630 uint8_t *alert_desc);
631int tls12_record_layer_write_overhead(struct tls12_record_layer *rl,
632 size_t *overhead);
633int tls12_record_layer_read_protected(struct tls12_record_layer *rl);
634int tls12_record_layer_write_protected(struct tls12_record_layer *rl);
635void tls12_record_layer_set_aead(struct tls12_record_layer *rl,
636 const EVP_AEAD *aead);
637void tls12_record_layer_set_cipher_hash(struct tls12_record_layer *rl,
638 const EVP_CIPHER *cipher, const EVP_MD *handshake_hash,
639 const EVP_MD *mac_hash);
640void tls12_record_layer_set_version(struct tls12_record_layer *rl,
641 uint16_t version);
642void tls12_record_layer_set_initial_epoch(struct tls12_record_layer *rl,
643 uint16_t epoch);
644uint16_t tls12_record_layer_initial_epoch(struct tls12_record_layer *rl);
645uint16_t tls12_record_layer_write_epoch(struct tls12_record_layer *rl);
646int tls12_record_layer_use_write_epoch(struct tls12_record_layer *rl,
647 uint16_t epoch);
648void tls12_record_layer_write_epoch_done(struct tls12_record_layer *rl,
649 uint16_t epoch);
650void tls12_record_layer_clear_read_state(struct tls12_record_layer *rl);
651void tls12_record_layer_clear_write_state(struct tls12_record_layer *rl);
652void tls12_record_layer_reflect_seq_num(struct tls12_record_layer *rl);
653void tls12_record_layer_read_cipher_hash(struct tls12_record_layer *rl,
654 EVP_CIPHER_CTX **cipher, EVP_MD_CTX **hash);
655int tls12_record_layer_change_read_cipher_state(struct tls12_record_layer *rl,
656 CBS *mac_key, CBS *key, CBS *iv);
657int tls12_record_layer_change_write_cipher_state(struct tls12_record_layer *rl,
658 CBS *mac_key, CBS *key, CBS *iv);
659int tls12_record_layer_open_record(struct tls12_record_layer *rl,
660 uint8_t *buf, size_t buf_len, uint8_t **out, size_t *out_len);
661int tls12_record_layer_seal_record(struct tls12_record_layer *rl,
662 uint8_t content_type, const uint8_t *content, size_t content_len,
663 CBB *out);
664
665typedef struct ssl_ctx_internal_st {
666 uint16_t min_tls_version;
667 uint16_t max_tls_version;
668
669 /*
670 * These may be zero to imply minimum or maximum version supported by
671 * the method.
672 */
673 uint16_t min_proto_version;
674 uint16_t max_proto_version;
675
676 unsigned long options;
677 unsigned long mode;
678
679 /* If this callback is not null, it will be called each
680 * time a session id is added to the cache. If this function
681 * returns 1, it means that the callback will do a
682 * SSL_SESSION_free() when it has finished using it. Otherwise,
683 * on 0, it means the callback has finished with it.
684 * If remove_session_cb is not null, it will be called when
685 * a session-id is removed from the cache. After the call,
686 * OpenSSL will SSL_SESSION_free() it. */
687 int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
688 void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
689 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
690 const unsigned char *data, int len, int *copy);
691
692 /* if defined, these override the X509_verify_cert() calls */
693 int (*app_verify_callback)(X509_STORE_CTX *, void *);
694 void *app_verify_arg;
695
696 /* get client cert callback */
697 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
698
699 /* cookie generate callback */
700 int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie,
701 unsigned int *cookie_len);
702
703 /* verify cookie callback */
704 int (*app_verify_cookie_cb)(SSL *ssl, const unsigned char *cookie,
705 unsigned int cookie_len);
706
707 void (*info_callback)(const SSL *ssl,int type,int val); /* used if SSL's info_callback is NULL */
708
709 /* callback that allows applications to peek at protocol messages */
710 void (*msg_callback)(int write_p, int version, int content_type,
711 const void *buf, size_t len, SSL *ssl, void *arg);
712 void *msg_callback_arg;
713
714 int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */
715
716 /* Default generate session ID callback. */
717 GEN_SESSION_CB generate_session_id;
718
719 /* TLS extensions servername callback */
720 int (*tlsext_servername_callback)(SSL*, int *, void *);
721 void *tlsext_servername_arg;
722
723 /* Callback to support customisation of ticket key setting */
724 int (*tlsext_ticket_key_cb)(SSL *ssl, unsigned char *name,
725 unsigned char *iv, EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
726
727 /* certificate status request info */
728 /* Callback for status request */
729 int (*tlsext_status_cb)(SSL *ssl, void *arg);
730 void *tlsext_status_arg;
731
732 struct lhash_st_SSL_SESSION *sessions;
733
734 /* Most session-ids that will be cached, default is
735 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
736 unsigned long session_cache_size;
737 struct ssl_session_st *session_cache_head;
738 struct ssl_session_st *session_cache_tail;
739
740 /* This can have one of 2 values, ored together,
741 * SSL_SESS_CACHE_CLIENT,
742 * SSL_SESS_CACHE_SERVER,
743 * Default is SSL_SESSION_CACHE_SERVER, which means only
744 * SSL_accept which cache SSL_SESSIONS. */
745 int session_cache_mode;
746
747 struct {
748 int sess_connect; /* SSL new conn - started */
749 int sess_connect_renegotiate;/* SSL reneg - requested */
750 int sess_connect_good; /* SSL new conne/reneg - finished */
751 int sess_accept; /* SSL new accept - started */
752 int sess_accept_renegotiate;/* SSL reneg - requested */
753 int sess_accept_good; /* SSL accept/reneg - finished */
754 int sess_miss; /* session lookup misses */
755 int sess_timeout; /* reuse attempt on timeouted session */
756 int sess_cache_full; /* session removed due to full cache */
757 int sess_hit; /* session reuse actually done */
758 int sess_cb_hit; /* session-id that was not
759 * in the cache was
760 * passed back via the callback. This
761 * indicates that the application is
762 * supplying session-id's from other
763 * processes - spooky :-) */
764 } stats;
765
766 CRYPTO_EX_DATA ex_data;
767
768 STACK_OF(SSL_CIPHER) *cipher_list_tls13;
769
770 struct cert_st /* CERT */ *cert;
771
772 /* Default values used when no per-SSL value is defined follow */
773
774 /* what we put in client cert requests */
775 STACK_OF(X509_NAME) *client_CA;
776
777 long max_cert_list;
778
779 int read_ahead;
780
781 int quiet_shutdown;
782
783 /* Maximum amount of data to send in one fragment.
784 * actual record size can be more than this due to
785 * padding and MAC overheads.
786 */
787 unsigned int max_send_fragment;
788
789#ifndef OPENSSL_NO_ENGINE
790 /* Engine to pass requests for client certs to
791 */
792 ENGINE *client_cert_engine;
793#endif
794
795 /* RFC 4507 session ticket keys */
796 unsigned char tlsext_tick_key_name[16];
797 unsigned char tlsext_tick_hmac_key[16];
798 unsigned char tlsext_tick_aes_key[16];
799
800 /* SRTP profiles we are willing to do from RFC 5764 */
801 STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
802
803 /*
804 * ALPN information.
805 */
806
807 /*
808 * Server callback function that allows the server to select the
809 * protocol for the connection.
810 * out: on successful return, this must point to the raw protocol
811 * name (without the length prefix).
812 * outlen: on successful return, this contains the length of out.
813 * in: points to the client's list of supported protocols in
814 * wire-format.
815 * inlen: the length of in.
816 */
817 int (*alpn_select_cb)(SSL *s, const unsigned char **out,
818 unsigned char *outlen, const unsigned char *in, unsigned int inlen,
819 void *arg);
820 void *alpn_select_cb_arg;
821
822 /* Client list of supported protocols in wire format. */
823 unsigned char *alpn_client_proto_list;
824 unsigned int alpn_client_proto_list_len;
825
826 size_t tlsext_ecpointformatlist_length;
827 uint8_t *tlsext_ecpointformatlist; /* our list */
828 size_t tlsext_supportedgroups_length;
829 uint16_t *tlsext_supportedgroups; /* our list */
830} SSL_CTX_INTERNAL;
831
832typedef struct ssl_internal_st {
833 struct tls13_ctx *tls13;
834
835 uint16_t min_tls_version;
836 uint16_t max_tls_version;
837
838 /*
839 * These may be zero to imply minimum or maximum version supported by
840 * the method.
841 */
842 uint16_t min_proto_version;
843 uint16_t max_proto_version;
844
845 unsigned long options; /* protocol behaviour */
846 unsigned long mode; /* API behaviour */
847
848 /* Client list of supported protocols in wire format. */
849 unsigned char *alpn_client_proto_list;
850 unsigned int alpn_client_proto_list_len;
851
852 /* XXX Callbacks */
853
854 /* true when we are actually in SSL_accept() or SSL_connect() */
855 int in_handshake;
856 int (*handshake_func)(SSL *);
857 /* callback that allows applications to peek at protocol messages */
858 void (*msg_callback)(int write_p, int version, int content_type,
859 const void *buf, size_t len, SSL *ssl, void *arg);
860 void *msg_callback_arg;
861
862 /* Default generate session ID callback. */
863 GEN_SESSION_CB generate_session_id;
864
865 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
866
867 void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */
868
869 /* TLS extension debug callback */
870 void (*tlsext_debug_cb)(SSL *s, int client_server, int type,
871 unsigned char *data, int len, void *arg);
872 void *tlsext_debug_arg;
873
874 /* TLS Session Ticket extension callback */
875 tls_session_ticket_ext_cb_fn tls_session_ticket_ext_cb;
876 void *tls_session_ticket_ext_cb_arg;
877
878 /* TLS pre-shared secret session resumption */
879 tls_session_secret_cb_fn tls_session_secret_cb;
880 void *tls_session_secret_cb_arg;
881
882 /* XXX non-callback */
883
884 /* This holds a variable that indicates what we were doing
885 * when a 0 or -1 is returned. This is needed for
886 * non-blocking IO so we know what request needs re-doing when
887 * in SSL_accept or SSL_connect */
888 int rwstate;
889
890 /* Imagine that here's a boolean member "init" that is
891 * switched as soon as SSL_set_{accept/connect}_state
892 * is called for the first time, so that "state" and
893 * "handshake_func" are properly initialized. But as
894 * handshake_func is == 0 until then, we use this
895 * test instead of an "init" member.
896 */
897
898 int new_session;/* Generate a new session or reuse an old one.
899 * NB: For servers, the 'new' session may actually be a previously
900 * cached session or even the previous session unless
901 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */
902 int quiet_shutdown;/* don't send shutdown packets */
903 int shutdown; /* we have shut things down, 0x01 sent, 0x02
904 * for received */
905 BUF_MEM *init_buf; /* buffer used during init */
906 void *init_msg; /* pointer to handshake message body, set by ssl3_get_message() */
907 int init_num; /* amount read/written */
908 int init_off; /* amount read/written */
909
910 /* used internally to point at a raw packet */
911 unsigned char *packet;
912 unsigned int packet_length;
913
914 int read_ahead; /* Read as many input bytes as possible
915 * (for non-blocking reads) */
916
917 int hit; /* reusing a previous session */
918
919 STACK_OF(SSL_CIPHER) *cipher_list_tls13;
920
921 struct tls12_record_layer *rl;
922
923 /* session info */
924
925 /* extra application data */
926 CRYPTO_EX_DATA ex_data;
927
928 /* client cert? */
929 /* for server side, keep the list of CA_dn we can use */
930 STACK_OF(X509_NAME) *client_CA;
931
932 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
933 * and SSL_write() calls, good for nbio debuging :-) */
934 int debug;
935 long max_cert_list;
936 int first_packet;
937
938 /* Expect OCSP CertificateStatus message */
939 int tlsext_status_expected;
940 /* OCSP status request only */
941 STACK_OF(OCSP_RESPID) *tlsext_ocsp_ids;
942 X509_EXTENSIONS *tlsext_ocsp_exts;
943
944 /* OCSP response received or to be sent */
945 unsigned char *tlsext_ocsp_resp;
946 size_t tlsext_ocsp_resp_len;
947
948 /* RFC4507 session ticket expected to be received or sent */
949 int tlsext_ticket_expected;
950
951 size_t tlsext_ecpointformatlist_length;
952 uint8_t *tlsext_ecpointformatlist; /* our list */
953 size_t tlsext_supportedgroups_length;
954 uint16_t *tlsext_supportedgroups; /* our list */
955
956 /* TLS Session Ticket extension override */
957 TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
958
959 STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles; /* What we'll do */
960 const SRTP_PROTECTION_PROFILE *srtp_profile; /* What's been chosen */
961
962 int renegotiate;/* 1 if we are renegotiating.
963 * 2 if we are a server and are inside a handshake
964 * (i.e. not just sending a HelloRequest) */
965
966 int rstate; /* where we are when reading */
967
968 int mac_packet;
969
970 int empty_record_count;
971} SSL_INTERNAL;
972
973typedef struct ssl3_record_internal_st {
974 int type; /* type of record */
975 unsigned int length; /* How many bytes available */
976 unsigned int padding_length; /* Number of padding bytes. */
977 unsigned int off; /* read/write offset into 'buf' */
978 unsigned char *data; /* pointer to the record data */
979 unsigned char *input; /* where the decode bytes are */
980 uint16_t epoch; /* epoch number, needed by DTLS1 */
981 unsigned char seq_num[8]; /* sequence number, needed by DTLS1 */
982} SSL3_RECORD_INTERNAL;
983
984typedef struct ssl3_buffer_internal_st {
985 unsigned char *buf; /* at least SSL3_RT_MAX_PACKET_SIZE bytes,
986 * see ssl3_setup_buffers() */
987 size_t len; /* buffer size */
988 int offset; /* where to 'copy from' */
989 int left; /* how many bytes left */
990} SSL3_BUFFER_INTERNAL;
991
992typedef struct ssl3_state_internal_st {
993 SSL3_BUFFER_INTERNAL rbuf; /* read IO goes into here */
994 SSL3_BUFFER_INTERNAL wbuf; /* write IO goes into here */
995
996 /* we allow one fatal and one warning alert to be outstanding,
997 * send close alert via the warning alert */
998 int alert_dispatch;
999 unsigned char send_alert[2];
1000
1001 /* flags for countermeasure against known-IV weakness */
1002 int need_empty_fragments;
1003 int empty_fragment_done;
1004
1005 SSL3_RECORD_INTERNAL rrec; /* each decoded record goes in here */
1006
1007 /* storage for Alert/Handshake protocol data received but not
1008 * yet processed by ssl3_read_bytes: */
1009 unsigned char alert_fragment[2];
1010 unsigned int alert_fragment_len;
1011 unsigned char handshake_fragment[4];
1012 unsigned int handshake_fragment_len;
1013
1014 /* partial write - check the numbers match */
1015 unsigned int wnum; /* number of bytes sent so far */
1016 int wpend_tot; /* number bytes written */
1017 int wpend_type;
1018 int wpend_ret; /* number of bytes submitted */
1019 const unsigned char *wpend_buf;
1020
1021 /* Transcript of handshake messages that have been sent and received. */
1022 BUF_MEM *handshake_transcript;
1023
1024 /* Rolling hash of handshake messages. */
1025 EVP_MD_CTX *handshake_hash;
1026
1027 /* this is set whenerver we see a change_cipher_spec message
1028 * come in when we are not looking for one */
1029 int change_cipher_spec;
1030
1031 int warn_alert;
1032 int fatal_alert;
1033
1034 /* This flag is set when we should renegotiate ASAP, basically when
1035 * there is no more data in the read or write buffers */
1036 int renegotiate;
1037 int total_renegotiations;
1038 int num_renegotiations;
1039
1040 int in_read_app_data;
1041
1042 SSL_HANDSHAKE hs;
1043
1044 struct {
1045 DH *dh;
1046
1047 EC_KEY *ecdh; /* holds short lived ECDH key */
1048 int ecdh_nid;
1049
1050 uint8_t *x25519;
1051 } tmp;
1052
1053 /* Connection binding to prevent renegotiation attacks */
1054 unsigned char previous_client_finished[EVP_MAX_MD_SIZE];
1055 unsigned char previous_client_finished_len;
1056 unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
1057 unsigned char previous_server_finished_len;
1058 int send_connection_binding; /* TODOEKR */
1059
1060 /* Set if we saw a Renegotiation Indication extension from our peer. */
1061 int renegotiate_seen;
1062
1063 /*
1064 * ALPN information.
1065 *
1066 * In a server these point to the selected ALPN protocol after the
1067 * ClientHello has been processed. In a client these contain the
1068 * protocol that the server selected once the ServerHello has been
1069 * processed.
1070 */
1071 unsigned char *alpn_selected;
1072 size_t alpn_selected_len;
1073} SSL3_STATE_INTERNAL;
1074#define S3I(s) (s->s3->internal)
1075
1076typedef struct ssl3_state_st {
1077 long flags;
1078
1079 unsigned char server_random[SSL3_RANDOM_SIZE];
1080 unsigned char client_random[SSL3_RANDOM_SIZE];
1081
1082 struct ssl3_state_internal_st *internal;
1083} SSL3_STATE;
1084
1085typedef struct cert_st {
1086 /* Current active set */
1087 CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array
1088 * Probably it would make more sense to store
1089 * an index, not a pointer. */
1090
1091 /* The following masks are for the key and auth
1092 * algorithms that are supported by the certs below */
1093 int valid;
1094 unsigned long mask_k;
1095 unsigned long mask_a;
1096
1097 DH *dh_tmp;
1098 DH *(*dh_tmp_cb)(SSL *ssl, int is_export, int keysize);
1099 int dh_tmp_auto;
1100
1101 CERT_PKEY pkeys[SSL_PKEY_NUM];
1102
1103 int references; /* >1 only if SSL_copy_session_id is used */
1104} CERT;
1105
1106
1107typedef struct sess_cert_st {
1108 STACK_OF(X509) *cert_chain; /* as received from peer */
1109
1110 /* The 'peer_...' members are used only by clients. */
1111 int peer_cert_type;
1112
1113 CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */
1114 CERT_PKEY peer_pkeys[SSL_PKEY_NUM];
1115 /* Obviously we don't have the private keys of these,
1116 * so maybe we shouldn't even use the CERT_PKEY type here. */
1117
1118 int peer_nid;
1119 DH *peer_dh_tmp;
1120 EC_KEY *peer_ecdh_tmp;
1121 uint8_t *peer_x25519_tmp;
1122
1123 int references; /* actually always 1 at the moment */
1124} SESS_CERT;
1125
1126/*#define SSL_DEBUG */
1127/*#define RSA_DEBUG */
1128
1129/*
1130 * Flag values for enc_flags.
1131 */
1132
1133/* Uses signature algorithms extension. */
1134#define SSL_ENC_FLAG_SIGALGS (1 << 1)
1135
1136/* Uses SHA256 default PRF. */
1137#define SSL_ENC_FLAG_SHA256_PRF (1 << 2)
1138
1139/* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
1140#define SSL_ENC_FLAG_TLS1_2_CIPHERS (1 << 4)
1141
1142/* Allow TLS 1.3 ciphersuites only. */
1143#define SSL_ENC_FLAG_TLS1_3_CIPHERS (1 << 5)
1144
1145#define TLSV1_ENC_FLAGS 0
1146#define TLSV1_1_ENC_FLAGS 0
1147#define TLSV1_2_ENC_FLAGS (SSL_ENC_FLAG_SIGALGS | \
1148 SSL_ENC_FLAG_SHA256_PRF | \
1149 SSL_ENC_FLAG_TLS1_2_CIPHERS)
1150#define TLSV1_3_ENC_FLAGS (SSL_ENC_FLAG_SIGALGS | \
1151 SSL_ENC_FLAG_TLS1_3_CIPHERS)
1152
1153extern const SSL_CIPHER ssl3_ciphers[];
1154
1155const char *ssl_version_string(int ver);
1156int ssl_version_set_min(const SSL_METHOD *meth, uint16_t proto_ver,
1157 uint16_t max_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver);
1158int ssl_version_set_max(const SSL_METHOD *meth, uint16_t proto_ver,
1159 uint16_t min_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver);
1160int ssl_enabled_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
1161int ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
1162uint16_t ssl_tls_version(uint16_t version);
1163uint16_t ssl_effective_tls_version(SSL *s);
1164int ssl_max_supported_version(SSL *s, uint16_t *max_ver);
1165int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver);
1166int ssl_check_version_from_server(SSL *s, uint16_t server_version);
1167int ssl_legacy_stack_version(SSL *s, uint16_t version);
1168int ssl_cipher_in_list(STACK_OF(SSL_CIPHER) *ciphers, const SSL_CIPHER *cipher);
1169int ssl_cipher_allowed_in_tls_version_range(const SSL_CIPHER *cipher,
1170 uint16_t min_ver, uint16_t max_ver);
1171
1172const SSL_METHOD *tls_legacy_method(void);
1173const SSL_METHOD *ssl_get_method(uint16_t version);
1174
1175void ssl_clear_cipher_state(SSL *s);
1176void ssl_clear_cipher_read_state(SSL *s);
1177void ssl_clear_cipher_write_state(SSL *s);
1178int ssl_clear_bad_session(SSL *s);
1179
1180CERT *ssl_cert_new(void);
1181CERT *ssl_cert_dup(CERT *cert);
1182void ssl_cert_free(CERT *c);
1183int ssl_cert_set0_chain(CERT *c, STACK_OF(X509) *chain);
1184int ssl_cert_set1_chain(CERT *c, STACK_OF(X509) *chain);
1185int ssl_cert_add0_chain_cert(CERT *c, X509 *cert);
1186int ssl_cert_add1_chain_cert(CERT *c, X509 *cert);
1187
1188SESS_CERT *ssl_sess_cert_new(void);
1189void ssl_sess_cert_free(SESS_CERT *sc);
1190int ssl_get_new_session(SSL *s, int session);
1191int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block,
1192 int *alert);
1193int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
1194SSL_CIPHER *OBJ_bsearch_ssl_cipher_id(SSL_CIPHER *key, SSL_CIPHER const *base,
1195 int num);
1196int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *ciphers, CBB *cbb);
1197STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, CBS *cbs);
1198STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
1199 STACK_OF(SSL_CIPHER) **pref, STACK_OF(SSL_CIPHER) *tls13,
1200 const char *rule_str);
1201int ssl_parse_ciphersuites(STACK_OF(SSL_CIPHER) **out_ciphers, const char *str);
1202int ssl_merge_cipherlists(STACK_OF(SSL_CIPHER) *cipherlist,
1203 STACK_OF(SSL_CIPHER) *cipherlist_tls13,
1204 STACK_OF(SSL_CIPHER) **out_cipherlist);
1205void ssl_update_cache(SSL *s, int mode);
1206int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
1207 const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size);
1208int ssl_cipher_get_evp_aead(const SSL_SESSION *s, const EVP_AEAD **aead);
1209int ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md);
1210
1211int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk);
1212int ssl_undefined_function(SSL *s);
1213int ssl_undefined_void_function(void);
1214int ssl_undefined_const_function(const SSL *s);
1215CERT_PKEY *ssl_get_server_send_pkey(const SSL *s);
1216EVP_PKEY *ssl_get_sign_pkey(SSL *s, const SSL_CIPHER *c, const EVP_MD **pmd,
1217 const struct ssl_sigalg **sap);
1218DH *ssl_get_auto_dh(SSL *s);
1219int ssl_cert_type(X509 *x, EVP_PKEY *pkey);
1220void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher);
1221STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
1222int ssl_has_ecc_ciphers(SSL *s);
1223int ssl_verify_alarm_type(long type);
1224
1225int SSL_SESSION_ticket(SSL_SESSION *ss, unsigned char **out, size_t *out_len);
1226
1227const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
1228int ssl3_send_server_certificate(SSL *s);
1229int ssl3_send_newsession_ticket(SSL *s);
1230int ssl3_send_cert_status(SSL *s);
1231int ssl3_get_finished(SSL *s, int state_a, int state_b);
1232int ssl3_send_change_cipher_spec(SSL *s, int state_a, int state_b);
1233int ssl3_do_write(SSL *s, int type);
1234int ssl3_send_alert(SSL *s, int level, int desc);
1235int ssl3_get_req_cert_types(SSL *s, CBB *cbb);
1236long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
1237int ssl3_send_finished(SSL *s, int state_a, int state_b);
1238int ssl3_num_ciphers(void);
1239const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
1240const SSL_CIPHER *ssl3_get_cipher_by_id(unsigned int id);
1241const SSL_CIPHER *ssl3_get_cipher_by_value(uint16_t value);
1242uint16_t ssl3_cipher_get_value(const SSL_CIPHER *c);
1243int ssl3_renegotiate(SSL *ssl);
1244
1245int ssl3_renegotiate_check(SSL *ssl);
1246
1247int ssl3_dispatch_alert(SSL *s);
1248int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
1249int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
1250int ssl3_output_cert_chain(SSL *s, CBB *cbb, CERT_PKEY *cpk);
1251SSL_CIPHER *ssl3_choose_cipher(SSL *ssl, STACK_OF(SSL_CIPHER) *clnt,
1252 STACK_OF(SSL_CIPHER) *srvr);
1253int ssl3_setup_buffers(SSL *s);
1254int ssl3_setup_init_buffer(SSL *s);
1255void ssl3_release_init_buffer(SSL *s);
1256int ssl3_setup_read_buffer(SSL *s);
1257int ssl3_setup_write_buffer(SSL *s);
1258void ssl3_release_buffer(SSL3_BUFFER_INTERNAL *b);
1259void ssl3_release_read_buffer(SSL *s);
1260void ssl3_release_write_buffer(SSL *s);
1261int ssl3_new(SSL *s);
1262void ssl3_free(SSL *s);
1263int ssl3_accept(SSL *s);
1264int ssl3_connect(SSL *s);
1265int ssl3_read(SSL *s, void *buf, int len);
1266int ssl3_peek(SSL *s, void *buf, int len);
1267int ssl3_write(SSL *s, const void *buf, int len);
1268int ssl3_shutdown(SSL *s);
1269void ssl3_clear(SSL *s);
1270long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg);
1271long ssl3_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg);
1272long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
1273long ssl3_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp)(void));
1274int ssl3_pending(const SSL *s);
1275
1276int ssl3_handshake_msg_hdr_len(SSL *s);
1277int ssl3_handshake_msg_start(SSL *s, CBB *handshake, CBB *body,
1278 uint8_t msg_type);
1279int ssl3_handshake_msg_finish(SSL *s, CBB *handshake);
1280int ssl3_handshake_write(SSL *s);
1281int ssl3_record_write(SSL *s, int type);
1282
1283int ssl3_do_change_cipher_spec(SSL *ssl);
1284
1285int ssl3_packet_read(SSL *s, int plen);
1286int ssl3_packet_extend(SSL *s, int plen);
1287int ssl_server_legacy_first_packet(SSL *s);
1288int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
1289 unsigned int len);
1290
1291/* some client-only functions */
1292int ssl3_send_client_hello(SSL *s);
1293int ssl3_get_dtls_hello_verify(SSL *s);
1294int ssl3_get_server_hello(SSL *s);
1295int ssl3_get_certificate_request(SSL *s);
1296int ssl3_get_new_session_ticket(SSL *s);
1297int ssl3_get_cert_status(SSL *s);
1298int ssl3_get_server_done(SSL *s);
1299int ssl3_send_client_verify(SSL *s);
1300int ssl3_send_client_certificate(SSL *s);
1301int ssl_do_client_cert_cb(SSL *s, X509 **px509, EVP_PKEY **ppkey);
1302int ssl3_send_client_key_exchange(SSL *s);
1303int ssl3_get_server_key_exchange(SSL *s);
1304int ssl3_get_server_certificate(SSL *s);
1305int ssl3_check_cert_and_algorithm(SSL *s);
1306int ssl3_check_finished(SSL *s);
1307
1308/* some server-only functions */
1309int ssl3_get_client_hello(SSL *s);
1310int ssl3_send_dtls_hello_verify_request(SSL *s);
1311int ssl3_send_server_hello(SSL *s);
1312int ssl3_send_hello_request(SSL *s);
1313int ssl3_send_server_key_exchange(SSL *s);
1314int ssl3_send_certificate_request(SSL *s);
1315int ssl3_send_server_done(SSL *s);
1316int ssl3_get_client_certificate(SSL *s);
1317int ssl3_get_client_key_exchange(SSL *s);
1318int ssl3_get_cert_verify(SSL *s);
1319
1320int ssl_kex_dummy_ecdhe_x25519(EVP_PKEY *pkey);
1321int ssl_kex_generate_ecdhe_ecp(EC_KEY *ecdh, int nid);
1322int ssl_kex_public_ecdhe_ecp(EC_KEY *ecdh, CBB *cbb);
1323int ssl_kex_peer_public_ecdhe_ecp(EC_KEY *ecdh, int nid, CBS *cbs);
1324int ssl_kex_derive_ecdhe_ecp(EC_KEY *ecdh, EC_KEY *ecdh_peer,
1325 uint8_t **shared_key, size_t *shared_key_len);
1326
1327int tls1_new(SSL *s);
1328void tls1_free(SSL *s);
1329void tls1_clear(SSL *s);
1330
1331int ssl_init_wbio_buffer(SSL *s, int push);
1332void ssl_free_wbio_buffer(SSL *s);
1333
1334int tls1_transcript_hash_init(SSL *s);
1335int tls1_transcript_hash_update(SSL *s, const unsigned char *buf, size_t len);
1336int tls1_transcript_hash_value(SSL *s, const unsigned char *out, size_t len,
1337 size_t *outlen);
1338void tls1_transcript_hash_free(SSL *s);
1339
1340int tls1_transcript_init(SSL *s);
1341void tls1_transcript_free(SSL *s);
1342void tls1_transcript_reset(SSL *s);
1343int tls1_transcript_append(SSL *s, const unsigned char *buf, size_t len);
1344int tls1_transcript_data(SSL *s, const unsigned char **data, size_t *len);
1345void tls1_transcript_freeze(SSL *s);
1346void tls1_transcript_unfreeze(SSL *s);
1347int tls1_transcript_record(SSL *s, const unsigned char *buf, size_t len);
1348
1349int tls1_PRF(SSL *s, const unsigned char *secret, size_t secret_len,
1350 const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len,
1351 const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len,
1352 const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len);
1353
1354void tls1_cleanup_key_block(SSL *s);
1355int tls1_change_read_cipher_state(SSL *s);
1356int tls1_change_write_cipher_state(SSL *s);
1357int tls1_setup_key_block(SSL *s);
1358int tls1_generate_key_block(SSL *s, uint8_t *key_block, size_t key_block_len);
1359int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
1360 const char *label, size_t llen, const unsigned char *p, size_t plen,
1361 int use_context);
1362int ssl_ok(SSL *s);
1363
1364int tls12_derive_finished(SSL *s);
1365int tls12_derive_peer_finished(SSL *s);
1366int tls12_derive_master_secret(SSL *s, uint8_t *premaster_secret,
1367 size_t premaster_secret_len);
1368
1369int ssl_using_ecc_cipher(SSL *s);
1370int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s);
1371
1372void tls1_get_formatlist(SSL *s, int client_formats, const uint8_t **pformats,
1373 size_t *pformatslen);
1374void tls1_get_group_list(SSL *s, int client_groups, const uint16_t **pgroups,
1375 size_t *pgroupslen);
1376
1377int tls1_set_groups(uint16_t **out_group_ids, size_t *out_group_ids_len,
1378 const int *groups, size_t ngroups);
1379int tls1_set_group_list(uint16_t **out_group_ids, size_t *out_group_ids_len,
1380 const char *groups);
1381
1382int tls1_ec_curve_id2nid(const uint16_t curve_id);
1383uint16_t tls1_ec_nid2curve_id(const int nid);
1384int tls1_check_curve(SSL *s, const uint16_t group_id);
1385int tls1_get_shared_curve(SSL *s);
1386
1387int ssl_check_clienthello_tlsext_early(SSL *s);
1388int ssl_check_clienthello_tlsext_late(SSL *s);
1389int ssl_check_serverhello_tlsext(SSL *s);
1390
1391#define TLS1_TICKET_FATAL_ERROR -1
1392#define TLS1_TICKET_NONE 0
1393#define TLS1_TICKET_EMPTY 1
1394#define TLS1_TICKET_NOT_DECRYPTED 2
1395#define TLS1_TICKET_DECRYPTED 3
1396
1397int tls1_process_ticket(SSL *s, CBS *ext_block, int *alert, SSL_SESSION **ret);
1398
1399int tls1_check_ec_server_key(SSL *s);
1400
1401/* s3_cbc.c */
1402void ssl3_cbc_copy_mac(unsigned char *out, const SSL3_RECORD_INTERNAL *rec,
1403 unsigned int md_size, unsigned int orig_len);
1404int ssl3_cbc_remove_padding(SSL3_RECORD_INTERNAL *rec, unsigned int eiv_len,
1405 unsigned int mac_size);
1406char ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx);
1407int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx, unsigned char *md_out,
1408 size_t *md_out_size, const unsigned char header[13],
1409 const unsigned char *data, size_t data_plus_mac_size,
1410 size_t data_plus_mac_plus_padding_size, const unsigned char *mac_secret,
1411 unsigned int mac_secret_length);
1412int SSL_state_func_code(int _state);
1413
1414#define SSLerror(s, r) SSL_error_internal(s, r, __FILE__, __LINE__)
1415#define SSLerrorx(r) ERR_PUT_error(ERR_LIB_SSL,(0xfff),(r),__FILE__,__LINE__)
1416void SSL_error_internal(const SSL *s, int r, char *f, int l);
1417
1418#ifndef OPENSSL_NO_SRTP
1419
1420int srtp_find_profile_by_name(const char *profile_name,
1421 const SRTP_PROTECTION_PROFILE **pptr, unsigned int len);
1422int srtp_find_profile_by_num(unsigned int profile_num,
1423 const SRTP_PROTECTION_PROFILE **pptr);
1424
1425#endif /* OPENSSL_NO_SRTP */
1426
1427__END_HIDDEN_DECLS
1428
1429#endif