Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ZD 18204: check hashsigalgo matches ssl suites. #7693

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -27368,7 +27368,45 @@ static byte MinHashAlgo(WOLFSSL* ssl)
return sha_mac;
}

/* Check if a given peer hashSigAlgo is supported in our ssl->suites or
* ssl->ctx->suites.
*
* Returns 1 on match.
* Returns 0 otherwise.
* */
static int SupportedHashSigAlgo(WOLFSSL* ssl, const byte * hashSigAlgo)
{
const Suites * suites = NULL;
word32 i = 0;

if (ssl == NULL || hashSigAlgo == NULL) {
return 0;
}

suites = WOLFSSL_SUITES(ssl);

if (suites == NULL || suites->hashSigAlgoSz == 0) {
return 0;
}

for (i = 0; (i+1) < suites->hashSigAlgoSz; i += HELLO_EXT_SIGALGO_SZ) {
if (XMEMCMP(&suites->hashSigAlgo[i], hashSigAlgo,
HELLO_EXT_SIGALGO_SZ) == 0) {
/* Match found. */
return 1;
}
}

return 0;
}

int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz)
{
return PickHashSigAlgo_ex(ssl, hashSigAlgo, hashSigAlgoSz, 0);
}

int PickHashSigAlgo_ex(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz,
int matchSuites)
{
word32 i;
int ret = WC_NO_ERR_TRACE(MATCH_SUITE_ERROR);
Expand Down Expand Up @@ -27409,6 +27447,14 @@ int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz)
if (!MatchSigAlgo(ssl, sigAlgo))
continue;

if (matchSuites) {
/* Keep looking if peer algorithm isn't supported in our ssl->suites
* or ssl->ctx->suites. */
if (!SupportedHashSigAlgo(ssl, &hashSigAlgo[i])) {
continue;
}
}

#ifdef HAVE_ED25519
if (ssl->pkCurveOID == ECC_ED25519_OID) {
/* Matched Ed25519 - set chosen and finished. */
Expand Down Expand Up @@ -35913,8 +35959,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
ret = SetCipherSpecs(ssl);
if (ret != 0)
return ret;
ret = PickHashSigAlgo(ssl, peerSuites->hashSigAlgo,
peerSuites->hashSigAlgoSz);
ret = PickHashSigAlgo_ex(ssl, peerSuites->hashSigAlgo,
peerSuites->hashSigAlgoSz, 1);
if (ret != 0)
return ret;

Expand Down
2 changes: 2 additions & 0 deletions wolfssl/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,8 @@ WOLFSSL_LOCAL int CompleteServerHello(WOLFSSL *ssl);
WOLFSSL_LOCAL int CheckVersion(WOLFSSL *ssl, ProtocolVersion pv);
WOLFSSL_LOCAL int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo,
word32 hashSigAlgoSz);
WOLFSSL_LOCAL int PickHashSigAlgo_ex(WOLFSSL* ssl, const byte* hashSigAlgo,
JacobBarthelmeh marked this conversation as resolved.
Show resolved Hide resolved
word32 hashSigAlgoSz, int matchSuites);
#if defined(WOLF_PRIVATE_KEY_ID) && !defined(NO_CHECK_PRIVATE_KEY)
WOLFSSL_LOCAL int CreateDevPrivateKey(void** pkey, byte* data, word32 length,
int hsType, int label, int id,
Expand Down