Skip to content

Commit 71581e3

Browse files
authored
Merge pull request wolfSSL#9098 from julek-wolfssl/fix-test_wolfSSL_tls_export
Fix test_wolfSSL_tls_export
2 parents 00860ba + d26b281 commit 71581e3

File tree

3 files changed

+91
-38
lines changed

3 files changed

+91
-38
lines changed

src/internal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ int wolfSSL_session_import_internal(WOLFSSL* ssl, const unsigned char* buf,
19111911
optSz = DTLS_EXPORT_OPT_SZ_4;
19121912
}
19131913
else {
1914-
optSz = TLS_EXPORT_OPT_SZ;
1914+
optSz = TLS_EXPORT_OPT_SZ_4;
19151915
}
19161916
break;
19171917

tests/api.c

Lines changed: 88 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10956,7 +10956,7 @@ static int test_wolfSSL_dtls_export(void)
1095610956

1095710957
#if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
1095810958
#ifdef WOLFSSL_TLS13
10959-
static const byte canned_client_tls13_session[] = {
10959+
static const byte canned_client_tls13_session_v4[] = {
1096010960
0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x00, 0x00,
1096110961
0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
1096210962
0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x01,
@@ -10995,6 +10995,33 @@ static const byte canned_client_tls13_session[] = {
1099510995
0x00, 0x03
1099610996
};
1099710997

10998+
static const byte canned_client_tls13_session_v5[] = {
10999+
0xa7, 0xa5, 0x01, 0x19, 0x00, 0x42, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80,
11000+
0x04, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x1c, 0x01, 0x00, 0x00, 0x01,
11001+
0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
11002+
0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
11003+
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x01, 0x0a, 0x0f, 0x10,
11004+
0x01, 0x02, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x04,
11005+
0x00, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
11006+
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00,
11007+
0x00, 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4f, 0x18, 0xd8, 0xc1, 0x24,
11008+
0xd8, 0xbb, 0x17, 0x9e, 0x31, 0xa3, 0xf8, 0xa7, 0x3c, 0xba, 0xec, 0xfa,
11009+
0xb4, 0x7f, 0xc5, 0x78, 0xeb, 0x6d, 0xe3, 0x2b, 0x7b, 0x94, 0xbe, 0x20,
11010+
0x11, 0x7e, 0x17, 0x10, 0xa7, 0x10, 0x19, 0xec, 0x62, 0xcc, 0xbe, 0xf5,
11011+
0x01, 0x35, 0x3c, 0xea, 0xef, 0x44, 0x3c, 0x40, 0xa2, 0xbc, 0x18, 0x43,
11012+
0xa1, 0xa1, 0x65, 0x5c, 0x48, 0xe2, 0xf9, 0x38, 0xeb, 0x11, 0x10, 0x72,
11013+
0x7c, 0x78, 0x22, 0x13, 0x3b, 0x19, 0x40, 0xf0, 0x73, 0xbe, 0x96, 0x14,
11014+
0x78, 0x26, 0xb9, 0x6b, 0x2e, 0x72, 0x22, 0x0d, 0x90, 0x94, 0xdd, 0x78,
11015+
0x77, 0xfc, 0x0c, 0x2e, 0x63, 0x6e, 0xf0, 0x0c, 0x35, 0x41, 0xcd, 0xf3,
11016+
0x49, 0x31, 0x08, 0xd0, 0x6f, 0x02, 0x3d, 0xc1, 0xd3, 0xb7, 0xee, 0x3a,
11017+
0xa0, 0x8e, 0xa1, 0x4d, 0xc3, 0x2e, 0x5e, 0x06, 0x00, 0x00, 0x00, 0x00,
11018+
0x00, 0x00, 0x00, 0x00, 0x0c, 0x35, 0x41, 0xcd, 0xf3, 0x49, 0x31, 0x08,
11019+
0xd0, 0x6f, 0x02, 0x3d, 0xc1, 0xd3, 0xb7, 0xee, 0x3a, 0xa0, 0x8e, 0xa1,
11020+
0x4d, 0xc3, 0x2e, 0x5e, 0x06, 0x00, 0x10, 0x00, 0x10, 0x00, 0x0c, 0x00,
11021+
0x10, 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20, 0x28, 0x00, 0x00,
11022+
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03
11023+
};
11024+
1099811025
static const byte canned_server_tls13_session[] = {
1099911026
0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x01, 0x00,
1100011027
0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
@@ -11035,7 +11062,7 @@ static const byte canned_server_tls13_session[] = {
1103511062
};
1103611063
#endif /* WOLFSSL_TLS13 */
1103711064

11038-
static const byte canned_client_session[] = {
11065+
static const byte canned_client_session_v4[] = {
1103911066
0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
1104011067
0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
1104111068
0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01,
@@ -11079,6 +11106,36 @@ static const byte canned_client_session[] = {
1107911106
0x00, 0x03
1108011107
};
1108111108

11109+
static const byte canned_client_session_v5[] = {
11110+
0xa7, 0xa5, 0x01, 0x41, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
11111+
0x02, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x01,
11112+
0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
11113+
0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11114+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x27, 0x0a, 0x0d, 0x10,
11115+
0x01, 0x01, 0x0a, 0x00, 0x05, 0x00, 0x01, 0x01, 0x01, 0x01, 0x03, 0x03,
11116+
0x00, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
11117+
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00,
11118+
0x00, 0x0a, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6d, 0x97, 0x15, 0x6e,
11119+
0x52, 0x27, 0xd6, 0x1d, 0x1d, 0xf5, 0x0d, 0x59, 0xa5, 0xac, 0x2e, 0x8c,
11120+
0x0e, 0xcb, 0x26, 0x1e, 0xe2, 0xce, 0xbb, 0xce, 0xe1, 0x7d, 0xd7, 0xef,
11121+
0xa5, 0x44, 0x80, 0x2a, 0xde, 0xbb, 0x75, 0xb0, 0x1d, 0x75, 0x17, 0x20,
11122+
0x4c, 0x08, 0x05, 0x1b, 0xba, 0x60, 0x1f, 0x6c, 0x91, 0x8c, 0xaa, 0xbb,
11123+
0xe5, 0xa3, 0x0b, 0x12, 0x3e, 0xc0, 0x35, 0x43, 0x1d, 0xe2, 0x10, 0xe2,
11124+
0x02, 0x92, 0x4b, 0x8f, 0x05, 0xa9, 0x4b, 0xcc, 0x90, 0xc3, 0x0e, 0xc2,
11125+
0x0f, 0xe9, 0x33, 0x85, 0x9b, 0x3c, 0x19, 0x21, 0xd5, 0x62, 0xe5, 0xe1,
11126+
0x17, 0x8f, 0x8c, 0x19, 0x52, 0xd8, 0x59, 0x10, 0x2d, 0x20, 0x6f, 0xba,
11127+
0xc1, 0x1c, 0xd1, 0x82, 0xc7, 0x32, 0x1b, 0xbb, 0xcc, 0x30, 0x03, 0xd7,
11128+
0x3a, 0xc8, 0x18, 0xed, 0x58, 0xc8, 0x11, 0xfe, 0x71, 0x9c, 0x71, 0xd8,
11129+
0x6b, 0xe0, 0x25, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11130+
0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11131+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11132+
0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x06,
11133+
0x01, 0x04, 0x08, 0x01, 0x20, 0x28, 0x00, 0x09, 0xe1, 0x50, 0x70, 0x02,
11134+
0x2f, 0x7e, 0xda, 0xbd, 0x40, 0xc5, 0x58, 0x87, 0xce, 0x43, 0xf3, 0xc5,
11135+
0x8f, 0xa1, 0x59, 0x93, 0xef, 0x7e, 0xd3, 0xd0, 0xb5, 0x87, 0x1d, 0x81,
11136+
0x54, 0x14, 0x63, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03
11137+
};
11138+
1108211139

1108311140
static const byte canned_server_session[] = {
1108411141
0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
@@ -11124,7 +11181,6 @@ static const byte canned_server_session[] = {
1112411181
0x00, 0x04
1112511182
};
1112611183

11127-
1112811184
static THREAD_RETURN WOLFSSL_THREAD tls_export_server(void* args)
1112911185
{
1113011186
SOCKET_T sockfd = 0;
@@ -11264,7 +11320,9 @@ static void load_tls13_canned_server(WOLFSSL* ssl)
1126411320

1126511321

1126611322
/* v is for version WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
11267-
static int test_wolfSSL_tls_export_run(int v)
11323+
static int test_wolfSSL_tls_export_run(method_provider server_method,
11324+
method_provider client_method, ssl_callback ssl_ready,
11325+
const byte* clientSession, int clientSessionSz, int cmpSess)
1126811326
{
1126911327
EXPECT_DECLS;
1127011328
SOCKET_T sockfd = 0;
@@ -11274,8 +11332,6 @@ static int test_wolfSSL_tls_export_run(int v)
1127411332
char reply[1024];
1127511333
word32 replySz;
1127611334
int msgSz = (int)XSTRLEN(msg);
11277-
const byte* clientSession = NULL;
11278-
int clientSessionSz = 0;
1127911335

1128011336
tcp_ready ready;
1128111337
func_args server_args;
@@ -11286,6 +11342,8 @@ static int test_wolfSSL_tls_export_run(int v)
1128611342
fdOpenSession(Task_self());
1128711343
#endif
1128811344

11345+
(void)cmpSess;
11346+
1128911347
InitTcpReady(&ready);
1129011348

1129111349
#if defined(USE_WINDOWS_API)
@@ -11295,29 +11353,9 @@ static int test_wolfSSL_tls_export_run(int v)
1129511353

1129611354
XMEMSET(&server_args, 0, sizeof(func_args));
1129711355
XMEMSET(&server_cbf, 0, sizeof(callback_functions));
11298-
switch (v) {
11299-
case WOLFSSL_TLSV1_2:
11300-
server_cbf.method = wolfTLSv1_2_server_method;
11301-
server_cbf.ssl_ready = load_tls12_canned_server;
11302-
11303-
/* setup the client side */
11304-
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
11305-
wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
11306-
clientSession = canned_client_session;
11307-
clientSessionSz = sizeof(canned_client_session);
11308-
break;
11309-
#ifdef WOLFSSL_TLS13
11310-
case WOLFSSL_TLSV1_3:
11311-
server_cbf.method = wolfTLSv1_3_server_method;
11312-
server_cbf.ssl_ready = load_tls13_canned_server;
11313-
11314-
/* setup the client side */
11315-
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
11316-
clientSession = canned_client_tls13_session;
11317-
clientSessionSz = sizeof(canned_client_tls13_session);
11318-
break;
11319-
#endif
11320-
}
11356+
server_cbf.method = server_method;
11357+
server_cbf.ssl_ready = ssl_ready;
11358+
ExpectNotNull(ctx = wolfSSL_CTX_new(client_method()));
1132111359
server_args.callbacks = &server_cbf;
1132211360
server_args.signal = &ready;
1132311361

@@ -11336,8 +11374,11 @@ static int test_wolfSSL_tls_export_run(int v)
1133611374
replySz = sizeof(reply);
1133711375
ExpectIntGT(wolfSSL_tls_export(ssl, (byte*)reply, &replySz), 0);
1133811376
#if !defined(NO_PSK) && defined(HAVE_ANON)
11339-
/* index 20 has is setting if PSK was on and 49 is if anon is allowed */
11340-
ExpectIntEQ(XMEMCMP(reply, clientSession, replySz), 0);
11377+
if (cmpSess) {
11378+
/* index 20 has is setting if PSK was on and 49 is if anon is allowed */
11379+
ExpectIntEQ(replySz, clientSessionSz);
11380+
ExpectBufEQ(reply, clientSession, replySz);
11381+
}
1134111382
#endif
1134211383
wolfSSL_set_fd(ssl, sockfd);
1134311384

@@ -11373,16 +11414,27 @@ static int test_wolfSSL_tls_export_run(int v)
1137311414

1137411415
static int test_wolfSSL_tls_export(void)
1137511416
{
11376-
int res = TEST_SKIPPED;
11417+
EXPECT_DECLS;
1137711418
#if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
11378-
test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_2);
11419+
EXPECT_TEST(test_wolfSSL_tls_export_run(wolfTLSv1_2_server_method,
11420+
wolfTLSv1_2_client_method, load_tls12_canned_server,
11421+
canned_client_session_v4, sizeof(canned_client_session_v4), 0));
11422+
EXPECT_TEST(test_wolfSSL_tls_export_run(wolfTLSv1_2_server_method,
11423+
wolfTLSv1_2_client_method, load_tls12_canned_server,
11424+
canned_client_session_v5, sizeof(canned_client_session_v5), 1));
1137911425
#ifdef WOLFSSL_TLS13
11380-
test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_3);
11426+
EXPECT_TEST(test_wolfSSL_tls_export_run(wolfTLSv1_3_server_method,
11427+
wolfTLSv1_3_client_method, load_tls13_canned_server,
11428+
canned_client_tls13_session_v4, sizeof(canned_client_tls13_session_v4),
11429+
0));
11430+
EXPECT_TEST(test_wolfSSL_tls_export_run(wolfTLSv1_3_server_method,
11431+
wolfTLSv1_3_client_method, load_tls13_canned_server,
11432+
canned_client_tls13_session_v5, sizeof(canned_client_tls13_session_v5),
11433+
1));
1138111434
#endif
11382-
res = TEST_RES_CHECK(1);
1138311435
#endif
1138411436

11385-
return res;
11437+
return EXPECT_RESULT();
1138611438
}
1138711439

1138811440
/*----------------------------------------------------------------------------*

wolfssl/internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,8 @@ enum Misc {
17131713
TLS_EXPORT_PRO = 167,/* wolfSSL protocol for serialized TLS */
17141714
DTLS_EXPORT_OPT_SZ = 62, /* amount of bytes used from Options */
17151715
DTLS_EXPORT_OPT_SZ_4 = 61, /* amount of bytes used from Options */
1716-
TLS_EXPORT_OPT_SZ = 65, /* amount of bytes used from Options */
1716+
TLS_EXPORT_OPT_SZ = 66, /* amount of bytes used from Options */
1717+
TLS_EXPORT_OPT_SZ_4 = 65, /* amount of bytes used from Options */
17171718
DTLS_EXPORT_OPT_SZ_3 = 60, /* amount of bytes used from Options */
17181719
DTLS_EXPORT_KEY_SZ = 325 + (DTLS_SEQ_SZ * 2),
17191720
/* max amount of bytes used from Keys */

0 commit comments

Comments
 (0)