Skip to content

Commit 8f4524e

Browse files
Merge pull request #6298 from rizlik/dtls13-null-cipher
dtls13: support Authentication and Integrity-Only Cipher Suites
2 parents 10b6105 + 35185e1 commit 8f4524e

3 files changed

Lines changed: 104 additions & 0 deletions

File tree

src/dtls13.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ static int Dtls13EncryptDecryptRecordNumber(WOLFSSL* ssl, byte* seq,
301301
byte mask[DTLS13_RN_MASK_SIZE];
302302
int ret;
303303

304+
#ifdef HAVE_NULL_CIPHER
305+
/* Do not encrypt record numbers with null cipher. See RFC 9150 Sec 9 */
306+
if (ssl->specs.bulk_cipher_algorithm == wolfssl_cipher_null)
307+
return 0;
308+
#endif /*HAVE_NULL_CIPHER */
309+
304310
ret = Dtls13GetRnMask(ssl, ciphertext, mask, dir);
305311
if (ret != 0)
306312
return ret;
@@ -2266,6 +2272,15 @@ int Dtls13SetRecordNumberKeys(WOLFSSL* ssl, enum encrypt_side side)
22662272
}
22672273
#endif /* HAVE_CHACHA */
22682274

2275+
#ifdef HAVE_NULL_CIPHER
2276+
if (ssl->specs.bulk_cipher_algorithm == wolfssl_cipher_null) {
2277+
#ifdef WOLFSSL_DEBUG_TLS
2278+
WOLFSSL_MSG("Skipping Record Number key provisioning with null cipher");
2279+
#endif /* WOLFSSL_DEBUG_TLS */
2280+
return 0;
2281+
}
2282+
#endif /* HAVE_NULL_CIPHER */
2283+
22692284
return NOT_COMPILED_IN;
22702285
}
22712286

tests/api.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65849,6 +65849,74 @@ static int test_dtls13_bad_epoch_ch(void)
6584965849
#endif
6585065850

6585165851

65852+
#if defined(HAVE_NULL_CIPHER) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
65853+
defined(WOLFSSL_DTLS13)
65854+
static byte* test_find_string(const char *string,
65855+
byte *buf, int buf_size)
65856+
{
65857+
int string_size, i;
65858+
65859+
string_size = XSTRLEN(string);
65860+
for (i = 0; i < buf_size - string_size - 1; i++) {
65861+
if (XSTRCMP((char*)&buf[i], string) == 0)
65862+
return &buf[i];
65863+
}
65864+
return NULL;
65865+
}
65866+
65867+
static int test_wolfSSL_dtls13_null_cipher(void)
65868+
{
65869+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
65870+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
65871+
struct test_memio_ctx test_ctx;
65872+
const char *test_str = "test";
65873+
int ret, test_str_size;
65874+
byte buf[255], *ptr;
65875+
65876+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
65877+
test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256";
65878+
ret = test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
65879+
wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method);
65880+
if (ret != 0)
65881+
return TEST_FAIL;
65882+
ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
65883+
if (ret != 0)
65884+
return TEST_FAIL;
65885+
test_str_size = XSTRLEN("test") + 1;
65886+
ret = wolfSSL_write(ssl_c, test_str, test_str_size);
65887+
if (ret != test_str_size)
65888+
return TEST_FAIL;
65889+
ret = wolfSSL_read(ssl_s, buf, sizeof(buf));
65890+
if (ret != test_str_size || XSTRCMP((char*)buf, test_str) != 0)
65891+
return TEST_FAIL;
65892+
65893+
ret = wolfSSL_write(ssl_c, test_str, test_str_size);
65894+
if (ret != test_str_size)
65895+
return TEST_FAIL;
65896+
65897+
/* check that the packet was sent cleartext */
65898+
ptr = test_find_string(test_str, test_ctx.s_buff, test_ctx.s_len);
65899+
if (ptr == NULL)
65900+
return TEST_FAIL;
65901+
/* modify the message */
65902+
*ptr = 'H';
65903+
/* bad messages should be ignored in DTLS */
65904+
ret = wolfSSL_read(ssl_s, buf, sizeof(buf));
65905+
if (ret != -1 || ssl_s->error != WANT_READ)
65906+
return TEST_FAIL;
65907+
65908+
wolfSSL_free(ssl_c);
65909+
wolfSSL_free(ssl_s);
65910+
wolfSSL_CTX_free(ctx_c);
65911+
wolfSSL_CTX_free(ctx_s);
65912+
return TEST_SUCCESS;
65913+
}
65914+
#else
65915+
static int test_wolfSSL_dtls13_null_cipher(void)
65916+
{
65917+
return TEST_SKIPPED;
65918+
}
65919+
#endif
6585265920
/*----------------------------------------------------------------------------*
6585365921
| Main
6585465922
*----------------------------------------------------------------------------*/
@@ -66886,6 +66954,7 @@ TEST_CASE testCases[] = {
6688666954
TEST_DECL(test_harden_no_secure_renegotiation),
6688766955
TEST_DECL(test_override_alt_cert_chain),
6688866956
TEST_DECL(test_dtls13_bad_epoch_ch),
66957+
TEST_DECL(test_wolfSSL_dtls13_null_cipher),
6688966958
/* If at some point a stub get implemented this test should fail indicating
6689066959
* a need to implement a new test case
6689166960
*/

tests/test-dtls13.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,23 @@
270270
-u
271271
-v 4
272272
-l TLS_AES_128_GCM_SHA256
273+
274+
# server DTLSv1.3 Integrity-only SHA256
275+
-u
276+
-v 4
277+
-l TLS13-SHA256-SHA256
278+
279+
# client DTLSv1.3 Integrity-only SHA256
280+
-u
281+
-v 4
282+
-l TLS13-SHA256-SHA256
283+
284+
# server DTSv1.3 Integrity-only SHA384
285+
-u
286+
-v 4
287+
-l TLS13-SHA384-SHA384
288+
289+
# client DTLSv1.3 Integrity-only SHA384
290+
-u
291+
-v 4
292+
-l TLS13-SHA384-SHA384

0 commit comments

Comments
 (0)