Skip to content

Commit 5b5d648

Browse files
committed
Fix write_dup with chacha-poly
1 parent f9bf96d commit 5b5d648

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
@@ -69273,6 +69273,146 @@ static int test_tls_multi_handshakes_one_record(void)
6927369273
return EXPECT_RESULT();
6927469274
}
6927569275

69276+
69277+
static int test_write_dup(void)
69278+
{
69279+
EXPECT_DECLS;
69280+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_WRITE_DUP)
69281+
size_t i, j;
69282+
char hiWorld[] = "dup message";
69283+
char readData[sizeof(hiWorld) + 5];
69284+
struct {
69285+
method_provider client_meth;
69286+
method_provider server_meth;
69287+
const char* version_name;
69288+
int version;
69289+
} methods[] = {
69290+
#ifndef WOLFSSL_NO_TLS12
69291+
{wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2", WOLFSSL_TLSV1_2},
69292+
#endif
69293+
#ifdef WOLFSSL_TLS13
69294+
{wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3", WOLFSSL_TLSV1_3},
69295+
#endif
69296+
};
69297+
struct {
69298+
const char* cipher;
69299+
int version;
69300+
} ciphers[] = {
69301+
/* For simplicity the macros are copied from internal.h */
69302+
/* TLS 1.2 */
69303+
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
69304+
#if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
69305+
#ifndef NO_RSA
69306+
{"ECDHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
69307+
#endif
69308+
#endif
69309+
#if !defined(NO_DH) && !defined(NO_RSA) && !defined(NO_TLS_DH)
69310+
{"DHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
69311+
#endif
69312+
#endif
69313+
#if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
69314+
!defined(NO_RSA) && defined(HAVE_AESGCM) && !defined(NO_TLS_DH)
69315+
#if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
69316+
{"DHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
69317+
#endif
69318+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
69319+
{"DHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
69320+
#endif
69321+
#endif
69322+
#if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
69323+
&& !defined(NO_TLS) && !defined(NO_AES)
69324+
#ifdef HAVE_AESGCM
69325+
#if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
69326+
#ifndef NO_RSA
69327+
{"ECDHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
69328+
#endif
69329+
#endif
69330+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
69331+
#ifndef NO_RSA
69332+
{"ECDHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
69333+
#endif
69334+
#endif
69335+
#endif
69336+
#endif
69337+
/* TLS 1.3 */
69338+
#ifdef WOLFSSL_TLS13
69339+
#ifdef HAVE_AESGCM
69340+
#if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
69341+
{"TLS13-AES128-GCM-SHA256", WOLFSSL_TLSV1_3},
69342+
#endif
69343+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
69344+
{"TLS13-AES256-GCM-SHA384", WOLFSSL_TLSV1_3},
69345+
#endif
69346+
#endif
69347+
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
69348+
#ifndef NO_SHA256
69349+
{"TLS13-CHACHA20-POLY1305-SHA256", WOLFSSL_TLSV1_3},
69350+
#endif
69351+
#endif
69352+
#ifdef HAVE_AESCCM
69353+
#if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
69354+
{"TLS13-AES128-CCM-SHA256", WOLFSSL_TLSV1_3},
69355+
#endif
69356+
#endif
69357+
#endif
69358+
};
69359+
69360+
for (i = 0; i < XELEM_CNT(methods); i++) {
69361+
for (j = 0; j < XELEM_CNT(ciphers) && !EXPECT_FAIL(); j++) {
69362+
struct test_memio_ctx test_ctx;
69363+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
69364+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
69365+
WOLFSSL *ssl_c2 = NULL;
69366+
69367+
if (methods[i].version != ciphers[j].version)
69368+
continue;
69369+
69370+
if (i == 0 && j == 0)
69371+
printf("\n");
69372+
69373+
printf("Testing %s with %s... ", methods[i].version_name,
69374+
ciphers[j].cipher);
69375+
69376+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
69377+
69378+
test_ctx.c_ciphers = test_ctx.s_ciphers = ciphers[j].cipher;
69379+
69380+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
69381+
methods[i].client_meth, methods[i].server_meth), 0);
69382+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
69383+
69384+
ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c));
69385+
ExpectIntEQ(wolfSSL_write(ssl_c, hiWorld, sizeof(hiWorld)),
69386+
WRITE_DUP_WRITE_E);
69387+
ExpectIntEQ(wolfSSL_write(ssl_c2, hiWorld, sizeof(hiWorld)),
69388+
sizeof(hiWorld));
69389+
69390+
ExpectIntEQ(wolfSSL_read(ssl_s, readData, sizeof(readData)),
69391+
sizeof(hiWorld));
69392+
ExpectIntEQ(wolfSSL_write(ssl_s, hiWorld, sizeof(hiWorld)),
69393+
sizeof(hiWorld));
69394+
69395+
ExpectIntEQ(wolfSSL_read(ssl_c2, readData, sizeof(readData)),
69396+
WRITE_DUP_READ_E);
69397+
ExpectIntEQ(wolfSSL_read(ssl_c, readData, sizeof(readData)),
69398+
sizeof(hiWorld));
69399+
69400+
if (EXPECT_SUCCESS())
69401+
printf("ok\n");
69402+
else
69403+
printf("failed\n");
69404+
69405+
wolfSSL_free(ssl_c);
69406+
wolfSSL_free(ssl_c2);
69407+
wolfSSL_free(ssl_s);
69408+
wolfSSL_CTX_free(ctx_c);
69409+
wolfSSL_CTX_free(ctx_s);
69410+
}
69411+
}
69412+
#endif
69413+
return EXPECT_RESULT();
69414+
}
69415+
6927669416
/*----------------------------------------------------------------------------*
6927769417
| Main
6927869418
*----------------------------------------------------------------------------*/
@@ -70577,6 +70717,7 @@ TEST_CASE testCases[] = {
7057770717
TEST_DECL(test_tls13_pq_groups),
7057870718
TEST_DECL(test_tls13_early_data),
7057970719
TEST_DECL(test_tls_multi_handshakes_one_record),
70720+
TEST_DECL(test_write_dup),
7058070721
/* This test needs to stay at the end to clean up any caches allocated. */
7058170722
TEST_DECL(test_wolfSSL_Cleanup)
7058270723
};

0 commit comments

Comments
 (0)