F 1483 : Fix SHA-1 prefix match overwriting SHA-256/384/512 output#216
F 1483 : Fix SHA-1 prefix match overwriting SHA-256/384/512 output#216miyazakh wants to merge 1 commit intowolfSSL:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes an algorithm-selection bug in the CLI hash command where SHA-1 prefix matching could incorrectly override SHA-256/384/512 digest output, and tightens algorithm validation to require exact matches.
Changes:
- Guard SHA-1 selection in
wolfCLU_hash/wolfCLU_hashSetupwithXSTRLEN(alg) == 3so only"sha"maps to SHA-1. - Change hash algorithm validation to exact string matching (
XSTRCMP) to avoid prefix-based acceptance. - Broaden OCSP interop test error-message matching; update
clu_x509_sign.chash-type switch version gating / case handling.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/hash/clu_hash.c |
Prevents SHA-1 branch from matching sha256/sha384/sha512 by requiring exact "sha". |
src/hash/clu_hash_setup.c |
Requires exact algorithm match during argument validation and ensures SHA-1 size only applies to "sha". |
tests/ocsp/ocsp-interop-test.sh |
Accepts additional common “file not found” phrasing in Test 6 logs. |
src/x509/clu_x509_sign.c |
Adjusts conditional compilation for unsupported hash-type cases in certificate signing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if LIBWOLFSSL_VERSION_HEX >= 0x05009000 | ||
| case WC_HASH_TYPE_SHA512_224: | ||
| case WC_HASH_TYPE_SHA512_256: | ||
| case WC_HASH_TYPE_SHAKE128: | ||
| case WC_HASH_TYPE_SHAKE256: | ||
| case WC_HASH_TYPE_SM3: | ||
| #elif LIBWOLFSSL_VERSION_HEX > 0x05001000 |
There was a problem hiding this comment.
The PR description doesn’t mention this change in certificate-signing hash handling. Also, introducing a new hard-coded wolfSSL version threshold (>= 0x05009000) is inconsistent with the rest of the codebase (which generally gates on > 0x05001000) and drops the previous per-feature guards (e.g., WOLFSSL_SHAKE128/WOLFSSL_SHAKE256). Consider documenting why 5.9.0 is required here, or switching to feature/enum-availability guards to avoid version-specific build regressions.
e43bb6a to
1a11f72
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| #ifndef NO_SHA | ||
| if (XSTRNCMP(alg, "sha", 3) == 0) | ||
| if ((XSTRNCMP(alg, "sha", 3) == 0) && (XSTRLEN(alg) == 3)) |
There was a problem hiding this comment.
Now that exact matching is the goal, consider replacing the XSTRNCMP(..., 3) && XSTRLEN(alg) == 3 pattern with a single exact comparison (e.g., XSTRCMP(alg, \"sha\") == 0). It’s simpler, more readable, and avoids a redundant length check.
| if ((XSTRNCMP(alg, "sha", 3) == 0) && (XSTRLEN(alg) == 3)) | |
| if (XSTRCMP(alg, "sha") == 0) |
| if (ret == WOLFCLU_SUCCESS && XSTRNCMP(alg, "sha", 3) == 0 | ||
| && XSTRLEN(alg) == 3) { |
There was a problem hiding this comment.
Same as in setup: since this branch should only run for the literal algorithm name, prefer an exact compare (e.g., XSTRCMP(alg, \"sha\") == 0) over XSTRNCMP + length guard. This reduces complexity and makes the intent unambiguous.
| if (ret == WOLFCLU_SUCCESS && XSTRNCMP(alg, "sha", 3) == 0 | |
| && XSTRLEN(alg) == 3) { | |
| if (ret == WOLFCLU_SUCCESS && XSTRCMP(alg, "sha") == 0) { |
| if (XSTRCMP(argv[2], algs[i]) == 0) { | ||
| alg = argv[2]; | ||
| algCheck = 1; | ||
| } |
There was a problem hiding this comment.
Switching from prefix matching to XSTRCMP changes the CLI’s accepted inputs: previously, a shorter string could match a longer algorithm name (depending on algs[]). If users relied on abbreviations/prefixes, this is a breaking behavior change—consider updating the CLI usage/help text accordingly, or implement a deliberate abbreviation scheme (e.g., accept prefixes only when they resolve uniquely).
Summary
XSTRNCMP(alg, "sha", 3)inwolfCLU_hashandwolfCLU_hashSetupmatched "sha256", "sha384", and "sha512", causing SHA-1 to overwrite
the correct digest and size
XSTRLEN(alg) == 3guard to the SHA-1 branch inclu_hash.candclu_hash_setup.calgCheckloop inclu_hash_setup.cto useXSTRCMPforexact matching instead of prefix matching
Depend on : #211 (Fixed)
Depend on : #219