Skip to content

Commit 1051590

Browse files
better errors when setting ech configs
1 parent e450b65 commit 1051590

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/ssl_ech.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ int SetEchConfigsEx(WOLFSSL_EchConfig** outputConfigs, void* heap,
513513
const byte* echConfigs, word32 echConfigsLen)
514514
{
515515
int ret = 0;
516+
int unsupportedAlgos = 0;
516517
word32 configIdx;
517518
word32 idx;
518519
int j;
@@ -704,6 +705,7 @@ int SetEchConfigsEx(WOLFSSL_EchConfig** outputConfigs, void* heap,
704705
* config and then try to parse another */
705706
if (ret > 0 || EchConfigGetSupportedCipherSuite(workingConfig) < 0) {
706707
ret = 0;
708+
unsupportedAlgos = 1;
707709
XFREE(workingConfig->cipherSuites, heap, DYNAMIC_TYPE_TMP_BUFFER);
708710
XFREE(workingConfig->publicName, heap, DYNAMIC_TYPE_TMP_BUFFER);
709711
XFREE(workingConfig->raw, heap, DYNAMIC_TYPE_TMP_BUFFER);
@@ -739,8 +741,11 @@ int SetEchConfigsEx(WOLFSSL_EchConfig** outputConfigs, void* heap,
739741
XFREE(lastConfig, heap, DYNAMIC_TYPE_TMP_BUFFER);
740742
}
741743

744+
/* syntactically correct but configs are not supported */
745+
if (ret == 0 && unsupportedAlgos)
746+
return UNSUPPORTED_SUITE;
742747
if (ret == 0)
743-
return WOLFSSL_FATAL_ERROR;
748+
return UNSUPPORTED_PROTO_VERSION;
744749

745750
return ret;
746751
}

src/tls.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14364,6 +14364,10 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1436414364
}
1436514365

1436614366
ret = SetRetryConfigs(ssl, readBuf, (word32)size);
14367+
if (ret == UNSUPPORTED_SUITE || ret == UNSUPPORTED_PROTO_VERSION) {
14368+
WOLFSSL_ERROR_VERBOSE(ret);
14369+
ret = 0;
14370+
}
1436714371

1436814372
if (ssl->echConfigs == NULL) {
1436914373
/* on GREASE connection configs must be checked syntactically and
@@ -16301,8 +16305,7 @@ static int TLSX_GetSizeWithEch(WOLFSSL* ssl, byte* semaphore, byte msgType,
1630116305
WC_ALLOC_VAR_EX(serverName, char, WOLFSSL_HOST_NAME_MAX, NULL,
1630216306
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
1630316307
r = TLSX_EchChangeSNI(ssl, &echX, serverName, &serverNameX, &extensions);
16304-
/* If ECH won't be written (mirrors guard in TLSX_WriteWithEch), exclude it
16305-
* from the size calculation to avoid a size/write mismatch */
16308+
/* If ECH won't be written exclude it from the size calculation */
1630616309
if (r == 0 && echX != NULL &&
1630716310
!ssl->options.echAccepted &&
1630816311
((WOLFSSL_ECH*)echX->data)->innerCount != 0) {

tests/api.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14383,6 +14383,8 @@ static int test_wolfSSL_Tls13_ECH_params_b64(void)
1438314383
#if !defined(NO_WOLFSSL_CLIENT)
1438414384
/* base64 ech configs from cloudflare-ech.com (these are good configs) */
1438514385
const char* b64Valid = "AEX+DQBBFAAgACBuAoQI8+liEVYQbXKBDeVgTmF2rfXuKO2knhwrN7jgTgAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA=";
14386+
/* ech configs with bad version */
14387+
const char* b64BadVers = "AEX+/gBBFAAgACBuAoQI8+liEVYQbXKBDeVgTmF2rfXuKO2knhwrN7jgTgAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA=";
1438614388
/* ech configs with bad/unsupported algorithm */
1438714389
const char* b64BadAlgo = "AEX+DQBBFP7+ACBuAoQI8+liEVYQbXKBDeVgTmF2rfXuKO2knhwrN7jgTgAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA=";
1438814390
/* ech configs with bad/unsupported ciphersuite */
@@ -14420,16 +14422,22 @@ static int test_wolfSSL_Tls13_ECH_params_b64(void)
1442014422
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
1442114423
b64Valid, 0));
1442214424

14425+
/* bad version */
14426+
ExpectIntEQ(UNSUPPORTED_PROTO_VERSION, wolfSSL_CTX_SetEchConfigsBase64(ctx,
14427+
b64BadVers, (word32)XSTRLEN(b64BadVers)));
14428+
ExpectIntEQ(UNSUPPORTED_PROTO_VERSION, wolfSSL_SetEchConfigsBase64(ssl,
14429+
b64BadVers, (word32)XSTRLEN(b64BadVers)));
14430+
1442314431
/* bad algorithm */
14424-
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetEchConfigsBase64(ctx,
14432+
ExpectIntEQ(UNSUPPORTED_SUITE, wolfSSL_CTX_SetEchConfigsBase64(ctx,
1442514433
b64BadAlgo, (word32)XSTRLEN(b64BadAlgo)));
14426-
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
14434+
ExpectIntEQ(UNSUPPORTED_SUITE, wolfSSL_SetEchConfigsBase64(ssl,
1442714435
b64BadAlgo, (word32)XSTRLEN(b64BadAlgo)));
1442814436

1442914437
/* bad ciphersuite */
14430-
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetEchConfigsBase64(ctx,
14438+
ExpectIntEQ(UNSUPPORTED_SUITE, wolfSSL_CTX_SetEchConfigsBase64(ctx,
1443114439
b64BadCiph, (word32)XSTRLEN(b64BadCiph)));
14432-
ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
14440+
ExpectIntEQ(UNSUPPORTED_SUITE, wolfSSL_SetEchConfigsBase64(ssl,
1443314441
b64BadCiph, (word32)XSTRLEN(b64BadCiph)));
1443414442

1443514443
/* unrecognized mandatory extension */

0 commit comments

Comments
 (0)