Skip to content

Commit 1c23d22

Browse files
Merge pull request #7693 from philljj/zd18204
Fixes ZD 18204: check hashsigalgo matches ssl suites.
2 parents ba1eedb + f7f3ba9 commit 1c23d22

3 files changed

Lines changed: 56 additions & 6 deletions

File tree

src/internal.c

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27390,7 +27390,40 @@ static byte MinHashAlgo(WOLFSSL* ssl)
2739027390
return sha_mac;
2739127391
}
2739227392

27393-
int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz)
27393+
/* Check if a given peer hashSigAlgo is supported in our ssl->suites or
27394+
* ssl->ctx->suites.
27395+
*
27396+
* Returns 1 on match.
27397+
* Returns 0 otherwise.
27398+
* */
27399+
static int SupportedHashSigAlgo(WOLFSSL* ssl, const byte * hashSigAlgo)
27400+
{
27401+
const Suites * suites = NULL;
27402+
word32 i = 0;
27403+
27404+
if (ssl == NULL || hashSigAlgo == NULL) {
27405+
return 0;
27406+
}
27407+
27408+
suites = WOLFSSL_SUITES(ssl);
27409+
27410+
if (suites == NULL || suites->hashSigAlgoSz == 0) {
27411+
return 0;
27412+
}
27413+
27414+
for (i = 0; (i+1) < suites->hashSigAlgoSz; i += HELLO_EXT_SIGALGO_SZ) {
27415+
if (XMEMCMP(&suites->hashSigAlgo[i], hashSigAlgo,
27416+
HELLO_EXT_SIGALGO_SZ) == 0) {
27417+
/* Match found. */
27418+
return 1;
27419+
}
27420+
}
27421+
27422+
return 0;
27423+
}
27424+
27425+
int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz,
27426+
int matchSuites)
2739427427
{
2739527428
word32 i;
2739627429
int ret = WC_NO_ERR_TRACE(MATCH_SUITE_ERROR);
@@ -27431,6 +27464,14 @@ int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo, word32 hashSigAlgoSz)
2743127464
if (!MatchSigAlgo(ssl, sigAlgo))
2743227465
continue;
2743327466

27467+
if (matchSuites) {
27468+
/* Keep looking if peer algorithm isn't supported in our ssl->suites
27469+
* or ssl->ctx->suites. */
27470+
if (!SupportedHashSigAlgo(ssl, &hashSigAlgo[i])) {
27471+
continue;
27472+
}
27473+
}
27474+
2743427475
#ifdef HAVE_ED25519
2743527476
if (ssl->pkCurveOID == ECC_ED25519_OID) {
2743627477
/* Matched Ed25519 - set chosen and finished. */
@@ -30051,7 +30092,7 @@ static int HashSkeData(WOLFSSL* ssl, enum wc_HashType hashType,
3005130092
if ((len > size) || ((*inOutIdx - begin) + len > size))
3005230093
return BUFFER_ERROR;
3005330094

30054-
if (PickHashSigAlgo(ssl, input + *inOutIdx, len) != 0 &&
30095+
if (PickHashSigAlgo(ssl, input + *inOutIdx, len, 0) != 0 &&
3005530096
ssl->buffers.certificate &&
3005630097
ssl->buffers.certificate->buffer) {
3005730098
#ifdef HAVE_PK_CALLBACKS
@@ -31086,6 +31127,15 @@ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input,
3108631127
ERROR_OUT(BUFFER_ERROR, exit_dske);
3108731128
}
3108831129

31130+
/* Check if hashSigAlgo in Server Key Exchange is supported
31131+
* in our ssl->suites or ssl->ctx->suites. */
31132+
if (!SupportedHashSigAlgo(ssl, &input[args->idx])) {
31133+
#ifdef WOLFSSL_EXTRA_ALERTS
31134+
SendAlert(ssl, alert_fatal, handshake_failure);
31135+
#endif
31136+
ERROR_OUT(MATCH_SUITE_ERROR, exit_dske);
31137+
}
31138+
3108931139
DecodeSigAlg(&input[args->idx], &ssl->options.peerHashAlgo,
3109031140
&sigAlgo);
3109131141
#ifndef NO_RSA
@@ -35937,7 +35987,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3593735987
if (ret != 0)
3593835988
return ret;
3593935989
ret = PickHashSigAlgo(ssl, peerSuites->hashSigAlgo,
35940-
peerSuites->hashSigAlgoSz);
35990+
peerSuites->hashSigAlgoSz, 1);
3594135991
if (ret != 0)
3594235992
return ret;
3594335993

@@ -36300,7 +36350,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3630036350
ret = SetCipherSpecs(ssl);
3630136351
if (ret == 0) {
3630236352
ret = PickHashSigAlgo(ssl, clSuites->hashSigAlgo,
36303-
clSuites->hashSigAlgoSz);
36353+
clSuites->hashSigAlgoSz, 0);
3630436354
}
3630536355
}
3630636356
else if (ret == 0) {

src/tls13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5740,7 +5740,7 @@ static int DoTls13CertificateRequest(WOLFSSL* ssl, const byte* input,
57405740
#endif
57415741
) {
57425742
if (PickHashSigAlgo(ssl, peerSuites.hashSigAlgo,
5743-
peerSuites.hashSigAlgoSz) != 0) {
5743+
peerSuites.hashSigAlgoSz, 0) != 0) {
57445744
WOLFSSL_ERROR_VERBOSE(INVALID_PARAMETER);
57455745
return INVALID_PARAMETER;
57465746
}

wolfssl/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ WOLFSSL_LOCAL int DoServerHello(WOLFSSL* ssl, const byte* input, word32* inOutI
21802180
WOLFSSL_LOCAL int CompleteServerHello(WOLFSSL *ssl);
21812181
WOLFSSL_LOCAL int CheckVersion(WOLFSSL *ssl, ProtocolVersion pv);
21822182
WOLFSSL_LOCAL int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo,
2183-
word32 hashSigAlgoSz);
2183+
word32 hashSigAlgoSz, int matchSuites);
21842184
#if defined(WOLF_PRIVATE_KEY_ID) && !defined(NO_CHECK_PRIVATE_KEY)
21852185
WOLFSSL_LOCAL int CreateDevPrivateKey(void** pkey, byte* data, word32 length,
21862186
int hsType, int label, int id,

0 commit comments

Comments
 (0)