@@ -15080,6 +15080,16 @@ static int test_ech_server_ctx_ready(WOLFSSL_CTX* ctx)
1508015080 return TEST_SUCCESS;
1508115081}
1508215082
15083+ /* Server ctx_ready callback: generate ECH config and opt into trial
15084+ * decryption at the CTX level so the SSL inherits it on creation */
15085+ static int test_ech_server_ctx_ready_trial_decrypt(WOLFSSL_CTX* ctx)
15086+ {
15087+ int ret = test_ech_server_ctx_ready(ctx);
15088+ if (ret == TEST_SUCCESS)
15089+ wolfSSL_CTX_SetEchEnableTrialDecrypt(ctx, 1);
15090+ return ret;
15091+ }
15092+
1508315093/* Server ssl_ready callback: set SNI */
1508415094static int test_ech_server_ssl_ready(WOLFSSL* ssl)
1508515095{
@@ -15687,6 +15697,84 @@ static int test_wolfSSL_Tls13_ECH_new_config(void)
1568715697 return EXPECT_RESULT();
1568815698}
1568915699
15700+ /* Test trial decryption for ECH: server has a single config, client receives a
15701+ * copy of it but its configId is overwritten so it cannot match the server's */
15702+ static int test_wolfSSL_Tls13_ECH_trial_decrypt(void)
15703+ {
15704+ EXPECT_DECLS;
15705+ test_ssl_memio_ctx test_ctx;
15706+
15707+ /* --- CTX-enabled, SSL-disabled override: ECH rejected --- */
15708+
15709+ XMEMSET(&test_ctx, 0, sizeof(test_ctx));
15710+
15711+ test_ctx.s_cb.method = wolfTLSv1_3_server_method;
15712+ test_ctx.c_cb.method = wolfTLSv1_3_client_method;
15713+
15714+ /* *_trial_decrypt sets enableEchTrialDecrypt to 1 - overriding the default
15715+ * value of 0 */
15716+ test_ctx.s_cb.ctx_ready = test_ech_server_ctx_ready_trial_decrypt;
15717+ test_ctx.s_cb.ssl_ready = test_ech_server_ssl_ready;
15718+ test_ctx.c_cb.ssl_ready = test_ech_client_ssl_ready;
15719+
15720+ ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
15721+
15722+ /* SSL inherited the CTX setting */
15723+ ExpectIntEQ(test_ctx.s_ctx->enableEchTrialDecrypt, 1);
15724+ ExpectIntEQ(test_ctx.s_ssl->options.enableEchTrialDecrypt, 1);
15725+
15726+ /* override on the SSL */
15727+ wolfSSL_SetEchEnableTrialDecrypt(test_ctx.s_ssl, 0);
15728+ ExpectIntEQ(test_ctx.s_ssl->options.enableEchTrialDecrypt, 0);
15729+
15730+ /* alter the client's configId so it does not match the server's configId */
15731+ ExpectNotNull(test_ctx.c_ssl->echConfigs);
15732+ ExpectNotNull(test_ctx.s_ctx->echConfigs);
15733+ if (EXPECT_SUCCESS()) {
15734+ test_ctx.c_ssl->echConfigs->configId =
15735+ (byte)(test_ctx.s_ctx->echConfigs->configId ^ 0x01);
15736+ }
15737+
15738+ ExpectIntNE(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
15739+ ExpectIntEQ(test_ctx.c_ssl->options.echAccepted, 0);
15740+ ExpectIntEQ(wolfSSL_get_error(test_ctx.c_ssl, 0),
15741+ WC_NO_ERR_TRACE(ECH_REQUIRED_E));
15742+
15743+ test_ssl_memio_cleanup(&test_ctx);
15744+
15745+ /* --- trial decryption opted in on the SSL: ECH accepted --- */
15746+
15747+ XMEMSET(&test_ctx, 0, sizeof(test_ctx));
15748+
15749+ test_ctx.s_cb.method = wolfTLSv1_3_server_method;
15750+ test_ctx.c_cb.method = wolfTLSv1_3_client_method;
15751+
15752+ test_ctx.s_cb.ctx_ready = test_ech_server_ctx_ready;
15753+ test_ctx.s_cb.ssl_ready = test_ech_server_ssl_ready;
15754+ test_ctx.c_cb.ssl_ready = test_ech_client_ssl_ready;
15755+
15756+ ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
15757+
15758+ /* opt into trial decryption on the SSL */
15759+ wolfSSL_SetEchEnableTrialDecrypt(test_ctx.s_ssl, 1);
15760+ ExpectIntEQ(test_ctx.s_ssl->options.enableEchTrialDecrypt, 1);
15761+
15762+ /* alter the client's configId so it does not match the server's configId */
15763+ ExpectNotNull(test_ctx.c_ssl->echConfigs);
15764+ ExpectNotNull(test_ctx.s_ctx->echConfigs);
15765+ if (EXPECT_SUCCESS()) {
15766+ test_ctx.c_ssl->echConfigs->configId =
15767+ (byte)(test_ctx.s_ctx->echConfigs->configId ^ 0x01);
15768+ }
15769+
15770+ ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
15771+ ExpectIntEQ(test_ctx.c_ssl->options.echAccepted, 1);
15772+
15773+ test_ssl_memio_cleanup(&test_ctx);
15774+
15775+ return EXPECT_RESULT();
15776+ }
15777+
1569015778/* Test GREASE ECH:
1569115779 * 1. client sends GREASE ECH extension but server has no ECH configs so it
1569215780 * ignores it, handshake succeeds normally
@@ -40600,6 +40688,7 @@ TEST_CASE testCases[] = {
4060040688 TEST_DECL(test_wolfSSL_Tls13_ECH_retry_configs_bad),
4060140689 TEST_DECL(test_wolfSSL_Tls13_ECH_retry_configs_auth_fail),
4060240690 TEST_DECL(test_wolfSSL_Tls13_ECH_new_config),
40691+ TEST_DECL(test_wolfSSL_Tls13_ECH_trial_decrypt),
4060340692 TEST_DECL(test_wolfSSL_Tls13_ECH_GREASE),
4060440693 TEST_DECL(test_wolfSSL_Tls13_ECH_disable_conn),
4060540694 TEST_DECL(test_wolfSSL_Tls13_ECH_long_SNI),
0 commit comments