1 /* ssl/statem/statem_locl.h */
2 /* ====================================================================
3 * Copyright (c) 1998-2015 The OpenSSL Project. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
31 * 6. Redistributions of any form whatsoever must retain the following
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
56 /*****************************************************************************
58 * The following definitions are PRIVATE to the state machine. They should *
59 * NOT be used outside of the state machine. *
61 *****************************************************************************/
63 /* Max message length definitions */
65 /* The spec allows for a longer length than this, but we limit it */
66 #define HELLO_VERIFY_REQUEST_MAX_LENGTH 258
67 #define SERVER_HELLO_MAX_LENGTH 20000
68 #define SERVER_KEY_EXCH_MAX_LENGTH 102400
69 #define SERVER_HELLO_DONE_MAX_LENGTH 0
70 #define CCS_MAX_LENGTH 1
71 /* Max should actually be 36 but we are generous */
72 #define FINISHED_MAX_LENGTH 64
74 /* Message processing return codes */
76 /* Something bad happened */
78 /* We've finished reading - swap to writing */
79 MSG_PROCESS_FINISHED_READING,
81 * We've completed the main processing of this message but there is some
82 * post processing to be done.
84 MSG_PROCESS_CONTINUE_PROCESSING,
85 /* We've finished this message - read the next message */
86 MSG_PROCESS_CONTINUE_READING
89 /* Flush the write BIO */
90 int statem_flush(SSL *s);
93 * TLS/DTLS client state machine functions
95 int ossl_statem_client_read_transition(SSL *s, int mt);
96 WRITE_TRAN ossl_statem_client_write_transition(SSL *s);
97 WORK_STATE ossl_statem_client_pre_work(SSL *s, WORK_STATE wst);
98 WORK_STATE ossl_statem_client_post_work(SSL *s, WORK_STATE wst);
99 int ossl_statem_client_construct_message(SSL *s);
100 unsigned long ossl_statem_client_max_message_size(SSL *s);
101 MSG_PROCESS_RETURN ossl_statem_client_process_message(SSL *s, PACKET *pkt);
102 WORK_STATE ossl_statem_client_post_process_message(SSL *s, WORK_STATE wst);
105 * TLS/DTLS server state machine functions
107 int ossl_statem_server_read_transition(SSL *s, int mt);
108 WRITE_TRAN ossl_statem_server_write_transition(SSL *s);
109 WORK_STATE ossl_statem_server_pre_work(SSL *s, WORK_STATE wst);
110 WORK_STATE ossl_statem_server_post_work(SSL *s, WORK_STATE wst);
111 int ossl_statem_server_construct_message(SSL *s);
112 unsigned long ossl_statem_server_max_message_size(SSL *s);
113 MSG_PROCESS_RETURN ossl_statem_server_process_message(SSL *s, PACKET *pkt);
114 WORK_STATE ossl_statem_server_post_process_message(SSL *s, WORK_STATE wst);
116 /* Functions for getting new message data */
117 __owur int tls_get_message_header(SSL *s, int *mt);
118 __owur int tls_get_message_body(SSL *s, unsigned long *len);
119 __owur int dtls_get_message(SSL *s, int *mt, unsigned long *len);
121 /* Message construction and processing functions */
122 __owur MSG_PROCESS_RETURN tls_process_change_cipher_spec(SSL *s, PACKET *pkt);
123 __owur MSG_PROCESS_RETURN tls_process_finished(SSL *s, PACKET *pkt);
124 __owur int tls_construct_change_cipher_spec(SSL *s);
125 __owur int dtls_construct_change_cipher_spec(SSL *s);
127 __owur int tls_construct_finished(SSL *s, const char *sender, int slen);
128 __owur WORK_STATE tls_finish_handshake(SSL *s, WORK_STATE wst);
129 __owur WORK_STATE dtls_wait_for_dry(SSL *s);
131 /* some client-only functions */
132 __owur int tls_construct_client_hello(SSL *s);
133 __owur MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt);
134 __owur MSG_PROCESS_RETURN tls_process_certificate_request(SSL *s, PACKET *pkt);
135 __owur MSG_PROCESS_RETURN tls_process_new_session_ticket(SSL *s, PACKET *pkt);
136 __owur MSG_PROCESS_RETURN tls_process_cert_status(SSL *s, PACKET *pkt);
137 __owur MSG_PROCESS_RETURN tls_process_server_done(SSL *s, PACKET *pkt);
138 __owur int tls_construct_client_verify(SSL *s);
139 __owur WORK_STATE tls_prepare_client_certificate(SSL *s, WORK_STATE wst);
140 __owur int tls_construct_client_certificate(SSL *s);
141 __owur int ssl_do_client_cert_cb(SSL *s, X509 **px509, EVP_PKEY **ppkey);
142 __owur int tls_construct_client_key_exchange(SSL *s);
143 __owur int tls_client_key_exchange_post_work(SSL *s);
144 __owur int tls_construct_cert_status(SSL *s);
145 __owur MSG_PROCESS_RETURN tls_process_key_exchange(SSL *s,
147 __owur MSG_PROCESS_RETURN tls_process_server_certificate(SSL *s, PACKET *pkt);
148 __owur int ssl3_check_cert_and_algorithm(SSL *s);
149 # ifndef OPENSSL_NO_NEXTPROTONEG
150 __owur int tls_construct_next_proto(SSL *s);
152 __owur MSG_PROCESS_RETURN dtls_process_hello_verify(SSL *s, PACKET *pkt);
154 /* some server-only functions */
155 __owur MSG_PROCESS_RETURN tls_process_client_hello(SSL *s, PACKET *pkt);
156 __owur WORK_STATE tls_post_process_client_hello(SSL *s, WORK_STATE wst);
157 __owur int tls_construct_server_hello(SSL *s);
158 __owur int tls_construct_hello_request(SSL *s);
159 __owur int dtls_construct_hello_verify_request(SSL *s);
160 __owur int tls_construct_server_certificate(SSL *s);
161 __owur int tls_construct_server_key_exchange(SSL *s);
162 __owur int tls_construct_certificate_request(SSL *s);
163 __owur int tls_construct_server_done(SSL *s);
164 __owur MSG_PROCESS_RETURN tls_process_client_certificate(SSL *s, PACKET *pkt);
165 __owur MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt);
166 __owur WORK_STATE tls_post_process_client_key_exchange(SSL *s, WORK_STATE wst);
167 __owur MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt);
168 # ifndef OPENSSL_NO_NEXTPROTONEG
169 __owur MSG_PROCESS_RETURN tls_process_next_proto(SSL *s, PACKET *pkt);
171 __owur int tls_construct_new_session_ticket(SSL *s);