Latest update - pre9
This commit is contained in:
@@ -912,7 +912,7 @@ static int init_server_name(SSL *s, unsigned int context)
|
||||
|
||||
static int final_server_name(SSL *s, unsigned int context, int sent)
|
||||
{
|
||||
int ret = SSL_TLSEXT_ERR_NOACK, discard;
|
||||
int ret = SSL_TLSEXT_ERR_NOACK;
|
||||
int altmp = SSL_AD_UNRECOGNIZED_NAME;
|
||||
int was_ticket = (SSL_get_options(s) & SSL_OP_NO_TICKET) == 0;
|
||||
|
||||
@@ -960,10 +960,8 @@ static int final_server_name(SSL *s, unsigned int context, int sent)
|
||||
* exceed sess_accept (zero) for the new context.
|
||||
*/
|
||||
if (SSL_IS_FIRST_HANDSHAKE(s) && s->ctx != s->session_ctx) {
|
||||
CRYPTO_atomic_add(&s->ctx->stats.sess_accept, 1, &discard,
|
||||
s->ctx->lock);
|
||||
CRYPTO_atomic_add(&s->session_ctx->stats.sess_accept, -1, &discard,
|
||||
s->session_ctx->lock);
|
||||
tsan_counter(&s->ctx->stats.sess_accept);
|
||||
tsan_counter(&s->session_ctx->stats.sess_accept);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+2
-1
@@ -123,7 +123,8 @@ void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,
|
||||
s->statem.in_init = 1;
|
||||
s->statem.state = MSG_FLOW_ERROR;
|
||||
ERR_put_error(ERR_LIB_SSL, func, reason, file, line);
|
||||
if (al != SSL_AD_NO_ALERT && !s->statem.invalid_enc_write_ctx)
|
||||
if (al != SSL_AD_NO_ALERT
|
||||
&& s->statem.enc_write_state != ENC_WRITE_STATE_INVALID)
|
||||
ssl3_send_alert(s, SSL3_AL_FATAL, al);
|
||||
}
|
||||
|
||||
|
||||
+18
-1
@@ -71,6 +71,22 @@ typedef enum {
|
||||
WRITE_STATE_POST_WORK
|
||||
} WRITE_STATE;
|
||||
|
||||
typedef enum {
|
||||
/* The enc_write_ctx can be used normally */
|
||||
ENC_WRITE_STATE_VALID,
|
||||
/* The enc_write_ctx cannot be used */
|
||||
ENC_WRITE_STATE_INVALID,
|
||||
/* Write alerts in plaintext, but otherwise use the enc_write_ctx */
|
||||
ENC_WRITE_STATE_WRITE_PLAIN_ALERTS
|
||||
} ENC_WRITE_STATES;
|
||||
|
||||
typedef enum {
|
||||
/* The enc_read_ctx can be used normally */
|
||||
ENC_READ_STATE_VALID,
|
||||
/* We may receive encrypted or plaintext alerts */
|
||||
ENC_READ_STATE_ALLOW_PLAIN_ALERTS
|
||||
} ENC_READ_STATES;
|
||||
|
||||
/*****************************************************************************
|
||||
* *
|
||||
* This structure should be considered "opaque" to anything outside of the *
|
||||
@@ -100,7 +116,8 @@ struct ossl_statem_st {
|
||||
/* Should we skip the CertificateVerify message? */
|
||||
unsigned int no_cert_verify;
|
||||
int use_timer;
|
||||
int invalid_enc_write_ctx;
|
||||
ENC_WRITE_STATES enc_write_state;
|
||||
ENC_READ_STATES enc_read_state;
|
||||
};
|
||||
typedef struct ossl_statem_st OSSL_STATEM;
|
||||
|
||||
|
||||
@@ -1409,7 +1409,6 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt)
|
||||
unsigned int compression;
|
||||
unsigned int sversion;
|
||||
unsigned int context;
|
||||
int discard;
|
||||
RAW_EXTENSION *extensions = NULL;
|
||||
#ifndef OPENSSL_NO_COMP
|
||||
SSL_COMP *comp;
|
||||
@@ -1616,8 +1615,7 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt)
|
||||
|| (SSL_IS_TLS13(s)
|
||||
&& s->session->ext.tick_identity
|
||||
!= TLSEXT_PSK_BAD_IDENTITY)) {
|
||||
CRYPTO_atomic_add(&s->session_ctx->stats.sess_miss, 1, &discard,
|
||||
s->session_ctx->lock);
|
||||
tsan_counter(&s->session_ctx->stats.sess_miss);
|
||||
if (!ssl_get_new_session(s, 0)) {
|
||||
/* SSLfatal() already called */
|
||||
goto err;
|
||||
@@ -2647,10 +2645,16 @@ MSG_PROCESS_RETURN tls_process_new_session_ticket(SSL *s, PACKET *pkt)
|
||||
PACKET extpkt;
|
||||
|
||||
if (!PACKET_as_length_prefixed_2(pkt, &extpkt)
|
||||
|| PACKET_remaining(pkt) != 0
|
||||
|| !tls_collect_extensions(s, &extpkt,
|
||||
SSL_EXT_TLS1_3_NEW_SESSION_TICKET,
|
||||
&exts, NULL, 1)
|
||||
|| PACKET_remaining(pkt) != 0) {
|
||||
SSLfatal(s, SSL_AD_DECODE_ERROR,
|
||||
SSL_F_TLS_PROCESS_NEW_SESSION_TICKET,
|
||||
SSL_R_LENGTH_MISMATCH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!tls_collect_extensions(s, &extpkt,
|
||||
SSL_EXT_TLS1_3_NEW_SESSION_TICKET, &exts,
|
||||
NULL, 1)
|
||||
|| !tls_parse_all_extensions(s,
|
||||
SSL_EXT_TLS1_3_NEW_SESSION_TICKET,
|
||||
exts, NULL, 0, 1)) {
|
||||
|
||||
+16
-16
@@ -132,23 +132,18 @@ int tls_setup_handshake(SSL *s)
|
||||
}
|
||||
if (SSL_IS_FIRST_HANDSHAKE(s)) {
|
||||
/* N.B. s->session_ctx == s->ctx here */
|
||||
CRYPTO_atomic_add(&s->session_ctx->stats.sess_accept, 1, &i,
|
||||
s->session_ctx->lock);
|
||||
tsan_counter(&s->session_ctx->stats.sess_accept);
|
||||
} else {
|
||||
/* N.B. s->ctx may not equal s->session_ctx */
|
||||
CRYPTO_atomic_add(&s->ctx->stats.sess_accept_renegotiate, 1, &i,
|
||||
s->ctx->lock);
|
||||
tsan_counter(&s->ctx->stats.sess_accept_renegotiate);
|
||||
|
||||
s->s3->tmp.cert_request = 0;
|
||||
}
|
||||
} else {
|
||||
int discard;
|
||||
if (SSL_IS_FIRST_HANDSHAKE(s))
|
||||
CRYPTO_atomic_add(&s->session_ctx->stats.sess_connect, 1, &discard,
|
||||
s->session_ctx->lock);
|
||||
tsan_counter(&s->session_ctx->stats.sess_connect);
|
||||
else
|
||||
CRYPTO_atomic_add(&s->session_ctx->stats.sess_connect_renegotiate,
|
||||
1, &discard, s->session_ctx->lock);
|
||||
tsan_counter(&s->session_ctx->stats.sess_connect_renegotiate);
|
||||
|
||||
/* mark client_random uninitialized */
|
||||
memset(s->s3->client_random, 0, sizeof(s->s3->client_random));
|
||||
@@ -752,6 +747,12 @@ MSG_PROCESS_RETURN tls_process_finished(SSL *s, PACKET *pkt)
|
||||
|
||||
/* This is a real handshake so make sure we clean it up at the end */
|
||||
if (s->server) {
|
||||
/*
|
||||
* To get this far we must have read encrypted data from the client. We
|
||||
* no longer tolerate unencrypted alerts. This value is ignored if less
|
||||
* than TLSv1.3
|
||||
*/
|
||||
s->statem.enc_read_state = ENC_READ_STATE_VALID;
|
||||
if (s->post_handshake_auth != SSL_PHA_REQUESTED)
|
||||
s->statem.cleanuphand = 1;
|
||||
if (SSL_IS_TLS13(s) && !tls13_save_handshake_digest_for_pha(s)) {
|
||||
@@ -1009,7 +1010,6 @@ unsigned long ssl3_output_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk)
|
||||
*/
|
||||
WORK_STATE tls_finish_handshake(SSL *s, WORK_STATE wst, int clearbufs, int stop)
|
||||
{
|
||||
int discard;
|
||||
void (*cb) (const SSL *ssl, int type, int val) = NULL;
|
||||
|
||||
if (clearbufs) {
|
||||
@@ -1055,8 +1055,7 @@ WORK_STATE tls_finish_handshake(SSL *s, WORK_STATE wst, int clearbufs, int stop)
|
||||
ssl_update_cache(s, SSL_SESS_CACHE_SERVER);
|
||||
|
||||
/* N.B. s->ctx may not equal s->session_ctx */
|
||||
CRYPTO_atomic_add(&s->ctx->stats.sess_accept_good, 1, &discard,
|
||||
s->ctx->lock);
|
||||
tsan_counter(&s->ctx->stats.sess_accept_good);
|
||||
s->handshake_func = ossl_statem_accept;
|
||||
|
||||
if (SSL_IS_DTLS(s) && !s->hit) {
|
||||
@@ -1084,12 +1083,10 @@ WORK_STATE tls_finish_handshake(SSL *s, WORK_STATE wst, int clearbufs, int stop)
|
||||
ssl_update_cache(s, SSL_SESS_CACHE_CLIENT);
|
||||
}
|
||||
if (s->hit)
|
||||
CRYPTO_atomic_add(&s->session_ctx->stats.sess_hit, 1, &discard,
|
||||
s->session_ctx->lock);
|
||||
tsan_counter(&s->session_ctx->stats.sess_hit);
|
||||
|
||||
s->handshake_func = ossl_statem_connect;
|
||||
CRYPTO_atomic_add(&s->session_ctx->stats.sess_connect_good, 1,
|
||||
&discard, s->session_ctx->lock);
|
||||
tsan_counter(&s->session_ctx->stats.sess_connect_good);
|
||||
|
||||
if (SSL_IS_DTLS(s) && s->hit) {
|
||||
/*
|
||||
@@ -1917,6 +1914,9 @@ int ssl_choose_client_version(SSL *s, int version, RAW_EXTENSION *extensions)
|
||||
if (highver != 0 && s->version != vent->version)
|
||||
continue;
|
||||
|
||||
if (highver == 0 && (s->mode & SSL_MODE_SEND_FALLBACK_SCSV) != 0)
|
||||
highver = vent->version;
|
||||
|
||||
method = vent->cmeth();
|
||||
err = ssl_method_error(s, method);
|
||||
if (err != 0) {
|
||||
|
||||
+27
-15
@@ -848,12 +848,7 @@ WORK_STATE ossl_statem_server_post_work(SSL *s, WORK_STATE wst)
|
||||
return WORK_MORE_A;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* TODO(TLS1.3): This actually causes a problem. We don't yet know
|
||||
* whether the next record we are going to receive is an unencrypted
|
||||
* alert, or an encrypted handshake message. We're going to need
|
||||
* something clever in the record layer for this.
|
||||
*/
|
||||
|
||||
if (SSL_IS_TLS13(s)) {
|
||||
if (!s->method->ssl3_enc->setup_key_block(s)
|
||||
|| !s->method->ssl3_enc->change_cipher_state(s,
|
||||
@@ -868,6 +863,12 @@ WORK_STATE ossl_statem_server_post_work(SSL *s, WORK_STATE wst)
|
||||
/* SSLfatal() already called */
|
||||
return WORK_ERROR;
|
||||
}
|
||||
/*
|
||||
* We don't yet know whether the next record we are going to receive
|
||||
* is an unencrypted alert, an encrypted alert, or an encrypted
|
||||
* handshake message. We temporarily tolerate unencrypted alerts.
|
||||
*/
|
||||
s->statem.enc_read_state = ENC_READ_STATE_ALLOW_PLAIN_ALERTS;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2371,15 +2372,19 @@ int tls_construct_server_hello(SSL *s, WPACKET *pkt)
|
||||
|
||||
if (!WPACKET_sub_memcpy_u8(pkt, session_id, sl)
|
||||
|| !s->method->put_cipher_by_char(s->s3->tmp.new_cipher, pkt, &len)
|
||||
|| !WPACKET_put_bytes_u8(pkt, compm)
|
||||
|| !tls_construct_extensions(s, pkt,
|
||||
s->hello_retry_request
|
||||
== SSL_HRR_PENDING
|
||||
? SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST
|
||||
: (SSL_IS_TLS13(s)
|
||||
? SSL_EXT_TLS1_3_SERVER_HELLO
|
||||
: SSL_EXT_TLS1_2_SERVER_HELLO),
|
||||
NULL, 0)) {
|
||||
|| !WPACKET_put_bytes_u8(pkt, compm)) {
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_SERVER_HELLO,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!tls_construct_extensions(s, pkt,
|
||||
s->hello_retry_request == SSL_HRR_PENDING
|
||||
? SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST
|
||||
: (SSL_IS_TLS13(s)
|
||||
? SSL_EXT_TLS1_3_SERVER_HELLO
|
||||
: SSL_EXT_TLS1_2_SERVER_HELLO),
|
||||
NULL, 0)) {
|
||||
/* SSLfatal() already called */
|
||||
return 0;
|
||||
}
|
||||
@@ -3520,6 +3525,13 @@ MSG_PROCESS_RETURN tls_process_client_certificate(SSL *s, PACKET *pkt)
|
||||
size_t chainidx;
|
||||
SSL_SESSION *new_sess = NULL;
|
||||
|
||||
/*
|
||||
* To get this far we must have read encrypted data from the client. We no
|
||||
* longer tolerate unencrypted alerts. This value is ignored if less than
|
||||
* TLSv1.3
|
||||
*/
|
||||
s->statem.enc_read_state = ENC_READ_STATE_VALID;
|
||||
|
||||
if ((sk = sk_X509_new_null()) == NULL) {
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CLIENT_CERTIFICATE,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
|
||||
Reference in New Issue
Block a user