Skip to content

Commit dec4caa

Browse files
authored
Merge pull request #7206 from julek-wolfssl/gh/7196
Fix write_dup with chacha-poly
2 parents 91e1fe4 + 5b5d648 commit dec4caa

2 files changed

Lines changed: 153 additions & 0 deletions

File tree

src/ssl.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,18 @@ static int DupSSL(WOLFSSL* dup, WOLFSSL* ssl)
15821582
XMEMCPY(&dup->version, &ssl->version, sizeof(ProtocolVersion));
15831583
XMEMCPY(&dup->chVersion, &ssl->chVersion, sizeof(ProtocolVersion));
15841584

1585+
#ifdef HAVE_ONE_TIME_AUTH
1586+
#ifdef HAVE_POLY1305
1587+
if (ssl->auth.setup && ssl->auth.poly1305 != NULL) {
1588+
dup->auth.poly1305 =
1589+
(Poly1305*)XMALLOC(sizeof(Poly1305), dup->heap, DYNAMIC_TYPE_CIPHER);
1590+
if (dup->auth.poly1305 == NULL)
1591+
return MEMORY_E;
1592+
dup->auth.setup = 1;
1593+
}
1594+
#endif
1595+
#endif
1596+
15851597
/* dup side now owns encrypt/write ciphers */
15861598
XMEMSET(&ssl->encrypt, 0, sizeof(Ciphers));
15871599

tests/api.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69353,6 +69353,146 @@ static int test_tls_multi_handshakes_one_record(void)
6935369353
return EXPECT_RESULT();
6935469354
}
6935569355

69356+
69357+
static int test_write_dup(void)
69358+
{
69359+
EXPECT_DECLS;
69360+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_WRITE_DUP)
69361+
size_t i, j;
69362+
char hiWorld[] = "dup message";
69363+
char readData[sizeof(hiWorld) + 5];
69364+
struct {
69365+
method_provider client_meth;
69366+
method_provider server_meth;
69367+
const char* version_name;
69368+
int version;
69369+
} methods[] = {
69370+
#ifndef WOLFSSL_NO_TLS12
69371+
{wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2", WOLFSSL_TLSV1_2},
69372+
#endif
69373+
#ifdef WOLFSSL_TLS13
69374+
{wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3", WOLFSSL_TLSV1_3},
69375+
#endif
69376+
};
69377+
struct {
69378+
const char* cipher;
69379+
int version;
69380+
} ciphers[] = {
69381+
/* For simplicity the macros are copied from internal.h */
69382+
/* TLS 1.2 */
69383+
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
69384+
#if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
69385+
#ifndef NO_RSA
69386+
{"ECDHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
69387+
#endif
69388+
#endif
69389+
#if !defined(NO_DH) && !defined(NO_RSA) && !defined(NO_TLS_DH)
69390+
{"DHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
69391+
#endif
69392+
#endif
69393+
#if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
69394+
!defined(NO_RSA) && defined(HAVE_AESGCM) && !defined(NO_TLS_DH)
69395+
#if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
69396+
{"DHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
69397+
#endif
69398+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
69399+
{"DHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
69400+
#endif
69401+
#endif
69402+
#if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
69403+
&& !defined(NO_TLS) && !defined(NO_AES)
69404+
#ifdef HAVE_AESGCM
69405+
#if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
69406+
#ifndef NO_RSA
69407+
{"ECDHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
69408+
#endif
69409+
#endif
69410+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
69411+
#ifndef NO_RSA
69412+
{"ECDHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
69413+
#endif
69414+
#endif
69415+
#endif
69416+
#endif
69417+
/* TLS 1.3 */
69418+
#ifdef WOLFSSL_TLS13
69419+
#ifdef HAVE_AESGCM
69420+
#if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
69421+
{"TLS13-AES128-GCM-SHA256", WOLFSSL_TLSV1_3},
69422+
#endif
69423+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
69424+
{"TLS13-AES256-GCM-SHA384", WOLFSSL_TLSV1_3},
69425+
#endif
69426+
#endif
69427+
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
69428+
#ifndef NO_SHA256
69429+
{"TLS13-CHACHA20-POLY1305-SHA256", WOLFSSL_TLSV1_3},
69430+
#endif
69431+
#endif
69432+
#ifdef HAVE_AESCCM
69433+
#if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
69434+
{"TLS13-AES128-CCM-SHA256", WOLFSSL_TLSV1_3},
69435+
#endif
69436+
#endif
69437+
#endif
69438+
};
69439+
69440+
for (i = 0; i < XELEM_CNT(methods); i++) {
69441+
for (j = 0; j < XELEM_CNT(ciphers) && !EXPECT_FAIL(); j++) {
69442+
struct test_memio_ctx test_ctx;
69443+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
69444+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
69445+
WOLFSSL *ssl_c2 = NULL;
69446+
69447+
if (methods[i].version != ciphers[j].version)
69448+
continue;
69449+
69450+
if (i == 0 && j == 0)
69451+
printf("\n");
69452+
69453+
printf("Testing %s with %s... ", methods[i].version_name,
69454+
ciphers[j].cipher);
69455+
69456+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
69457+
69458+
test_ctx.c_ciphers = test_ctx.s_ciphers = ciphers[j].cipher;
69459+
69460+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
69461+
methods[i].client_meth, methods[i].server_meth), 0);
69462+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
69463+
69464+
ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c));
69465+
ExpectIntEQ(wolfSSL_write(ssl_c, hiWorld, sizeof(hiWorld)),
69466+
WRITE_DUP_WRITE_E);
69467+
ExpectIntEQ(wolfSSL_write(ssl_c2, hiWorld, sizeof(hiWorld)),
69468+
sizeof(hiWorld));
69469+
69470+
ExpectIntEQ(wolfSSL_read(ssl_s, readData, sizeof(readData)),
69471+
sizeof(hiWorld));
69472+
ExpectIntEQ(wolfSSL_write(ssl_s, hiWorld, sizeof(hiWorld)),
69473+
sizeof(hiWorld));
69474+
69475+
ExpectIntEQ(wolfSSL_read(ssl_c2, readData, sizeof(readData)),
69476+
WRITE_DUP_READ_E);
69477+
ExpectIntEQ(wolfSSL_read(ssl_c, readData, sizeof(readData)),
69478+
sizeof(hiWorld));
69479+
69480+
if (EXPECT_SUCCESS())
69481+
printf("ok\n");
69482+
else
69483+
printf("failed\n");
69484+
69485+
wolfSSL_free(ssl_c);
69486+
wolfSSL_free(ssl_c2);
69487+
wolfSSL_free(ssl_s);
69488+
wolfSSL_CTX_free(ctx_c);
69489+
wolfSSL_CTX_free(ctx_s);
69490+
}
69491+
}
69492+
#endif
69493+
return EXPECT_RESULT();
69494+
}
69495+
6935669496
/*----------------------------------------------------------------------------*
6935769497
| Main
6935869498
*----------------------------------------------------------------------------*/
@@ -70657,6 +70797,7 @@ TEST_CASE testCases[] = {
7065770797
TEST_DECL(test_tls13_pq_groups),
7065870798
TEST_DECL(test_tls13_early_data),
7065970799
TEST_DECL(test_tls_multi_handshakes_one_record),
70800+
TEST_DECL(test_write_dup),
7066070801
/* This test needs to stay at the end to clean up any caches allocated. */
7066170802
TEST_DECL(test_wolfSSL_Cleanup)
7066270803
};

0 commit comments

Comments
 (0)