Skip to content

Commit 5efc4a7

Browse files
committed
Fix tests
1 parent 3bdb43e commit 5efc4a7

File tree

2 files changed

+107
-81
lines changed

2 files changed

+107
-81
lines changed

src/internal.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6669,9 +6669,11 @@ int InitSSL_Suites(WOLFSSL* ssl)
66696669
byte haveAnon = 0;
66706670
byte haveRSA = 0;
66716671
byte haveMcast = 0;
6672+
byte haveCertSetupCb = 0;
66726673

66736674
(void)haveAnon; /* Squash unused var warnings */
66746675
(void)haveMcast;
6676+
(void)haveCertSetupCb;
66756677

66766678
if (!ssl)
66776679
return BAD_FUNC_ARG;
@@ -6690,6 +6692,10 @@ int InitSSL_Suites(WOLFSSL* ssl)
66906692
haveMcast = (byte)ssl->options.haveMcast;
66916693
#endif /* WOLFSSL_MULTICAST */
66926694
#endif /* !NO_CERTS && !WOLFSSL_SESSION_EXPORT */
6695+
#if defined(WOLFSSL_TLS13) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA)
6696+
if (ssl->ctx->certSetupCb != NULL)
6697+
haveCertSetupCb = 1;
6698+
#endif /* WOLFSSL_TLS13 && !NO_CERTS && OPENSSL_EXTRA */
66936699

66946700
#ifdef WOLFSSL_EARLY_DATA
66956701
if (ssl->options.side == WOLFSSL_SERVER_END)
@@ -6717,10 +6723,11 @@ int InitSSL_Suites(WOLFSSL* ssl)
67176723
}
67186724

67196725
#if !defined(NO_CERTS) && !defined(WOLFSSL_SESSION_EXPORT)
6720-
/* make sure server has cert and key unless using PSK, Anon, or
6721-
* Multicast. This should be true even if just switching ssl ctx */
6726+
/* make sure server has cert and key unless using PSK, Anon,
6727+
* Multicast or cert setup callback. This should be true even if just
6728+
* switching ssl ctx */
67226729
if (ssl->options.side == WOLFSSL_SERVER_END &&
6723-
!havePSK && !haveAnon && !haveMcast) {
6730+
!havePSK && !haveAnon && !haveMcast && !haveCertSetupCb) {
67246731

67256732
/* server certificate must be loaded */
67266733
if (!ssl->buffers.certificate || !ssl->buffers.certificate->buffer) {

tests/api/test_tls_ext.c

Lines changed: 97 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ int test_wolfSSL_DisableExtendedMasterSecret(void)
129129
}
130130

131131

132+
#if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
133+
!defined(WOLFSSL_NO_CA_NAMES) && !defined(NO_BIO) && \
134+
!defined(NO_CERTS) && !defined(NO_TLS) && (defined(OPENSSL_EXTRA) || \
135+
defined(OPENSSL_EXTRA_X509_SMALL)) && (defined(WOLFSSL_TLS13) || \
136+
(!defined(WOLFSSL_NO_TLS12) && (defined(OPENSSL_ALL) || \
137+
defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY)))) && \
138+
!defined(SINGLE_THREADED) && defined(SESSION_CERTS)
132139
struct client_cb_arg {
133140
WOLF_STACK_OF(X509_NAME) *names1;
134141
WOLF_STACK_OF(X509_NAME) *names2;
@@ -145,13 +152,16 @@ static int certificate_authorities_client_cb(WOLFSSL *ssl, void *_arg) {
145152
return 0;
146153
return 1;
147154
}
155+
#endif
148156

149157
int test_certificate_authorities_certificate_request(void) {
150158
EXPECT_DECLS;
151159
#if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
152160
!defined(WOLFSSL_NO_CA_NAMES) && !defined(NO_BIO) && \
153-
!defined(NO_CERTS) && (defined(OPENSSL_EXTRA) || \
154-
defined(OPENSSL_EXTRA_SMALL))
161+
!defined(NO_CERTS) && !defined(NO_TLS) && (defined(OPENSSL_EXTRA) || \
162+
defined(OPENSSL_EXTRA_X509_SMALL)) && (defined(WOLFSSL_TLS13) || \
163+
(!defined(WOLFSSL_NO_TLS12) && (defined(OPENSSL_ALL) || \
164+
defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY))))
155165
struct test_params {
156166
method_provider client_meth;
157167
method_provider server_meth;
@@ -161,24 +171,29 @@ int test_certificate_authorities_certificate_request(void) {
161171
/* TLS 1.3 uses certificate_authorities extension */
162172
{wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, 0},
163173
#endif
164-
#ifndef WOLFSSL_NO_TLS12
174+
#if !defined(WOLFSSL_NO_TLS12) && (defined(OPENSSL_ALL) || \
175+
defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY))
165176
/* TLS 1.2 directly embeds CA names in CertificateRequest */
166177
{wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, 0},
167178
#endif
168179
#ifdef WOLFSSL_DTLS13
169180
{wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, 1},
170181
#endif
171-
#ifdef WOLFSSL_DTLS
182+
#if defined(WOLFSSL_DTLS) && (defined(OPENSSL_ALL) || \
183+
defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY))
172184
{wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, 1},
173185
#endif
174186
};
175187
size_t i;
176188

177189
for (i = 0; i < sizeof(params) / sizeof(*params); i++) {
178-
WOLFSSL_CTX *ctx;
179-
WOLFSSL *ssl;
190+
WOLFSSL_CTX *ctx = NULL;
191+
WOLFSSL *ssl = NULL;
180192
WOLF_STACK_OF(X509_NAME) *names1 = NULL, *names2 = NULL;
181-
X509_NAME *name;
193+
X509_NAME *name = NULL;
194+
195+
if (EXPECT_FAIL())
196+
break;
182197

183198
ExpectNotNull(ctx = wolfSSL_CTX_new(params[i].server_meth()));
184199

@@ -192,6 +207,7 @@ int test_certificate_authorities_certificate_request(void) {
192207
wolfSSL_X509_NAME_free(name);
193208
name = NULL;
194209
}
210+
wolfSSL_sk_X509_NAME_free(names2);
195211
names2 = wolfSSL_load_client_CA_file(caCertFile);
196212
ExpectNotNull(names2);
197213

@@ -228,6 +244,7 @@ int test_certificate_authorities_certificate_request(void) {
228244
wolfSSL_X509_NAME_free(name);
229245
name = NULL;
230246
}
247+
wolfSSL_sk_X509_NAME_free(names2);
231248
names2 = wolfSSL_load_client_CA_file(caCertFile);
232249
ExpectNotNull(names2);
233250

@@ -265,12 +282,6 @@ int test_certificate_authorities_certificate_request(void) {
265282
cliCertFile, NULL));
266283

267284
start_thread(test_server_nofail, &server_args, &server_thread);
268-
wait_tcp_ready(&server_args);
269-
270-
tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port,
271-
params[i].doUdp, 0, NULL);
272-
if (params[i].doUdp)
273-
udp_connect(&sockfd, wolfSSLIP, server_args.signal->port);
274285

275286
ExpectNotNull(ctx_client = wolfSSL_CTX_new(
276287
params[i].client_meth()));
@@ -281,6 +292,11 @@ int test_certificate_authorities_certificate_request(void) {
281292
certificate_authorities_client_cb, &client_cb_arg);
282293

283294
ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
295+
296+
wait_tcp_ready(&server_args);
297+
tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port,
298+
params[i].doUdp, 0, ssl_client);
299+
284300
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl_client, sockfd));
285301
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_connect(ssl_client));
286302

@@ -307,6 +323,11 @@ int test_certificate_authorities_certificate_request(void) {
307323
}
308324

309325

326+
#if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
327+
!defined(WOLFSSL_NO_CA_NAMES) && !defined(NO_BIO) && \
328+
!defined(NO_CERTS) && defined(WOLFSSL_TLS13) && (defined(OPENSSL_EXTRA) || \
329+
defined(OPENSSL_EXTRA_X509_SMALL)) && \
330+
!defined(SINGLE_THREADED) && defined(SESSION_CERTS)
310331
static int certificate_authorities_server_cb(WOLFSSL *ssl, void *_arg) {
311332
int *names_num = (int *)_arg;
312333
WOLF_STACK_OF(X509_NAME) *names = wolfSSL_get0_peer_CA_list(ssl);
@@ -317,13 +338,15 @@ static int certificate_authorities_server_cb(WOLFSSL *ssl, void *_arg) {
317338
return 0;
318339
return 1;
319340
}
341+
#endif
320342

321343
int test_certificate_authorities_client_hello(void) {
322344
EXPECT_DECLS;
323345
#if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
324346
!defined(WOLFSSL_NO_CA_NAMES) && !defined(NO_BIO) && \
325-
!defined(NO_CERTS) && (defined(OPENSSL_EXTRA) || \
326-
defined(OPENSSL_EXTRA_SMALL))
347+
!defined(NO_CERTS) && defined(WOLFSSL_TLS13) && (defined(OPENSSL_EXTRA) || \
348+
defined(OPENSSL_EXTRA_X509_SMALL)) && \
349+
!defined(SINGLE_THREADED) && defined(SESSION_CERTS)
327350

328351
struct test_params {
329352
method_provider client_meth;
@@ -341,88 +364,84 @@ int test_certificate_authorities_client_hello(void) {
341364
size_t i;
342365

343366
for (i = 0; i < sizeof(params) / sizeof(*params); i++) {
344-
WOLFSSL_CTX *ctx;
367+
WOLFSSL_CTX *ctx = NULL;
345368
int server_cb_arg;
369+
tcp_ready ready;
370+
func_args server_args;
371+
callback_functions server_cb;
372+
THREAD_TYPE server_thread;
373+
WOLFSSL *ssl_client = NULL;
374+
WOLFSSL_CTX *ctx_client = NULL;
375+
SOCKET_T sockfd = 0;
376+
WOLF_STACK_OF(X509_NAME) *names1 = NULL, *names2 = NULL;
377+
X509_NAME *name = NULL;
378+
379+
if (EXPECT_FAIL())
380+
break;
346381

347382
ExpectNotNull(ctx = wolfSSL_CTX_new(params[i].server_meth()));
348383
wolfSSL_CTX_set_cert_cb(ctx, certificate_authorities_server_cb,
349384
&server_cb_arg);
350385

351-
#if !defined(SINGLE_THREADED) && defined(SESSION_CERTS)
352-
{
353-
tcp_ready ready;
354-
func_args server_args;
355-
callback_functions server_cb;
356-
THREAD_TYPE server_thread;
357-
WOLFSSL *ssl_client = NULL;
358-
WOLFSSL_CTX *ctx_client = NULL;
359-
SOCKET_T sockfd = 0;
360-
WOLF_STACK_OF(X509_NAME) *names1 = NULL, *names2 = NULL;
361-
X509_NAME *name;
362-
363-
StartTCP();
364-
InitTcpReady(&ready);
365-
XMEMSET(&server_args, 0, sizeof(func_args));
366-
XMEMSET(&server_cb, 0, sizeof(callback_functions));
386+
StartTCP();
387+
InitTcpReady(&ready);
388+
XMEMSET(&server_args, 0, sizeof(func_args));
389+
XMEMSET(&server_cb, 0, sizeof(callback_functions));
367390

391+
server_args.signal = &ready;
392+
server_args.callbacks = &server_cb;
368393

369-
server_args.signal = &ready;
370-
server_args.callbacks = &server_cb;
394+
server_cb.ctx = ctx;
395+
server_cb.isSharedCtx = 1;
396+
server_cb.doUdp = params[i].doUdp;
371397

372-
server_cb.ctx = ctx;
373-
server_cb.isSharedCtx = 1;
374-
server_cb.doUdp = params[i].doUdp;
398+
start_thread(test_server_nofail, &server_args, &server_thread);
375399

376-
start_thread(test_server_nofail, &server_args, &server_thread);
377-
wait_tcp_ready(&server_args);
400+
ExpectNotNull(ctx_client = wolfSSL_CTX_new(
401+
params[i].client_meth()));
402+
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(
403+
ctx_client, caCertFile, NULL));
378404

379-
tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port,
380-
params[i].doUdp, 0, NULL);
381-
if (params[i].doUdp)
382-
udp_connect(&sockfd, wolfSSLIP, server_args.signal->port);
405+
ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
383406

384-
ExpectNotNull(ctx_client = wolfSSL_CTX_new(
385-
params[i].client_meth()));
386-
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(
387-
ctx_client, caCertFile, NULL));
407+
AssertTrue(wolfSSL_use_certificate_file(ssl_client, cliCertFile,
408+
SSL_FILETYPE_PEM));
409+
AssertTrue(wolfSSL_use_PrivateKey_file(ssl_client, cliKeyFile,
410+
SSL_FILETYPE_PEM));
388411

389-
ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
412+
names1 = wolfSSL_load_client_CA_file(caCertFile);
413+
ExpectNotNull(names1);
414+
names2 = wolfSSL_load_client_CA_file(cliCertFile);
415+
ExpectNotNull(names2);
416+
ExpectNotNull(name = wolfSSL_sk_X509_NAME_value(names2, 0));
417+
ExpectIntEQ(2, wolfSSL_sk_X509_NAME_push(names1, name));
418+
if (EXPECT_FAIL()) {
419+
wolfSSL_X509_NAME_free(name);
420+
name = NULL;
421+
}
422+
wolfSSL_sk_X509_NAME_free(names2);
423+
names2 = wolfSSL_load_client_CA_file(cliCertFile);
424+
ExpectNotNull(names2);
390425

391-
AssertTrue(wolfSSL_use_certificate_file(ssl_client, cliCertFile,
392-
SSL_FILETYPE_PEM));
393-
AssertTrue(wolfSSL_use_PrivateKey_file(ssl_client, cliKeyFile,
394-
SSL_FILETYPE_PEM));
426+
/* verify that set0_CA_list takes precedence */
427+
wolfSSL_set0_CA_list(ssl_client, names1);
428+
wolfSSL_CTX_set0_CA_list(ctx_client, names2);
395429

396-
names1 = wolfSSL_load_client_CA_file(caCertFile);
397-
ExpectNotNull(names1);
398-
names2 = wolfSSL_load_client_CA_file(cliCertFile);
399-
ExpectNotNull(names2);
400-
ExpectNotNull(name = wolfSSL_sk_X509_NAME_value(names2, 0));
401-
ExpectIntEQ(2, wolfSSL_sk_X509_NAME_push(names1, name));
402-
if (EXPECT_FAIL()) {
403-
wolfSSL_X509_NAME_free(name);
404-
name = NULL;
405-
}
406-
names2 = wolfSSL_load_client_CA_file(cliCertFile);
407-
ExpectNotNull(names2);
408-
409-
/* verify that set0_CA_list takes precedence */
410-
wolfSSL_set0_CA_list(ssl_client, names1);
411-
wolfSSL_CTX_set0_CA_list(ctx_client, names2);
430+
wait_tcp_ready(&server_args);
431+
tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port,
432+
params[i].doUdp, 0, ssl_client);
412433

413-
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl_client, sockfd));
414-
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_connect(ssl_client));
434+
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl_client, sockfd));
435+
ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_connect(ssl_client));
415436

416-
wolfSSL_shutdown(ssl_client);
417-
wolfSSL_free(ssl_client);
418-
wolfSSL_CTX_free(ctx_client);
437+
wolfSSL_shutdown(ssl_client);
438+
wolfSSL_free(ssl_client);
439+
wolfSSL_CTX_free(ctx_client);
419440

420-
CloseSocket(sockfd);
441+
CloseSocket(sockfd);
421442

422-
join_thread(server_thread);
423-
FreeTcpReady(&ready);
424-
}
425-
#endif
443+
join_thread(server_thread);
444+
FreeTcpReady(&ready);
426445
ExpectIntEQ(2, server_cb_arg);
427446
wolfSSL_CTX_free(ctx);
428447
}

0 commit comments

Comments
 (0)