@@ -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) {
0 commit comments