ASN template depth fix - #11404
Conversation
5a93a41 to
3c4f3f9
Compare
|
3c4f3f9 to
156c3d4
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11404
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 7
7 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
156c3d4 to
15c98f9
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11404
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
15c98f9 to
b69d2df
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11404
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
| * silently skipped. */ | ||
| inSz = sizeof(badAlgIdLenLong); inOutIdx = 0; | ||
| ret = wc_RsaPublicKeyDecode(badAlgIdLenLong, &inOutIdx, keyPub, inSz); | ||
| #ifndef WOLFSSL_NO_DECODE_EXTRA |
There was a problem hiding this comment.
RSA regression checks expect the legacy error in template builds · Missing/incorrect platform conditionals
The new WOLFSSL_NO_DECODE_EXTRA branches expect ASN_RSA_KEY_E even with WOLFSSL_ASN_TEMPLATE. That decoder parses the full SPKI template, returns ASN_PARSE_E, and fails this valid build configuration.
Suggested fix: Expect ASN_PARSE_E when WOLFSSL_ASN_TEMPLATE is defined; use ASN_RSA_KEY_E only for the legacy no-decode-extra path.
|
|
||
| /* should have bit tag length and seq next */ | ||
| ret = CheckBitString(input, inOutIdx, NULL, inSz, 1, NULL); | ||
| ret = CheckBitString(input, inOutIdx, NULL, seqEndIdx, 1, NULL); |
There was a problem hiding this comment.
RSA decoder ignores the BIT STRING content boundary · Logic errors
CheckBitString() discards the BIT STRING length, so RSAPublicKey integers are parsed beyond its declared content and malformed SPKI is accepted. Adjacent #11290 concerns GetAlgoIdImpl's AlgorithmIdentifier boundary.
Related known finding #11290 (similar but distinct): Both are legacy ASN.1 boundary-validation omissions, but #11290 parses AlgorithmIdentifier in GetAlgoIdImpl while this parses RSAPublicKey inside a BIT STRING in wc_RsaPublicKeyDecode_ex. The faulting nested structures and required bounds checks differ, so separate patches are required.
Suggested fix: Capture the BIT STRING length, bound the nested SEQUENCE and integers to its end, and require both nested structures to be exactly consumed.
Basis: RFC 3279 §2.3.1 specifies that the subjectPublicKey BIT STRING contains the DER-encoded RSAPublicKey value.
| if (tag != ECC_PREFIX_0) | ||
| return ASN_ECC_KEY_E; | ||
| if (GetLength(input, inOutIdx, &length, inSz) <= 0) | ||
| if (GetLength(input, inOutIdx, &length, seqEndIdx) <= 0) |
There was a problem hiding this comment.
ECPrivateKey parameter wrapper length is discarded · Logic errors
The [0] length is parsed but discarded while algEndIdx remains seqEndIdx, allowing curve parameters to cross their ECPrivateKey wrapper. Adjacent #11292 is the same boundary class in a PKCS7 parser.
Related known finding #11290 (similar but distinct): Both discard an ASN.1 container boundary in asn_orig.c, but #11290 concerns AlgorithmIdentifier parsing in GetAlgoIdImpl whereas this concerns the explicit ECPrivateKey [0] parameters wrapper in wc_EccPublicKeyDecode. The operations, root parsing context, and fix locations differ.
Suggested fix: Compute the [0] content end, bound all named and explicit parameter parsing to it, and require exact consumption before parsing [1].
Basis: RFC 5915 §3 defines ECPrivateKey parameters as an explicitly tagged [0] ECParameters value with its own content boundary.
Track the actual depth and compare to expected. Added tests for this.
b69d2df to
b324103
Compare
Description
Track the actual depth and compare to expected.
Added tests for this.
Testing
Added tests.