DPDK patches and discussions
 help / color / mirror / Atom feed
From: Aakash Sasidharan <asasidharan@marvell.com>
To: Akhil Goyal <gakhil@marvell.com>, Fan Zhang <fanzhang.oss@gmail.com>
Cc: <jerinj@marvell.com>, <anoobj@marvell.com>,
	<vvelumuri@marvell.com>, <asasidharan@marvell.com>,
	<dev@dpdk.org>
Subject: [PATCH v3 08/21] test/security: unit test to verify zero TLS records
Date: Tue, 12 Mar 2024 23:21:30 +0530	[thread overview]
Message-ID: <20240312175143.1664699-9-asasidharan@marvell.com> (raw)
In-Reply-To: <20240312175143.1664699-1-asasidharan@marvell.com>

From: Vidya Sagar Velumuri <vvelumuri@marvell.com>

Add unit tests to verify the zero len TLS records. Zero len packets are
allowed when content type is app data while zero packet length with
other content type (such as handshake) would result in an error.

Signed-off-by: Vidya Sagar Velumuri <vvelumuri@marvell.com>
---
 app/test/test_cryptodev.c                     | 51 ++++++++++++++++++-
 app/test/test_cryptodev_security_tls_record.c |  5 +-
 app/test/test_cryptodev_security_tls_record.h |  2 +-
 3 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 5cb878b9ba..fa63b9743f 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -11984,6 +11984,9 @@ test_tls_record_proto_all(const struct tls_record_test_flags *flags)
 		payload_len = TLS_RECORD_PLAINTEXT_MIN_LEN;
 		if (flags->nb_segs_in_mbuf)
 			payload_len = RTE_MAX(payload_len, flags->nb_segs_in_mbuf);
+
+		if (flags->zero_len)
+			payload_len = 0;
 again:
 		test_tls_record_td_prepare(sec_alg_list[i].param1, sec_alg_list[i].param2, flags,
 					   td_outb, nb_pkts, payload_len);
@@ -11992,8 +11995,16 @@ test_tls_record_proto_all(const struct tls_record_test_flags *flags)
 		if (ret == TEST_SKIPPED)
 			continue;
 
-		if (ret == TEST_FAILED)
+		if (flags->zero_len &&
+		    ((flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
+		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
+		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE))) {
+			if (ret == TEST_SUCCESS)
+				return TEST_FAILED;
+			goto skip_decrypt;
+		} else if (ret == TEST_FAILED) {
 			return TEST_FAILED;
+		}
 
 		test_tls_record_td_update(td_inb, td_outb, nb_pkts, flags);
 
@@ -12009,6 +12020,7 @@ test_tls_record_proto_all(const struct tls_record_test_flags *flags)
 				return TEST_FAILED;
 		}
 
+skip_decrypt:
 		if (flags->data_walkthrough && (++payload_len <= max_payload_len))
 			goto again;
 
@@ -12123,6 +12135,35 @@ test_tls_record_proto_custom_content_type(void)
 	return test_tls_record_proto_all(&flags);
 }
 
+static int
+test_tls_record_proto_zero_len(void)
+{
+	struct tls_record_test_flags flags = {
+		.zero_len = 1
+	};
+	struct crypto_testsuite_params *ts_params = &testsuite_params;
+	struct rte_cryptodev_info dev_info;
+
+	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
+
+	return test_tls_record_proto_all(&flags);
+}
+
+static int
+test_tls_record_proto_zero_len_non_app(void)
+{
+	struct tls_record_test_flags flags = {
+		.zero_len = 1,
+		.content_type = TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE,
+	};
+	struct crypto_testsuite_params *ts_params = &testsuite_params;
+	struct rte_cryptodev_info dev_info;
+
+	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
+
+	return test_tls_record_proto_all(&flags);
+}
+
 static int
 test_dtls_1_2_record_proto_data_walkthrough(void)
 {
@@ -17251,6 +17292,14 @@ static struct unit_test_suite tls12_record_proto_testsuite  = {
 			"Custom content type",
 			ut_setup_security, ut_teardown,
 			test_tls_record_proto_custom_content_type),
+		TEST_CASE_NAMED_ST(
+			"Zero len TLS record with content type as app",
+			ut_setup_security, ut_teardown,
+			test_tls_record_proto_zero_len),
+		TEST_CASE_NAMED_ST(
+			"Zero len TLS record with content type as ctrl",
+			ut_setup_security, ut_teardown,
+			test_tls_record_proto_zero_len_non_app),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
diff --git a/app/test/test_cryptodev_security_tls_record.c b/app/test/test_cryptodev_security_tls_record.c
index 9a2af259c9..c5410a4c92 100644
--- a/app/test/test_cryptodev_security_tls_record.c
+++ b/app/test/test_cryptodev_security_tls_record.c
@@ -103,13 +103,15 @@ test_tls_record_td_prepare(const struct crypto_param *param1, const struct crypt
 		}
 	}
 
-	if (flags->data_walkthrough) {
+	if (flags->data_walkthrough || flags->zero_len) {
 		test_sec_proto_pattern_set(td->input_text.data, data_len);
 		td->input_text.len = data_len;
 	}
 
 	if (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_CUSTOM)
 		td->app_type = RTE_TLS_TYPE_MAX;
+	else if (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE)
+		td->app_type = RTE_TLS_TYPE_HANDSHAKE;
 
 	tls_pkt_size = td->input_text.len;
 
@@ -232,6 +234,7 @@ test_tls_record_res_d_prepare(const uint8_t *output_text, uint32_t len,
 
 	memcpy(&res_d->input_text.data, output_text, len);
 	res_d->input_text.len = len;
+	res_d->output_text.len = td->input_text.len;
 
 	res_d->tls_record_xform.type = RTE_SECURITY_TLS_SESS_TYPE_READ;
 	if (res_d->aead) {
diff --git a/app/test/test_cryptodev_security_tls_record.h b/app/test/test_cryptodev_security_tls_record.h
index d6c74ce54c..102fbc1e69 100644
--- a/app/test/test_cryptodev_security_tls_record.h
+++ b/app/test/test_cryptodev_security_tls_record.h
@@ -98,6 +98,7 @@ struct tls_record_test_flags {
 	enum rte_security_tls_version tls_version;
 	bool pkt_corruption;
 	enum tls_record_test_content_type content_type;
+	bool zero_len;
 };
 
 extern struct tls_record_test_data tls_test_data_aes_128_gcm_v1;
@@ -140,5 +141,4 @@ void test_tls_record_td_update(struct tls_record_test_data td_inb[],
 
 int test_tls_record_post_process(const struct rte_mbuf *m, const struct tls_record_test_data *td,
 				 struct tls_record_test_data *res_d, bool silent);
-
 #endif
-- 
2.25.1


  parent reply	other threads:[~2024-03-12 17:52 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05  7:21 [PATCH 00/21] Improvements and new test cases Aakash Sasidharan
2024-03-05  7:21 ` [PATCH 01/21] test/security: enable AES-GCM in combined mode TLS Aakash Sasidharan
2024-03-05  7:21 ` [PATCH 02/21] test/security: add TLS 1.2 data walkthrough test Aakash Sasidharan
2024-03-05  7:21 ` [PATCH 03/21] test/security: add DTLS " Aakash Sasidharan
2024-03-05  7:21 ` [PATCH 04/21] test/security: add TLS SG " Aakash Sasidharan
2024-03-05  7:21 ` [PATCH 05/21] test/security: unit test for TLS packet corruption Aakash Sasidharan
2024-03-05  7:21 ` [PATCH 06/21] test/security: unit test for custom content verification Aakash Sasidharan
2024-03-05  7:21 ` [PATCH 07/21] test/cryptodev: allow zero packet length buffers Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 08/21] test/security: unit test to verify zero TLS records Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 09/21] test/security: add unit tests for DTLS-1.2 Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 10/21] test/security: add TLS/DTLS 1.2 AES-256-SHA384 vectors Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 11/21] test/security: add DTLS 1.2 anti-replay tests Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 12/21] test/security: add more DTLS anti-replay window sz Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 13/21] test/crypto: update verification of header Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 14/21] test/crypto: add TLS 1.3 vectors Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 15/21] test/crypto: update framework to verify tls-1.3 Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 16/21] test/crypto: test to verify hdr corruption in TLS Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 17/21] test/crypto: test to verify custom content type " Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 18/21] test/crypto: test to verify zero len record " Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 19/21] test/crypto: unit tests to verify padding " Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 20/21] test/crypto: unit tests for padding in DTLS-1.2 Aakash Sasidharan
2024-03-05  7:22 ` [PATCH 21/21] test/security: add out of place sgl test case for TLS 1.2 Aakash Sasidharan
2024-03-08 13:35   ` Akhil Goyal
2024-03-05 13:23 ` [PATCH 00/21] Improvements and new test cases Anoob Joseph
2024-03-12  7:17 ` [PATCH v2 " Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 01/21] test/security: enable AES-GCM in combined mode TLS Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 02/21] test/security: add TLS 1.2 data walkthrough test Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 03/21] test/security: add DTLS " Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 04/21] test/security: add TLS SG " Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 05/21] test/security: unit test for TLS packet corruption Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 06/21] test/security: unit test for custom content verification Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 07/21] test/cryptodev: allow zero packet length buffers Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 08/21] test/security: unit test to verify zero TLS records Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 09/21] test/security: add unit tests for DTLS-1.2 Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 10/21] test/security: add TLS/DTLS 1.2 AES-256-SHA384 vectors Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 11/21] test/security: add DTLS 1.2 anti-replay tests Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 12/21] test/security: add more DTLS anti-replay window sz Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 13/21] test/crypto: update verification of header Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 14/21] test/crypto: add TLS 1.3 vectors Aakash Sasidharan
2024-03-12  7:17   ` [PATCH v2 15/21] test/crypto: update framework to verify tls-1.3 Aakash Sasidharan
2024-03-12  7:18   ` [PATCH v2 16/21] test/crypto: test to verify hdr corruption in TLS Aakash Sasidharan
2024-03-12  7:18   ` [PATCH v2 17/21] test/crypto: test to verify custom content type " Aakash Sasidharan
2024-03-12  7:18   ` [PATCH v2 18/21] test/crypto: test to verify zero len record " Aakash Sasidharan
2024-03-12  7:18   ` [PATCH v2 19/21] test/crypto: unit tests to verify padding " Aakash Sasidharan
2024-03-12  7:18   ` [PATCH v2 20/21] test/crypto: unit tests for padding in DTLS-1.2 Aakash Sasidharan
2024-03-12  7:18   ` [PATCH v2 21/21] test/security: add out of place sgl test case for TLS 1.2 Aakash Sasidharan
2024-03-12 17:51   ` [PATCH v3 00/21] Improvements and new test cases Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 01/21] test/security: enable AES-GCM in combined mode TLS Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 02/21] test/security: add TLS 1.2 data walkthrough test Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 03/21] test/security: add DTLS " Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 04/21] test/security: add TLS SG " Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 05/21] test/security: unit test for TLS packet corruption Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 06/21] test/security: unit test for custom content verification Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 07/21] test/cryptodev: allow zero packet length buffers Aakash Sasidharan
2024-03-12 17:51     ` Aakash Sasidharan [this message]
2024-03-12 17:51     ` [PATCH v3 09/21] test/security: add unit tests for DTLS-1.2 Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 10/21] test/security: add TLS/DTLS 1.2 AES-256-SHA384 vectors Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 11/21] test/security: add DTLS 1.2 anti-replay tests Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 12/21] test/security: add more DTLS anti-replay window sz Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 13/21] test/crypto: update verification of header Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 14/21] test/crypto: add TLS 1.3 vectors Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 15/21] test/crypto: update framework to verify tls-1.3 Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 16/21] test/crypto: test to verify hdr corruption in TLS Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 17/21] test/crypto: test to verify custom content type " Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 18/21] test/crypto: test to verify zero len record " Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 19/21] test/crypto: unit tests to verify padding " Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 20/21] test/crypto: unit tests for padding in DTLS-1.2 Aakash Sasidharan
2024-03-12 17:51     ` [PATCH v3 21/21] test/security: add out of place sgl test case for TLS 1.2 Aakash Sasidharan
2024-03-13  5:50     ` [PATCH v4 00/21] Improvements and new test cases Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 01/21] test/security: enable AES-GCM in combined mode TLS Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 02/21] test/security: add TLS 1.2 data walkthrough test Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 03/21] test/security: add DTLS " Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 04/21] test/security: add TLS SG " Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 05/21] test/security: unit test for TLS packet corruption Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 06/21] test/security: unit test for custom content verification Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 07/21] test/cryptodev: allow zero packet length buffers Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 08/21] test/security: unit test to verify zero TLS records Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 09/21] test/security: add unit tests for DTLS-1.2 Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 10/21] test/security: add TLS/DTLS 1.2 AES-256-SHA384 vectors Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 11/21] test/security: add DTLS 1.2 anti-replay tests Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 12/21] test/security: add more DTLS anti-replay window sz Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 13/21] test/crypto: update verification of header Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 14/21] test/crypto: add TLS 1.3 vectors Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 15/21] test/crypto: update framework to verify tls-1.3 Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 16/21] test/crypto: test to verify hdr corruption in TLS Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 17/21] test/crypto: test to verify custom content type " Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 18/21] test/crypto: test to verify zero len record " Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 19/21] test/crypto: unit tests to verify padding " Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 20/21] test/crypto: unit tests for padding in DTLS-1.2 Aakash Sasidharan
2024-03-13  5:50       ` [PATCH v4 21/21] test/security: add out of place sgl test case for TLS 1.2 Aakash Sasidharan
2024-03-13 10:58       ` [PATCH v5 00/21] Improvements and new test cases Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 01/21] test/security: enable AES-GCM in combined mode TLS Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 02/21] test/security: add TLS 1.2 data walkthrough test Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 03/21] test/security: add DTLS " Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 04/21] test/security: add TLS SG " Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 05/21] test/security: unit test for TLS packet corruption Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 06/21] test/security: unit test for custom content verification Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 07/21] test/cryptodev: allow zero packet length buffers Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 08/21] test/security: unit test to verify zero TLS records Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 09/21] test/security: add unit tests for DTLS-1.2 Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 10/21] test/security: add TLS/DTLS 1.2 AES-256-SHA384 vectors Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 11/21] test/security: add DTLS 1.2 anti-replay tests Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 12/21] test/security: add more DTLS anti-replay window sz Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 13/21] test/crypto: update verification of header Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 14/21] test/crypto: add TLS 1.3 vectors Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 15/21] test/crypto: update framework to verify tls-1.3 Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 16/21] test/crypto: test to verify hdr corruption in TLS Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 17/21] test/crypto: test to verify custom content type " Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 18/21] test/crypto: test to verify zero len record " Aakash Sasidharan
2024-03-13 10:58         ` [PATCH v5 19/21] test/crypto: unit tests to verify padding " Aakash Sasidharan
2024-03-13 10:59         ` [PATCH v5 20/21] test/crypto: unit tests for padding in DTLS-1.2 Aakash Sasidharan
2024-03-13 10:59         ` [PATCH v5 21/21] test/security: add out of place sgl test case for TLS 1.2 Aakash Sasidharan
2024-03-13 14:25         ` [PATCH v5 00/21] Improvements and new test cases Akhil Goyal
2024-03-15 18:27           ` Patrick Robb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240312175143.1664699-9-asasidharan@marvell.com \
    --to=asasidharan@marvell.com \
    --cc=anoobj@marvell.com \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    --cc=gakhil@marvell.com \
    --cc=jerinj@marvell.com \
    --cc=vvelumuri@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).