1 /* $OpenBSD: ssl_locl.h,v 1.178 2017/03/10 16:03:27 jsing Exp $ */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
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.
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).
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.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
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)"
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
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.]
58 /* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
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
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/)"
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.
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.
87 * 6. Redistributions of any form whatsoever must retain the following
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
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 * ====================================================================
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).
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.
116 /* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
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.
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.
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.
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
143 #ifndef HEADER_SSL_LOCL_H
144 #define HEADER_SSL_LOCL_H
146 #include <sys/types.h>
154 #include <openssl/opensslconf.h>
155 #include <openssl/bio.h>
156 #include <openssl/buffer.h>
157 #include <openssl/dsa.h>
158 #include <openssl/err.h>
159 #include <openssl/rsa.h>
160 #include <openssl/ssl.h>
161 #include <openssl/stack.h>
163 #include "bytestring.h"
167 #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
168 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
169 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
170 *((c)++)=(unsigned char)(((l) )&0xff))
172 #define l2n8(l,c) (*((c)++)=(unsigned char)(((l)>>56)&0xff), \
173 *((c)++)=(unsigned char)(((l)>>48)&0xff), \
174 *((c)++)=(unsigned char)(((l)>>40)&0xff), \
175 *((c)++)=(unsigned char)(((l)>>32)&0xff), \
176 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
177 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
178 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
179 *((c)++)=(unsigned char)(((l) )&0xff))
181 #define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \
182 (((unsigned int)(c[1])) )),c+=2)
183 #define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \
184 c[1]=(unsigned char)(((s) )&0xff)),c+=2)
186 #define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \
187 c[1]=(unsigned char)(((l)>> 8)&0xff), \
188 c[2]=(unsigned char)(((l) )&0xff)),c+=3)
192 #define SSL_DECRYPT 0
193 #define SSL_ENCRYPT 1
196 * Define the Bitmasks for SSL_CIPHER.algorithms.
197 * This bits are used packed as dense as possible. If new methods/ciphers
198 * etc will be added, the bits a likely to change, so this information
199 * is for internal library use only, even though SSL_CIPHER.algorithms
200 * can be publicly accessed.
201 * Use the according functions for cipher management instead.
203 * The bit mask handling in the selection and sorting scheme in
204 * ssl_create_cipher_list() has only limited capabilities, reflecting
205 * that the different entities within are mutually exclusive:
206 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
209 /* Bits for algorithm_mkey (key exchange algorithm) */
210 #define SSL_kRSA 0x00000001L /* RSA key exchange */
211 #define SSL_kDHE 0x00000008L /* tmp DH key no DH cert */
212 #define SSL_kECDHE 0x00000080L /* ephemeral ECDH */
213 #define SSL_kGOST 0x00000200L /* GOST key exchange */
215 /* Bits for algorithm_auth (server authentication) */
216 #define SSL_aRSA 0x00000001L /* RSA auth */
217 #define SSL_aDSS 0x00000002L /* DSS auth */
218 #define SSL_aNULL 0x00000004L /* no auth (i.e. use ADH or AECDH) */
219 #define SSL_aECDSA 0x00000040L /* ECDSA auth*/
220 #define SSL_aGOST01 0x00000200L /* GOST R 34.10-2001 signature auth */
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 #define SSL_CHACHA20POLY1305_OLD 0x00002000L
238 #define SSL_AES (SSL_AES128|SSL_AES256|SSL_AES128GCM|SSL_AES256GCM)
239 #define SSL_CAMELLIA (SSL_CAMELLIA128|SSL_CAMELLIA256)
242 /* Bits for algorithm_mac (symmetric authentication) */
244 #define SSL_MD5 0x00000001L
245 #define SSL_SHA1 0x00000002L
246 #define SSL_GOST94 0x00000004L
247 #define SSL_GOST89MAC 0x00000008L
248 #define SSL_SHA256 0x00000010L
249 #define SSL_SHA384 0x00000020L
250 /* Not a real MAC, just an indication it is part of cipher */
251 #define SSL_AEAD 0x00000040L
252 #define SSL_STREEBOG256 0x00000080L
254 /* Bits for algorithm_ssl (protocol version) */
255 #define SSL_SSLV3 0x00000002L
256 #define SSL_TLSV1 SSL_SSLV3 /* for now */
257 #define SSL_TLSV1_2 0x00000004L
260 /* Bits for algorithm2 (handshake digests and other extra flags) */
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)
271 /* When adding new digest in the ssl_ciph.c and increment SSM_MD_NUM_IDX
272 * make sure to update this constant too */
273 #define SSL_MAX_DIGEST 7
275 #define SSL3_CK_ID 0x03000000
276 #define SSL3_CK_VALUE_MASK 0x0000ffff
278 #define TLS1_PRF_DGST_MASK (0xff << TLS1_PRF_DGST_SHIFT)
280 #define TLS1_PRF_DGST_SHIFT 10
281 #define TLS1_PRF_MD5 (SSL_HANDSHAKE_MAC_MD5 << TLS1_PRF_DGST_SHIFT)
282 #define TLS1_PRF_SHA1 (SSL_HANDSHAKE_MAC_SHA << TLS1_PRF_DGST_SHIFT)
283 #define TLS1_PRF_SHA256 (SSL_HANDSHAKE_MAC_SHA256 << TLS1_PRF_DGST_SHIFT)
284 #define TLS1_PRF_SHA384 (SSL_HANDSHAKE_MAC_SHA384 << TLS1_PRF_DGST_SHIFT)
285 #define TLS1_PRF_GOST94 (SSL_HANDSHAKE_MAC_GOST94 << TLS1_PRF_DGST_SHIFT)
286 #define TLS1_PRF_STREEBOG256 (SSL_HANDSHAKE_MAC_STREEBOG256 << TLS1_PRF_DGST_SHIFT)
287 #define TLS1_PRF (TLS1_PRF_MD5 | TLS1_PRF_SHA1)
289 /* Stream MAC for GOST ciphersuites from cryptopro draft
290 * (currently this also goes into algorithm2) */
291 #define TLS1_STREAM_MAC 0x04
294 * SSL_CIPHER_ALGORITHM2_VARIABLE_NONCE_IN_RECORD is an algorithm2 flag that
295 * indicates that the variable part of the nonce is included as a prefix of
296 * the record (AES-GCM, for example, does this with an 8-byte variable nonce.)
298 #define SSL_CIPHER_ALGORITHM2_VARIABLE_NONCE_IN_RECORD (1 << 22)
301 * SSL_CIPHER_ALGORITHM2_AEAD is an algorithm2 flag that indicates the cipher
302 * is implemented via an EVP_AEAD.
304 #define SSL_CIPHER_ALGORITHM2_AEAD (1 << 23)
307 * SSL_CIPHER_AEAD_FIXED_NONCE_LEN returns the number of bytes of fixed nonce
308 * for an SSL_CIPHER with the SSL_CIPHER_ALGORITHM2_AEAD flag.
310 #define SSL_CIPHER_AEAD_FIXED_NONCE_LEN(ssl_cipher) \
311 (((ssl_cipher->algorithm2 >> 24) & 0xf) * 2)
314 * Cipher strength information.
316 #define SSL_STRONG_MASK 0x000001fcL
317 #define SSL_STRONG_NONE 0x00000004L
318 #define SSL_LOW 0x00000020L
319 #define SSL_MEDIUM 0x00000040L
320 #define SSL_HIGH 0x00000080L
323 * The keylength (measured in RSA key bits, I guess) for temporary keys.
324 * Cipher argument is so that this can be variable in the future.
326 #define SSL_C_PKEYLENGTH(c) 1024
328 /* Check if an SSL structure is using DTLS. */
329 #define SSL_IS_DTLS(s) \
330 (s->method->internal->version == DTLS1_VERSION)
332 /* See if we need explicit IV. */
333 #define SSL_USE_EXPLICIT_IV(s) \
334 (s->method->internal->ssl3_enc->enc_flags & SSL_ENC_FLAG_EXPLICIT_IV)
336 /* See if we use signature algorithms extension. */
337 #define SSL_USE_SIGALGS(s) \
338 (s->method->internal->ssl3_enc->enc_flags & SSL_ENC_FLAG_SIGALGS)
340 /* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
341 #define SSL_USE_TLS1_2_CIPHERS(s) \
342 (s->method->internal->ssl3_enc->enc_flags & SSL_ENC_FLAG_TLS1_2_CIPHERS)
344 /* Mostly for SSLv3 */
345 #define SSL_PKEY_RSA_ENC 0
346 #define SSL_PKEY_RSA_SIGN 1
347 #define SSL_PKEY_DSA_SIGN 2
348 #define SSL_PKEY_DH_RSA 3
349 #define SSL_PKEY_DH_DSA 4
350 #define SSL_PKEY_ECC 5
351 #define SSL_PKEY_GOST01 6
352 #define SSL_PKEY_NUM 7
354 #define SSL_MAX_EMPTY_RECORDS 32
356 /* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
357 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
358 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
359 * SSL_kDHE <- RSA_ENC | RSA_SIGN | DSA_SIGN
360 * SSL_aRSA <- RSA_ENC | RSA_SIGN
361 * SSL_aDSS <- DSA_SIGN
365 #define CERT_INVALID 0
366 #define CERT_PUBLIC_KEY 1
367 #define CERT_PRIVATE_KEY 2
370 /* From ECC-TLS draft, used in encoding the curve type in
373 #define EXPLICIT_PRIME_CURVE_TYPE 1
374 #define EXPLICIT_CHAR2_CURVE_TYPE 2
375 #define NAMED_CURVE_TYPE 3
377 typedef struct ssl_method_internal_st
{
380 uint16_t min_version
;
381 uint16_t max_version
;
383 int (*ssl_new
)(SSL
*s
);
384 void (*ssl_clear
)(SSL
*s
);
385 void (*ssl_free
)(SSL
*s
);
387 int (*ssl_accept
)(SSL
*s
);
388 int (*ssl_connect
)(SSL
*s
);
389 int (*ssl_read
)(SSL
*s
, void *buf
, int len
);
390 int (*ssl_peek
)(SSL
*s
, void *buf
, int len
);
391 int (*ssl_write
)(SSL
*s
, const void *buf
, int len
);
392 int (*ssl_shutdown
)(SSL
*s
);
394 int (*ssl_renegotiate
)(SSL
*s
);
395 int (*ssl_renegotiate_check
)(SSL
*s
);
397 long (*ssl_get_message
)(SSL
*s
, int st1
, int stn
, int mt
,
399 int (*ssl_read_bytes
)(SSL
*s
, int type
, unsigned char *buf
,
401 int (*ssl_write_bytes
)(SSL
*s
, int type
, const void *buf_
, int len
);
403 int (*ssl_pending
)(const SSL
*s
);
404 const struct ssl_method_st
*(*get_ssl_method
)(int version
);
406 long (*get_timeout
)(void);
407 int (*ssl_version
)(void);
409 struct ssl3_enc_method
*ssl3_enc
; /* Extra SSLv3/TLS stuff */
410 } SSL_METHOD_INTERNAL
;
412 typedef struct ssl_session_internal_st
{
413 CRYPTO_EX_DATA ex_data
; /* application specific data */
415 /* These are used to make removal of session-ids more
416 * efficient and to implement a maximum cache size. */
417 struct ssl_session_st
*prev
, *next
;
419 /* Used to indicate that session resumption is not allowed.
420 * Applications can also set this bit for a new session via
421 * not_resumable_session_cb to disable session caching and tickets. */
424 /* The cert is the certificate used to establish this connection */
425 struct sess_cert_st
/* SESS_CERT */ *sess_cert
;
427 size_t tlsext_ecpointformatlist_length
;
428 uint8_t *tlsext_ecpointformatlist
; /* peer's list */
429 size_t tlsext_supportedgroups_length
;
430 uint16_t *tlsext_supportedgroups
; /* peer's list */
431 } SSL_SESSION_INTERNAL
;
432 #define SSI(s) (s->session->internal)
434 typedef struct ssl_ctx_internal_st
{
435 uint16_t min_version
;
436 uint16_t max_version
;
438 unsigned long options
;
441 /* If this callback is not null, it will be called each
442 * time a session id is added to the cache. If this function
443 * returns 1, it means that the callback will do a
444 * SSL_SESSION_free() when it has finished using it. Otherwise,
445 * on 0, it means the callback has finished with it.
446 * If remove_session_cb is not null, it will be called when
447 * a session-id is removed from the cache. After the call,
448 * OpenSSL will SSL_SESSION_free() it. */
449 int (*new_session_cb
)(struct ssl_st
*ssl
, SSL_SESSION
*sess
);
450 void (*remove_session_cb
)(struct ssl_ctx_st
*ctx
, SSL_SESSION
*sess
);
451 SSL_SESSION
*(*get_session_cb
)(struct ssl_st
*ssl
,
452 unsigned char *data
, int len
, int *copy
);
454 /* if defined, these override the X509_verify_cert() calls */
455 int (*app_verify_callback
)(X509_STORE_CTX
*, void *);
456 void *app_verify_arg
;
458 /* get client cert callback */
459 int (*client_cert_cb
)(SSL
*ssl
, X509
**x509
, EVP_PKEY
**pkey
);
461 /* cookie generate callback */
462 int (*app_gen_cookie_cb
)(SSL
*ssl
, unsigned char *cookie
,
463 unsigned int *cookie_len
);
465 /* verify cookie callback */
466 int (*app_verify_cookie_cb
)(SSL
*ssl
, unsigned char *cookie
,
467 unsigned int cookie_len
);
469 void (*info_callback
)(const SSL
*ssl
,int type
,int val
); /* used if SSL's info_callback is NULL */
471 /* callback that allows applications to peek at protocol messages */
472 void (*msg_callback
)(int write_p
, int version
, int content_type
,
473 const void *buf
, size_t len
, SSL
*ssl
, void *arg
);
474 void *msg_callback_arg
;
476 int (*default_verify_callback
)(int ok
,X509_STORE_CTX
*ctx
); /* called 'verify_callback' in the SSL */
478 /* Default generate session ID callback. */
479 GEN_SESSION_CB generate_session_id
;
481 /* TLS extensions servername callback */
482 int (*tlsext_servername_callback
)(SSL
*, int *, void *);
483 void *tlsext_servername_arg
;
485 /* Callback to support customisation of ticket key setting */
486 int (*tlsext_ticket_key_cb
)(SSL
*ssl
, unsigned char *name
,
487 unsigned char *iv
, EVP_CIPHER_CTX
*ectx
, HMAC_CTX
*hctx
, int enc
);
489 /* certificate status request info */
490 /* Callback for status request */
491 int (*tlsext_status_cb
)(SSL
*ssl
, void *arg
);
492 void *tlsext_status_arg
;
494 struct lhash_st_SSL_SESSION
*sessions
;
496 /* Most session-ids that will be cached, default is
497 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
498 unsigned long session_cache_size
;
499 struct ssl_session_st
*session_cache_head
;
500 struct ssl_session_st
*session_cache_tail
;
502 /* This can have one of 2 values, ored together,
503 * SSL_SESS_CACHE_CLIENT,
504 * SSL_SESS_CACHE_SERVER,
505 * Default is SSL_SESSION_CACHE_SERVER, which means only
506 * SSL_accept which cache SSL_SESSIONS. */
507 int session_cache_mode
;
510 int sess_connect
; /* SSL new conn - started */
511 int sess_connect_renegotiate
;/* SSL reneg - requested */
512 int sess_connect_good
; /* SSL new conne/reneg - finished */
513 int sess_accept
; /* SSL new accept - started */
514 int sess_accept_renegotiate
;/* SSL reneg - requested */
515 int sess_accept_good
; /* SSL accept/reneg - finished */
516 int sess_miss
; /* session lookup misses */
517 int sess_timeout
; /* reuse attempt on timeouted session */
518 int sess_cache_full
; /* session removed due to full cache */
519 int sess_hit
; /* session reuse actually done */
520 int sess_cb_hit
; /* session-id that was not
522 * passed back via the callback. This
523 * indicates that the application is
524 * supplying session-id's from other
525 * processes - spooky :-) */
528 CRYPTO_EX_DATA ex_data
;
530 /* same cipher_list but sorted for lookup */
531 STACK_OF(SSL_CIPHER
) *cipher_list_by_id
;
533 struct cert_st
/* CERT */ *cert
;
535 /* Default values used when no per-SSL value is defined follow */
537 /* what we put in client cert requests */
538 STACK_OF(X509_NAME
) *client_CA
;
546 /* Maximum amount of data to send in one fragment.
547 * actual record size can be more than this due to
548 * padding and MAC overheads.
550 unsigned int max_send_fragment
;
552 #ifndef OPENSSL_NO_ENGINE
553 /* Engine to pass requests for client certs to
555 ENGINE
*client_cert_engine
;
558 /* RFC 4507 session ticket keys */
559 unsigned char tlsext_tick_key_name
[16];
560 unsigned char tlsext_tick_hmac_key
[16];
561 unsigned char tlsext_tick_aes_key
[16];
563 /* SRTP profiles we are willing to do from RFC 5764 */
564 STACK_OF(SRTP_PROTECTION_PROFILE
) *srtp_profiles
;
566 /* Next protocol negotiation information */
567 /* (for experimental NPN extension). */
569 /* For a server, this contains a callback function by which the set of
570 * advertised protocols can be provided. */
571 int (*next_protos_advertised_cb
)(SSL
*s
, const unsigned char **buf
,
572 unsigned int *len
, void *arg
);
573 void *next_protos_advertised_cb_arg
;
574 /* For a client, this contains a callback function that selects the
575 * next protocol from the list provided by the server. */
576 int (*next_proto_select_cb
)(SSL
*s
, unsigned char **out
,
577 unsigned char *outlen
, const unsigned char *in
,
578 unsigned int inlen
, void *arg
);
579 void *next_proto_select_cb_arg
;
583 * (we are in the process of transitioning from NPN to ALPN).
587 * Server callback function that allows the server to select the
588 * protocol for the connection.
589 * out: on successful return, this must point to the raw protocol
590 * name (without the length prefix).
591 * outlen: on successful return, this contains the length of out.
592 * in: points to the client's list of supported protocols in
594 * inlen: the length of in.
596 int (*alpn_select_cb
)(SSL
*s
, const unsigned char **out
,
597 unsigned char *outlen
, const unsigned char *in
, unsigned int inlen
,
599 void *alpn_select_cb_arg
;
601 /* Client list of supported protocols in wire format. */
602 unsigned char *alpn_client_proto_list
;
603 unsigned int alpn_client_proto_list_len
;
605 size_t tlsext_ecpointformatlist_length
;
606 uint8_t *tlsext_ecpointformatlist
; /* our list */
607 size_t tlsext_supportedgroups_length
;
608 uint16_t *tlsext_supportedgroups
; /* our list */
611 typedef struct ssl_internal_st
{
612 uint16_t min_version
;
613 uint16_t max_version
;
615 unsigned long options
; /* protocol behaviour */
616 unsigned long mode
; /* API behaviour */
618 /* Next protocol negotiation. For the client, this is the protocol that
619 * we sent in NextProtocol and is set when handling ServerHello
622 * For a server, this is the client's selected_protocol from
623 * NextProtocol and is set when handling the NextProtocol message,
624 * before the Finished message. */
625 unsigned char *next_proto_negotiated
;
626 unsigned char next_proto_negotiated_len
;
628 /* Client list of supported protocols in wire format. */
629 unsigned char *alpn_client_proto_list
;
630 unsigned int alpn_client_proto_list_len
;
634 /* true when we are actually in SSL_accept() or SSL_connect() */
636 int (*handshake_func
)(SSL
*);
637 /* callback that allows applications to peek at protocol messages */
638 void (*msg_callback
)(int write_p
, int version
, int content_type
,
639 const void *buf
, size_t len
, SSL
*ssl
, void *arg
);
640 void *msg_callback_arg
;
642 /* Default generate session ID callback. */
643 GEN_SESSION_CB generate_session_id
;
645 int (*verify_callback
)(int ok
,X509_STORE_CTX
*ctx
); /* fail if callback returns 0 */
647 void (*info_callback
)(const SSL
*ssl
,int type
,int val
); /* optional informational callback */
649 /* TLS extension debug callback */
650 void (*tlsext_debug_cb
)(SSL
*s
, int client_server
, int type
,
651 unsigned char *data
, int len
, void *arg
);
652 void *tlsext_debug_arg
;
654 /* TLS Session Ticket extension callback */
655 tls_session_ticket_ext_cb_fn tls_session_ticket_ext_cb
;
656 void *tls_session_ticket_ext_cb_arg
;
658 /* TLS pre-shared secret session resumption */
659 tls_session_secret_cb_fn tls_session_secret_cb
;
660 void *tls_session_secret_cb_arg
;
662 /* XXX non-callback */
664 int type
; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
666 /* This holds a variable that indicates what we were doing
667 * when a 0 or -1 is returned. This is needed for
668 * non-blocking IO so we know what request needs re-doing when
669 * in SSL_accept or SSL_connect */
672 /* Imagine that here's a boolean member "init" that is
673 * switched as soon as SSL_set_{accept/connect}_state
674 * is called for the first time, so that "state" and
675 * "handshake_func" are properly initialized. But as
676 * handshake_func is == 0 until then, we use this
677 * test instead of an "init" member.
680 int new_session
;/* Generate a new session or reuse an old one.
681 * NB: For servers, the 'new' session may actually be a previously
682 * cached session or even the previous session unless
683 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */
684 int quiet_shutdown
;/* don't send shutdown packets */
685 int shutdown
; /* we have shut things down, 0x01 sent, 0x02
687 BUF_MEM
*init_buf
; /* buffer used during init */
688 void *init_msg
; /* pointer to handshake message body, set by ssl3_get_message() */
689 int init_num
; /* amount read/written */
690 int init_off
; /* amount read/written */
692 /* used internally to point at a raw packet */
693 unsigned char *packet
;
694 unsigned int packet_length
;
696 int read_ahead
; /* Read as many input bytes as possible
697 * (for non-blocking reads) */
699 int hit
; /* reusing a previous session */
702 STACK_OF(SSL_CIPHER
) *cipher_list_by_id
;
704 /* These are the ones being used, the ones in SSL_SESSION are
705 * the ones to be 'copied' into these ones */
708 SSL_AEAD_CTX
*aead_read_ctx
; /* AEAD context. If non-NULL, then
709 enc_read_ctx and read_hash are
712 SSL_AEAD_CTX
*aead_write_ctx
; /* AEAD context. If non-NULL, then
713 enc_write_ctx and write_hash are
716 EVP_CIPHER_CTX
*enc_write_ctx
; /* cryptographic state */
717 EVP_MD_CTX
*write_hash
; /* used for mac generation */
721 /* extra application data */
722 CRYPTO_EX_DATA ex_data
;
725 /* for server side, keep the list of CA_dn we can use */
726 STACK_OF(X509_NAME
) *client_CA
;
728 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
729 * and SSL_write() calls, good for nbio debuging :-) */
734 int servername_done
; /* no further mod of servername
735 0 : call the servername extension callback.
736 1 : prepare 2, allow last ack just after in server callback.
737 2 : don't call servername callback, no ack in server hello
740 /* Expect OCSP CertificateStatus message */
741 int tlsext_status_expected
;
742 /* OCSP status request only */
743 STACK_OF(OCSP_RESPID
) *tlsext_ocsp_ids
;
744 X509_EXTENSIONS
*tlsext_ocsp_exts
;
745 /* OCSP response received or to be sent */
746 unsigned char *tlsext_ocsp_resp
;
747 int tlsext_ocsp_resplen
;
749 /* RFC4507 session ticket expected to be received or sent */
750 int tlsext_ticket_expected
;
752 size_t tlsext_ecpointformatlist_length
;
753 uint8_t *tlsext_ecpointformatlist
; /* our list */
754 size_t tlsext_supportedgroups_length
;
755 uint16_t *tlsext_supportedgroups
; /* our list */
757 /* TLS Session Ticket extension override */
758 TLS_SESSION_TICKET_EXT
*tlsext_session_ticket
;
760 STACK_OF(SRTP_PROTECTION_PROFILE
) *srtp_profiles
; /* What we'll do */
761 SRTP_PROTECTION_PROFILE
*srtp_profile
; /* What's been chosen */
763 int renegotiate
;/* 1 if we are renegotiating.
764 * 2 if we are a server and are inside a handshake
765 * (i.e. not just sending a HelloRequest) */
767 int state
; /* where we are */
768 int rstate
; /* where we are when reading */
772 int empty_record_count
;
775 typedef struct ssl3_state_internal_st
{
776 int delay_buf_pop_ret
;
778 unsigned char read_sequence
[SSL3_SEQUENCE_SIZE
];
779 int read_mac_secret_size
;
780 unsigned char read_mac_secret
[EVP_MAX_MD_SIZE
];
781 unsigned char write_sequence
[SSL3_SEQUENCE_SIZE
];
782 int write_mac_secret_size
;
783 unsigned char write_mac_secret
[EVP_MAX_MD_SIZE
];
785 /* flags for countermeasure against known-IV weakness */
786 int need_empty_fragments
;
787 int empty_fragment_done
;
789 SSL3_RECORD rrec
; /* each decoded record goes in here */
790 SSL3_RECORD wrec
; /* goes out from here */
792 /* storage for Alert/Handshake protocol data received but not
793 * yet processed by ssl3_read_bytes: */
794 unsigned char alert_fragment
[2];
795 unsigned int alert_fragment_len
;
796 unsigned char handshake_fragment
[4];
797 unsigned int handshake_fragment_len
;
799 /* partial write - check the numbers match */
800 unsigned int wnum
; /* number of bytes sent so far */
801 int wpend_tot
; /* number bytes written */
803 int wpend_ret
; /* number of bytes submitted */
804 const unsigned char *wpend_buf
;
806 /* used during startup, digest all incoming/outgoing packets */
807 BIO
*handshake_buffer
;
809 /* Rolling hash of handshake messages. */
810 EVP_MD_CTX
*handshake_hash
;
812 /* this is set whenerver we see a change_cipher_spec message
813 * come in when we are not looking for one */
814 int change_cipher_spec
;
819 /* This flag is set when we should renegotiate ASAP, basically when
820 * there is no more data in the read or write buffers */
822 int total_renegotiations
;
823 int num_renegotiations
;
825 int in_read_app_data
;
828 /* actually only needs to be 16+20 */
829 unsigned char cert_verify_md
[EVP_MAX_MD_SIZE
*2];
831 /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
832 unsigned char finish_md
[EVP_MAX_MD_SIZE
*2];
834 unsigned char peer_finish_md
[EVP_MAX_MD_SIZE
*2];
835 int peer_finish_md_len
;
837 unsigned long message_size
;
840 /* used to hold the new cipher we are going to use */
841 const SSL_CIPHER
*new_cipher
;
844 EC_KEY
*ecdh
; /* holds short lived ECDH key */
848 /* used when SSL_ST_FLUSH_DATA is entered */
853 /* used for certificate requests */
856 char ctype
[SSL3_CT_NUMBER
];
857 STACK_OF(X509_NAME
) *ca_names
;
859 int key_block_length
;
860 unsigned char *key_block
;
862 const EVP_CIPHER
*new_sym_enc
;
863 const EVP_AEAD
*new_aead
;
864 const EVP_MD
*new_hash
;
865 int new_mac_pkey_type
;
869 /* Connection binding to prevent renegotiation attacks */
870 unsigned char previous_client_finished
[EVP_MAX_MD_SIZE
];
871 unsigned char previous_client_finished_len
;
872 unsigned char previous_server_finished
[EVP_MAX_MD_SIZE
];
873 unsigned char previous_server_finished_len
;
874 int send_connection_binding
; /* TODOEKR */
876 /* Set if we saw the Next Protocol Negotiation extension from our peer.
878 int next_proto_neg_seen
;
882 * (we are in the process of transitioning from NPN to ALPN).
886 * In a server these point to the selected ALPN protocol after the
887 * ClientHello has been processed. In a client these contain the
888 * protocol that the server selected once the ServerHello has been
891 unsigned char *alpn_selected
;
892 unsigned int alpn_selected_len
;
893 } SSL3_STATE_INTERNAL
;
894 #define S3I(s) (s->s3->internal)
896 typedef struct dtls1_state_internal_st
{
897 unsigned int send_cookie
;
898 unsigned char cookie
[DTLS1_COOKIE_LENGTH
];
899 unsigned char rcvd_cookie
[DTLS1_COOKIE_LENGTH
];
900 unsigned int cookie_len
;
903 * The current data and handshake epoch. This is initially
904 * undefined, and starts at zero once the initial handshake is
907 unsigned short r_epoch
;
908 unsigned short w_epoch
;
910 /* records being received in the current epoch */
913 /* renegotiation starts a new set of sequence numbers */
914 DTLS1_BITMAP next_bitmap
;
916 /* handshake message numbers */
917 unsigned short handshake_write_seq
;
918 unsigned short next_handshake_write_seq
;
920 unsigned short handshake_read_seq
;
922 /* save last sequence number for retransmissions */
923 unsigned char last_write_sequence
[8];
925 /* Received handshake records (processed and unprocessed) */
926 record_pqueue unprocessed_rcds
;
927 record_pqueue processed_rcds
;
929 /* Buffered handshake messages */
930 struct _pqueue
*buffered_messages
;
932 /* Buffered application records.
933 * Only for records between CCS and Finished
934 * to prevent either protocol violation or
935 * unnecessary message loss.
937 record_pqueue buffered_app_data
;
939 /* Is set when listening for new connections with dtls1_listen() */
942 unsigned int mtu
; /* max DTLS packet size */
944 struct hm_header_st w_msg_hdr
;
945 struct hm_header_st r_msg_hdr
;
947 struct dtls1_timeout_st timeout
;
949 /* storage for Alert/Handshake protocol data received but not
950 * yet processed by ssl3_read_bytes: */
951 unsigned char alert_fragment
[DTLS1_AL_HEADER_LENGTH
];
952 unsigned int alert_fragment_len
;
953 unsigned char handshake_fragment
[DTLS1_HM_HEADER_LENGTH
];
954 unsigned int handshake_fragment_len
;
956 unsigned int retransmitting
;
957 unsigned int change_cipher_spec_ok
;
958 } DTLS1_STATE_INTERNAL
;
959 #define D1I(s) (s->d1->internal)
961 typedef struct cert_pkey_st
{
963 EVP_PKEY
*privatekey
;
964 /* Digest to use when signing */
965 const EVP_MD
*digest
;
968 typedef struct cert_st
{
969 /* Current active set */
970 CERT_PKEY
*key
; /* ALWAYS points to an element of the pkeys array
971 * Probably it would make more sense to store
972 * an index, not a pointer. */
974 /* The following masks are for the key and auth
975 * algorithms that are supported by the certs below */
977 unsigned long mask_k
;
978 unsigned long mask_a
;
981 DH
*(*dh_tmp_cb
)(SSL
*ssl
, int is_export
, int keysize
);
985 EC_KEY
*(*ecdh_tmp_cb
)(SSL
*ssl
, int is_export
, int keysize
);
988 CERT_PKEY pkeys
[SSL_PKEY_NUM
];
990 int references
; /* >1 only if SSL_copy_session_id is used */
994 typedef struct sess_cert_st
{
995 STACK_OF(X509
) *cert_chain
; /* as received from peer */
997 /* The 'peer_...' members are used only by clients. */
1000 CERT_PKEY
*peer_key
; /* points to an element of peer_pkeys (never NULL!) */
1001 CERT_PKEY peer_pkeys
[SSL_PKEY_NUM
];
1002 /* Obviously we don't have the private keys of these,
1003 * so maybe we shouldn't even use the CERT_PKEY type here. */
1006 EC_KEY
*peer_ecdh_tmp
;
1007 uint8_t *peer_x25519_tmp
;
1009 int references
; /* actually always 1 at the moment */
1012 /*#define SSL_DEBUG */
1013 /*#define RSA_DEBUG */
1015 typedef struct ssl3_enc_method
{
1016 int (*enc
)(SSL
*, int);
1017 unsigned int enc_flags
;
1021 * Flag values for enc_flags.
1024 /* Uses explicit IV. */
1025 #define SSL_ENC_FLAG_EXPLICIT_IV (1 << 0)
1027 /* Uses signature algorithms extension. */
1028 #define SSL_ENC_FLAG_SIGALGS (1 << 1)
1030 /* Uses SHA256 default PRF. */
1031 #define SSL_ENC_FLAG_SHA256_PRF (1 << 2)
1033 /* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
1034 #define SSL_ENC_FLAG_TLS1_2_CIPHERS (1 << 4)
1037 * ssl_aead_ctx_st contains information about an AEAD that is being used to
1038 * encrypt an SSL connection.
1040 struct ssl_aead_ctx_st
{
1043 * fixed_nonce contains any bytes of the nonce that are fixed for all
1046 unsigned char fixed_nonce
[12];
1047 unsigned char fixed_nonce_len
;
1048 unsigned char variable_nonce_len
;
1049 unsigned char xor_fixed_nonce
;
1050 unsigned char tag_len
;
1052 * variable_nonce_in_record is non-zero if the variable nonce
1053 * for a record is included as a prefix before the ciphertext.
1055 char variable_nonce_in_record
;
1058 extern SSL_CIPHER ssl3_ciphers
[];
1060 const char *ssl_version_string(int ver
);
1061 int ssl_enabled_version_range(SSL
*s
, uint16_t *min_ver
, uint16_t *max_ver
);
1062 int ssl_supported_version_range(SSL
*s
, uint16_t *min_ver
, uint16_t *max_ver
);
1063 int ssl_max_shared_version(SSL
*s
, uint16_t peer_ver
, uint16_t *max_ver
);
1064 uint16_t ssl_max_server_version(SSL
*s
);
1066 const SSL_METHOD
*dtls1_get_client_method(int ver
);
1067 const SSL_METHOD
*dtls1_get_server_method(int ver
);
1068 const SSL_METHOD
*tls1_get_client_method(int ver
);
1069 const SSL_METHOD
*tls1_get_server_method(int ver
);
1071 extern SSL3_ENC_METHOD DTLSv1_enc_data
;
1072 extern SSL3_ENC_METHOD TLSv1_enc_data
;
1073 extern SSL3_ENC_METHOD TLSv1_1_enc_data
;
1074 extern SSL3_ENC_METHOD TLSv1_2_enc_data
;
1076 void ssl_clear_cipher_ctx(SSL
*s
);
1077 int ssl_clear_bad_session(SSL
*s
);
1078 CERT
*ssl_cert_new(void);
1079 CERT
*ssl_cert_dup(CERT
*cert
);
1080 int ssl_cert_inst(CERT
**o
);
1081 void ssl_cert_free(CERT
*c
);
1082 SESS_CERT
*ssl_sess_cert_new(void);
1083 void ssl_sess_cert_free(SESS_CERT
*sc
);
1084 int ssl_get_new_session(SSL
*s
, int session
);
1085 int ssl_get_prev_session(SSL
*s
, unsigned char *session
, int len
,
1086 const unsigned char *limit
);
1087 int ssl_cipher_id_cmp(const SSL_CIPHER
*a
, const SSL_CIPHER
*b
);
1088 SSL_CIPHER
*OBJ_bsearch_ssl_cipher_id(SSL_CIPHER
*key
, SSL_CIPHER
const *base
, int num
);
1089 int ssl_cipher_ptr_id_cmp(const SSL_CIPHER
* const *ap
,
1090 const SSL_CIPHER
* const *bp
);
1091 STACK_OF(SSL_CIPHER
) *ssl_bytes_to_cipher_list(SSL
*s
, const unsigned char *p
,
1093 int ssl_cipher_list_to_bytes(SSL
*s
, STACK_OF(SSL_CIPHER
) *sk
,
1094 unsigned char *p
, size_t maxlen
, size_t *outlen
);
1095 STACK_OF(SSL_CIPHER
) *ssl_create_cipher_list(const SSL_METHOD
*meth
,
1096 STACK_OF(SSL_CIPHER
) **pref
, STACK_OF(SSL_CIPHER
) **sorted
,
1097 const char *rule_str
);
1098 void ssl_update_cache(SSL
*s
, int mode
);
1099 int ssl_cipher_get_evp(const SSL_SESSION
*s
, const EVP_CIPHER
**enc
,
1100 const EVP_MD
**md
, int *mac_pkey_type
, int *mac_secret_size
);
1101 int ssl_cipher_get_evp_aead(const SSL_SESSION
*s
, const EVP_AEAD
**aead
);
1102 int ssl_get_handshake_evp_md(SSL
*s
, const EVP_MD
**md
);
1104 int ssl_verify_cert_chain(SSL
*s
, STACK_OF(X509
) *sk
);
1105 int ssl_undefined_function(SSL
*s
);
1106 int ssl_undefined_void_function(void);
1107 int ssl_undefined_const_function(const SSL
*s
);
1108 CERT_PKEY
*ssl_get_server_send_pkey(const SSL
*s
);
1109 X509
*ssl_get_server_send_cert(const SSL
*);
1110 EVP_PKEY
*ssl_get_sign_pkey(SSL
*s
, const SSL_CIPHER
*c
, const EVP_MD
**pmd
);
1111 DH
*ssl_get_auto_dh(SSL
*s
);
1112 int ssl_cert_type(X509
*x
, EVP_PKEY
*pkey
);
1113 void ssl_set_cert_masks(CERT
*c
, const SSL_CIPHER
*cipher
);
1114 STACK_OF(SSL_CIPHER
) *ssl_get_ciphers_by_id(SSL
*s
);
1115 int ssl_verify_alarm_type(long type
);
1116 void ssl_load_ciphers(void);
1118 const SSL_CIPHER
*ssl3_get_cipher_by_char(const unsigned char *p
);
1119 int ssl3_put_cipher_by_char(const SSL_CIPHER
*c
, unsigned char *p
);
1120 int ssl3_send_server_certificate(SSL
*s
);
1121 int ssl3_send_newsession_ticket(SSL
*s
);
1122 int ssl3_send_cert_status(SSL
*s
);
1123 int ssl3_get_finished(SSL
*s
, int state_a
, int state_b
);
1124 int ssl3_send_change_cipher_spec(SSL
*s
, int state_a
, int state_b
);
1125 int ssl3_do_write(SSL
*s
, int type
);
1126 int ssl3_send_alert(SSL
*s
, int level
, int desc
);
1127 int ssl3_get_req_cert_type(SSL
*s
, unsigned char *p
);
1128 long ssl3_get_message(SSL
*s
, int st1
, int stn
, int mt
, long max
, int *ok
);
1129 int ssl3_send_finished(SSL
*s
, int a
, int b
, const char *sender
, int slen
);
1130 int ssl3_num_ciphers(void);
1131 const SSL_CIPHER
*ssl3_get_cipher(unsigned int u
);
1132 const SSL_CIPHER
*ssl3_get_cipher_by_id(unsigned int id
);
1133 const SSL_CIPHER
*ssl3_get_cipher_by_value(uint16_t value
);
1134 uint16_t ssl3_cipher_get_value(const SSL_CIPHER
*c
);
1135 int ssl3_renegotiate(SSL
*ssl
);
1137 int ssl3_renegotiate_check(SSL
*ssl
);
1139 int ssl3_dispatch_alert(SSL
*s
);
1140 int ssl3_read_bytes(SSL
*s
, int type
, unsigned char *buf
, int len
, int peek
);
1141 int ssl3_write_bytes(SSL
*s
, int type
, const void *buf
, int len
);
1142 int ssl3_output_cert_chain(SSL
*s
, CBB
*cbb
, X509
*x
);
1143 SSL_CIPHER
*ssl3_choose_cipher(SSL
*ssl
, STACK_OF(SSL_CIPHER
) *clnt
,
1144 STACK_OF(SSL_CIPHER
) *srvr
);
1145 int ssl3_setup_buffers(SSL
*s
);
1146 int ssl3_setup_init_buffer(SSL
*s
);
1147 int ssl3_setup_read_buffer(SSL
*s
);
1148 int ssl3_setup_write_buffer(SSL
*s
);
1149 int ssl3_release_read_buffer(SSL
*s
);
1150 int ssl3_release_write_buffer(SSL
*s
);
1151 int ssl3_new(SSL
*s
);
1152 void ssl3_free(SSL
*s
);
1153 int ssl3_accept(SSL
*s
);
1154 int ssl3_connect(SSL
*s
);
1155 int ssl3_read(SSL
*s
, void *buf
, int len
);
1156 int ssl3_peek(SSL
*s
, void *buf
, int len
);
1157 int ssl3_write(SSL
*s
, const void *buf
, int len
);
1158 int ssl3_shutdown(SSL
*s
);
1159 void ssl3_clear(SSL
*s
);
1160 long ssl3_ctrl(SSL
*s
, int cmd
, long larg
, void *parg
);
1161 long ssl3_ctx_ctrl(SSL_CTX
*s
, int cmd
, long larg
, void *parg
);
1162 long ssl3_callback_ctrl(SSL
*s
, int cmd
, void (*fp
)(void));
1163 long ssl3_ctx_callback_ctrl(SSL_CTX
*s
, int cmd
, void (*fp
)(void));
1164 int ssl3_pending(const SSL
*s
);
1166 int ssl3_handshake_msg_hdr_len(SSL
*s
);
1167 unsigned char *ssl3_handshake_msg_start(SSL
*s
, uint8_t htype
);
1168 void ssl3_handshake_msg_finish(SSL
*s
, unsigned int len
);
1169 int ssl3_handshake_msg_start_cbb(SSL
*s
, CBB
*handshake
, CBB
*body
,
1171 int ssl3_handshake_msg_finish_cbb(SSL
*s
, CBB
*handshake
);
1172 int ssl3_handshake_write(SSL
*s
);
1174 void tls1_record_sequence_increment(unsigned char *seq
);
1175 int ssl3_do_change_cipher_spec(SSL
*ssl
);
1177 int ssl23_read(SSL
*s
, void *buf
, int len
);
1178 int ssl23_peek(SSL
*s
, void *buf
, int len
);
1179 int ssl23_write(SSL
*s
, const void *buf
, int len
);
1180 long ssl23_default_timeout(void);
1182 long tls1_default_timeout(void);
1183 int dtls1_do_write(SSL
*s
, int type
);
1184 int ssl3_packet_read(SSL
*s
, int plen
);
1185 int ssl3_packet_extend(SSL
*s
, int plen
);
1186 int ssl_server_legacy_first_packet(SSL
*s
);
1187 int dtls1_read_bytes(SSL
*s
, int type
, unsigned char *buf
, int len
, int peek
);
1188 int ssl3_write_pending(SSL
*s
, int type
, const unsigned char *buf
,
1190 void dtls1_set_message_header(SSL
*s
, unsigned char mt
, unsigned long len
,
1191 unsigned long frag_off
, unsigned long frag_len
);
1193 int dtls1_write_app_data_bytes(SSL
*s
, int type
, const void *buf
, int len
);
1194 int dtls1_write_bytes(SSL
*s
, int type
, const void *buf
, int len
);
1196 int dtls1_send_change_cipher_spec(SSL
*s
, int a
, int b
);
1197 unsigned long dtls1_output_cert_chain(SSL
*s
, X509
*x
);
1198 int dtls1_read_failed(SSL
*s
, int code
);
1199 int dtls1_buffer_message(SSL
*s
, int ccs
);
1200 int dtls1_retransmit_message(SSL
*s
, unsigned short seq
,
1201 unsigned long frag_off
, int *found
);
1202 int dtls1_get_queue_priority(unsigned short seq
, int is_ccs
);
1203 int dtls1_retransmit_buffered_messages(SSL
*s
);
1204 void dtls1_clear_record_buffer(SSL
*s
);
1205 int dtls1_get_message_header(unsigned char *data
,
1206 struct hm_header_st
*msg_hdr
);
1207 void dtls1_get_ccs_header(unsigned char *data
, struct ccs_header_st
*ccs_hdr
);
1208 void dtls1_reset_seq_numbers(SSL
*s
, int rw
);
1209 void dtls1_build_sequence_number(unsigned char *dst
, unsigned char *seq
,
1210 unsigned short epoch
);
1211 long dtls1_default_timeout(void);
1212 struct timeval
* dtls1_get_timeout(SSL
*s
, struct timeval
* timeleft
);
1213 int dtls1_check_timeout_num(SSL
*s
);
1214 int dtls1_handle_timeout(SSL
*s
);
1215 const SSL_CIPHER
*dtls1_get_cipher(unsigned int u
);
1216 void dtls1_start_timer(SSL
*s
);
1217 void dtls1_stop_timer(SSL
*s
);
1218 int dtls1_is_timer_expired(SSL
*s
);
1219 void dtls1_double_timeout(SSL
*s
);
1220 unsigned int dtls1_min_mtu(void);
1222 /* some client-only functions */
1223 int ssl3_client_hello(SSL
*s
);
1224 int ssl3_get_server_hello(SSL
*s
);
1225 int ssl3_get_certificate_request(SSL
*s
);
1226 int ssl3_get_new_session_ticket(SSL
*s
);
1227 int ssl3_get_cert_status(SSL
*s
);
1228 int ssl3_get_server_done(SSL
*s
);
1229 int ssl3_send_client_verify(SSL
*s
);
1230 int ssl3_send_client_certificate(SSL
*s
);
1231 int ssl_do_client_cert_cb(SSL
*s
, X509
**px509
, EVP_PKEY
**ppkey
);
1232 int ssl3_send_client_key_exchange(SSL
*s
);
1233 int ssl3_get_server_key_exchange(SSL
*s
);
1234 int ssl3_get_server_certificate(SSL
*s
);
1235 int ssl3_check_cert_and_algorithm(SSL
*s
);
1236 int ssl3_check_finished(SSL
*s
);
1237 int ssl3_send_next_proto(SSL
*s
);
1239 /* some server-only functions */
1240 int ssl3_get_client_hello(SSL
*s
);
1241 int ssl3_send_server_hello(SSL
*s
);
1242 int ssl3_send_hello_request(SSL
*s
);
1243 int ssl3_send_server_key_exchange(SSL
*s
);
1244 int ssl3_send_certificate_request(SSL
*s
);
1245 int ssl3_send_server_done(SSL
*s
);
1246 int ssl3_get_client_certificate(SSL
*s
);
1247 int ssl3_get_client_key_exchange(SSL
*s
);
1248 int ssl3_get_cert_verify(SSL
*s
);
1249 int ssl3_get_next_proto(SSL
*s
);
1251 int ssl23_accept(SSL
*s
);
1252 int ssl23_connect(SSL
*s
);
1253 int ssl23_read_bytes(SSL
*s
, int n
);
1254 int ssl23_write_bytes(SSL
*s
);
1256 int tls1_new(SSL
*s
);
1257 void tls1_free(SSL
*s
);
1258 void tls1_clear(SSL
*s
);
1260 int dtls1_new(SSL
*s
);
1261 int dtls1_accept(SSL
*s
);
1262 int dtls1_connect(SSL
*s
);
1263 void dtls1_free(SSL
*s
);
1264 void dtls1_clear(SSL
*s
);
1265 long dtls1_ctrl(SSL
*s
, int cmd
, long larg
, void *parg
);
1266 int dtls1_shutdown(SSL
*s
);
1268 long dtls1_get_message(SSL
*s
, int st1
, int stn
, int mt
, long max
, int *ok
);
1269 int dtls1_get_record(SSL
*s
);
1270 int dtls1_dispatch_alert(SSL
*s
);
1271 int dtls1_enc(SSL
*s
, int snd
);
1273 int ssl_init_wbio_buffer(SSL
*s
, int push
);
1274 void ssl_free_wbio_buffer(SSL
*s
);
1276 int tls1_handshake_hash_init(SSL
*s
);
1277 int tls1_handshake_hash_update(SSL
*s
, const unsigned char *buf
, size_t len
);
1278 int tls1_handshake_hash_value(SSL
*s
, const unsigned char *out
, size_t len
,
1280 void tls1_handshake_hash_free(SSL
*s
);
1282 int tls1_init_finished_mac(SSL
*s
);
1283 int tls1_finish_mac(SSL
*s
, const unsigned char *buf
, int len
);
1284 void tls1_free_digest_list(SSL
*s
);
1285 void tls1_cleanup_key_block(SSL
*s
);
1286 int tls1_digest_cached_records(SSL
*s
);
1287 int tls1_change_cipher_state(SSL
*s
, int which
);
1288 int tls1_setup_key_block(SSL
*s
);
1289 int tls1_enc(SSL
*s
, int snd
);
1290 int tls1_final_finish_mac(SSL
*s
, const char *str
, int slen
, unsigned char *p
);
1291 int tls1_mac(SSL
*ssl
, unsigned char *md
, int snd
);
1292 int tls1_generate_master_secret(SSL
*s
, unsigned char *out
,
1293 unsigned char *p
, int len
);
1294 int tls1_export_keying_material(SSL
*s
, unsigned char *out
, size_t olen
,
1295 const char *label
, size_t llen
, const unsigned char *p
, size_t plen
,
1297 int tls1_alert_code(int code
);
1300 int ssl_check_srvr_ecc_cert_and_alg(X509
*x
, SSL
*s
);
1302 int tls1_set_groups(uint16_t **out_group_ids
, size_t *out_group_ids_len
,
1303 const int *groups
, size_t ngroups
);
1304 int tls1_set_groups_list(uint16_t **out_group_ids
, size_t *out_group_ids_len
,
1305 const char *groups
);
1307 int tls1_ec_curve_id2nid(const uint16_t curve_id
);
1308 uint16_t tls1_ec_nid2curve_id(const int nid
);
1309 int tls1_check_curve(SSL
*s
, const uint16_t curve_id
);
1310 int tls1_get_shared_curve(SSL
*s
);
1312 unsigned char *ssl_add_clienthello_tlsext(SSL
*s
, unsigned char *p
,
1313 unsigned char *limit
);
1315 unsigned char *ssl_add_serverhello_tlsext(SSL
*s
, unsigned char *p
,
1316 unsigned char *limit
);
1318 int ssl_parse_clienthello_tlsext(SSL
*s
, unsigned char **data
,
1319 unsigned char *d
, int n
, int *al
);
1320 int ssl_parse_serverhello_tlsext(SSL
*s
, unsigned char **data
,
1322 int ssl_check_clienthello_tlsext_early(SSL
*s
);
1323 int ssl_check_clienthello_tlsext_late(SSL
*s
);
1324 int ssl_check_serverhello_tlsext(SSL
*s
);
1326 #define tlsext_tick_md EVP_sha256
1327 int tls1_process_ticket(SSL
*s
, const unsigned char *session_id
, int len
,
1328 const unsigned char *limit
, SSL_SESSION
**ret
);
1329 int tls12_get_sigandhash(unsigned char *p
, const EVP_PKEY
*pk
,
1331 int tls12_get_sigid(const EVP_PKEY
*pk
);
1332 const EVP_MD
*tls12_get_hash(unsigned char hash_alg
);
1334 void ssl_clear_hash_ctx(EVP_MD_CTX
**hash
);
1335 int ssl_add_serverhello_renegotiate_ext(SSL
*s
, unsigned char *p
,
1336 int *len
, int maxlen
);
1337 int ssl_parse_serverhello_renegotiate_ext(SSL
*s
, const unsigned char *d
,
1339 int ssl_add_clienthello_renegotiate_ext(SSL
*s
, unsigned char *p
,
1340 int *len
, int maxlen
);
1341 int ssl_parse_clienthello_renegotiate_ext(SSL
*s
, const unsigned char *d
,
1343 long ssl_get_algorithm2(SSL
*s
);
1344 int tls1_process_sigalgs(SSL
*s
, const unsigned char *data
, int dsize
);
1345 int tls12_get_req_sig_algs(SSL
*s
, unsigned char *p
);
1347 int tls1_check_ec_server_key(SSL
*s
);
1348 int tls1_check_ec_tmp_key(SSL
*s
);
1350 int ssl_add_clienthello_use_srtp_ext(SSL
*s
, unsigned char *p
,
1351 int *len
, int maxlen
);
1352 int ssl_parse_clienthello_use_srtp_ext(SSL
*s
, const unsigned char *d
,
1354 int ssl_add_serverhello_use_srtp_ext(SSL
*s
, unsigned char *p
,
1355 int *len
, int maxlen
);
1356 int ssl_parse_serverhello_use_srtp_ext(SSL
*s
, const unsigned char *d
,
1360 void ssl3_cbc_copy_mac(unsigned char *out
, const SSL3_RECORD
*rec
,
1361 unsigned md_size
, unsigned orig_len
);
1362 int tls1_cbc_remove_padding(const SSL
*s
, SSL3_RECORD
*rec
,
1363 unsigned block_size
, unsigned mac_size
);
1364 char ssl3_cbc_record_digest_supported(const EVP_MD_CTX
*ctx
);
1365 int ssl3_cbc_digest_record(const EVP_MD_CTX
*ctx
, unsigned char *md_out
,
1366 size_t *md_out_size
, const unsigned char header
[13],
1367 const unsigned char *data
, size_t data_plus_mac_size
,
1368 size_t data_plus_mac_plus_padding_size
, const unsigned char *mac_secret
,
1369 unsigned mac_secret_length
);
1370 int SSL_state_func_code(int _state
);
1372 #define SSLerror(s, r) ERR_PUT_error(ERR_LIB_SSL, \
1373 (SSL_state_func_code(s->internal->state)),(r),__FILE__,__LINE__)
1374 #define SSLerrorx(r) ERR_PUT_error(ERR_LIB_SSL,(0xfff),(r),__FILE__,__LINE__)