/*
- * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
rl->s = s;
}
-void RECORD_LAYER_clear(RECORD_LAYER *rl)
+int RECORD_LAYER_clear(RECORD_LAYER *rl)
{
+ int ret = 1;
+
+ /* Clear any buffered records we no longer need */
+ while (rl->curr_rec < rl->num_recs)
+ ret &= ssl_release_record(rl->s,
+ &(rl->tlsrecs[rl->curr_rec++]),
+ 0);
+
+
rl->wnum = 0;
memset(rl->handshake_fragment, 0, sizeof(rl->handshake_fragment));
rl->handshake_fragment_len = 0;
rl->wpend_tot = 0;
rl->wpend_type = 0;
- rl->wpend_ret = 0;
rl->wpend_buf = NULL;
+ rl->alert_count = 0;
+ rl->num_recs = 0;
+ rl->curr_rec = 0;
+
+ BIO_free(rl->rrlnext);
+ rl->rrlnext = NULL;
if (rl->rrlmethod != NULL)
rl->rrlmethod->free(rl->rrl); /* Ignore return value */
if (rl->d)
DTLS_RECORD_LAYER_clear(rl);
+
+ return ret;
+}
+
+int RECORD_LAYER_reset(RECORD_LAYER *rl)
+{
+ int ret;
+
+ ret = RECORD_LAYER_clear(rl);
+
+ /* We try and reset both record layers even if one fails */
+ ret &= ssl_set_new_record_layer(rl->s,
+ SSL_CONNECTION_IS_DTLS(rl->s)
+ ? DTLS_ANY_VERSION : TLS_ANY_VERSION,
+ OSSL_RECORD_DIRECTION_READ,
+ OSSL_RECORD_PROTECTION_LEVEL_NONE, NULL, 0,
+ NULL, 0, NULL, 0, NULL, 0, NULL, 0,
+ NID_undef, NULL, NULL, NULL);
+
+ ret &= ssl_set_new_record_layer(rl->s,
+ SSL_CONNECTION_IS_DTLS(rl->s)
+ ? DTLS_ANY_VERSION : TLS_ANY_VERSION,
+ OSSL_RECORD_DIRECTION_WRITE,
+ OSSL_RECORD_PROTECTION_LEVEL_NONE, NULL, 0,
+ NULL, 0, NULL, 0, NULL, 0, NULL, 0,
+ NID_undef, NULL, NULL, NULL);
+
+ /* SSLfatal already called in the event of failure */
+ return ret;
}
/* Checks if we have unprocessed read ahead data pending */
TLS_RECORD *rdata;
pitem *item, *iter;
- iter = pqueue_iterator(sc->rlayer.d->buffered_app_data.q);
+ iter = pqueue_iterator(sc->rlayer.d->buffered_app_data);
while ((item = pqueue_next(&iter)) != NULL) {
rdata = item->data;
num += rdata->length;
return shrt;
}
-static int tls_write_check_pending(SSL_CONNECTION *s, int type,
+static int tls_write_check_pending(SSL_CONNECTION *s, uint8_t type,
const unsigned char *buf, size_t len)
{
if (s->rlayer.wpend_tot == 0)
* Call this to write data in records of type 'type' It will return <= 0 if
* not all data has been sent or non-blocking IO.
*/
-int ssl3_write_bytes(SSL *ssl, int type, const void *buf_, size_t len,
+int ssl3_write_bytes(SSL *ssl, uint8_t type, const void *buf_, size_t len,
size_t *written)
{
const unsigned char *buf = buf_;
/* Retry needed */
i = HANDLE_RLAYER_WRITE_RETURN(s,
s->rlayer.wrlmethod->retry_write_records(s->rlayer.wrl));
- if (i <= 0)
+ if (i <= 0) {
+ s->rlayer.wnum = tot;
return i;
+ }
tot += s->rlayer.wpend_tot;
s->rlayer.wpend_tot = 0;
} /* else no retry required */
s->rlayer.wpend_tot = 0;
s->rlayer.wpend_type = type;
s->rlayer.wpend_buf = buf;
- s->rlayer.wpend_ret = len;
}
if (tot == len) { /* done? */
i = ssl->method->ssl_dispatch_alert(ssl);
if (i <= 0) {
/* SSLfatal() already called if appropriate */
+ s->rlayer.wnum = tot;
return i;
}
/* if it went, fall through and send more stuff */
} else {
ERR_new();
ERR_set_debug(file, line, 0);
+ /*
+ * This reason code is part of the API and may be used by
+ * applications for control flow decisions.
+ */
ossl_statem_fatal(s, SSL_AD_DECODE_ERROR,
SSL_R_UNEXPECTED_EOF_WHILE_READING, NULL);
}
* Return up to 'len' payload bytes received in 'type' records.
* 'type' is one of the following:
*
- * - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
+ * - SSL3_RT_HANDSHAKE (when tls_get_message_header and tls_get_message_body
+ * call us)
* - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us)
* - 0 (during a shutdown, no data has to be returned)
*
* Application data protocol
* none of our business
*/
-int ssl3_read_bytes(SSL *ssl, int type, int *recvd_type, unsigned char *buf,
- size_t len, int peek, size_t *readbytes)
+int ssl3_read_bytes(SSL *ssl, uint8_t type, uint8_t *recvd_type,
+ unsigned char *buf, size_t len,
+ int peek, size_t *readbytes)
{
int i, j, ret;
size_t n, curr_rec, totalbytes;
prev = s->rlayer.rrlnext;
if (SSL_CONNECTION_IS_DTLS(s)
&& level != OSSL_RECORD_PROTECTION_LEVEL_NONE)
- epoch = DTLS_RECORD_LAYER_get_r_epoch(&s->rlayer) + 1; /* new epoch */
+ epoch = dtls1_get_epoch(s, SSL3_CC_READ); /* new epoch */
#ifndef OPENSSL_NO_DGRAM
if (SSL_CONNECTION_IS_DTLS(s))
} else {
if (SSL_CONNECTION_IS_DTLS(s)
&& level != OSSL_RECORD_PROTECTION_LEVEL_NONE)
- epoch = DTLS_RECORD_LAYER_get_w_epoch(&s->rlayer) + 1; /* new epoch */
+ epoch = dtls1_get_epoch(s, SSL3_CC_WRITE); /* new epoch */
}
/*