Repository navigation
feat(libSceLibreSsl): implement i2d_X509_PUBKEY - #13546
JaceTheBlu wants to merge 46 commits into
Conversation
…_ASN1_OBJECT i2t_ASN1_OBJECT threw and was declared without parameters. It now prints an object's long name, or its short name, or its dotted OID, as OBJ_obj2txt does in LibreSSL 2.5.4, the version string the module holds: the NID is the object's own or found by the same binary search over the same order, an unassigned NID reports OBJ_R_UNKNOWN_NID for each name lookup, a truncated subidentifier returns 0 after the parts already written, and arcs past 64 bits are printed exactly. The 956 objects (short and long names, NID, OID) and their search order are generated from 2.5.4's objects.txt and obj_mac.num with its own objects.pl and obj_dat.pl, so d2i code can later hand out the same static objects LibreSSL does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…blocks On Linux the first exception the allocation test throws goes through libc's unwinder, which caches two frame descriptions with operator new for the rest of the process. The test counted them as blocks leaked by i2t_ASN1_OBJECT and failed every fault case. A first failing conversion now runs before the counted cases, and the blocks it leaves are not tracked. Against the head before the allocation fix the test still reports the escaped exceptions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The export threw and was declared without parameters. It follows LibreSSL 2.5.4's x509_obj.c: each entry is written as /SN=value with the short name from the object table, or the dotted OID when the NID is unknown, bytes outside ' ' to '~' escaped as \xHH and the zero filler of a four-byte GeneralString dropped. A caller buffer keeps the entries that fit; without one the text grows in a guest-heap BUF_MEM as buffer.c and recallocarray do, and a failed allocation returns null after the BUF and X509 malloc errors. d2i_X509 needs it for the cached subject line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # core/libs/prx/libSceLibreSsl/Export.cpp # core/libs/prx/libSceLibreSsl/include/Api.hpp # core/libs/prx/libSceLibreSsl/src/X509Name.cpp # docs/dev/debt/libSceLibreSsl.md
# Conflicts: # core/libs/prx/libSceLibreSsl/CMakeLists.txt # core/libs/prx/libSceLibreSsl/include/Api.hpp # docs/dev/debt/libSceLibreSsl.md
# Conflicts: # core/libs/prx/libSceLibreSsl/CMakeLists.txt # docs/dev/debt/libSceLibreSsl.md
# Conflicts: # docs/dev/debt/libSceLibreSsl.md
# Conflicts: # core/libs/prx/libSceLibreSsl/CMakeLists.txt # docs/dev/debt/libSceLibreSsl.md
# Conflicts: # core/libs/prx/libSceLibreSsl/CMakeLists.txt # core/libs/prx/libSceLibreSsl/Export.cpp # core/libs/prx/libSceLibreSsl/include/Api.hpp # docs/dev/debt/libSceLibreSsl.md
Port the LibreSSL 2.5.4 template decoder for the items an X509 holds (certificate, X509_CINF, algorithms, names with their canonical encoding, validity, public key, extensions and ASN1_TYPE), with the X509 layouts of x509.h, the x509 reference count and cached subject, and the error codes LibreSSL queues. guest_libressl_oracle compares generated and mutated certificates with LibreSSL 2.5.4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port the LibreSSL 2.5.4 template encoder for the items an X509_PUBKEY holds, with i2c_ASN1_INTEGER and i2c_ASN1_BIT_STRING, and compare it with LibreSSL in the oracle on decoded and altered keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
Progress report (8763aef → 08100a4)📈 System libraries: 45.23% (+0.0051%, +2 implemented functions) ✅ 2 implemented
Changed libraries (implemented exports)
|
…ports Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…name-oneline # Conflicts: # docs/dev/debt/libSceLibreSsl.md
…-x509 # Conflicts: # core/libs/prx/libSceLibreSsl/tests/Oracle.cpp # docs/dev/debt/libSceLibreSsl.md
…ated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # core/libs/prx/libSceLibreSsl/tests/Oracle.cpp
The key encoding comparison reads reference certificates through the LP64 layout too, so it runs only when the host long is 8 bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main reverted the wcstombs change that made guest_multibyte_locale fail on Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main reverted the wcstombs change that made guest_multibyte_locale fail on Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head 8057ade57bd671539090517c8d17fb765098b812 using the prepared diff and the pinned repository reader. No commands or tests were run; the build, test, and oracle results in the description are author-reported.
Read all changed lines in CMakeLists.txt, Api.hpp, src/X509.cpp, tests/Oracle.cpp, tests/OracleReference.cpp, tests/X509.cpp, and docs/dev/debt/libSceLibreSsl.md, plus the relevant Export.cpp diff. All changed files were included; no files were excluded.
Results
| Check | Result | Note |
|---|---|---|
| Diff review | passed | Prepared patch inspected |
| Tests | not run | Results reported by author |
| Windows and console behavior | not run | Author reports not tested |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full build, registered tests, oracle comparisons, Windows behavior, title behavior, and console behavior were not independently verified. The description reports a Debian/GCC 14.2 build and passing tests at a different head (16388cabad); those are author-reported results, not runs on this reviewed head.
To get this to a good state
Nothing is required.
main reads certificateInfo->enc in X509Store.cpp, so the decoder, its tests and the oracle use that name too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change based on the source inspected; the reported tests were not run in this review.
What I ran
Reviewed head b97fded6b7be929b146fe207b402938ae96db3d7 using repo_read.py to inspect the prepared diff, manifest, and changed source and test files. No build or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Encoder and related API changes inspected |
| Build and tests | not run | Description reports host tests; not independently verified |
Findings
Blocking
None found in the inspected code.
Non-blocking
None.
Not verified
The full text of core/libs/prx/libSceLibreSsl/tests/Oracle.cpp and core/libs/prx/libSceLibreSsl/tests/OracleReference.cpp was not read; those files were included in the review bundle but excluded from detailed inspection. Build, automated tests, Windows behavior, title behavior, and console behavior were not verified. The description reports a Debian Release build and 38 passing tests, plus 11,646 oracle cases; these are author-reported results.
To get this to a good state
Nothing is required.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_X509 collect_data adds each segment to the buffer length in size_t, so the buffer growth limit rejects a too-long constructed string before any int conversion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: fix d2i_X509 so decode failures do not leave a freed certificate pointer in the caller’s output.
What I ran
Reviewed head 08100a4b9d7ad08f135b037f1e393a38b01f70c5 using the prepared diff and pinned reader. No build or tests were run. The author reports a Debian/GCC 14.2 build, 38 passing tests, and 11,646 oracle cases; those results were not independently verified.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | All eight changed files read |
| Build and tests | not run | Author-reported only |
| Console behavior | not run | Not verified on console |
Findings
Blocking
core/libs/prx/libSceLibreSsl/src/X509.cpp:2051:ItemDecodefrees the reused certificate on failure (SequenceDecode’s failure path callsItemFree), but this wrapper returns null without clearing*certificate. The existing reuse test expects the output pointer to be null after a failed decode, but its call passes the now-freed pointer back in and does not check the pointer’s value. Clear the caller’s output pointer when decoding fails, and ensure the failed decode path does not leave a dangling pointer.
Non-blocking
None.
Not verified
No commands, build, tests, or console execution were performed. All changed files were included and read: core/libs/prx/libSceLibreSsl/CMakeLists.txt, core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/prx/libSceLibreSsl/include/Api.hpp, core/libs/prx/libSceLibreSsl/src/X509.cpp, core/libs/prx/libSceLibreSsl/tests/Oracle.cpp, core/libs/prx/libSceLibreSsl/tests/OracleReference.cpp, core/libs/prx/libSceLibreSsl/tests/X509.cpp, and docs/dev/debt/libSceLibreSsl.md.
To get this to a good state
Fix the dangling output pointer on decode failure, then rerun the X.509 tests and allocator test on the new head.
|
@MarcZX10 Thanks for the review. I checked the blocking point: the caller's pointer is already cleared, so I'm leaving the code as it is.
The reuse test checks this. In Linux: all 203 |
There was a problem hiding this comment.
On Linux, CTest passed guest_libressl_x509_der and guest_libressl_x509_der_allocator with this revision integrated. The default cases cover DER algorithm identifiers, omitted fields, and bit-string padding. The allocator variant passed separately.
AI-assisted: yes.
What
Implements
i2d_X509_PUBKEYin libSceLibreSsl, on top of theX509decoder from #13266. This is stacked on #13266, and through it #11359 and #11129. Merge those first; this PR's own diff is then only the encoder, its tests and its debt entry.src/X509.cppports the LibreSSL 2.5.4 template encoder (tasn_enc.c) for the items anX509_PUBKEYholds. It reuses the item tables of the decoder.ASN1_TYPEparameters of every type are encoded, including high tag numbers, and SEQUENCE, SET and OTHER values written as they are.i2c_ASN1_INTEGERhandles padding and negative values, as LibreSSL does.i2c_ASN1_BIT_STRINGcounts unused bits whenASN1_STRING_FLAG_BITS_LEFTis not set, and clears them otherwise.outreturns the length;*outgets a buffer from the guest heap;*outand the pointer advances.PutHeader, which the canonical name encoding already used, now also takes a tag class.There is a new entry in
docs/dev/debt/libSceLibreSsl.md, and the pending count goes from 286 to 285.These cases throw instead of being encoded, because nothing reachable from an
X509_PUBKEYneeds them:These cases throw where LibreSSL reads before the data or faults:
BITS_LEFT, and a negative zero INTEGER;ASN1_TYPE;Tested
Debian container, GCC 14.2, full Release build of head
16388cabad:ctest -R 'libressl|crypto_memcmp'passes 38 of 38.tools/check_test_registration.pyandpython3 tools/check_conventions.py --base upstream/mainpass.guest_libressl_x509checks that a decoded key encodes back to its DER in all three output forms, and that nothing is written outside the encoding. It also checks:BITS_LEFT;guest_libressl_oracle(ANYPS5_LIBRESSL_ORACLE) now also decodes random certificates with both implementations and encodes their public keys. In 60% of runs it first applies the same change to both keys:It compares the return value, the bytes, the pointer advance and the error queue for each output form. The 11,646 cases show no difference. The only differences the oracle reports are the 6
AES_set_*_keycases already described in the debt file.Not tested on Windows, on a title or on a console.
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)🤖 Generated with Claude Code