Skip to content

Commit 53bf3bb

Browse files
committed
TLS 1.3: duplicate extension alert code fix
The specification states to return illegal_parameter when a message is syntactically correct but semantically invalid. (RFC 8446 section 6, Paragraph 5)
1 parent 19cba1c commit 53bf3bb

File tree

4 files changed

+108
-10
lines changed

4 files changed

+108
-10
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.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12944,7 +12944,13 @@ static int test_tls_ext_duplicate(void)
1294412944
/* can return duplicate ext error or socket error if the peer closed down
1294512945
* while sending alert */
1294612946
if (wolfSSL_get_error(ssl, 0) != WC_NO_ERR_TRACE(SOCKET_ERROR_E)) {
12947-
ExpectIntEQ(wolfSSL_get_error(ssl, 0), WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E));
12947+
WOLFSSL_ALERT_HISTORY h;
12948+
12949+
ExpectIntEQ(wolfSSL_get_error(ssl, 0),
12950+
WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E));
12951+
ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
12952+
ExpectIntEQ(h.last_tx.code, illegal_parameter);
12953+
ExpectIntEQ(h.last_tx.level, alert_fatal);
1294812954
}
1294912955

1295012956
wolfSSL_free(ssl);

tests/api/test_tls13.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,3 +2318,92 @@ int test_tls13_hrr_different_cs(void)
23182318
#endif
23192319
return EXPECT_RESULT();
23202320
}
2321+
2322+
#if defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_SERVER) && \
2323+
defined(HAVE_ECC)
2324+
/* Called when writing. */
2325+
static int DESend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
2326+
{
2327+
(void)ssl;
2328+
(void)buf;
2329+
(void)sz;
2330+
(void)ctx;
2331+
2332+
return sz;
2333+
}
2334+
/* Called when reading. */
2335+
static int DERecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
2336+
{
2337+
WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
2338+
int len = (int)msg->length;
2339+
2340+
(void)ssl;
2341+
(void)sz;
2342+
2343+
/* Pass back as much of message as will fit in buffer. */
2344+
if (len > sz)
2345+
len = sz;
2346+
XMEMCPY(buf, msg->buffer, len);
2347+
/* Move over returned data. */
2348+
msg->buffer += len;
2349+
msg->length -= len;
2350+
2351+
/* Amount actually copied. */
2352+
return len;
2353+
}
2354+
#endif
2355+
2356+
int test_tls13_duplicate_extension(void)
2357+
{
2358+
EXPECT_DECLS;
2359+
#if defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_SERVER) && \
2360+
defined(HAVE_ECC)
2361+
WOLFSSL_CTX *ctx = NULL;
2362+
WOLFSSL *ssl = NULL;
2363+
byte serverHello[] = {
2364+
0x16, 0x03, 0x03, 0x00, 0x81, 0x02, 0x00, 0x00,
2365+
0x7d, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01,
2366+
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
2367+
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
2368+
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
2369+
0x01, 0x01, 0x01, 0x00, 0x13, 0x01, 0x00, 0x00,
2370+
0x55, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x00,
2371+
0x33, 0x00, 0x45, 0x00, 0x17, 0x00, 0x41, 0x04,
2372+
0x0c, 0x90, 0x1d, 0x42, 0x3c, 0x83, 0x1c, 0xa8,
2373+
0x5e, 0x27, 0xc7, 0x3c, 0x26, 0x3b, 0xa1, 0x32,
2374+
0x72, 0x1b, 0xb9, 0xd7, 0xa8, 0x4c, 0x4f, 0x03,
2375+
0x80, 0xb2, 0xa6, 0x75, 0x6f, 0xd6, 0x01, 0x33,
2376+
0x1c, 0x88, 0x70, 0x23, 0x4d, 0xec, 0x87, 0x85,
2377+
0x04, 0xc1, 0x74, 0x14, 0x4f, 0xa4, 0xb1, 0x4b,
2378+
0x66, 0xa6, 0x51, 0x69, 0x16, 0x06, 0xd8, 0x17,
2379+
0x3e, 0x55, 0xbd, 0x37, 0xe3, 0x81, 0x56, 0x9e,
2380+
0x00, 0x2b, 0x00, 0x02, 0x03, 0x04
2381+
};
2382+
WOLFSSL_BUFFER_INFO msg;
2383+
WOLFSSL_ALERT_HISTORY h;
2384+
2385+
/* Set up wolfSSL context. */
2386+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
2387+
/* Read from 'msg'. */
2388+
wolfSSL_SetIORecv(ctx, DERecv);
2389+
/* No where to send to - dummy sender. */
2390+
wolfSSL_SetIOSend(ctx, DESend);
2391+
2392+
/* Test cipher suite list with many copies of a cipher suite. */
2393+
ExpectNotNull(ssl = wolfSSL_new(ctx));
2394+
msg.buffer = serverHello;
2395+
msg.length = (unsigned int)sizeof(serverHello);
2396+
wolfSSL_SetIOReadCtx(ssl, &msg);
2397+
2398+
ExpectIntEQ(wolfSSL_connect_TLSv13(ssl),
2399+
WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
2400+
ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
2401+
ExpectIntEQ(h.last_tx.code, illegal_parameter);
2402+
ExpectIntEQ(h.last_tx.level, alert_fatal);
2403+
wolfSSL_free(ssl);
2404+
wolfSSL_CTX_free(ctx);
2405+
#endif
2406+
return EXPECT_RESULT();
2407+
}
2408+
2409+

tests/api/test_tls13.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ int test_tls13_pq_groups(void);
3232
int test_tls13_early_data(void);
3333
int test_tls13_same_ch(void);
3434
int test_tls13_hrr_different_cs(void);
35+
int test_tls13_duplicate_extension(void);
3536

36-
#define TEST_TLS13_DECLS \
37-
TEST_DECL_GROUP("tls13", test_tls13_apis), \
38-
TEST_DECL_GROUP("tls13", test_tls13_cipher_suites), \
39-
TEST_DECL_GROUP("tls13", test_tls13_bad_psk_binder), \
40-
TEST_DECL_GROUP("tls13", test_tls13_rpk_handshake), \
41-
TEST_DECL_GROUP("tls13", test_tls13_pq_groups), \
42-
TEST_DECL_GROUP("tls13", test_tls13_early_data), \
43-
TEST_DECL_GROUP("tls13", test_tls13_same_ch), \
44-
TEST_DECL_GROUP("tls13", test_tls13_hrr_different_cs)
37+
#define TEST_TLS13_DECLS \
38+
TEST_DECL_GROUP("tls13", test_tls13_apis), \
39+
TEST_DECL_GROUP("tls13", test_tls13_cipher_suites), \
40+
TEST_DECL_GROUP("tls13", test_tls13_bad_psk_binder), \
41+
TEST_DECL_GROUP("tls13", test_tls13_rpk_handshake), \
42+
TEST_DECL_GROUP("tls13", test_tls13_pq_groups), \
43+
TEST_DECL_GROUP("tls13", test_tls13_early_data), \
44+
TEST_DECL_GROUP("tls13", test_tls13_same_ch), \
45+
TEST_DECL_GROUP("tls13", test_tls13_hrr_different_cs), \
46+
TEST_DECL_GROUP("tls13", test_tls13_duplicate_extension)
4547

4648
#endif /* WOLFCRYPT_TEST_TLS13_H */

0 commit comments

Comments
 (0)