Skip to content

Commit 032dbe6

Browse files
ECH fixes F-292, F-28
1 parent e17ac41 commit 032dbe6

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/tls.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14031,6 +14031,7 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1403114031
}
1403214032
if (size == 0)
1403314033
return BAD_FUNC_ARG;
14034+
1403414035
/* retry configs */
1403514036
if (msgType == encrypted_extensions) {
1403614037
ret = wolfSSL_SetEchConfigs(ssl, readBuf, size);
@@ -14039,16 +14040,17 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1403914040
ret = 0;
1404014041
}
1404114042
/* HRR with special confirmation */
14042-
else if (msgType == hello_retry_request && ssl->echConfigs != NULL &&
14043-
!ssl->options.disableECH) {
14043+
else if (msgType == hello_retry_request && ssl->echConfigs != NULL) {
1404414044
/* length must be 8 */
1404514045
if (size != ECH_ACCEPT_CONFIRMATION_SZ)
1404614046
return BAD_FUNC_ARG;
14047+
1404714048
/* get extension */
1404814049
echX = TLSX_Find(ssl->extensions, TLSX_ECH);
1404914050
if (echX == NULL)
1405014051
return BAD_FUNC_ARG;
1405114052
ech = (WOLFSSL_ECH*)echX->data;
14053+
1405214054
ech->confBuf = (byte*)readBuf;
1405314055
}
1405414056
else if (msgType == client_hello && ssl->ctx->echConfigs != NULL) {
@@ -14057,6 +14059,7 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1405714059
if (echX == NULL)
1405814060
return BAD_FUNC_ARG;
1405914061
ech = (WOLFSSL_ECH*)echX->data;
14062+
1406014063
/* read the ech parameters before the payload */
1406114064
ech->type = *readBuf_p;
1406214065
readBuf_p++;
@@ -14135,11 +14138,11 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1413514138
}
1413614139
readBuf_p += len;
1413714140
offset += len;
14138-
/* read hello inner len */
14141+
/* read payload (encrypted CH) len */
1413914142
ato16(readBuf_p, &ech->innerClientHelloLen);
1414014143
readBuf_p += 2;
1414114144
offset += 2;
14142-
/* Check payload is no biffer than remaining bytes. */
14145+
/* Check payload is no bigger than remaining bytes. */
1414314146
if (ech->innerClientHelloLen > size - offset) {
1414414147
return BAD_FUNC_ARG;
1414514148
}
@@ -14157,7 +14160,7 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1415714160
/* set the ech payload of the copy to zeros */
1415814161
XMEMSET(aadCopy + (readBuf_p - ech->aad), 0,
1415914162
ech->innerClientHelloLen + WC_AES_BLOCK_SIZE);
14160-
/* free the old ech in case this is our second client hello */
14163+
/* free the old ech when this is the second client hello */
1416114164
if (ech->innerClientHello != NULL)
1416214165
XFREE(ech->innerClientHello, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
1416314166
/* allocate the inner payload buffer */
@@ -14168,24 +14171,23 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size,
1416814171
XFREE(aadCopy, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
1416914172
return MEMORY_E;
1417014173
}
14171-
/* first check if the config id matches */
14174+
/* try to decrypt with matching configId */
1417214175
echConfig = ssl->ctx->echConfigs;
1417314176
while (echConfig != NULL) {
14174-
/* decrypt with this config */
1417514177
if (echConfig->configId == ech->configId) {
1417614178
ret = TLSX_ExtractEch(ech, echConfig, aadCopy, ech->aadLen,
1417714179
ssl->heap);
1417814180
break;
1417914181
}
1418014182
echConfig = echConfig->next;
1418114183
}
14182-
/* try to decrypt with all configs */
14184+
/* otherwise, try to decrypt with all configs */
1418314185
if (echConfig == NULL || ret != 0) {
1418414186
echConfig = ssl->ctx->echConfigs;
1418514187
while (echConfig != NULL) {
1418614188
ret = TLSX_ExtractEch(ech, echConfig, aadCopy, ech->aadLen,
1418714189
ssl->heap);
14188-
if (ret== 0)
14190+
if (ret == 0)
1418914191
break;
1419014192
echConfig = echConfig->next;
1419114193
}

0 commit comments

Comments
 (0)