feat(libSceLibreSsl): implement ASN.1 integer and string helpers #10005
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10005"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by AZLisme on 2026-10-23T03:50:09Z.
What
Implement five missing
libSceLibreSslexports:ASN1_INTEGER_get,ASN1_STRING_data,ASN1_STRING_length,ASN1_STRING_type, andASN1_STRING_to_UTF8. The integer accessor uses a 64-bit guestlong; string accessors preserve the supplied pointer, length and tag. Conversion supports every string tag accepted by the pinned implementation, including embedded NULs, and returns a separately allocated, terminated UTF-8 buffer through guest libc and its application allocator.Signatures, the 24-byte guest string layout and behavior follow LibreSSL 2.5.4 ASN.1 sources, including
asn1.h,a_int.c,asn1_lib.c,a_strex.c,a_mbstr.canda_utf8.c. Firmware 13.40 reports this version in discussion #8981; console behavior was not independently measured. Nonpositive integer lengths return zero for valid INTEGER tags, as 2.5.4 does.Malformed encodings and allocation failure still throw until ASN.1 error-queue reporting is implemented; these are recorded in
docs/dev/debt/libSceLibreSsl.md. The regression suite keeps successful conversions, argument validation and successful allocator/free ownership coverage without requiring those unfinished error paths to throw. The integer accessor handles the full representable signed range, including negative magnitude2^63, without signed overflow; larger unrepresentable values remain recorded as debt.The five exports now have their sole declarations in
include/Api.hpp, reached throughlibSceLibreSsl.hpp. The implementation and tests share itsAsn1Stringrecord; local export declarations and duplicate layouts are removed. The formerint function(void)declarations were unknown-signature placeholders for throwing stubs. The implemented API requires the pinned source’s arguments, pointer returns and 64-bit guestlong, so those public declarations are corrected rather than retained. Guest libc allocation/free declarations also come from its canonical header.Tested
Local Arch Linux x86-64, GCC 16.2.1, CMake 4.4.4, Ninja, Release with
BUILD_TESTING=ON: exact head6098cf2e6463f0a1726c121b5e3616d450c38246, rebased ontodc15ed65375228a0f69c41d7770c4c118adb38f2. Rebuilt the actual runtime libraries and nine focused executables.ctest --test-dir build -R 'libressl|crypto_memcmp' --output-on-failure: 10/10 passed, including both ASN.1 registrations and main's error-queue regression.ctest --test-dir build -R '^public_headers' -j2 --output-on-failure: 65/65 passed. Conventions and whitespace checks pass.Coverage includes supported conversion tags and Unicode boundaries, embedded NULs, input preservation, accessors, signed integer limits including
INT64_MIN, legacy nonpositive lengths, argument validation and successful application allocation followed by guestfree. The overlap scanner and manual name/NID audits found no duplicate implementation. The latest refresh checked all 18 listed PR heads, including new ENGINE/init PR #10878 and the updated EC-helper PR #10395; neither duplicates these helpers or introduces a prerequisite.Full Linux/Windows run 40155070561, attempt 2 is successful for exact head
6098cf2e6463f0a1726c121b5e3616d450c38246merged onto main52a8bed576e5c54a7f443728cdf663a080f8f9ed. The fresh Linux checkout/merge log independently verifies both commits.guest_floating_pointpassed.The first Linux attempt failed the intermittent
guest_floating_pointassertion, which also reproduced on an isolated build of the exact base without this PR's changes. The base-reproduction evidence remains recorded; the successful retry does not establish or fix its underlying cause. The ASN.1 patch is unchanged.Earlier run 40151824506 passed both configured platform suites for previous head
454f66248dd919868c706aa599af34fe039b5f1c; it does not qualify this rebase. macOS, PS5 and titles were not tested. No GPU code changed.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)Overlap and rebase coordination
No prerequisite is required. As proposed by its author, draft #10418 will follow #10005 and rebase afterward. If a shared branch lands first, rebase while preserving the union of library sources, focused tests and Windows PATH entries; remove only the five throwing declarations replaced here. Keep independent debt entries and recount remaining throwing exports from the resulting source. Rerun relevant builds, focused tests, conventions and overlap checks before updating with
--force-with-lease. This rebase preserved main's AES, DES, X509 error-string, RAND/CRYPTO runtime and ERR queue implementations, regression targets and debt entries; the reconciled pending-export count is 348.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:33:49Z.
Review: CHANGES_REQUESTED
I found a mismatch between the implementation and its own new regression. In
core/libs/prx/libSceLibreSsl/src/Asn1.cpp,ASN1_INTEGER_get_nid_postfixrejectslength > 8but does not reject negative lengths. For the test caseString value{-1, 2, data, 0}, the loop executes zero times,magnitudestays 0, and the function returns 0;Integers()asserts that this input returns -1. LibreSSL 2.5.4 also explicitly rejectsaint->length < 0inASN1_INTEGER_get_int64before decoding. Please add the negative-length check and rerunguest_libressl_asn1_testsand the focused test set; the reported 5/5 result should then be reconciled with the exact current source/head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:41:21Z.
Review: APPROVED
The updated exact head
1ba3d6defa37205b5149c33fd01ac0d0b47f7c47resolves my earlier negative-length finding. The newlength <= 0guard avoids reading invalid data for nonpositive lengths, and the expanded regression covers INT32_MIN, -8, -1 and zero with both integer tags and null/valid/inaccessible data pointers. I also verified the version distinction in the cited source: LibreSSL 2.5.4ASN1_INTEGER_getloops zero times for a negative length and returns 0, while the laterASN1_INTEGER_get_int64explicitly rejects negative lengths. The implementation and updated tests now match the 2.5.4 contract the PR documents.The author reports the exact-head ASN.1 tests and focused suite passing 5/5, plus conventions and whitespace checks; the hosted conventions check now passes. I did not run the C++ test executable locally in this session. My earlier request for changes applied to the superseded head and is resolved by this update.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T23:15:52Z.
Review: CHANGES_REQUESTED
One remaining signed-boundary mismatch in
ASN1_INTEGER_get_nid_postfix: the magnitude guard rejects0x8000000000000000before the negative tag can produceINT64_MIN. This is a valid 8-byte negative ASN.1 INTEGER magnitude in the representation used here. The pinned LibreSSL 2.5.4ASN1_INTEGER_getaccumulates throughsizeof(long)and applies the negative tag afterward; it has no positive-magnitude guard at this point:github.com/libressl/openbsd@2e2c612066/src/lib/libcrypto/asn1/a_int.c (L1778-L1825). Please handle the negative2^63boundary with unsigned arithmetic before rejecting other unrepresentable magnitudes, and add a regression using bytes{0x80, 0, 0, 0, 0, 0, 0, 0}, length 8 and type0x102, expectingINT64_MIN. The existing positive maximum test does not cover this boundary. I have not run the project test executable locally; this is a source and arithmetic review. The PR also currently reports a conflict with main in the debt file per the maintainer’s latest comment, so preserve both entries when rebasing.