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