Repository navigation
Conversation
… EVP_PKCS82PKEY EVP_PKCS82PKEY differed from LibreSSL 4.0.0 for RSA and EC keys: - it refused an rsaEncryption AlgorithmIdentifier whose parameter is not NULL, where rsa_param_decode ignores the parameter unless the key is RSA-PSS; - it refused bytes after the RSAPrivateKey or the ECPrivateKey inside the OCTET STRING, where d2i_RSAPrivateKey and d2i_ECPrivateKey leave them unread; - on an RSA key that does not decode it queued ERR_R_RSA_LIB before EVP_R_PRIVATE_KEY_DECODE_ERROR. Only old_rsa_priv_decode, the traditional path, raises that one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Pkcs8WithKeySuffix added DerHeaderLength(der, offset, length) and length in one expression. The call writes length and the other operand reads it, and the order of the two is unspecified. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…blicKeyInfo d2i_PUBKEY and d2i_RSA_PUBKEY were stricter than LibreSSL 4.0.0 for an rsaEncryption key: - they refused an AlgorithmIdentifier parameter that is not NULL, where rsa_param_decode ignores the parameter unless the key is RSA-PSS; - they refused bytes after the RSAPublicKey inside the BIT STRING, where d2i_RSAPublicKey leaves them unread. An OID or SEQUENCE parameter is now accepted, an OID being validated as c2i_ASN1_OBJECT_cbs does. EC keys are unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 2fc2aa3098:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_libressl3_key_der_testsbuilt cleanly. - CTest (
guest_libressl3_key_der):1/1 Test #4730: guest_libressl3_key_der .......... Passed 0.23 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceLibreSsl3/src/KeyDer.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4730: guest_libressl3_key_der ..........Subprocess aborted***Exception: 0.70 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified ValidObjectEncoding in core/libs/prx/libSceLibreSsl3/src/KeyDer.cpp:758-772 correctly implements ASN.1 OID arc parsing, rejects empty content, leading 0x80 arc bytes, and unclosed variable-length arc octets
- Verified ParseAlgorithm in core/libs/prx/libSceLibreSsl3/src/KeyDer.cpp:781-805 validates parameter TLVs for RSA keys, properly allowing absent parameters, NULL (0x05) with empty payload, valid OID (0x06), and SEQUENCE (0x30), setting ErrLibAsn1 errors appropriately
- Verified DecodeSpki in core/libs/prx/libSceLibreSsl3/src/KeyDer.cpp:868 passes allowTrailing=true to DecodeRsaPkey matching upstream LibreSSL rsa_pub_decode behavior
- Verified technical debt fragment docs/dev/debt/changes/fix-libressl3-rsa-spki-parameter-and-trailing.md accurately documents remaining divergences and conforms to AGENTS.md debt guidelines
- Verified comprehensive unit test coverage in core/libs/prx/libSceLibreSsl3/tests/KeyDer.cpp:506-621 asserting valid parameters, trailing bytes handling, broken RSA key payloads, and invalid parameter encodings with appropriate error stack checks
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the inspected implementation and tests support merging.
What I ran
Reviewed head 2fc2aa3098e536a1a1b2668327d777face2f1464 against base main. I read the prepared description, commits, diff, manifest, and all changed lines in KeyDer.cpp, tests/KeyDer.cpp, and the debt fragment. I inspected the touched DER reader and RSA decoder context with repo_read.py. No commands or tests were run during this review.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed lines | passed | All changed files read |
| Targeted implementation context | passed | RSA SPKI parsing and decode path |
| Tests and prechecks | not run | Author-reported only |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports Windows 11/MinGW tests, convention and debt checks, and mutation controls; these were not run independently. Console behavior and equivalence against a running LibreSSL 4.0.0 binary were not verified. No files were excluded from the review bundle.
To get this to a good state
Nothing is required.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
What
Stacked on #25008: only the last commit is new. It is the public-key counterpart of that PR.
For an RSA key in a
SubjectPublicKeyInfo,d2i_PUBKEYandd2i_RSA_PUBKEYinlibSceLibreSsl3were stricter than LibreSSL 4.0.0 in two ways. The source isrsa_pub_decode:AlgorithmIdentifierparameter that is notNULLrsa_param_decodereturns 1 at once unless the OID is RSA-PSSRSAPublicKeyinside theBIT STRINGd2i_RSAPublicKey(NULL, &p, pklen)stops at the end of the sequence and nothing checks the cursorASN1_R_SEQUENCE_LENGTH_MISMATCHPEM_read_bio_PUBKEYgoes throughd2i_PUBKEYand gets the same change.The parameter. It is an
ANYin the source, decoded before the key is looked at, so a malformed one still fails. The RSA branch ofParseAlgorithmnow accepts:NULLwith empty content, as before;c2i_ASN1_OBJECT_cbsdoes (not empty, no arc starting with0x80, last arc complete), elseASN1_R_INVALID_OBJECT_ENCODING. The validation copiesoid_parse_arc, including its 64-bit accumulator: an arc that wraps to zero and is followed by0x80is refused, as in the source;SEQUENCE, whose content is kept unparsed in the source.Not changed:
ERR_R_RSA_LIB,X509_R_PUBLIC_KEY_DECODE_ERROR. Unlike the private path of fix(libSceLibreSsl3): follow rsa_priv_decode and eckey_priv_decode in EVP_PKCS82PKEY #25008, 4.0.0 does raiseERR_R_RSA_LIBhere (rsa_ameth.cL179).Still refused where 4.0.0 accepts (listed in the debt fragment): a parameter of another
ANYtype (integer, strings, set, ...), aBIT STRINGwith 1 to 7 unused bits, and the RSA-PSS OID. The first is the same subset the PKCS#8 decoder has after #24999.Tested
Windows 11, MinGW GCC 15.2. Not tested on a console.
One new test function in
guest_libressl3_key_der, built from the RSA and P-256SubjectPublicKeyInfovectors the file already has:NULL, four OIDs, threeSEQUENCEs) times 4 endings (none, 1, 2 and 3 extra bytes), throughd2i_PUBKEYandd2i_RSA_PUBKEY: key returned, cursor at the end of the structure, queue empty, samenandeas the reference key;RSAPublicKeyvalues that do not decode, under each parameter: null, cursor untouched, queue = ASN.1 errors, thenERR_R_RSA_LIB, thenX509_R_PUBLIC_KEY_DECODE_ERROR;ASN1_R_INVALID_OBJECT_ENCODING), two parameters, a truncated one,NULLwith content, a primitiveSEQUENCEtag;NULLparameter, with none, and with a byte after the point are still refused.With
KeyDer.cppfrom #25008 the test fails at the first accepted case that the old code refused; with the change it passes, andguest_libressl3_pem_keysstill passes.Negative controls. 13 mutations of
KeyDer.cpp, each rebuilt and run on its own, all make the test fail: trailing bytes refused again, OID orSEQUENCErefused, any tag accepted, the OID not validated,NULLwith content accepted, another error code for a bad OID, and six on the OID validation itself (empty content, leading0x80,0x80refused everywhere, truncated arc, no wrap, a 32-bit accumulator).python tools/check_conventions.py --base origin/mainandpython tools/debt_fold.py --checkpass.Not verified. The expected queues come from reading the source, not from running a LibreSSL 4.0.0 binary.
Overlap (
python tools/pr_overlap.py --branch fix/libressl3-rsa-spki-parameter-and-trailing):d2i_PUBKEYwrapper further down inKeyDer.cpp; the tool merges it with this branch without a conflict.mainand sharesKeyDer.cppandtests/KeyDer.cpp. I read its diff: inKeyDer.cppit changes the EC private-key decoder and encoder, notParseAlgorithmorDecodeSpki; in the test it extendsTestEcPublicAndPrivateand adds a call inmain.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)