Repository navigation
feat(libSceLibreSsl): implement X509_STORE_add_cert - #13285
JaceTheBlu wants to merge 43 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 X509_STORE_add_cert from LibreSSL 2.5.4 x509_lu.c: the 16-byte X509_OBJECT, the extra certificate reference, the subject lookup that sorts the object cache by canonical subject before each push, and the malloc failure errors. X509_STORE_free now frees stored certificates. Adding a certificate whose subject is already in the store throws, as LibreSSL then compares the two with X509_cmp, which needs the SHA-1 hash and extension cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
The duplicate-certificate and modified-subject error paths leak the candidate object and its added certificate reference, and the PR description does not use the required template.
What I ran
Reviewed head 25592c3e2a6db62703e28744073b56a03c784f33 against PR base 8e68a7d7b9f6aeedb0ca03eee115571640555988; the dependency checker confirmed #13266's current head is included in this PR. Its merge-preview result became stale while main advanced, so I do not rely on it. Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5. No C++ build or tests were run locally.
git diff --check 8e68a7d7b9f6aeedb0ca03eee115571640555988...25592c3e2a6db62703e28744073b56a03c784f33
python3 tools/check_conventions.py --base 8e68a7d7b9f6aeedb0ca03eee115571640555988 --head 25592c3e2a6db62703e28744073b56a03c784f33 --title 'feat(libSceLibreSsl): implement X509_STORE_add_cert' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13285-25592c3e2a6d/pr-body.md
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 8e68a7d7b9f6aeedb0ca03eee115571640555988 --head 25592c3e2a6db62703e28744073b56a03c784f33 --json
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13285
python3 tools/pr_stack_check.py 13285 --repo boykopovar/AnyPS5 --output-dir /tmp/stack-13285Results
| Check | Result |
|---|---|
| Diff whitespace | Passed; git diff --check produced no output. |
| Conventions and PR template | Failed: the required ### What, ### Tested, and ### Checklist headings are absent. |
| ABI audit | passed_with_warnings; its two lexical findings are private helpers (CompareObjects, LoadFile), not exported functions. This is not a complete ABI or compile check. |
| Dependency/mergeability | #13266's exact head is included. The current-main preview became stale because main advanced during the check; no conclusion is drawn from that preview. |
| Focused and oracle tests | The author reports 38/38 `libressl |
| Hosted CI | Intake, conventions, labels, eligibility, and progress report were queued at final refresh. |
Unedited check output excerpts
(pull request): error: [pr-template] Fill in the pull request template: add the '### What' heading of the template
(pull request): error: [pr-template] Fill in the pull request template: add the '### Tested' heading of the template
(pull request): error: [pr-template] Fill in the pull request template: add the '### Checklist' heading of the template
3 findings, 3 errors; GitHub shows at most 10 error annotations, the job summary lists all
{
"status": "passed_with_warnings",
"findings": [
{
"symbol": "CompareObjects",
"kind": "public-declaration-not-found",
"message": "No APS5_VABI declaration was found in a header; verify whether this is intentionally private or missing from the public interface."
},
{
"symbol": "LoadFile",
"kind": "public-declaration-not-found",
"message": "No APS5_VABI declaration was found in a header; verify whether this is intentionally private or missing from the public interface."
}
]
}Findings
Blocking
X509_STORE_add_cert_nid_postfixincrementscertificate->referencesand allocatesobjectbeforeFind. For duplicate subjects and modified subjects,Findthrows through the documented unsupported paths; that bypasses both the decrement andfree_nid_postfix(object). Each such call leaks the object and leaves the certificate reference count elevated. Clean up the candidate object and undo the reference increment on every exceptional exit (for example, use scoped ownership), then extendSameSubjectto assert unchanged references after each thrown call.- The PR description omits the repository-required template headings and checklist. Please preserve and fill in the template sections, including
### What,### Tested, and### Checklistwith the declared dependencies. The repository's conventions check currently fails on these omissions.
Non-blocking
The implementation and test changes are extensive; I reviewed the store insertion path and the new duplicate/modified-subject cases that expose the resource leak. The author-reported test and oracle results have not been independently reproduced here.
Sources
- Insertion increments the reference before the throwing lookup.
- Duplicate and modified-subject tests currently check only that an exception is thrown.
- Repository PR template and dependency checklist rules.
Not verified
I did not build or run C++ tests or the LibreSSL oracle. Hosted CI was pending. The precheck's merge preview was stale after main advanced; ABI-audit warnings are lexical and need no public-export conclusion. I did not run the test-quality helper because it is absent from the isolated precheck checkout.
To get this to a good state
Please make the insertion path exception-safe, assert the reference counts remain unchanged after the expected throws, and update the description using the repository template. I will rerun the same diff, conventions, ABI, and dependency checks on the new head; build-dependent tests remain outside this initial no-build review.
|
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 (85f73c1 → 0ecf9da)📈 System libraries: 42.89% (+0.01%, +2 implemented functions) ✅ 2 implemented
Changed libraries (implemented exports)
|
…t throws The duplicate-subject and modified-subject paths threw after taking a certificate reference and allocating the object. Drop the reference and free the object before rethrowing, and check the counts in the tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Windows result for head Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, The tree also carried the open PR #13286, merged cleanly, so the run is a joint one. The tests this PR adds or extends all pass: AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine. |
|
@MarcZX10 Thanks. Both points are addressed on
I reran on this head:
(Sorry for the close/reopen just before this; that was a misclick.) |
…ports Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
….cpp ports Also drop the executable bit that four files of this branch gained. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compare decoded certificates with the reference only when the host long is 8 bytes. On an LLP64 host the reference library lays X509 out with 4-byte longs, so the oracle compared two different layouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The store 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>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The inspected implementation at head f27b826502d2ab01205e20a2603e9371e7285d40 has no verified blocking defect; the description reports passing tests, but I did not run them.
What I ran
No commands or tests were run. I inspected the prepared diff and targeted source through repo_read.py.
Results
| Check | Result | Note |
|---|---|---|
| Prepared diff inspection | passed | Reviewed relevant store changes |
| Tests | not run | Results in the description are author reported |
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
The full review is incomplete: I did not read all changed files, so an approval is not justified. The manifest indicates changes across multiple files; I inspected the description, commits, the start of the diff, and targeted ranges in X509Store.cpp. files.json was not available at the review path; exclusions and the complete set of reviewed files are not verified. Tests, Windows, title, and console behavior were not verified.
To get this to a good state
Nothing is required.
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.
feat(libSceLibreSsl): implement X509_STORE_add_cert — no blocking findings
Nothing blocks this; the points below are optional. The review is partial (see Not verified), so this is a comment, not an approval.
What I ran
- Read
description.md,commits.md,manifest.jsonand the first 995 lines ofdiff.patch(CMake,Export.cpp,include/Api.hpp, the start ofsrc/X509.cpp). - Read
diff.patchlines 2030–2075 (d2i_X509,X509_free,CertInfo) and 2076–2355 (src/X509Store.cpp: comparator,Sort/Find,FreeObject,X509_STORE_free,X509_STORE_add_cert). repo_read.py searchfor uses of the renamedencfield and for theX509_freeandd2i_X509definitions. Both searches returned 0 matching lines, so they checked nothing.- No build and no test run. The description reports
ctest -R 'libressl|crypto_memcmp'at 38/38 on head41809f501b; I did not reproduce it.
Results
| Check | Result | Note |
|---|---|---|
Build and ctest |
Not run | Description reports a pass; not reproduced here. |
Logic read: X509_STORE_add_cert |
Read | src/X509Store.cpp:2322–2350 (diff). Reference is taken before the lookup and dropped on every failure path. Null certificate returns 0 with no error. |
Logic read: comparator and Find |
Read | src/X509Store.cpp:2231–2294 (diff). Duplicate subjects throw, as the description says. |
| Store free | Read | src/X509Store.cpp:2305–2315 (diff). Stored certificates are released with X509_free. |
d2i_X509 / X509_free |
Read in part | src/X509.cpp:2059–2071 (diff). The body of the decoder was not read. |
Rename of LibreSslX509CertInfo::enc to encoding |
Not checked | Search returned no matches; callers not verified. |
| Test files | Not read | tests/X509.cpp, tests/X509Store.cpp, tests/Oracle.cpp, tests/OracleReference.cpp. |
| Debt entry | Not read | docs/dev/debt/libSceLibreSsl.md, hunks at lines 128, 157 and 173. The "286 to 285" count is not verified. |
Findings
Blocking
None found in the code I read.
Non-blocking
None recorded. I did not find a concrete defect in the sections I read.
Not verified
- Build,
ctest, and the 3,000-case oracle run. None were run here. src/X509.cppfrom diff line 995 to the end of the new file (about 1,900 lines in total) and the decoder body insrc/X509.cpparound thed2i_X509call.- The
enctoencodingrename ininclude/Api.hppand all its callers in the library. The reader search returned no matches, so this was not checked. - The
static_assertoffsets insrc/X509.cppfor the new 176-byteLibreSslX509layout. They were not checked against the header. - The four test files and the debt entry (listed above).
files.jsonwas not read, so I cannot say which files it lists asreviewed.
To get this to a good state
Nothing is required.
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
|
Retested head Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, The tests this PR adds or extends, AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: reject oversized DER lengths before narrowing them to int.
What I ran
Reviewed head 0ecf9daf7de09ff04cdd0a826f559eeda44c78bc using the prepared diff and repo_read.py source reader. No tests or build commands were run. The description reports a Debian/GCC 14.2 test run; that result was not independently run here.
Results
| Check | Result | Note |
|---|---|---|
| Source review | failed | Oversized DER length can be narrowed |
| Tests/build | not run | Author reports passing tests |
Findings
Blocking
core/libs/prx/libSceLibreSsl/src/X509.cpp:1247:PrimitiveDecodenarrows the decoded content length fromint64_ttointwithout checking that it fits. A valid encoded length aboveINT_MAXcan wrap or truncate, causingContentToValueto process a length different from the encoded content length and potentially read past the input buffer. Reject values aboveINT_MAXbefore this cast (and preserve the matching error behavior).
Non-blocking
None.
Not verified
- The reported test suite and build were not run during this review.
- Windows, title, and console behavior were not tested, as the author also notes.
- Read all changed files listed in the manifest:
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/src/X509Store.cpp,core/libs/prx/libSceLibreSsl/tests/Oracle.cpp,core/libs/prx/libSceLibreSsl/tests/OracleReference.cpp,core/libs/prx/libSceLibreSsl/tests/X509.cpp,core/libs/prx/libSceLibreSsl/tests/X509Store.cpp, anddocs/dev/debt/libSceLibreSsl.md. No files were excluded by the prepared manifest.
To get this to a good state
Reject DER content lengths that cannot be represented by int before casting, add coverage for that boundary, and rerun the reported build and test checks on the updated head.
|
Retested head Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, The tests this PR adds or extends, AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine. |
|
Closing this one: #23574 put an The rest of the stack (#13266, #13546, #13547, #13877) does not depend on this PR and stays open, up to date with |
What
Implements
X509_STORE_add_certin libSceLibreSsl, on top of theX509from #13266. This is stacked on #13266, and through it #11359 and #11129. Merge those first; this PR's own diff is then only the store change, its tests and its debt entry.It follows LibreSSL 2.5.4
x509_lu.c:X509_OBJECTand gives the certificate one more reference.sk_find. That lookup sorts the cache first, through the store's comparator: by type, then by canonical subject length, then by its bytes. So each new certificate is pushed after the sorted ones, and the next add sorts again.ERR_R_MALLOC_FAILUREfromERR_LIB_X509on the queue. A failed push also drops the reference and frees the object.The comparator that
X509_STORE_newinstalls no longer throws for certificates.X509_STORE_freenow frees stored certificates withX509_free, assk_X509_OBJECT_pop_freedoes.There is a new entry in
docs/dev/debt/libSceLibreSsl.md, and the pending count goes from 286 to 285.Adding a certificate whose subject is already in the store throws, including adding the same certificate twice. LibreSSL then calls
X509_cmp, which needs:X509_check_purpose's SHA-1 hash and extension cache;These cases also throw:
When it throws, the add first drops the reference it took and frees its object, so the certificate and the store are left as they were. The
X509_STOREentry no longer says that stored certificates throw.Tested
Debian container, GCC 14.2, full Release build of head
ed7a8e090a:ctest -R 'libressl|crypto_memcmp'passes 38 of 38.tools/check_test_registration.pyandpython3 tools/check_conventions.py --base upstream/mainpass.guest_libressl_x509_storechecks:guest_libressl_x509_store_allocatorchecks three failures:It checks the error code, the reference count and what is freed, and that a later add succeeds.
guest_libressl_oracle(ANYPS5_LIBRESSL_ORACLE) now also fills a store on each side with 1 to 14 random certificates with distinct subjects, plus some null ones. After each add, it compares:X509_STORE_free.The 3,000 cases show no difference. The 6
AES_set_*_keycases are the existing ones 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