#define OSSL_LIBSSL_RECORD_LAYER_PARAM_TLSTREE "tlstree"
#define OSSL_LIBSSL_RECORD_LAYER_PARAM_MAX_FRAG_LEN "max_frag_len"
#define OSSL_LIBSSL_RECORD_LAYER_PARAM_MAX_EARLY_DATA "max_early_data"
+#define OSSL_LIBSSL_RECORD_LAYER_PARAM_BLOCK_PADDING "block_padding"
# ifdef __cplusplus
}
if (!ktls_int_check_supported_cipher(rl, ciph, md, taglen))
return OSSL_RECORD_RETURN_NON_FATAL_ERR;
- /*
- * TODO(RECLAYER): For the write side we need to add a check for
- * use of s->record_padding_cb
- */
-
/* All future data will get encrypted by ktls. Flush the BIO or skip ktls */
if (rl->direction == OSSL_RECORD_DIRECTION_WRITE) {
- if (BIO_flush(rl->bio) <= 0)
- return OSSL_RECORD_RETURN_NON_FATAL_ERR;
+ if (BIO_flush(rl->bio) <= 0)
+ return OSSL_RECORD_RETURN_NON_FATAL_ERR;
+
+ /* KTLS does not support record padding */
+ if (rl->padding != NULL || rl->block_padding > 0)
+ return OSSL_RECORD_RETURN_NON_FATAL_ERR;
}
if (!ktls_configure_crypto(rl->libctx, rl->version, ciph, md, rl->sequence,
/* The amount of early data that we have sent/received */
size_t early_data_count;
+ /* TLSv1.3 record padding */
+ size_t block_padding;
+
/* Only used by SSLv3 */
unsigned char mac_secret[EVP_MAX_MD_SIZE];
return 0;
}
- p = OSSL_PARAM_locate_const(options,
- OSSL_LIBSSL_RECORD_LAYER_READ_BUFFER_LEN);
- if (p != NULL && !OSSL_PARAM_get_size_t(p, &rl->rbuf.default_len)) {
- ERR_raise(ERR_LIB_SSL, SSL_R_FAILED_TO_GET_PARAMETER);
- return 0;
+ if (rl->direction == OSSL_RECORD_DIRECTION_READ) {
+ p = OSSL_PARAM_locate_const(options,
+ OSSL_LIBSSL_RECORD_LAYER_READ_BUFFER_LEN);
+ if (p != NULL && !OSSL_PARAM_get_size_t(p, &rl->rbuf.default_len)) {
+ ERR_raise(ERR_LIB_SSL, SSL_R_FAILED_TO_GET_PARAMETER);
+ return 0;
+ }
+ } else {
+ p = OSSL_PARAM_locate_const(options,
+ OSSL_LIBSSL_RECORD_LAYER_PARAM_BLOCK_PADDING);
+ if (p != NULL && !OSSL_PARAM_get_size_t(p, &rl->block_padding)) {
+ ERR_raise(ERR_LIB_SSL, SSL_R_FAILED_TO_GET_PARAMETER);
+ return 0;
+ }
}
if (rl->level == OSSL_RECORD_PROTECTION_LEVEL_APPLICATION) {
if (rl->padding != NULL) {
padding = rl->padding(rl->cbarg, thistempl->type, rlen);
- } else if (s->block_padding > 0) {
- size_t mask = s->block_padding - 1;
+ } else if (rl->block_padding > 0) {
+ size_t mask = rl->block_padding - 1;
size_t remainder;
/* optimize for power of 2 */
- if ((s->block_padding & mask) == 0)
+ if ((rl->block_padding & mask) == 0)
remainder = rlen & mask;
else
- remainder = rlen % s->block_padding;
+ remainder = rlen % rl->block_padding;
/* don't want to add a block of padding if we don't have to */
if (remainder == 0)
padding = 0;
else
- padding = s->block_padding - remainder;
+ padding = rl->block_padding - remainder;
}
if (padding > 0) {
/* do not allow the record to exceed max plaintext length */
SSL_CONNECTION *s = cbarg;
SSL *ssl = SSL_CONNECTION_GET_SSL(s);
- return s->record_padding_cb(ssl, type, len, s->record_padding_arg);
+ return s->rlayer.record_padding_cb(ssl, type, len,
+ s->rlayer.record_padding_arg);
}
static const OSSL_DISPATCH rlayer_dispatch[] = {
&s->rlayer.default_read_buf_len);
*opts++ = OSSL_PARAM_construct_int(OSSL_LIBSSL_RECORD_LAYER_PARAM_READ_AHEAD,
&s->rlayer.read_ahead);
+ } else {
+ *opts++ = OSSL_PARAM_construct_size_t(OSSL_LIBSSL_RECORD_LAYER_PARAM_BLOCK_PADDING,
+ &s->rlayer.block_padding);
}
*opts = OSSL_PARAM_construct_end();
continue;
break;
case OSSL_FUNC_RLAYER_PADDING:
- if (s->record_padding_cb == NULL)
+ if (s->rlayer.record_padding_cb == NULL)
continue;
break;
default:
unsigned int alert_count;
DTLS_RECORD_LAYER *d;
+ /* TLS1.3 padding callback */
+ size_t (*record_padding_cb)(SSL *s, int type, size_t len, void *arg);
+ void *record_padding_arg;
+ size_t block_padding;
+
/* How many records we have read from the record layer */
size_t num_recs;
/* The next record from the record layer that we need to process */
s->msg_callback_arg = ctx->msg_callback_arg;
s->verify_mode = ctx->verify_mode;
s->not_resumable_session_cb = ctx->not_resumable_session_cb;
- s->record_padding_cb = ctx->record_padding_cb;
- s->record_padding_arg = ctx->record_padding_arg;
- s->block_padding = ctx->block_padding;
+ s->rlayer.record_padding_cb = ctx->record_padding_cb;
+ s->rlayer.record_padding_arg = ctx->record_padding_arg;
+ s->rlayer.block_padding = ctx->block_padding;
s->sid_ctx_length = ctx->sid_ctx_length;
if (!ossl_assert(s->sid_ctx_length <= sizeof(s->sid_ctx)))
goto err;
b = SSL_get_wbio(ssl);
if (b == NULL || !BIO_get_ktls_send(b)) {
- sc->record_padding_cb = cb;
+ sc->rlayer.record_padding_cb = cb;
return 1;
}
return 0;
if (sc == NULL)
return;
- sc->record_padding_arg = arg;
+ sc->rlayer.record_padding_arg = arg;
}
void *SSL_get_record_padding_callback_arg(const SSL *ssl)
if (sc == NULL)
return NULL;
- return sc->record_padding_arg;
+ return sc->rlayer.record_padding_arg;
}
int SSL_set_block_padding(SSL *ssl, size_t block_size)
/* block size of 0 or 1 is basically no padding */
if (block_size == 1)
- sc->block_padding = 0;
+ sc->rlayer.block_padding = 0;
else if (block_size <= SSL3_RT_MAX_PLAIN_LENGTH)
- sc->block_padding = block_size;
+ sc->rlayer.block_padding = block_size;
else
return 0;
return 1;
*/
uint32_t early_data_count;
- /* TLS1.3 padding callback */
- size_t (*record_padding_cb)(SSL *s, int type, size_t len, void *arg);
- void *record_padding_arg;
- size_t block_padding;
-
/* The number of TLS1.3 tickets to automatically send */
size_t num_tickets;
/* The number of TLS1.3 tickets actually sent so far */
goto skip_ktls;
/* ktls does not support record padding */
- if (s->record_padding_cb != NULL)
+ if (s->rlayer.record_padding_cb != NULL || s->rlayer.block_padding > 0)
goto skip_ktls;
/* check that cipher is supported */