X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=ssl%2Fssl_lib.c;h=f169611c017c4b4e2012b86cf82bb2ca742e7b6a;hp=baeb3bbec80c2a7b88166b3ac6b895c907cd004b;hb=69687aa829bc8bdcaf5468eb3dd0ada13700b7aa;hpb=f7e393be4725c33739d46a58de94a06ebdc6e49d diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index baeb3bbec8..f169611c01 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -741,7 +741,7 @@ int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, { /* * A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp shows how - * we can "construct" a session to give us the desired check - ie. to + * we can "construct" a session to give us the desired check - i.e. to * find if there's a session in the hash table that would conflict with * any new session built out of this id/id_len and the ssl_version in use * by this SSL. @@ -1015,6 +1015,7 @@ void SSL_free(SSL *s) #endif OPENSSL_free(s->ext.ocsp.resp); OPENSSL_free(s->ext.alpn); + OPENSSL_free(s->ext.tls13_cookie); OPENSSL_free(s->clienthello); sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free); @@ -1320,7 +1321,7 @@ int SSL_has_pending(const SSL *s) * data. That data may not result in any application data, or we may fail * to parse the records for some reason. */ - if (SSL_pending(s)) + if (RECORD_LAYER_processed_read_pending(&s->rlayer)) return 1; return RECORD_LAYER_read_pending(&s->rlayer); @@ -1605,20 +1606,21 @@ int SSL_read_ex(SSL *s, void *buf, size_t num, size_t *readbytes) return ret; } -int SSL_read_early(SSL *s, void *buf, size_t num, size_t *readbytes) +int SSL_read_early_data(SSL *s, void *buf, size_t num, size_t *readbytes) { int ret; if (!s->server) { - SSLerr(SSL_F_SSL_READ_EARLY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); - return SSL_READ_EARLY_ERROR; + SSLerr(SSL_F_SSL_READ_EARLY_DATA, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return SSL_READ_EARLY_DATA_ERROR; } switch (s->early_data_state) { case SSL_EARLY_DATA_NONE: if (!SSL_in_before(s)) { - SSLerr(SSL_F_SSL_READ_EARLY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); - return SSL_READ_EARLY_ERROR; + SSLerr(SSL_F_SSL_READ_EARLY_DATA, + ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return SSL_READ_EARLY_DATA_ERROR; } /* fall through */ @@ -1628,7 +1630,7 @@ int SSL_read_early(SSL *s, void *buf, size_t num, size_t *readbytes) if (ret <= 0) { /* NBIO or error */ s->early_data_state = SSL_EARLY_DATA_ACCEPT_RETRY; - return SSL_READ_EARLY_ERROR; + return SSL_READ_EARLY_DATA_ERROR; } /* fall through */ @@ -1637,39 +1639,28 @@ int SSL_read_early(SSL *s, void *buf, size_t num, size_t *readbytes) s->early_data_state = SSL_EARLY_DATA_READING; ret = SSL_read_ex(s, buf, num, readbytes); /* - * Record layer will call ssl_end_of_early_data_seen() if we see - * that alert - which updates the early_data_state to - * SSL_EARLY_DATA_FINISHED_READING + * State machine will update early_data_state to + * SSL_EARLY_DATA_FINISHED_READING if we get an EndOfEarlyData + * message */ if (ret > 0 || (ret <= 0 && s->early_data_state != SSL_EARLY_DATA_FINISHED_READING)) { s->early_data_state = SSL_EARLY_DATA_READ_RETRY; - return ret > 0 ? SSL_READ_EARLY_SUCCESS : SSL_READ_EARLY_ERROR; + return ret > 0 ? SSL_READ_EARLY_DATA_SUCCESS + : SSL_READ_EARLY_DATA_ERROR; } } else { s->early_data_state = SSL_EARLY_DATA_FINISHED_READING; } *readbytes = 0; - return SSL_READ_EARLY_FINISH; + return SSL_READ_EARLY_DATA_FINISH; default: - SSLerr(SSL_F_SSL_READ_EARLY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); - return SSL_READ_EARLY_ERROR; + SSLerr(SSL_F_SSL_READ_EARLY_DATA, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return SSL_READ_EARLY_DATA_ERROR; } } -int ssl_end_of_early_data_seen(SSL *s) -{ - if (s->early_data_state == SSL_EARLY_DATA_READING - || s->early_data_state == SSL_EARLY_DATA_READ_RETRY) { - s->early_data_state = SSL_EARLY_DATA_FINISHED_READING; - ossl_statem_finish_early_data(s); - return 1; - } - - return 0; -} - int SSL_get_early_data_status(const SSL *s) { return s->ext.early_data; @@ -1748,15 +1739,9 @@ int ssl_write_internal(SSL *s, const void *buf, size_t num, size_t *written) return -1; } - if (s->early_data_state == SSL_EARLY_DATA_WRITE_RETRY) { - /* - * We're still writing early data. We need to stop that so we can write - * normal data - */ - if (!SSL_write_early_finish(s)) - return 0; - } else if (s->early_data_state == SSL_EARLY_DATA_CONNECT_RETRY - || s->early_data_state == SSL_EARLY_DATA_ACCEPT_RETRY) { + if (s->early_data_state == SSL_EARLY_DATA_CONNECT_RETRY + || s->early_data_state == SSL_EARLY_DATA_ACCEPT_RETRY + || s->early_data_state == SSL_EARLY_DATA_READ_RETRY) { SSLerr(SSL_F_SSL_WRITE_INTERNAL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; } @@ -1812,21 +1797,18 @@ int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written) return ret; } -int SSL_write_early(SSL *s, const void *buf, size_t num, size_t *written) +int SSL_write_early_data(SSL *s, const void *buf, size_t num, size_t *written) { int ret; - if (s->server) { - SSLerr(SSL_F_SSL_WRITE_EARLY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); - return 0; - } - switch (s->early_data_state) { case SSL_EARLY_DATA_NONE: - if (!SSL_in_before(s) + if (s->server + || !SSL_in_before(s) || s->session == NULL || s->session->ext.max_early_data == 0) { - SSLerr(SSL_F_SSL_WRITE_EARLY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + SSLerr(SSL_F_SSL_WRITE_EARLY_DATA, + ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; } /* fall through */ @@ -1847,36 +1829,17 @@ int SSL_write_early(SSL *s, const void *buf, size_t num, size_t *written) s->early_data_state = SSL_EARLY_DATA_WRITE_RETRY; return ret; - default: - SSLerr(SSL_F_SSL_WRITE_EARLY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); - return 0; - } -} - -int SSL_write_early_finish(SSL *s) -{ - int ret; - - if (s->early_data_state != SSL_EARLY_DATA_WRITE_RETRY) { - SSLerr(SSL_F_SSL_WRITE_EARLY_FINISH, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); - return 0; - } + case SSL_EARLY_DATA_READ_RETRY: + /* We are a server writing to an unauthenticated client */ + s->early_data_state = SSL_EARLY_DATA_UNAUTH_WRITING; + ret = SSL_write_ex(s, buf, num, written); + s->early_data_state = SSL_EARLY_DATA_READ_RETRY; + return ret; - s->early_data_state = SSL_EARLY_DATA_WRITING; - ret = ssl3_send_alert(s, SSL3_AL_WARNING, SSL_AD_END_OF_EARLY_DATA); - if (ret <= 0) { - s->early_data_state = SSL_EARLY_DATA_WRITE_RETRY; + default: + SSLerr(SSL_F_SSL_WRITE_EARLY_DATA, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; } - s->early_data_state = SSL_EARLY_DATA_FINISHED_WRITING; - /* - * We set the enc_write_ctx back to NULL because we may end up writing - * in cleartext again if we get a HelloRetryRequest from the server. - */ - EVP_CIPHER_CTX_free(s->enc_write_ctx); - s->enc_write_ctx = NULL; - ossl_statem_set_in_init(s, 1); - return 1; } int SSL_shutdown(SSL *s) @@ -2583,8 +2546,8 @@ void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, } /* - * SSL_get0_alpn_selected gets the selected ALPN protocol (if any) from - * |ssl|. On return it sets |*data| to point to |*len| bytes of protocol name + * SSL_get0_alpn_selected gets the selected ALPN protocol (if any) from |ssl|. + * On return it sets |*data| to point to |*len| bytes of protocol name * (not including the leading length-prefix byte). If the server didn't * respond with a negotiated protocol then |*len| will be zero. */ @@ -3184,10 +3147,7 @@ int SSL_get_error(const SSL *s, int i) } if (SSL_want_write(s)) { - /* - * Access wbio directly - in order to use the buffered bio if - * present - */ + /* Access wbio directly - in order to use the buffered bio if present */ bio = s->wbio; if (BIO_should_write(bio)) return (SSL_ERROR_WANT_WRITE); @@ -3242,21 +3202,7 @@ int SSL_do_handshake(SSL *s) return -1; } - if (s->early_data_state == SSL_EARLY_DATA_WRITE_RETRY - || s->early_data_state == SSL_EARLY_DATA_READ_RETRY) { - /* - * We skip this if we were called via SSL_read_early() or - * SSL_write_early() - */ - if (s->early_data_state == SSL_EARLY_DATA_WRITE_RETRY) { - int edfin; - - edfin = SSL_write_early_finish(s); - if (edfin <= 0) - return edfin; - } - ossl_statem_set_in_init(s, 1); - } + ossl_statem_check_finish_init(s, -1); s->method->ssl_renegotiate_check(s, 0); @@ -3944,7 +3890,7 @@ void SSL_set_not_resumable_session_callback(SSL *ssl, /* * Allocates new EVP_MD_CTX and sets pointer to it into given pointer * variable, freeing EVP_MD_CTX previously stored in that variable, if any. - * If EVP_MD pointer is passed, initializes ctx with this md. + * If EVP_MD pointer is passed, initializes ctx with this |md|. * Returns the newly allocated ctx; */