summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorFelipe Pereira Stival <v0idpwn@gmail.com>2026-11-18 17:35:49 -0300
committerPaolo Abeni <pabeni@redhat.com>2026-11-26 11:27:10 +0100
commitd26b244cdec331b987ae2202ef23c92ab43a8afe (patch)
tree1b0bfa28160653aa6fbb4a853a7b39480ef7a606 /tools/testing
parent285ca329ad4bfc32d0f383340c40a40c8157ac7c (diff)
selftests: tls: add a poll test for a queued KeyUpdate
Check that poll() reports a read event when a recv() for data has decrypted and queued a KeyUpdate. Once the KeyUpdate has been read, check that poll() doesn't report a record sent with the new key. Signed-off-by: Felipe Pereira Stival <v0idpwn@gmail.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://patch.msgid.link/20261118-v0idpwn-tls-poll-parked-keyupdate-v1-2-8e25101e7be6@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/net/tls.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c
index bd2797f9f619..59e403b5f12c 100644
--- a/tools/testing/selftests/net/tls.c
+++ b/tools/testing/selftests/net/tls.c
@@ -2421,6 +2421,46 @@ TEST_F(tls, rekey_poll_delay)
}
}
+TEST_F(tls, rekey_poll_queued)
+{
+ char const *test_str = "test_message";
+ struct tls_crypto_info_keys tls12;
+ struct pollfd pfd = { };
+ char buf[100];
+ int send_len;
+
+ if (self->notls)
+ SKIP(return, "no TLS support");
+
+ if (variant->tls_version != TLS_1_3_VERSION)
+ return;
+
+ /* data followed by a KeyUpdate */
+ send_len = strlen(test_str) + 1;
+ EXPECT_EQ(send(self->fd, test_str, send_len, 0), send_len);
+ tls_send_keyupdate(_metadata, self->fd);
+
+ /* reading the data decrypts the KeyUpdate and leaves it queued */
+ EXPECT_EQ(recv(self->cfd, buf, sizeof(buf), MSG_WAITALL), send_len);
+ EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
+
+ /* KeyUpdate hasn't been read, expect cfd to be readable */
+ pfd.fd = self->cfd;
+ pfd.events = POLLIN;
+ EXPECT_EQ(poll(&pfd, 1, 0), 1);
+
+ /* get KeyUpdate */
+ tls_recv_keyupdate(_metadata, self->cfd, 0);
+
+ /* update TX key and send with it */
+ tls_crypto_info_init(variant->tls_version, variant->cipher_type, &tls12, 1);
+ EXPECT_EQ(setsockopt(self->fd, SOL_TLS, TLS_TX, &tls12, tls12.len), 0);
+ EXPECT_EQ(send(self->fd, test_str, send_len, 0), send_len);
+
+ /* key hasn't been updated, expect cfd to be non-readable */
+ EXPECT_EQ(poll(&pfd, 1, 0), 0);
+}
+
struct raw_rec {
unsigned int plain_len;
unsigned char plain_data[100];