2 * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /*****************************************************************************
12 * The following definitions are PRIVATE to the state machine. They should *
13 * NOT be used outside of the state machine. *
15 *****************************************************************************/
17 /* Max message length definitions */
19 /* The spec allows for a longer length than this, but we limit it */
20 #define HELLO_VERIFY_REQUEST_MAX_LENGTH 258
21 #define SERVER_HELLO_MAX_LENGTH 20000
22 #define SERVER_KEY_EXCH_MAX_LENGTH 102400
23 #define SERVER_HELLO_DONE_MAX_LENGTH 0
24 #define CCS_MAX_LENGTH 1
25 /* Max should actually be 36 but we are generous */
26 #define FINISHED_MAX_LENGTH 64
28 /* Message processing return codes */
30 /* Something bad happened */
32 /* We've finished reading - swap to writing */
33 MSG_PROCESS_FINISHED_READING
,
35 * We've completed the main processing of this message but there is some
36 * post processing to be done.
38 MSG_PROCESS_CONTINUE_PROCESSING
,
39 /* We've finished this message - read the next message */
40 MSG_PROCESS_CONTINUE_READING
43 /* Flush the write BIO */
44 int statem_flush(SSL
*s
);
46 typedef int (*confunc_f
) (SSL
*s
, WPACKET
*pkt
);
49 * TLS/DTLS client state machine functions
51 int ossl_statem_client_read_transition(SSL
*s
, int mt
);
52 WRITE_TRAN
ossl_statem_client_write_transition(SSL
*s
);
53 WORK_STATE
ossl_statem_client_pre_work(SSL
*s
, WORK_STATE wst
);
54 WORK_STATE
ossl_statem_client_post_work(SSL
*s
, WORK_STATE wst
);
55 int ossl_statem_client_construct_message(SSL
*s
, WPACKET
*pkt
,
56 confunc_f
*confunc
, int *mt
);
57 size_t ossl_statem_client_max_message_size(SSL
*s
);
58 MSG_PROCESS_RETURN
ossl_statem_client_process_message(SSL
*s
, PACKET
*pkt
);
59 WORK_STATE
ossl_statem_client_post_process_message(SSL
*s
, WORK_STATE wst
);
62 * TLS/DTLS server state machine functions
64 int ossl_statem_server_read_transition(SSL
*s
, int mt
);
65 WRITE_TRAN
ossl_statem_server_write_transition(SSL
*s
);
66 WORK_STATE
ossl_statem_server_pre_work(SSL
*s
, WORK_STATE wst
);
67 WORK_STATE
ossl_statem_server_post_work(SSL
*s
, WORK_STATE wst
);
68 int ossl_statem_server_construct_message(SSL
*s
, WPACKET
*pkt
,
69 confunc_f
*confunc
,int *mt
);
70 size_t ossl_statem_server_max_message_size(SSL
*s
);
71 MSG_PROCESS_RETURN
ossl_statem_server_process_message(SSL
*s
, PACKET
*pkt
);
72 WORK_STATE
ossl_statem_server_post_process_message(SSL
*s
, WORK_STATE wst
);
74 /* Functions for getting new message data */
75 __owur
int tls_get_message_header(SSL
*s
, int *mt
);
76 __owur
int tls_get_message_body(SSL
*s
, size_t *len
);
77 __owur
int dtls_get_message(SSL
*s
, int *mt
, size_t *len
);
79 /* Message construction and processing functions */
80 __owur MSG_PROCESS_RETURN
tls_process_change_cipher_spec(SSL
*s
, PACKET
*pkt
);
81 __owur MSG_PROCESS_RETURN
tls_process_finished(SSL
*s
, PACKET
*pkt
);
82 __owur
int tls_construct_change_cipher_spec(SSL
*s
, WPACKET
*pkt
);
83 __owur
int dtls_construct_change_cipher_spec(SSL
*s
, WPACKET
*pkt
);
85 __owur
int tls_construct_finished(SSL
*s
, WPACKET
*pkt
);
86 __owur WORK_STATE
tls_finish_handshake(SSL
*s
, WORK_STATE wst
);
87 __owur WORK_STATE
dtls_wait_for_dry(SSL
*s
);
89 int tls_collect_extensions(PACKET
*packet
, RAW_EXTENSION
**res
,
90 size_t *numfound
, int *ad
);
92 /* some client-only functions */
93 __owur
int tls_construct_client_hello(SSL
*s
, WPACKET
*pkt
);
94 __owur MSG_PROCESS_RETURN
tls_process_server_hello(SSL
*s
, PACKET
*pkt
);
95 __owur MSG_PROCESS_RETURN
tls_process_certificate_request(SSL
*s
, PACKET
*pkt
);
96 __owur MSG_PROCESS_RETURN
tls_process_new_session_ticket(SSL
*s
, PACKET
*pkt
);
97 __owur MSG_PROCESS_RETURN
tls_process_cert_status(SSL
*s
, PACKET
*pkt
);
98 __owur MSG_PROCESS_RETURN
tls_process_server_done(SSL
*s
, PACKET
*pkt
);
99 __owur
int tls_construct_client_verify(SSL
*s
, WPACKET
*pkt
);
100 __owur WORK_STATE
tls_prepare_client_certificate(SSL
*s
, WORK_STATE wst
);
101 __owur
int tls_construct_client_certificate(SSL
*s
, WPACKET
*pkt
);
102 __owur
int ssl_do_client_cert_cb(SSL
*s
, X509
**px509
, EVP_PKEY
**ppkey
);
103 __owur
int tls_construct_client_key_exchange(SSL
*s
, WPACKET
*pkt
);
104 __owur
int tls_client_key_exchange_post_work(SSL
*s
);
105 __owur
int tls_construct_cert_status(SSL
*s
, WPACKET
*pkt
);
106 __owur MSG_PROCESS_RETURN
tls_process_key_exchange(SSL
*s
, PACKET
*pkt
);
107 __owur MSG_PROCESS_RETURN
tls_process_server_certificate(SSL
*s
, PACKET
*pkt
);
108 __owur
int ssl3_check_cert_and_algorithm(SSL
*s
);
109 #ifndef OPENSSL_NO_NEXTPROTONEG
110 __owur
int tls_construct_next_proto(SSL
*s
, WPACKET
*pkt
);
112 __owur MSG_PROCESS_RETURN
dtls_process_hello_verify(SSL
*s
, PACKET
*pkt
);
114 /* some server-only functions */
115 __owur MSG_PROCESS_RETURN
tls_process_client_hello(SSL
*s
, PACKET
*pkt
);
116 __owur WORK_STATE
tls_post_process_client_hello(SSL
*s
, WORK_STATE wst
);
117 __owur
int tls_construct_server_hello(SSL
*s
, WPACKET
*pkt
);
118 __owur
int dtls_construct_hello_verify_request(SSL
*s
, WPACKET
*pkt
);
119 __owur
int tls_construct_server_certificate(SSL
*s
, WPACKET
*pkt
);
120 __owur
int tls_construct_server_key_exchange(SSL
*s
, WPACKET
*pkt
);
121 __owur
int tls_construct_certificate_request(SSL
*s
, WPACKET
*pkt
);
122 __owur
int tls_construct_server_done(SSL
*s
, WPACKET
*pkt
);
123 __owur MSG_PROCESS_RETURN
tls_process_client_certificate(SSL
*s
, PACKET
*pkt
);
124 __owur MSG_PROCESS_RETURN
tls_process_client_key_exchange(SSL
*s
, PACKET
*pkt
);
125 __owur WORK_STATE
tls_post_process_client_key_exchange(SSL
*s
, WORK_STATE wst
);
126 __owur MSG_PROCESS_RETURN
tls_process_cert_verify(SSL
*s
, PACKET
*pkt
);
127 #ifndef OPENSSL_NO_NEXTPROTONEG
128 __owur MSG_PROCESS_RETURN
tls_process_next_proto(SSL
*s
, PACKET
*pkt
);
130 __owur
int tls_construct_new_session_ticket(SSL
*s
, WPACKET
*pkt
);