2 * Copyright 2015-2017 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 #include "internal/cryptlib.h"
11 #include <openssl/rand.h>
12 #include "../ssl_locl.h"
13 #include "statem_locl.h"
16 * This file implements the SSL/TLS/DTLS state machines.
18 * There are two primary state machines:
20 * 1) Message flow state machine
21 * 2) Handshake state machine
23 * The Message flow state machine controls the reading and sending of messages
24 * including handling of non-blocking IO events, flushing of the underlying
25 * write BIO, handling unexpected messages, etc. It is itself broken into two
26 * separate sub-state machines which control reading and writing respectively.
28 * The Handshake state machine keeps track of the current SSL/TLS handshake
29 * state. Transitions of the handshake state are the result of events that
30 * occur within the Message flow state machine.
32 * Overall it looks like this:
34 * --------------------------------------------- -------------------
36 * | Message flow state machine | | |
38 * | -------------------- -------------------- | Transition | Handshake state |
39 * | | MSG_FLOW_READING | | MSG_FLOW_WRITING | | Event | machine |
40 * | | sub-state | | sub-state | |----------->| |
41 * | | machine for | | machine for | | | |
42 * | | reading messages | | writing messages | | | |
43 * | -------------------- -------------------- | | |
45 * --------------------------------------------- -------------------
49 /* Sub state machine return values */
51 /* Something bad happened or NBIO */
53 /* Sub state finished go to the next sub state */
55 /* Sub state finished and handshake was completed */
56 SUB_STATE_END_HANDSHAKE
59 static int state_machine(SSL *s, int server);
60 static void init_read_state_machine(SSL *s);
61 static SUB_STATE_RETURN read_state_machine(SSL *s);
62 static void init_write_state_machine(SSL *s);
63 static SUB_STATE_RETURN write_state_machine(SSL *s);
65 OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl)
67 return ssl->statem.hand_state;
70 int SSL_in_init(SSL *s)
72 return s->statem.in_init;
75 int SSL_is_init_finished(SSL *s)
77 return !(s->statem.in_init) && (s->statem.hand_state == TLS_ST_OK);
80 int SSL_in_before(SSL *s)
83 * Historically being "in before" meant before anything had happened. In the
84 * current code though we remain in the "before" state for a while after we
85 * have started the handshake process (e.g. as a server waiting for the
86 * first message to arrive). There "in before" is taken to mean "in before"
87 * and not started any handshake process yet.
89 return (s->statem.hand_state == TLS_ST_BEFORE)
90 && (s->statem.state == MSG_FLOW_UNINITED);
94 * Clear the state machine state and reset back to MSG_FLOW_UNINITED
96 void ossl_statem_clear(SSL *s)
98 s->statem.state = MSG_FLOW_UNINITED;
99 s->statem.hand_state = TLS_ST_BEFORE;
100 s->statem.in_init = 1;
101 s->statem.no_cert_verify = 0;
105 * Set the state machine up ready for a renegotiation handshake
107 void ossl_statem_set_renegotiate(SSL *s)
109 s->statem.in_init = 1;
110 s->statem.request_state = TLS_ST_SW_HELLO_REQ;
114 * Put the state machine into an error state and send an alert if appropriate.
115 * This is a permanent error for the current connection.
117 void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,
120 s->statem.in_init = 1;
121 s->statem.state = MSG_FLOW_ERROR;
122 ERR_put_error(ERR_LIB_SSL, func, reason, file, line);
123 if (s->statem.hand_state != TLS_ST_BEFORE
124 && s->statem.hand_state != TLS_ST_CW_CLNT_HELLO) {
126 * We only send an alert if we've got as far as actually sending or
127 * receiving a message.
129 ssl3_send_alert(s, SSL3_AL_FATAL, al);
134 * Discover whether the current connection is in the error state.
136 * Valid return values are:
140 int ossl_statem_in_error(const SSL *s)
142 if (s->statem.state == MSG_FLOW_ERROR)
148 void ossl_statem_set_in_init(SSL *s, int init)
150 s->statem.in_init = init;
153 int ossl_statem_get_in_handshake(SSL *s)
155 return s->statem.in_handshake;
158 void ossl_statem_set_in_handshake(SSL *s, int inhand)
161 s->statem.in_handshake++;
163 s->statem.in_handshake--;
166 /* Are we in a sensible state to skip over unreadable early data? */
167 int ossl_statem_skip_early_data(SSL *s)
169 if (s->ext.early_data != SSL_EARLY_DATA_REJECTED)
172 if (!s->server || s->statem.hand_state != TLS_ST_EARLY_DATA)
179 * Called when we are in SSL_read*(), SSL_write*(), or SSL_accept()
180 * /SSL_connect()/SSL_do_handshake(). Used to test whether we are in an early
181 * data state and whether we should attempt to move the handshake on if so.
182 * |sending| is 1 if we are attempting to send data (SSL_write*()), 0 if we are
183 * attempting to read data (SSL_read*()), or -1 if we are in SSL_do_handshake()
186 void ossl_statem_check_finish_init(SSL *s, int sending)
189 if (s->statem.hand_state == TLS_ST_PENDING_EARLY_DATA_END
190 || s->statem.hand_state == TLS_ST_EARLY_DATA) {
191 ossl_statem_set_in_init(s, 1);
192 if (s->early_data_state == SSL_EARLY_DATA_WRITE_RETRY) {
194 * SSL_connect() or SSL_do_handshake() has been called directly.
195 * We don't allow any more writing of early data.
197 s->early_data_state = SSL_EARLY_DATA_FINISHED_WRITING;
200 } else if (!s->server) {
201 if ((sending && (s->statem.hand_state == TLS_ST_PENDING_EARLY_DATA_END
202 || s->statem.hand_state == TLS_ST_EARLY_DATA)
203 && s->early_data_state != SSL_EARLY_DATA_WRITING)
204 || (!sending && s->statem.hand_state == TLS_ST_EARLY_DATA)) {
205 ossl_statem_set_in_init(s, 1);
207 * SSL_write() has been called directly. We don't allow any more
208 * writing of early data.
210 if (sending && s->early_data_state == SSL_EARLY_DATA_WRITE_RETRY)
211 s->early_data_state = SSL_EARLY_DATA_FINISHED_WRITING;
214 if (s->early_data_state == SSL_EARLY_DATA_FINISHED_READING
215 && s->statem.hand_state == TLS_ST_EARLY_DATA)
216 ossl_statem_set_in_init(s, 1);
220 void ossl_statem_set_hello_verify_done(SSL *s)
222 s->statem.state = MSG_FLOW_UNINITED;
223 s->statem.in_init = 1;
225 * This will get reset (briefly) back to TLS_ST_BEFORE when we enter
226 * state_machine() because |state| is MSG_FLOW_UNINITED, but until then any
227 * calls to SSL_in_before() will return false. Also calls to
228 * SSL_state_string() and SSL_state_string_long() will return something
231 s->statem.hand_state = TLS_ST_SR_CLNT_HELLO;
234 int ossl_statem_connect(SSL *s)
236 return state_machine(s, 0);
239 int ossl_statem_accept(SSL *s)
241 return state_machine(s, 1);
244 typedef void (*info_cb) (const SSL *, int, int);
246 static info_cb get_callback(SSL *s)
248 if (s->info_callback != NULL)
249 return s->info_callback;
250 else if (s->ctx->info_callback != NULL)
251 return s->ctx->info_callback;
257 * The main message flow state machine. We start in the MSG_FLOW_UNINITED or
258 * MSG_FLOW_FINISHED state and finish in MSG_FLOW_FINISHED. Valid states and
259 * transitions are as follows:
261 * MSG_FLOW_UNINITED MSG_FLOW_FINISHED
263 * +-----------------------+
265 * MSG_FLOW_WRITING <---> MSG_FLOW_READING
273 * We may exit at any point due to an error or NBIO event. If an NBIO event
274 * occurs then we restart at the point we left off when we are recalled.
275 * MSG_FLOW_WRITING and MSG_FLOW_READING have sub-state machines associated with them.
277 * In addition to the above there is also the MSG_FLOW_ERROR state. We can move
278 * into that state at any point in the event that an irrecoverable error occurs.
280 * Valid return values are:
284 static int state_machine(SSL *s, int server)
287 void (*cb) (const SSL *ssl, int type, int val) = NULL;
288 OSSL_STATEM *st = &s->statem;
292 if (st->state == MSG_FLOW_ERROR) {
293 /* Shouldn't have been called if we're already in the error state */
300 cb = get_callback(s);
303 if (!SSL_in_init(s) || SSL_in_before(s)) {
307 #ifndef OPENSSL_NO_SCTP
308 if (SSL_IS_DTLS(s) && BIO_dgram_is_sctp(SSL_get_wbio(s))) {
310 * Notify SCTP BIO socket to enter handshake mode and prevent stream
311 * identifier other than 0.
313 BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,
314 st->in_handshake, NULL);
318 /* Initialise state machine */
319 if (st->state == MSG_FLOW_UNINITED
320 || st->state == MSG_FLOW_FINISHED) {
321 if (st->state == MSG_FLOW_UNINITED) {
322 st->hand_state = TLS_ST_BEFORE;
323 st->request_state = TLS_ST_BEFORE;
328 cb(s, SSL_CB_HANDSHAKE_START, 1);
330 if (SSL_IS_DTLS(s)) {
331 if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00) &&
332 (server || (s->version & 0xff00) != (DTLS1_BAD_VER & 0xff00))) {
333 SSLerr(SSL_F_STATE_MACHINE, ERR_R_INTERNAL_ERROR);
337 if ((s->version >> 8) != SSL3_VERSION_MAJOR) {
338 SSLerr(SSL_F_STATE_MACHINE, ERR_R_INTERNAL_ERROR);
343 if (!ssl_security(s, SSL_SECOP_VERSION, 0, s->version, NULL)) {
344 SSLerr(SSL_F_STATE_MACHINE, SSL_R_VERSION_TOO_LOW);
348 if (s->init_buf == NULL) {
349 if ((buf = BUF_MEM_new()) == NULL) {
352 if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
359 if (!ssl3_setup_buffers(s)) {
365 * Should have been reset by tls_process_finished, too.
367 s->s3->change_cipher_spec = 0;
370 * Ok, we now need to push on a buffering BIO ...but not with
373 #ifndef OPENSSL_NO_SCTP
374 if (!SSL_IS_DTLS(s) || !BIO_dgram_is_sctp(SSL_get_wbio(s)))
376 if (!ssl_init_wbio_buffer(s)) {
380 if ((SSL_in_before(s))
382 if (!tls_setup_handshake(s))
385 if (SSL_IS_FIRST_HANDSHAKE(s))
386 st->read_state_first_init = 1;
389 st->state = MSG_FLOW_WRITING;
390 init_write_state_machine(s);
393 while (st->state != MSG_FLOW_FINISHED) {
394 if (st->state == MSG_FLOW_READING) {
395 ssret = read_state_machine(s);
396 if (ssret == SUB_STATE_FINISHED) {
397 st->state = MSG_FLOW_WRITING;
398 init_write_state_machine(s);
403 } else if (st->state == MSG_FLOW_WRITING) {
404 ssret = write_state_machine(s);
405 if (ssret == SUB_STATE_FINISHED) {
406 st->state = MSG_FLOW_READING;
407 init_read_state_machine(s);
408 } else if (ssret == SUB_STATE_END_HANDSHAKE) {
409 st->state = MSG_FLOW_FINISHED;
416 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_STATE_MACHINE,
417 ERR_R_INTERNAL_ERROR);
427 #ifndef OPENSSL_NO_SCTP
428 if (SSL_IS_DTLS(s) && BIO_dgram_is_sctp(SSL_get_wbio(s))) {
430 * Notify SCTP BIO socket to leave handshake mode and allow stream
431 * identifier other than 0.
433 BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,
434 st->in_handshake, NULL);
441 cb(s, SSL_CB_ACCEPT_EXIT, ret);
443 cb(s, SSL_CB_CONNECT_EXIT, ret);
449 * Initialise the MSG_FLOW_READING sub-state machine
451 static void init_read_state_machine(SSL *s)
453 OSSL_STATEM *st = &s->statem;
455 st->read_state = READ_STATE_HEADER;
458 static int grow_init_buf(SSL *s, size_t size) {
460 size_t msg_offset = (char *)s->init_msg - s->init_buf->data;
462 if (!BUF_MEM_grow_clean(s->init_buf, (int)size))
465 if (size < msg_offset)
468 s->init_msg = s->init_buf->data + msg_offset;
474 * This function implements the sub-state machine when the message flow is in
475 * MSG_FLOW_READING. The valid sub-states and transitions are:
477 * READ_STATE_HEADER <--+<-------------+
480 * READ_STATE_BODY -----+-->READ_STATE_POST_PROCESS
482 * +----------------------------+
484 * [SUB_STATE_FINISHED]
486 * READ_STATE_HEADER has the responsibility for reading in the message header
487 * and transitioning the state of the handshake state machine.
489 * READ_STATE_BODY reads in the rest of the message and then subsequently
492 * READ_STATE_POST_PROCESS is an optional step that may occur if some post
493 * processing activity performed on the message may block.
495 * Any of the above states could result in an NBIO event occurring in which case
496 * control returns to the calling application. When this function is recalled we
497 * will resume in the same state where we left off.
499 static SUB_STATE_RETURN read_state_machine(SSL *s)
501 OSSL_STATEM *st = &s->statem;
504 int (*transition) (SSL *s, int mt);
506 MSG_PROCESS_RETURN(*process_message) (SSL *s, PACKET *pkt);
507 WORK_STATE(*post_process_message) (SSL *s, WORK_STATE wst);
508 size_t (*max_message_size) (SSL *s);
509 void (*cb) (const SSL *ssl, int type, int val) = NULL;
511 cb = get_callback(s);
514 transition = ossl_statem_server_read_transition;
515 process_message = ossl_statem_server_process_message;
516 max_message_size = ossl_statem_server_max_message_size;
517 post_process_message = ossl_statem_server_post_process_message;
519 transition = ossl_statem_client_read_transition;
520 process_message = ossl_statem_client_process_message;
521 max_message_size = ossl_statem_client_max_message_size;
522 post_process_message = ossl_statem_client_post_process_message;
525 if (st->read_state_first_init) {
527 st->read_state_first_init = 0;
531 switch (st->read_state) {
532 case READ_STATE_HEADER:
533 /* Get the state the peer wants to move to */
534 if (SSL_IS_DTLS(s)) {
536 * In DTLS we get the whole message in one go - header and body
538 ret = dtls_get_message(s, &mt, &len);
540 ret = tls_get_message_header(s, &mt);
544 /* Could be non-blocking IO */
545 return SUB_STATE_ERROR;
549 /* Notify callback of an impending state change */
551 cb(s, SSL_CB_ACCEPT_LOOP, 1);
553 cb(s, SSL_CB_CONNECT_LOOP, 1);
556 * Validate that we are allowed to move to the new state and move
557 * to that state if so
559 if (!transition(s, mt)) {
560 ossl_statem_set_error(s);
561 return SUB_STATE_ERROR;
564 if (s->s3->tmp.message_size > max_message_size(s)) {
565 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
566 SSLerr(SSL_F_READ_STATE_MACHINE, SSL_R_EXCESSIVE_MESSAGE_SIZE);
567 return SUB_STATE_ERROR;
570 /* dtls_get_message already did this */
572 && s->s3->tmp.message_size > 0
573 && !grow_init_buf(s, s->s3->tmp.message_size
574 + SSL3_HM_HEADER_LENGTH)) {
575 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
576 SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_BUF_LIB);
577 return SUB_STATE_ERROR;
580 st->read_state = READ_STATE_BODY;
583 case READ_STATE_BODY:
584 if (!SSL_IS_DTLS(s)) {
585 /* We already got this above for DTLS */
586 ret = tls_get_message_body(s, &len);
588 /* Could be non-blocking IO */
589 return SUB_STATE_ERROR;
594 if (!PACKET_buf_init(&pkt, s->init_msg, len)) {
595 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
596 SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_INTERNAL_ERROR);
597 return SUB_STATE_ERROR;
599 ret = process_message(s, &pkt);
601 /* Discard the packet data */
605 case MSG_PROCESS_ERROR:
606 return SUB_STATE_ERROR;
608 case MSG_PROCESS_FINISHED_READING:
609 if (SSL_IS_DTLS(s)) {
612 return SUB_STATE_FINISHED;
614 case MSG_PROCESS_CONTINUE_PROCESSING:
615 st->read_state = READ_STATE_POST_PROCESS;
616 st->read_state_work = WORK_MORE_A;
620 st->read_state = READ_STATE_HEADER;
625 case READ_STATE_POST_PROCESS:
626 st->read_state_work = post_process_message(s, st->read_state_work);
627 switch (st->read_state_work) {
632 return SUB_STATE_ERROR;
634 case WORK_FINISHED_CONTINUE:
635 st->read_state = READ_STATE_HEADER;
638 case WORK_FINISHED_STOP:
639 if (SSL_IS_DTLS(s)) {
642 return SUB_STATE_FINISHED;
647 /* Shouldn't happen */
648 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
649 SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_INTERNAL_ERROR);
650 ossl_statem_set_error(s);
651 return SUB_STATE_ERROR;
657 * Send a previously constructed message to the peer.
659 static int statem_do_write(SSL *s)
661 OSSL_STATEM *st = &s->statem;
663 if (st->hand_state == TLS_ST_CW_CHANGE
664 || st->hand_state == TLS_ST_SW_CHANGE) {
666 return dtls1_do_write(s, SSL3_RT_CHANGE_CIPHER_SPEC);
668 return ssl3_do_write(s, SSL3_RT_CHANGE_CIPHER_SPEC);
670 return ssl_do_write(s);
675 * Initialise the MSG_FLOW_WRITING sub-state machine
677 static void init_write_state_machine(SSL *s)
679 OSSL_STATEM *st = &s->statem;
681 st->write_state = WRITE_STATE_TRANSITION;
685 * This function implements the sub-state machine when the message flow is in
686 * MSG_FLOW_WRITING. The valid sub-states and transitions are:
688 * +-> WRITE_STATE_TRANSITION ------> [SUB_STATE_FINISHED]
691 * | WRITE_STATE_PRE_WORK -----> [SUB_STATE_END_HANDSHAKE]
697 * | WRITE_STATE_POST_WORK
701 * WRITE_STATE_TRANSITION transitions the state of the handshake state machine
703 * WRITE_STATE_PRE_WORK performs any work necessary to prepare the later
704 * sending of the message. This could result in an NBIO event occurring in
705 * which case control returns to the calling application. When this function
706 * is recalled we will resume in the same state where we left off.
708 * WRITE_STATE_SEND sends the message and performs any work to be done after
711 * WRITE_STATE_POST_WORK performs any work necessary after the sending of the
712 * message has been completed. As for WRITE_STATE_PRE_WORK this could also
713 * result in an NBIO event.
715 static SUB_STATE_RETURN write_state_machine(SSL *s)
717 OSSL_STATEM *st = &s->statem;
719 WRITE_TRAN(*transition) (SSL *s);
720 WORK_STATE(*pre_work) (SSL *s, WORK_STATE wst);
721 WORK_STATE(*post_work) (SSL *s, WORK_STATE wst);
722 int (*get_construct_message_f) (SSL *s, WPACKET *pkt,
723 int (**confunc) (SSL *s, WPACKET *pkt),
725 void (*cb) (const SSL *ssl, int type, int val) = NULL;
726 int (*confunc) (SSL *s, WPACKET *pkt);
730 cb = get_callback(s);
733 transition = ossl_statem_server_write_transition;
734 pre_work = ossl_statem_server_pre_work;
735 post_work = ossl_statem_server_post_work;
736 get_construct_message_f = ossl_statem_server_construct_message;
738 transition = ossl_statem_client_write_transition;
739 pre_work = ossl_statem_client_pre_work;
740 post_work = ossl_statem_client_post_work;
741 get_construct_message_f = ossl_statem_client_construct_message;
745 switch (st->write_state) {
746 case WRITE_STATE_TRANSITION:
748 /* Notify callback of an impending state change */
750 cb(s, SSL_CB_ACCEPT_LOOP, 1);
752 cb(s, SSL_CB_CONNECT_LOOP, 1);
754 switch (transition(s)) {
755 case WRITE_TRAN_CONTINUE:
756 st->write_state = WRITE_STATE_PRE_WORK;
757 st->write_state_work = WORK_MORE_A;
760 case WRITE_TRAN_FINISHED:
761 return SUB_STATE_FINISHED;
764 case WRITE_TRAN_ERROR:
765 return SUB_STATE_ERROR;
769 case WRITE_STATE_PRE_WORK:
770 switch (st->write_state_work = pre_work(s, st->write_state_work)) {
775 return SUB_STATE_ERROR;
777 case WORK_FINISHED_CONTINUE:
778 st->write_state = WRITE_STATE_SEND;
781 case WORK_FINISHED_STOP:
782 return SUB_STATE_END_HANDSHAKE;
784 if (!get_construct_message_f(s, &pkt, &confunc, &mt)) {
785 ossl_statem_set_error(s);
786 return SUB_STATE_ERROR;
788 if (mt == SSL3_MT_DUMMY) {
789 /* Skip construction and sending. This isn't a "real" state */
790 st->write_state = WRITE_STATE_POST_WORK;
791 st->write_state_work = WORK_MORE_A;
794 if (!WPACKET_init(&pkt, s->init_buf)
795 || !ssl_set_handshake_header(s, &pkt, mt)
796 || (confunc != NULL && !confunc(s, &pkt))
797 || !ssl_close_construct_packet(s, &pkt, mt)
798 || !WPACKET_finish(&pkt)) {
799 WPACKET_cleanup(&pkt);
800 ossl_statem_set_error(s);
801 return SUB_STATE_ERROR;
806 case WRITE_STATE_SEND:
807 if (SSL_IS_DTLS(s) && st->use_timer) {
808 dtls1_start_timer(s);
810 ret = statem_do_write(s);
812 return SUB_STATE_ERROR;
814 st->write_state = WRITE_STATE_POST_WORK;
815 st->write_state_work = WORK_MORE_A;
818 case WRITE_STATE_POST_WORK:
819 switch (st->write_state_work = post_work(s, st->write_state_work)) {
824 return SUB_STATE_ERROR;
826 case WORK_FINISHED_CONTINUE:
827 st->write_state = WRITE_STATE_TRANSITION;
830 case WORK_FINISHED_STOP:
831 return SUB_STATE_END_HANDSHAKE;
836 return SUB_STATE_ERROR;
842 * Flush the write BIO
844 int statem_flush(SSL *s)
846 s->rwstate = SSL_WRITING;
847 if (BIO_flush(s->wbio) <= 0) {
850 s->rwstate = SSL_NOTHING;
856 * Called by the record layer to determine whether application data is
857 * allowed to be received in the current handshake state or not.
860 * 1: Yes (application data allowed)
861 * 0: No (application data not allowed)
863 int ossl_statem_app_data_allowed(SSL *s)
865 OSSL_STATEM *st = &s->statem;
867 if (st->state == MSG_FLOW_UNINITED)
870 if (!s->s3->in_read_app_data || (s->s3->total_renegotiations == 0))
875 * If we're a server and we haven't got as far as writing our
876 * ServerHello yet then we allow app data
878 if (st->hand_state == TLS_ST_BEFORE
879 || st->hand_state == TLS_ST_SR_CLNT_HELLO)
883 * If we're a client and we haven't read the ServerHello yet then we
886 if (st->hand_state == TLS_ST_CW_CLNT_HELLO)