|
47 | 47 | #endif |
48 | 48 | #if defined(WOLFSSL_STATIC_MEMORY) |
49 | 49 | #include <wolfssl/wolfcrypt/memory.h> |
| 50 | + |
| 51 | +#if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY) |
| 52 | + #if (defined(HAVE_ECC) && !defined(ALT_ECC_SIZE)) || \ |
| 53 | + defined(SESSION_CERTS) |
| 54 | + #ifdef OPENSSL_EXTRA |
| 55 | + #define TEST_TLS_STATIC_MEMSZ (400000) |
| 56 | + #else |
| 57 | + #define TEST_TLS_STATIC_MEMSZ (320000) |
| 58 | + #endif |
| 59 | + #else |
| 60 | + #define TEST_TLS_STATIC_MEMSZ (80000) |
| 61 | + #endif |
| 62 | +#endif |
| 63 | + |
50 | 64 | #endif /* WOLFSSL_STATIC_MEMORY */ |
51 | 65 | #ifndef HEAP_HINT |
52 | 66 | #define HEAP_HINT NULL |
@@ -6800,11 +6814,11 @@ static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args) |
6800 | 6814 | } |
6801 | 6815 | #else |
6802 | 6816 | ctx = wolfSSL_CTX_new(callbacks->method()); |
| 6817 | +#endif |
6803 | 6818 | if (ctx == NULL) { |
6804 | 6819 | fprintf(stderr, "CTX new failed\n"); |
6805 | 6820 | goto cleanup; |
6806 | 6821 | } |
6807 | | -#endif |
6808 | 6822 |
|
6809 | 6823 | /* set defaults */ |
6810 | 6824 | if (callbacks->caPemFile == NULL) |
@@ -7053,14 +7067,12 @@ static void run_wolfssl_client(void* args) |
7053 | 7067 | } |
7054 | 7068 | } |
7055 | 7069 | #else |
7056 | | - if (ctx == NULL) { |
7057 | | - ctx = wolfSSL_CTX_new(callbacks->method()); |
7058 | | - } |
| 7070 | + ctx = wolfSSL_CTX_new(callbacks->method()); |
| 7071 | +#endif |
7059 | 7072 | if (ctx == NULL) { |
7060 | 7073 | fprintf(stderr, "CTX new failed\n"); |
7061 | 7074 | goto cleanup; |
7062 | 7075 | } |
7063 | | -#endif |
7064 | 7076 |
|
7065 | 7077 | #ifdef WOLFSSL_TIRTOS |
7066 | 7078 | fdOpenSession(Task_self()); |
@@ -9353,90 +9365,117 @@ static int test_wolfSSL_UseSNI_connection(void) |
9353 | 9365 | callback_functions client_cb; |
9354 | 9366 | callback_functions server_cb; |
9355 | 9367 | size_t i; |
9356 | | - |
| 9368 | +#ifdef WOLFSSL_STATIC_MEMORY |
| 9369 | + byte cliMem[TEST_TLS_STATIC_MEMSZ]; |
| 9370 | + byte svrMem[TEST_TLS_STATIC_MEMSZ]; |
| 9371 | +#endif |
9357 | 9372 | struct { |
9358 | 9373 | method_provider client_meth; |
9359 | 9374 | method_provider server_meth; |
| 9375 | + #ifdef WOLFSSL_STATIC_MEMORY |
| 9376 | + wolfSSL_method_func client_meth_ex; |
| 9377 | + wolfSSL_method_func server_meth_ex; |
| 9378 | + #endif |
9360 | 9379 | } methods[] = { |
9361 | 9380 | #if defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_TLS13) |
9362 | | - {wolfSSLv23_client_method, wolfSSLv23_server_method}, |
| 9381 | + {wolfSSLv23_client_method, wolfSSLv23_server_method |
| 9382 | + #ifdef WOLFSSL_STATIC_MEMORY |
| 9383 | + ,wolfSSLv23_client_method_ex, wolfSSLv23_server_method_ex |
| 9384 | + #endif |
| 9385 | + }, |
9363 | 9386 | #endif |
9364 | 9387 | #ifndef WOLFSSL_NO_TLS12 |
9365 | | - {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method}, |
| 9388 | + {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method |
| 9389 | + #ifdef WOLFSSL_STATIC_MEMORY |
| 9390 | + ,wolfTLSv1_2_client_method_ex, wolfTLSv1_2_server_method_ex |
| 9391 | + #endif |
| 9392 | + }, |
9366 | 9393 | #endif |
9367 | 9394 | #ifdef WOLFSSL_TLS13 |
9368 | | - {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method}, |
| 9395 | + {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method |
| 9396 | + #ifdef WOLFSSL_STATIC_MEMORY |
| 9397 | + ,wolfTLSv1_3_client_method_ex, wolfTLSv1_3_server_method_ex |
| 9398 | + #endif |
| 9399 | + }, |
9369 | 9400 | #endif |
9370 | 9401 | }; |
9371 | 9402 | size_t methodsSz = sizeof(methods) / sizeof(*methods); |
9372 | 9403 |
|
9373 | 9404 | for (i = 0; i < methodsSz; i++) { |
9374 | | - XMEMSET(&client_cb, 0, sizeof(callback_functions)); |
9375 | | - XMEMSET(&server_cb, 0, sizeof(callback_functions)); |
9376 | | - client_cb.method = methods[i].client_meth; |
9377 | | - server_cb.method = methods[i].server_meth; |
9378 | | - client_cb.devId = testDevId; |
9379 | | - server_cb.devId = testDevId; |
9380 | | - |
9381 | | - /* success case at ctx */ |
9382 | | - printf("success case at ctx\n"); |
9383 | | - client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL; |
9384 | | - server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching; |
9385 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9386 | | - |
9387 | | - /* success case at ssl */ |
9388 | | - printf("success case at ssl\n"); |
9389 | | - client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching; |
9390 | | - server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching; |
9391 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9392 | | - |
9393 | | - /* default mismatch behavior */ |
9394 | | - printf("default mismatch behavior\n"); |
9395 | | - client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client; |
9396 | | - server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server; |
9397 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9398 | | - |
9399 | | - /* continue on mismatch */ |
9400 | | - printf("continue on mismatch\n"); |
9401 | | - client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL; |
9402 | | - server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching; |
9403 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9404 | | - |
9405 | | - /* fake answer on mismatch */ |
9406 | | - printf("fake answer on mismatch\n"); |
9407 | | - client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL; |
9408 | | - server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching; |
9409 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9410 | | - |
9411 | | - /* sni abort - success */ |
9412 | | - printf("sni abort - success\n"); |
9413 | | - client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL; |
9414 | | - server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching; |
9415 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9416 | | - |
9417 | | - /* sni abort - abort when absent (ctx) */ |
9418 | | - printf("sni abort - abort when absent (ctx)\n"); |
9419 | | - client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client; |
9420 | | - server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server; |
9421 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9422 | | - |
9423 | | - /* sni abort - abort when absent (ssl) */ |
9424 | | - printf("sni abort - abort when absent (ssl)\n"); |
9425 | | - client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client; |
9426 | | - server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server; |
9427 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9428 | | - |
9429 | | - /* sni abort - success when overwritten */ |
9430 | | - printf("sni abort - success when overwritten\n"); |
9431 | | - client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL; |
9432 | | - server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_no_matching; |
9433 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
9434 | | - |
9435 | | - /* sni abort - success when allowing mismatches */ |
9436 | | - printf("sni abort - success when allowing mismatches\n"); |
9437 | | - client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL; |
9438 | | - server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching; |
9439 | | - test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9405 | + XMEMSET(&client_cb, 0, sizeof(callback_functions)); |
| 9406 | + XMEMSET(&server_cb, 0, sizeof(callback_functions)); |
| 9407 | + client_cb.method = methods[i].client_meth; |
| 9408 | + server_cb.method = methods[i].server_meth; |
| 9409 | + client_cb.devId = testDevId; |
| 9410 | + server_cb.devId = testDevId; |
| 9411 | + #ifdef WOLFSSL_STATIC_MEMORY |
| 9412 | + client_cb.method_ex = methods[i].client_meth_ex; |
| 9413 | + server_cb.method_ex = methods[i].server_meth_ex; |
| 9414 | + client_cb.mem = cliMem; |
| 9415 | + client_cb.memSz = (word32)sizeof(cliMem); |
| 9416 | + server_cb.mem = svrMem; |
| 9417 | + server_cb.memSz = (word32)sizeof(svrMem);; |
| 9418 | + #endif |
| 9419 | + |
| 9420 | + /* success case at ctx */ |
| 9421 | + printf("\n\tsuccess case at ctx\n"); |
| 9422 | + client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL; |
| 9423 | + server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching; |
| 9424 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9425 | + |
| 9426 | + /* success case at ssl */ |
| 9427 | + printf("\tsuccess case at ssl\n"); |
| 9428 | + client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching; |
| 9429 | + server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching; |
| 9430 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9431 | + |
| 9432 | + /* default mismatch behavior */ |
| 9433 | + printf("\tdefault mismatch behavior\n"); |
| 9434 | + client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client; |
| 9435 | + server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server; |
| 9436 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9437 | + |
| 9438 | + /* continue on mismatch */ |
| 9439 | + printf("\tcontinue on mismatch\n"); |
| 9440 | + client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL; |
| 9441 | + server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching; |
| 9442 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9443 | + |
| 9444 | + /* fake answer on mismatch */ |
| 9445 | + printf("\tfake answer on mismatch\n"); |
| 9446 | + client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL; |
| 9447 | + server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching; |
| 9448 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9449 | + |
| 9450 | + /* sni abort - success */ |
| 9451 | + printf("\tsni abort - success\n"); |
| 9452 | + client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL; |
| 9453 | + server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching; |
| 9454 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9455 | + |
| 9456 | + /* sni abort - abort when absent (ctx) */ |
| 9457 | + printf("\tsni abort - abort when absent (ctx)\n"); |
| 9458 | + client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client; |
| 9459 | + server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server; |
| 9460 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9461 | + |
| 9462 | + /* sni abort - abort when absent (ssl) */ |
| 9463 | + printf("\tsni abort - abort when absent (ssl)\n"); |
| 9464 | + client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client; |
| 9465 | + server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server; |
| 9466 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9467 | + |
| 9468 | + /* sni abort - success when overwritten */ |
| 9469 | + printf("\tsni abort - success when overwritten\n"); |
| 9470 | + client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL; |
| 9471 | + server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_no_matching; |
| 9472 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
| 9473 | + |
| 9474 | + /* sni abort - success when allowing mismatches */ |
| 9475 | + printf("\tsni abort - success when allowing mismatches\n"); |
| 9476 | + client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL; |
| 9477 | + server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching; |
| 9478 | + test_wolfSSL_client_server(&client_cb, &server_cb); |
9440 | 9479 | } |
9441 | 9480 |
|
9442 | 9481 | res = TEST_RES_CHECK(1); |
@@ -57657,17 +57696,6 @@ static int test_wolfSSL_CTX_StaticMemory_TLS(int tlsVer, |
57657 | 57696 | #endif /* WOLFSSL_STATIC_MEMORY && HAVE_IO_TESTS_DEPENDENCIES */ |
57658 | 57697 |
|
57659 | 57698 | #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY) |
57660 | | -#if (defined(HAVE_ECC) && !defined(ALT_ECC_SIZE)) || \ |
57661 | | - defined(SESSION_CERTS) |
57662 | | - #ifdef OPENSSL_EXTRA |
57663 | | - #define TEST_TLS_STATIC_MEMSZ (400000) |
57664 | | - #else |
57665 | | - #define TEST_TLS_STATIC_MEMSZ (320000) |
57666 | | - #endif |
57667 | | -#else |
57668 | | - #define TEST_TLS_STATIC_MEMSZ (80000) |
57669 | | -#endif |
57670 | | - |
57671 | 57699 | static int test_wolfSSL_CTX_StaticMemory_SSL(WOLFSSL_CTX* ctx) |
57672 | 57700 | { |
57673 | 57701 | EXPECT_DECLS; |
|
0 commit comments