f5381 enforce trailerField==1 in DecodeRsaPssParams#10595
Open
miyazakh wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request tightens RFC 8017 conformance for RSASSA-PSS parameter decoding by enforcing trailerField == trailerFieldBC(1) (i.e., integer value 1) in DecodeRsaPssParams, while preserving legacy permissive behavior when WOLFSSL_NO_ASN_STRICT is defined. It also extends the unit tests to cover valid and invalid trailerField encodings.
Changes:
- Enforce
trailerFieldvalue validation (== 1) in both ASN-template and non-template decoding paths (guarded by!WOLFSSL_NO_ASN_STRICT). - Add unit tests covering
trailerFieldvalues1(valid),2and0(invalid in strict mode).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
wolfcrypt/src/asn.c |
Adds strict-mode validation of trailerField value in both template and non-template decode paths. |
tests/api/test_asn.c |
Adds trailerField-focused DecodeRsaPssParams test vectors (strict and non-strict coverage via preprocessor guards). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
asn: enforce trailerField == trailerFieldBC(1) in DecodeRsaPssParams
Summary
trailerFieldparameter in RSASSA-PSS-paramsequals
trailerFieldBC(1)as mandated by RFC 8017 §A.2.3, in both the ASNtemplate and non-template paths of
DecodeRsaPssParams.test_wc_DecodeRsaPssParamswith three trailerField-specificcases covering the valid value and two invalid values.
Problem
RFC 8017 §A.2.3 defines:
and states:
DecodeRsaPssParamsparsed thetrailerFieldelement syntactically butnever validated its integer value, so any value was silently accepted.
Non-template path (
!WOLFSSL_ASN_TEMPLATE)Template path (
WOLFSSL_ASN_TEMPLATE)RSAPSSPARAMSASN_IDX_TRAILERINTappeared in the enum butGetASN_Int16Bitwas never called for it, soGetASN_Itemsvalidatedonly the ASN.1 type tag while the integer value went completely unread.
Impact
error in both paths.
regardless; a non-conformant
trailerFieldin an AlgorithmIdentifier istherefore accepted by the parser while an RFC-compliant peer would reject it.
vulnerability.
Fix
Both paths now reject
trailerField != 1withASN_PARSE_EwhenWOLFSSL_NO_ASN_STRICTis not defined (the default). WhenWOLFSSL_NO_ASN_STRICTis defined the previous permissive behaviour ispreserved for backward compatibility.
Template path (
wolfcrypt/src/asn.c)Non-template path (
wolfcrypt/src/asn.c)Test
Three cases added to
test_wc_DecodeRsaPssParamsintests/api/test_asn.c. All use a minimal DER-encoded RSASSA-PSS-paramscontaining only the
trailerFieldcomponent:SEQUENCE { [3] CONSTRUCTED { INTEGER <value> } }.30 05 a3 03 02 01 010(success)30 05 a3 03 02 01 02!WOLFSSL_NO_ASN_STRICTASN_PARSE_E30 05 a3 03 02 01 00!WOLFSSL_NO_ASN_STRICTASN_PARSE_ETests 10 and 11 exercise both the template and non-template paths with
the same DER input; the path is selected at build time.
How to build and run
Template path (default), strict mode — all three tests active:
./configure --enable-rsapss --enable-all \ CFLAGS="-DNO_WOLFSSL_CIPHER_SUITE_TEST" git clean -dfx && make ./tests/unit.test --list | grep DecodeRsaPssParams ./tests/unit.test -<N>Non-template path, strict mode:
./configure --enable-rsapss --enable-all --enable-asn=original \ CFLAGS="-DNO_WOLFSSL_CIPHER_SUITE_TEST" git clean -dfx && makeNon-strict mode — only Test 9 active, Tests 10/11 compiled out:
./configure --enable-rsapss --enable-all \ CFLAGS="-DNO_WOLFSSL_CIPHER_SUITE_TEST -DWOLFSSL_NO_ASN_STRICT" git clean -dfx && makeFiles changed
wolfcrypt/src/asn.ctrailerFieldvalue; non-template path: enforcetrailerField == 1; both guarded by!WOLFSSL_NO_ASN_STRICTtests/api/test_asn.ctest_wc_DecodeRsaPssParamsChecklist