feat(libSceLibreSsl): implement X509_STORE_add_cert #13285
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13285"
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 JaceTheBlu on 2026-10-30T11:48:04Z.
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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T11:52:46Z.
Review: CHANGES_REQUESTED
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
25592c3e2a6db62703e28744073b56a03c784f33against PR base8e68a7d7b9f6aeedb0ca03eee115571640555988; the dependency checker confirmed #13266's current head is included in this PR. Its merge-preview result became stale whilemainadvanced, 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.Results
git diff --checkproduced no output.### What,### Tested, and### Checklistheadings are absent.passed_with_warnings; its two lexical findings are private helpers (CompareObjects,LoadFile), not exported functions. This is not a complete ABI or compile check.mainadvanced during the check; no conclusion is drawn from that preview.Unedited check output excerpts
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.### 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
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
mainadvanced; 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.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T20:01:06Z.
Review: COMMENTED
Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement;
Unblocks: noneis allowed. The technical points below are unaffected.1. Adapted third-party code is in-tree.
core/libs/prx/libSceLibreSsl/src/X509Store.cppopens with "Derived from LibreSSL 2.5.4 ... x509_lu.c, x509_vpm.c, by_file.c, x509_cmp.c, stack.c, obj_dat.c" followed by the full Eric Young licence text, and the description says the add "follows LibreSSL 2.5.4x509_lu.c". CONTRIBUTING.md puts third-party code in a source-built submodule under3rdparty/<name>, with only the guest ABI adapters in the library. The same request has already been made on the parent #13266 forsrc/X509.cpp; this file needs the same treatment, and it makes sense to settle the layout once for the stack rather than per PR.2. No title reaches this. The checklist says "Unblocks: none" and the description says "Not tested on Windows, on a title or on a console". Please add a title ID with a log line showing a title on main reaching
X509_STORE_add_cert(the NotImplemented line for it is enough), or state that none is known.3. The common case still throws. Per the description, adding a certificate whose subject is already in the store throws, and that includes adding the same certificate twice. A title that loads a CA bundle with duplicate subjects (cross-signed roots are common) would hit that; can you say whether any title import path is expected to avoid it?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T06:05:22Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: reject negative DER lengths before decoding.
What I ran
Reviewed head
a528736c695012ba72091290edf221f7719a4f39from the prepared diff and repository reader. No commands or tests were run; the reported build and test results are author supplied.Results
Findings
Blocking
core/libs/prx/libSceLibreSsl/src/X509.cpp:1863accepts a negativelength. It passes that value toItemDecode;GetObjectconverts it touint64_tatX509.cpp:887, then reads the DER header through the supplied input pointer. With a non-null pointer to an empty or undersized buffer, this can read out of bounds instead of rejecting the invalid length. Reject negative lengths before starting the decode and add a regression test.Non-blocking
None.
Sources
X509.cpplines 1863–1869 and 880–921.Not verified
No tests were run during this review. Windows, title, and console behavior were not verified. The author reports those platforms were not tested. All changed files listed in the review manifest were read:
CMakeLists.txt,Export.cpp,include/Api.hpp,src/X509.cpp,src/X509Store.cpp,tests/Oracle.cpp,tests/OracleReference.cpp,tests/X509.cpp,tests/X509Store.cpp, anddocs/dev/debt/libSceLibreSsl.md. No changed files were excluded.To get this to a good state
Reject negative
d2i_X509lengths and add a regression test for a negative length with a non-null input pointer; rerun the relevant tests on the new head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T11:10:23Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation at head
f27b826502d2ab01205e20a2603e9371e7285d40has 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
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.jsonwas 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.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T09:26:27Z.
Review: COMMENTED
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
description.md,commits.md,manifest.jsonand the first 995 lines ofdiff.patch(CMake,Export.cpp,include/Api.hpp, the start ofsrc/X509.cpp).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.ctest -R 'libressl|crypto_memcmp'at 38/38 on head41809f501b; I did not reproduce it.Results
ctestX509_STORE_add_certsrc/X509Store.cpp:2322–2350(diff). Reference is taken before the lookup and dropped on every failure path. Null certificate returns 0 with no error.Findsrc/X509Store.cpp:2231–2294(diff). Duplicate subjects throw, as the description says.src/X509Store.cpp:2305–2315(diff). Stored certificates are released withX509_free.d2i_X509/X509_freesrc/X509.cpp:2059–2071(diff). The body of the decoder was not read.LibreSslX509CertInfo::enctoencodingtests/X509.cpp,tests/X509Store.cpp,tests/Oracle.cpp,tests/OracleReference.cpp.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
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.enctoencodingrename ininclude/Api.hppand all its callers in the library. The reader search returned no matches, so this was not checked.static_assertoffsets insrc/X509.cppfor the new 176-byteLibreSslX509layout. They were not checked against the header.files.jsonwas not read, so I cannot say which files it lists asreviewed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T13:31:11Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: reject oversized DER lengths before narrowing them to
int.What I ran
Reviewed head
0ecf9daf7de09ff04cdd0a826f559eeda44c78bcusing the prepared diff andrepo_read.pysource 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
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
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
intbefore casting, add coverage for that boundary, and rerun the reported build and test checks on the updated head.Pull request closed