|
35 | 35 | #include <wolfcrypt/src/misc.c> |
36 | 36 | #endif |
37 | 37 |
|
| 38 | +#include <wolfssl/internal.h> |
38 | 39 | #include <tests/unit.h> |
| 40 | +#include <tests/utils.h> |
39 | 41 | #include <tests/api/test_tls_ext.h> |
40 | 42 |
|
| 43 | +int test_tls_ems_downgrade(void) |
| 44 | +{ |
| 45 | + EXPECT_DECLS; |
| 46 | +#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \ |
| 47 | + defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \ |
| 48 | + defined(HAVE_SESSION_TICKET) |
| 49 | + struct test_memio_ctx test_ctx; |
| 50 | + WOLFSSL_CTX *ctx_c = NULL; |
| 51 | + WOLFSSL_CTX *ctx_s = NULL; |
| 52 | + WOLFSSL *ssl_c = NULL; |
| 53 | + WOLFSSL *ssl_s = NULL; |
| 54 | + WOLFSSL_SESSION* session = NULL; |
| 55 | + /* TLS EMS extension in binary form */ |
| 56 | + const char ems_ext[] = { 0x00, 0x17, 0x00, 0x00 }; |
| 57 | + char data = 0; |
| 58 | + |
| 59 | + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); |
| 60 | + |
| 61 | + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, |
| 62 | + wolfTLS_client_method, wolfTLS_server_method), 0); |
| 63 | + |
| 64 | + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); |
| 65 | + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); |
| 66 | + |
| 67 | + /* Verify that the EMS extension is present in Client's message */ |
| 68 | + ExpectNotNull(mymemmem(test_ctx.s_buff, test_ctx.s_len, |
| 69 | + ems_ext, sizeof(ems_ext))); |
| 70 | + |
| 71 | + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); |
| 72 | + ExpectIntEQ(wolfSSL_version(ssl_c), TLS1_3_VERSION); |
| 73 | + |
| 74 | + /* Do a round of reads to exchange the ticket message */ |
| 75 | + ExpectIntEQ(wolfSSL_read(ssl_s, &data, sizeof(data)), -1); |
| 76 | + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); |
| 77 | + ExpectIntEQ(wolfSSL_read(ssl_c, &data, sizeof(data)), -1); |
| 78 | + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); |
| 79 | + |
| 80 | + ExpectNotNull(session = wolfSSL_get1_session(ssl_c)); |
| 81 | + ExpectTrue(session->haveEMS); |
| 82 | + |
| 83 | + wolfSSL_free(ssl_c); |
| 84 | + ssl_c = NULL; |
| 85 | + wolfSSL_free(ssl_s); |
| 86 | + ssl_s = NULL; |
| 87 | + |
| 88 | + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, |
| 89 | + wolfTLS_client_method, wolfTLS_server_method), 0); |
| 90 | + |
| 91 | + /* Resuming the connection */ |
| 92 | + ExpectIntEQ(wolfSSL_set_session(ssl_c, session), WOLFSSL_SUCCESS); |
| 93 | + ExpectIntEQ(wolfSSL_connect(ssl_c), -1); |
| 94 | + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); |
| 95 | + |
| 96 | + /* Verify that the EMS extension is still present in the resumption CH |
| 97 | + * even though we used TLS 1.3 */ |
| 98 | + ExpectNotNull(mymemmem(test_ctx.s_buff, test_ctx.s_len, |
| 99 | + ems_ext, sizeof(ems_ext))); |
| 100 | + |
| 101 | + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); |
| 102 | + ExpectIntEQ(wolfSSL_version(ssl_c), TLS1_3_VERSION); |
| 103 | + |
| 104 | + wolfSSL_SESSION_free(session); |
| 105 | + wolfSSL_free(ssl_c); |
| 106 | + wolfSSL_free(ssl_s); |
| 107 | + wolfSSL_CTX_free(ctx_c); |
| 108 | + wolfSSL_CTX_free(ctx_s); |
| 109 | +#endif |
| 110 | + return EXPECT_RESULT(); |
| 111 | +} |
| 112 | + |
| 113 | + |
41 | 114 | int test_wolfSSL_DisableExtendedMasterSecret(void) |
42 | 115 | { |
43 | 116 | EXPECT_DECLS; |
|
0 commit comments