From nobody Mon Nov 15 20:03:53 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 12BCD1889C83; Mon, 15 Nov 2021 20:03:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HtKrn65Ctz3DCn; Mon, 15 Nov 2021 20:03:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5E5D31FE42; Mon, 15 Nov 2021 20:03:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AFK3rwL087793; Mon, 15 Nov 2021 20:03:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AFK3r5a087792; Mon, 15 Nov 2021 20:03:53 GMT (envelope-from git) Date: Mon, 15 Nov 2021 20:03:53 GMT Message-Id: <202111152003.1AFK3r5a087792@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: d1c369f926e7 - main - ktls: Add tests ensuring various invalid cipher suites are rejected. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d1c369f926e7d04354d044cc13d8ecfb3e325636 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=d1c369f926e7d04354d044cc13d8ecfb3e325636 commit d1c369f926e7d04354d044cc13d8ecfb3e325636 Author: John Baldwin AuthorDate: 2021-11-15 19:30:48 +0000 Commit: John Baldwin CommitDate: 2021-11-15 19:30:48 +0000 ktls: Add tests ensuring various invalid cipher suites are rejected. Reviewed by: markj Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D32843 --- tests/sys/kern/ktls_test.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/sys/kern/ktls_test.c b/tests/sys/kern/ktls_test.c index 423ccf65cb0c..ef0f7405b3fd 100644 --- a/tests/sys/kern/ktls_test.c +++ b/tests/sys/kern/ktls_test.c @@ -1187,6 +1187,70 @@ AES_CBC_TESTS(GEN_TRANSMIT_PADDING_TESTS); */ TLS_10_TESTS(GEN_TRANSMIT_EMPTY_FRAGMENT_TEST); +static void +test_ktls_invalid_transmit_cipher_suite(struct tls_enable *en) +{ + int sockets[2]; + + ATF_REQUIRE_MSG(socketpair_tcp(sockets), "failed to create sockets"); + + ATF_REQUIRE(setsockopt(sockets[1], IPPROTO_TCP, TCP_TXTLS_ENABLE, en, + sizeof(*en)) == -1); + ATF_REQUIRE(errno == EINVAL); + + close(sockets[1]); + close(sockets[0]); +} + +#define GEN_INVALID_TRANSMIT_TEST(name, cipher_alg, key_size, auth_alg, \ + minor) \ +ATF_TC_WITHOUT_HEAD(ktls_transmit_invalid_##name); \ +ATF_TC_BODY(ktls_transmit_invalid_##name, tc) \ +{ \ + struct tls_enable en; \ + uint64_t seqno; \ + \ + ATF_REQUIRE_KTLS(); \ + seqno = random(); \ + build_tls_enable(cipher_alg, key_size, auth_alg, minor, seqno, \ + &en); \ + test_ktls_invalid_transmit_cipher_suite(&en); \ + free_tls_enable(&en); \ +} + +#define ADD_INVALID_TRANSMIT_TEST(name, cipher_alg, key_size, auth_alg, \ + minor) \ + ATF_TP_ADD_TC(tp, ktls_transmit_invalid_##name); + +#define INVALID_CIPHER_SUITES(M) \ + M(aes128_cbc_1_0_sha256, CRYPTO_AES_CBC, 128 / 8, \ + CRYPTO_SHA2_256_HMAC, TLS_MINOR_VER_ZERO) \ + M(aes128_cbc_1_0_sha384, CRYPTO_AES_CBC, 128 / 8, \ + CRYPTO_SHA2_384_HMAC, TLS_MINOR_VER_ZERO) \ + M(aes128_gcm_1_0, CRYPTO_AES_NIST_GCM_16, 128 / 8, 0, \ + TLS_MINOR_VER_ZERO) \ + M(chacha20_poly1305_1_0, CRYPTO_CHACHA20_POLY1305, 256 / 8, 0, \ + TLS_MINOR_VER_ZERO) \ + M(aes128_cbc_1_1_sha256, CRYPTO_AES_CBC, 128 / 8, \ + CRYPTO_SHA2_256_HMAC, TLS_MINOR_VER_ONE) \ + M(aes128_cbc_1_1_sha384, CRYPTO_AES_CBC, 128 / 8, \ + CRYPTO_SHA2_384_HMAC, TLS_MINOR_VER_ONE) \ + M(aes128_gcm_1_1, CRYPTO_AES_NIST_GCM_16, 128 / 8, 0, \ + TLS_MINOR_VER_ONE) \ + M(chacha20_poly1305_1_1, CRYPTO_CHACHA20_POLY1305, 256 / 8, 0, \ + TLS_MINOR_VER_ONE) \ + M(aes128_cbc_1_3_sha1, CRYPTO_AES_CBC, 128 / 8, \ + CRYPTO_SHA1_HMAC, TLS_MINOR_VER_THREE) \ + M(aes128_cbc_1_3_sha256, CRYPTO_AES_CBC, 128 / 8, \ + CRYPTO_SHA2_256_HMAC, TLS_MINOR_VER_THREE) \ + M(aes128_cbc_1_3_sha384, CRYPTO_AES_CBC, 128 / 8, \ + CRYPTO_SHA2_384_HMAC, TLS_MINOR_VER_THREE) + +/* + * Ensure that invalid cipher suites are rejected for transmit. + */ +INVALID_CIPHER_SUITES(GEN_INVALID_TRANSMIT_TEST); + ATF_TP_ADD_TCS(tp) { AES_CBC_TESTS(ADD_TRANSMIT_TESTS); @@ -1194,6 +1258,7 @@ ATF_TP_ADD_TCS(tp) CHACHA20_TESTS(ADD_TRANSMIT_TESTS); AES_CBC_TESTS(ADD_TRANSMIT_PADDING_TESTS); TLS_10_TESTS(ADD_TRANSMIT_EMPTY_FRAGMENT_TEST); + INVALID_CIPHER_SUITES(ADD_INVALID_TRANSMIT_TEST); return (atf_no_error()); }