Skip to content

Commit 9156b50

Browse files
Merge pull request #9538 from SparkiDev/tls13_dup_ext_alert_code_fix
TLS 1.3: duplicate extension alert code fix
2 parents 95afe9c + d3863e5 commit 9156b50

File tree

3 files changed

+103
-11
lines changed

3 files changed

+103
-11
lines changed

src/internal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35235,6 +35235,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3523535235
case WC_NO_ERR_TRACE(INVALID_PARAMETER):
3523635236
case WC_NO_ERR_TRACE(HRR_COOKIE_ERROR):
3523735237
case WC_NO_ERR_TRACE(BAD_BINDER):
35238+
case WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E):
3523835239
return illegal_parameter;
3523935240
case WC_NO_ERR_TRACE(INCOMPLETE_DATA):
3524035241
return missing_extension;

tests/api/test_tls13.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,3 +2483,92 @@ int test_tls13_ks_missing(void)
24832483
#endif
24842484
return EXPECT_RESULT();
24852485
}
2486+
2487+
#if defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) && \
2488+
defined(HAVE_ECC)
2489+
/* Called when writing. */
2490+
static int DESend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
2491+
{
2492+
(void)ssl;
2493+
(void)buf;
2494+
(void)sz;
2495+
(void)ctx;
2496+
2497+
return sz;
2498+
}
2499+
/* Called when reading. */
2500+
static int DERecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
2501+
{
2502+
WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
2503+
int len = (int)msg->length;
2504+
2505+
(void)ssl;
2506+
(void)sz;
2507+
2508+
/* Pass back as much of message as will fit in buffer. */
2509+
if (len > sz)
2510+
len = sz;
2511+
XMEMCPY(buf, msg->buffer, len);
2512+
/* Move over returned data. */
2513+
msg->buffer += len;
2514+
msg->length -= len;
2515+
2516+
/* Amount actually copied. */
2517+
return len;
2518+
}
2519+
#endif
2520+
2521+
int test_tls13_duplicate_extension(void)
2522+
{
2523+
EXPECT_DECLS;
2524+
#if defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) && \
2525+
defined(HAVE_ECC)
2526+
WOLFSSL_CTX *ctx = NULL;
2527+
WOLFSSL *ssl = NULL;
2528+
byte serverHello[] = {
2529+
0x16, 0x03, 0x03, 0x00, 0x81, 0x02, 0x00, 0x00,
2530+
0x7d, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01,
2531+
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
2532+
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
2533+
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
2534+
0x01, 0x01, 0x01, 0x00, 0x13, 0x01, 0x00, 0x00,
2535+
0x55, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x00,
2536+
0x33, 0x00, 0x45, 0x00, 0x17, 0x00, 0x41, 0x04,
2537+
0x0c, 0x90, 0x1d, 0x42, 0x3c, 0x83, 0x1c, 0xa8,
2538+
0x5e, 0x27, 0xc7, 0x3c, 0x26, 0x3b, 0xa1, 0x32,
2539+
0x72, 0x1b, 0xb9, 0xd7, 0xa8, 0x4c, 0x4f, 0x03,
2540+
0x80, 0xb2, 0xa6, 0x75, 0x6f, 0xd6, 0x01, 0x33,
2541+
0x1c, 0x88, 0x70, 0x23, 0x4d, 0xec, 0x87, 0x85,
2542+
0x04, 0xc1, 0x74, 0x14, 0x4f, 0xa4, 0xb1, 0x4b,
2543+
0x66, 0xa6, 0x51, 0x69, 0x16, 0x06, 0xd8, 0x17,
2544+
0x3e, 0x55, 0xbd, 0x37, 0xe3, 0x81, 0x56, 0x9e,
2545+
0x00, 0x2b, 0x00, 0x02, 0x03, 0x04
2546+
};
2547+
WOLFSSL_BUFFER_INFO msg;
2548+
WOLFSSL_ALERT_HISTORY h;
2549+
2550+
/* Set up wolfSSL context. */
2551+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
2552+
/* Read from 'msg'. */
2553+
wolfSSL_SetIORecv(ctx, DERecv);
2554+
/* No where to send to - dummy sender. */
2555+
wolfSSL_SetIOSend(ctx, DESend);
2556+
2557+
/* Test cipher suite list with many copies of a cipher suite. */
2558+
ExpectNotNull(ssl = wolfSSL_new(ctx));
2559+
msg.buffer = serverHello;
2560+
msg.length = (unsigned int)sizeof(serverHello);
2561+
wolfSSL_SetIOReadCtx(ssl, &msg);
2562+
2563+
ExpectIntEQ(wolfSSL_connect_TLSv13(ssl),
2564+
WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
2565+
ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
2566+
ExpectIntEQ(h.last_tx.code, illegal_parameter);
2567+
ExpectIntEQ(h.last_tx.level, alert_fatal);
2568+
wolfSSL_free(ssl);
2569+
wolfSSL_CTX_free(ctx);
2570+
#endif
2571+
return EXPECT_RESULT();
2572+
}
2573+
2574+

tests/api/test_tls13.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ int test_tls13_same_ch(void);
3434
int test_tls13_hrr_different_cs(void);
3535
int test_tls13_sg_missing(void);
3636
int test_tls13_ks_missing(void);
37+
int test_tls13_duplicate_extension(void);
3738

38-
#define TEST_TLS13_DECLS \
39-
TEST_DECL_GROUP("tls13", test_tls13_apis), \
40-
TEST_DECL_GROUP("tls13", test_tls13_cipher_suites), \
41-
TEST_DECL_GROUP("tls13", test_tls13_bad_psk_binder), \
42-
TEST_DECL_GROUP("tls13", test_tls13_rpk_handshake), \
43-
TEST_DECL_GROUP("tls13", test_tls13_pq_groups), \
44-
TEST_DECL_GROUP("tls13", test_tls13_early_data), \
45-
TEST_DECL_GROUP("tls13", test_tls13_same_ch), \
46-
TEST_DECL_GROUP("tls13", test_tls13_hrr_different_cs), \
47-
TEST_DECL_GROUP("tls13", test_tls13_sg_missing), \
48-
TEST_DECL_GROUP("tls13", test_tls13_ks_missing)
39+
#define TEST_TLS13_DECLS \
40+
TEST_DECL_GROUP("tls13", test_tls13_apis), \
41+
TEST_DECL_GROUP("tls13", test_tls13_cipher_suites), \
42+
TEST_DECL_GROUP("tls13", test_tls13_bad_psk_binder), \
43+
TEST_DECL_GROUP("tls13", test_tls13_rpk_handshake), \
44+
TEST_DECL_GROUP("tls13", test_tls13_pq_groups), \
45+
TEST_DECL_GROUP("tls13", test_tls13_early_data), \
46+
TEST_DECL_GROUP("tls13", test_tls13_same_ch), \
47+
TEST_DECL_GROUP("tls13", test_tls13_hrr_different_cs), \
48+
TEST_DECL_GROUP("tls13", test_tls13_sg_missing), \
49+
TEST_DECL_GROUP("tls13", test_tls13_ks_missing), \
50+
TEST_DECL_GROUP("tls13", test_tls13_duplicate_extension)
4951

5052
#endif /* WOLFCRYPT_TEST_TLS13_H */

0 commit comments

Comments
 (0)