Skip to content

Commit e8e6dfc

Browse files
committed
handshake: support record size limit extension
RFC 8449 [1] Section 4 defines the record_size_limit TLS extension, which allows peers to negotiate a maximum plaintext record size during the TLS handshake. The value must be between 64 bytes and 16,384 bytes (2^14). If a TLS endpoint receives a record larger than its advertised limit, it must send a fatal record_overflow alert. This patch adds support for extracting the record size limit value from the gnutls session and passing it to the kernel. This is to be used by the kernel at the tls layer limit outgoing records to the maximum record size limit as specified by the endpoint. [1] https://www.rfc-editor.org/rfc/rfc8449#section-4 Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
1 parent 89e80e0 commit e8e6dfc

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/tlshd/handshake.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static void tlshd_save_nagle(gnutls_session_t session, int *saved)
8080
void tlshd_start_tls_handshake(gnutls_session_t session,
8181
struct tlshd_handshake_parms *parms)
8282
{
83+
ssize_t record_size_limit;
8384
int saved, ret;
8485
char *desc;
8586

@@ -112,6 +113,11 @@ void tlshd_start_tls_handshake(gnutls_session_t session,
112113
gnutls_free(desc);
113114

114115
parms->session_status = tlshd_initialize_ktls(session);
116+
record_size_limit = gnutls_record_get_record_size_limit(session);
117+
if (record_size_limit <= 0)
118+
tlshd_log_notice("Inavlid Record size limit: %zd\n", record_size_limit);
119+
else
120+
parms->record_size_limit = (uint32_t)record_size_limit;
115121
}
116122

117123
/**

src/tlshd/netlink.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ static const struct tlshd_handshake_parms tlshd_default_handshake_parms = {
331331
.peerids = NULL,
332332
.remote_peerids = NULL,
333333
.msg_status = 0,
334+
.record_size_limit = 0,
334335
.session_status = EIO,
335336
};
336337

@@ -505,6 +506,12 @@ void tlshd_genl_done(struct tlshd_handshake_parms *parms)
505506
if (err < 0)
506507
goto out_free;
507508

509+
err = nla_put_u32(msg, HANDSHAKE_A_DONE_RECORD_SIZE_LIMIT, parms->record_size_limit);
510+
if (err < 0) {
511+
tlshd_log_nl_error("nla_put record_size_limit", err);
512+
goto out_free;
513+
}
514+
508515
sendit:
509516
if (tlshd_delay_done) {
510517
/* Undocumented tlshd.conf parameter:

src/tlshd/netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum {
5555
HANDSHAKE_A_DONE_STATUS = 1,
5656
HANDSHAKE_A_DONE_SOCKFD,
5757
HANDSHAKE_A_DONE_REMOTE_AUTH,
58+
HANDSHAKE_A_DONE_RECORD_SIZE_LIMIT,
5859

5960
__HANDSHAKE_A_DONE_MAX,
6061
HANDSHAKE_A_DONE_MAX = (__HANDSHAKE_A_DONE_MAX - 1)

src/tlshd/tlshd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct tlshd_handshake_parms {
4141
GArray *peerids;
4242
GArray *remote_peerids;
4343
int msg_status;
44+
uint32_t record_size_limit;
4445

4546
unsigned int session_status;
4647
};

0 commit comments

Comments
 (0)