Skip to content

Commit f6041b4

Browse files
move echAccepted to decrypt-time on server
1 parent bb5728a commit f6041b4

4 files changed

Lines changed: 35 additions & 11 deletions

File tree

src/ssl_ech.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ void wolfSSL_SetEchEnable(WOLFSSL* ssl, byte enable)
483483
/* Walk the ECHConfigExtension list and check for mandatory extensions.
484484
* Returns:
485485
* 0 if all extensions are known/optional,
486-
* 1 if an unsupported mandatory extension (high bit set) is present,
487486
* error otherwise. */
488487
static int EchConfigCheckExtensions(const byte* exts, word16 extsLen)
489488
{
@@ -497,7 +496,7 @@ static int EchConfigCheckExtensions(const byte* exts, word16 extsLen)
497496
if (bytesLeft - 4 < extDataLen)
498497
return BUFFER_E;
499498
if (extType & 0x8000)
500-
return 1;
499+
return UNSUPPORTED_EXTENSION;
501500
exts += 4 + extDataLen;
502501
bytesLeft -= 4 + extDataLen;
503502
}
@@ -707,7 +706,8 @@ int SetEchConfigsEx(WOLFSSL_EchConfig** outputConfigs, void* heap,
707706

708707
/* KEM, ciphersuite, or mandatory extension not supported, free this
709708
* config and then try to parse another */
710-
if (ret > 0 || EchConfigGetSupportedCipherSuite(workingConfig) < 0) {
709+
if (ret == WC_NO_ERR_TRACE(UNSUPPORTED_EXTENSION) ||
710+
EchConfigGetSupportedCipherSuite(workingConfig) < 0) {
711711
ret = 0;
712712
unsupportedAlgos = 1;
713713
XFREE(workingConfig->cipherSuites, heap, DYNAMIC_TYPE_TMP_BUFFER);

src/tls.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14489,8 +14489,9 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1448914489
}
1449014490
/* if we failed to extract/expand */
1449114491
if (ret != 0) {
14492-
WOLFSSL_MSG("Failed to decrypt InnerHello");
14493-
if (ech->hpkeContext != NULL) {
14492+
WOLFSSL_MSG("ECH rejected");
14493+
14494+
if (ssl->options.echAccepted == 1) {
1449414495
/* on SH2 this is fatal */
1449514496
SendAlert(ssl, alert_fatal, decrypt_error);
1449614497
WOLFSSL_ERROR_VERBOSE(DECRYPT_ERROR);
@@ -14512,11 +14513,20 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1451214513
* Also, if it exists, copy sessionID from outer hello */
1451314514
ret = TLSX_ECH_ExpandOuterExtensions(ssl, ech, ssl->heap);
1451414515
}
14516+
14517+
if (ret == 0){
14518+
WOLFSSL_MSG("ECH accepted");
14519+
ssl->options.echAccepted = 1;
14520+
}
14521+
else {
14522+
WOLFSSL_MSG("ECH rejected");
14523+
}
1451514524
}
1451614525
if (ret != 0) {
1451714526
XFREE(ech->innerClientHello, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
1451814527
ech->innerClientHello = NULL;
1451914528
}
14529+
1452014530
XFREE(aadCopy, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
1452114531
}
1452214532

src/tls13.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,7 +3863,7 @@ static int EchHashHelloInner(WOLFSSL* ssl, WOLFSSL_ECH* ech)
38633863
tmpHashes = ssl->hsHashes;
38643864

38653865
ssl->hsHashes = ssl->hsHashesEch;
3866-
if (ssl->options.echAccepted == 0 && ssl->hsHashes == NULL) {
3866+
if (ssl->hsHashes == NULL) {
38673867
ret = InitHandshakeHashes(ssl);
38683868
if (ret == 0) {
38693869
ssl->hsHashesEch = ssl->hsHashes;
@@ -5184,15 +5184,14 @@ static int EchCheckAcceptance(WOLFSSL* ssl, byte* label, word16 labelSz,
51845184
}
51855185
}
51865186
else {
5187-
WOLFSSL_MSG("ECH rejected");
5188-
51895187
if (msgType != hello_retry_request && ssl->options.echAccepted) {
51905188
/* the SH has rejected ECH after the HRR has accepted it
51915189
* RFC 9849, section 6.1.5 */
51925190
WOLFSSL_MSG("ECH rejected, but it was previously accepted...");
51935191
ret = INVALID_PARAMETER;
51945192
}
51955193
else {
5194+
WOLFSSL_MSG("ECH rejected");
51965195
ret = 0;
51975196
}
51985197
ssl->options.echAccepted = 0;
@@ -7087,12 +7086,9 @@ static int EchWriteAcceptance(WOLFSSL* ssl, byte* label, word16 labelSz,
70877086
output + acceptOffset);
70887087

70897088
if (ret == 0) {
7090-
WOLFSSL_MSG("ECH accepted");
7091-
70927089
tmpHashes = ssl->hsHashes;
70937090
ssl->hsHashes = ssl->hsHashesEch;
70947091

7095-
ssl->options.echAccepted = 1;
70967092
/* after HRR, hsHashesEch must contain:
70977093
* message_hash(ClientHelloInner1) || HRR (actual, not zeros) */
70987094
if (msgType == hello_retry_request) {

tests/api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14878,6 +14878,22 @@ static int test_wolfSSL_Tls13_ECH_HRR(void)
1487814878
return test_wolfSSL_ECH_conn_ex(wolfTLSv1_3_server_method,
1487914879
wolfTLSv1_3_client_method, 1);
1488014880
}
14881+
14882+
static int test_wolfSSL_SubTls13_ECH(void)
14883+
{
14884+
EXPECT_DECLS;
14885+
14886+
#ifndef WOLFSSL_NO_TLS12
14887+
ExpectIntNE(test_wolfSSL_ECH_conn_ex(wolfTLSv1_3_server_method,
14888+
wolfTLSv1_2_client_method, 0), WOLFSSL_SUCCESS);
14889+
ExpectIntNE(test_wolfSSL_ECH_conn_ex(wolfTLSv1_2_server_method,
14890+
wolfTLSv1_3_client_method, 0), WOLFSSL_SUCCESS);
14891+
ExpectIntNE(test_wolfSSL_ECH_conn_ex(wolfSSLv23_server_method,
14892+
wolfTLSv1_2_client_method, 0), WOLFSSL_SUCCESS);
14893+
#endif
14894+
14895+
return EXPECT_RESULT();
14896+
}
1488114897
#endif /* HAVE_IO_TESTS_DEPENDENCIES */
1488214898

1488314899
#ifdef HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
@@ -16262,6 +16278,7 @@ static int test_wolfSSL_Tls13_ECH_tamper_ex(struct test_ssl_memio_ctx* test_ctx)
1626216278
test_ctx->c_cb.ssl_ready = test_ech_client_ssl_ready;
1626316279

1626416280
ExpectIntEQ(test_ssl_memio_setup(test_ctx), TEST_SUCCESS);
16281+
1626516282
return EXPECT_RESULT();
1626616283
}
1626716284

@@ -38392,6 +38409,7 @@ TEST_CASE testCases[] = {
3839238409
/* Uses Assert in handshake callback. */
3839338410
TEST_DECL(test_wolfSSL_Tls13_ECH),
3839438411
TEST_DECL(test_wolfSSL_Tls13_ECH_HRR),
38412+
TEST_DECL(test_wolfSSL_SubTls13_ECH),
3839538413
#endif
3839638414
#if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
3839738415
TEST_DECL(test_wolfSSL_Tls13_ECH_all_algos),

0 commit comments

Comments
 (0)