X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=ssl%2Fstatem%2Fstatem.c;h=e63d0ada0b0c1f780208ffedc2e51ba03786c10d;hb=8af91fd9d08487e0dffb6ccac5f42633c964f3f0;hp=a1807f2a40dce3d489fa316edd789de29324b256;hpb=564547e482406c2d4c56a59e288b3a479dac2d74;p=oweals%2Fopenssl.git diff --git a/ssl/statem/statem.c b/ssl/statem/statem.c index a1807f2a40..e63d0ada0b 100644 --- a/ssl/statem/statem.c +++ b/ssl/statem/statem.c @@ -161,18 +161,53 @@ int ossl_statem_skip_early_data(SSL *s) if (s->statem.hand_state != TLS_ST_SW_HELLO_RETRY_REQUEST) return 0; } else { - if (s->statem.hand_state != TLS_ST_SW_FINISHED) + if (!s->server || s->statem.hand_state != TLS_ST_EARLY_DATA) return 0; } return 1; } -void ossl_statem_check_finish_init(SSL *s, int send) +/* + * Called when we are in SSL_read*(), SSL_write*(), or SSL_accept() + * /SSL_connect()/SSL_do_handshake(). Used to test whether we are in an early + * data state and whether we should attempt to move the handshake on if so. + * |sending| is 1 if we are attempting to send data (SSL_write*()), 0 if we are + * attempting to read data (SSL_read*()), or -1 if we are in SSL_do_handshake() + * or similar. + */ +void ossl_statem_check_finish_init(SSL *s, int sending) { - if ((send && s->statem.hand_state == TLS_ST_CW_PENDING_EARLY_DATA_END) - || (!send && s->statem.hand_state == TLS_ST_CW_EARLY_DATA)) - ossl_statem_set_in_init(s, 1); + if (sending == -1) { + if (s->statem.hand_state == TLS_ST_PENDING_EARLY_DATA_END + || s->statem.hand_state == TLS_ST_EARLY_DATA) { + ossl_statem_set_in_init(s, 1); + if (s->early_data_state == SSL_EARLY_DATA_WRITE_RETRY) { + /* + * SSL_connect() or SSL_do_handshake() has been called directly. + * We don't allow any more writing of early data. + */ + s->early_data_state = SSL_EARLY_DATA_FINISHED_WRITING; + } + } + } else if (!s->server) { + if ((sending && (s->statem.hand_state == TLS_ST_PENDING_EARLY_DATA_END + || s->statem.hand_state == TLS_ST_EARLY_DATA) + && s->early_data_state != SSL_EARLY_DATA_WRITING) + || (!sending && s->statem.hand_state == TLS_ST_EARLY_DATA)) { + ossl_statem_set_in_init(s, 1); + /* + * SSL_write() has been called directly. We don't allow any more + * writing of early data. + */ + if (sending && s->early_data_state == SSL_EARLY_DATA_WRITE_RETRY) + s->early_data_state = SSL_EARLY_DATA_FINISHED_WRITING; + } + } else { + if (s->early_data_state == SSL_EARLY_DATA_FINISHED_READING + && s->statem.hand_state == TLS_ST_EARLY_DATA) + ossl_statem_set_in_init(s, 1); + } } void ossl_statem_set_hello_verify_done(SSL *s) @@ -337,9 +372,7 @@ static int state_machine(SSL *s, int server) goto end; } - if ((SSL_IS_FIRST_HANDSHAKE(s) - && s->early_data_state != SSL_EARLY_DATA_FINISHED_WRITING - && s->early_data_state != SSL_EARLY_DATA_FINISHED_READING) + if ((SSL_in_before(s)) || s->renegotiate) { if (!tls_setup_handshake(s)) { ossl_statem_set_error(s); @@ -744,8 +777,17 @@ static SUB_STATE_RETURN write_state_machine(SSL *s) case WORK_FINISHED_STOP: return SUB_STATE_END_HANDSHAKE; } + if (!get_construct_message_f(s, &pkt, &confunc, &mt)) { + ossl_statem_set_error(s); + return SUB_STATE_ERROR; + } + if (mt == SSL3_MT_DUMMY) { + /* Skip construction and sending. This isn't a "real" state */ + st->write_state = WRITE_STATE_POST_WORK; + st->write_state_work = WORK_MORE_A; + break; + } if (!WPACKET_init(&pkt, s->init_buf) - || !get_construct_message_f(s, &pkt, &confunc, &mt) || !ssl_set_handshake_header(s, &pkt, mt) || (confunc != NULL && !confunc(s, &pkt)) || !ssl_close_construct_packet(s, &pkt, mt)