diff options
author | Todd Short <tshort@akamai.com> | 2017-04-05 12:35:25 -0400 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2017-05-02 09:44:43 +0100 |
commit | c649d10d3fee9fe22e4ae6bdf7f8117b91b92b03 (patch) | |
tree | e72effbded8ac2531b21ead7c2d95ee26d1652cc /ssl/record | |
parent | 20ee2bf138323c6688b6e8d71d695cf2bd53f857 (diff) |
TLS1.3 Padding
Add padding callback for application control
Standard block_size callback
Documentation and tests included
Configuration file/s_client/s_srver option
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3130)
Diffstat (limited to 'ssl/record')
-rw-r--r-- | ssl/record/rec_layer_s3.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c index 14c6778ae6..43c4a949d7 100644 --- a/ssl/record/rec_layer_s3.c +++ b/ssl/record/rec_layer_s3.c @@ -860,15 +860,44 @@ int do_ssl3_write(SSL *s, int type, const unsigned char *buf, } if (SSL_TREAT_AS_TLS13(s) && s->enc_write_ctx != NULL) { + size_t padding = 0; + if (!WPACKET_put_bytes_u8(thispkt, type)) { SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR); goto err; } SSL3_RECORD_add_length(thiswr, 1); - /* - * TODO(TLS1.3): Padding goes here. Do we need an API to add this? - * For now, use no padding - */ + + /* Add TLS1.3 padding */ + if (s->record_padding_cb != NULL) { + size_t rlen = SSL3_RECORD_get_length(thiswr); + + padding = s->record_padding_cb(s, type, rlen, s->record_padding_arg); + /* do not allow the record to exceed max plaintext length */ + if (padding > (SSL3_RT_MAX_PLAIN_LENGTH - rlen)) + padding = SSL3_RT_MAX_PLAIN_LENGTH - rlen; + } else if (s->block_padding > 0) { + size_t mask = s->block_padding - 1; + size_t remainder; + + /* optimize for power of 2 */ + if ((s->block_padding & mask) == 0) + remainder = SSL3_RECORD_get_length(thiswr) & mask; + else + remainder = SSL3_RECORD_get_length(thiswr) % s->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; + } + if (padding > 0) { + if (!WPACKET_memset(thispkt, 0, padding)) { + SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR); + goto err; + } + SSL3_RECORD_add_length(thiswr, padding); + } } /* |