feat(libSceLibreSsl): implement X509_INFO_free #13547

Open
JaceTheBlu wants to merge 48 commits from upstream-pr/13547 into main
JaceTheBlu commented 2026-10-30 18:01:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JaceTheBlu on 2026-10-30T18:01:26Z.


What

Implements X509_INFO_free in libSceLibreSsl, on top of the X509_free from #13266.

Review scope. This PR is stacked on #13266 and has its commits, so the diff against main also contains the d2i_X509 decoder, the X509 layouts in Api.hpp and the oracle code of #13266. Those are reviewed in #13266. The part that belongs to this PR is:

  • X509_INFO_free and the LibreSslX509Info layout (src/X509.cpp, include/Api.hpp);
  • its cases in tests/X509.cpp;
  • CompareInfoFrees in tests/Oracle.cpp;
  • its debt entry.

Once #13266 is merged, the diff shrinks to these.

It follows LibreSSL 2.5.4 x_info.c:

  • A null pointer does nothing.
  • Each call drops one reference.
  • The last reference frees the certificate with X509_free, then the encrypted data and the structure from the guest heap.

Api.hpp gains the 72-byte X509_INFO layout, checked with offsetof against the 2.5.4 headers.

There is a new entry in docs/dev/debt/libSceLibreSsl.md.

No export creates an X509_INFO yet, since PEM_X509_INFO_read_bio still throws. Releasing the last reference of one that holds a CRL or an X509_PKEY throws before anything changes, as no export creates either.

Tested

Debian container, GCC 14.2, Release build of head 516d98fa0e (merged with main on Nov 21): ctest -R 'libressl|crypto_memcmp' passes 201 of 201. tools/check_test_registration.py and python3 tools/check_conventions.py --base upstream/main pass.

  • guest_libressl_x509 checks:
    • a null pointer;
    • a shared X509_INFO, which only loses a reference;
    • that a CRL or private key throws on the last reference and leaves both reference counts unchanged, but not on a shared one;
    • the release of the certificate on the last reference;
    • a null certificate and null encrypted data.
  • guest_libressl_x509_allocator checks that the last X509_INFO_free frees the structure, its encrypted data and its only certificate, with nothing left allocated.
  • guest_libressl_oracle (ANYPS5_LIBRESSL_ORACLE) now also builds an X509_INFO on each side. Each one has 1 to 3 references, an optional decoded certificate with 1 to 3 references, and optional encrypted data. The oracle compares the reference counts and the remaining fields after X509_INFO_free. The 3,000 cases show no difference. Like the other certificate comparisons, it runs only on hosts whose long is 8 bytes, since it reads the reference certificates through the guest LP64 layout. The 6 AES_set_*_key cases are the existing ones described in the debt file.

Not tested on Windows, on a title or on a console.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #13266 (#11359 and #11129 are merged)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5088845800 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13547). Originally posted by [JaceTheBlu](https://github.com/JaceTheBlu) on 2026-10-30T18:01:26Z. --- ### What Implements `X509_INFO_free` in libSceLibreSsl, on top of the `X509_free` from #13266. **Review scope.** This PR is stacked on #13266 and has its commits, so the diff against `main` also contains the `d2i_X509` decoder, the `X509` layouts in `Api.hpp` and the oracle code of #13266. Those are reviewed in #13266. The part that belongs to this PR is: - `X509_INFO_free` and the `LibreSslX509Info` layout (`src/X509.cpp`, `include/Api.hpp`); - its cases in `tests/X509.cpp`; - `CompareInfoFrees` in `tests/Oracle.cpp`; - its debt entry. Once #13266 is merged, the diff shrinks to these. It follows LibreSSL 2.5.4 `x_info.c`: - A null pointer does nothing. - Each call drops one reference. - The last reference frees the certificate with `X509_free`, then the encrypted data and the structure from the guest heap. `Api.hpp` gains the 72-byte `X509_INFO` layout, checked with `offsetof` against the 2.5.4 headers. There is a new entry in `docs/dev/debt/libSceLibreSsl.md`. No export creates an `X509_INFO` yet, since `PEM_X509_INFO_read_bio` still throws. Releasing the last reference of one that holds a CRL or an `X509_PKEY` throws before anything changes, as no export creates either. ### Tested Debian container, GCC 14.2, Release build of head `516d98fa0e` (merged with `main` on Nov 21): `ctest -R 'libressl|crypto_memcmp'` passes 201 of 201. `tools/check_test_registration.py` and `python3 tools/check_conventions.py --base upstream/main` pass. - **`guest_libressl_x509`** checks: - a null pointer; - a shared `X509_INFO`, which only loses a reference; - that a CRL or private key throws on the last reference and leaves both reference counts unchanged, but not on a shared one; - the release of the certificate on the last reference; - a null certificate and null encrypted data. - **`guest_libressl_x509_allocator`** checks that the last `X509_INFO_free` frees the structure, its encrypted data and its only certificate, with nothing left allocated. - **`guest_libressl_oracle`** (`ANYPS5_LIBRESSL_ORACLE`) now also builds an `X509_INFO` on each side. Each one has 1 to 3 references, an optional decoded certificate with 1 to 3 references, and optional encrypted data. The oracle compares the reference counts and the remaining fields after `X509_INFO_free`. The 3,000 cases show no difference. Like the other certificate comparisons, it runs only on hosts whose `long` is 8 bytes, since it reads the reference certificates through the guest LP64 layout. The 6 `AES_set_*_key` cases are the existing ones described in the debt file. Not tested on Windows, on a title or on a console. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #13266 (#11359 and #11129 are merged) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CnRJay commented 2026-11-01 19:50:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:50:19Z.

Review: COMMENTED


Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement; Unblocks: none is allowed. The technical points below are unaffected.

Two process points; I have not reviewed X509_INFO_free itself.

  1. Stacked on open PRs. The branch carries about 50 commits and 11 files (+3606) because it sits on #13266 (still open) and through it #11359 and #11129, so the claimed "own diff is only this function" is not what GitHub shows, and CI cannot isolate the change. #13546 and #13877 are stacked on the same chain. Please retarget or rebase after the base merges.

  2. The PR itself says "No export creates an X509_INFO yet, since PEM_X509_INFO_read_bio still throws", so nothing can ever hand this function a non-null pointer on main. With "Unblocks: none" and no title tested, it has no title ID and no log line reaching it. It should wait for the creator export, or name the title that calls X509_INFO_free today with a null pointer.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729925169 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13547#pullrequestreview-5729925169). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:50:19Z. **Review:** COMMENTED --- **Correction (2026-11-01):** the title-ID/log demand below is not a CONTRIBUTING requirement; `Unblocks: none` is allowed. The technical points below are unaffected. Two process points; I have not reviewed `X509_INFO_free` itself. 1. Stacked on open PRs. The branch carries about 50 commits and 11 files (+3606) because it sits on #13266 (still open) and through it #11359 and #11129, so the claimed "own diff is only this function" is not what GitHub shows, and CI cannot isolate the change. #13546 and #13877 are stacked on the same chain. Please retarget or rebase after the base merges. 2. The PR itself says "No export creates an `X509_INFO` yet, since `PEM_X509_INFO_read_bio` still throws", so nothing can ever hand this function a non-null pointer on main. With "Unblocks: none" and no title tested, it has no title ID and no log line reaching it. It should wait for the creator export, or name the title that calls `X509_INFO_free` today with a null pointer.
MarcZX10 commented 2026-11-20 06:44:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T06:44:41Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional. The review is incomplete for the full patch, so a formal merge decision is not justified.

What I ran

Read the prepared diff and inspected the X509_INFO_free implementation, its direct tests, the X509_INFO layout, test registration, and debt entry at head f3d2bdd28864f77d6c375f45ccc2b6882b41f350. No commands or tests were run.

Results

Check Result Note
Direct free path passed Null, shared, and final-reference paths inspected
Test execution not run Reported results are author-supplied
Full patch review not run Decoder and oracle additions not fully inspected

Findings

Blocking

None verified in the inspected X509_INFO_free path.

Non-blocking

  • The description says the PR’s own diff is only X509_INFO_free, its tests, and a debt entry, but the prepared diff also contains extensive d2i_X509 decoder, API layout, and oracle changes. Please clarify the intended review scope or update the description to match the diff.

Not verified

The patch changes eight files, all included in the prepared review folder. I inspected portions of X509.cpp, Api.hpp, and tests/X509.cpp, plus CMakeLists.txt, Export.cpp, and the debt entry. I did not read all changed lines in those files or inspect the changed lines in tests/Oracle.cpp and tests/OracleReference.cpp; therefore the decoder implementation, oracle changes, and their coverage remain unverified. No tests were run. Windows, title, and console behavior were not confirmed.

To get this to a good state

Nothing is required. Optional: clarify the description’s scope relative to the full diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988586096 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13547#pullrequestreview-5988586096). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T06:44:41Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. The review is incomplete for the full patch, so a formal merge decision is not justified. ## What I ran Read the prepared diff and inspected the `X509_INFO_free` implementation, its direct tests, the `X509_INFO` layout, test registration, and debt entry at head `f3d2bdd28864f77d6c375f45ccc2b6882b41f350`. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Direct free path | passed | Null, shared, and final-reference paths inspected | | Test execution | not run | Reported results are author-supplied | | Full patch review | not run | Decoder and oracle additions not fully inspected | ## Findings ### Blocking None verified in the inspected `X509_INFO_free` path. ### Non-blocking - The description says the PR’s own diff is only `X509_INFO_free`, its tests, and a debt entry, but the prepared diff also contains extensive `d2i_X509` decoder, API layout, and oracle changes. Please clarify the intended review scope or update the description to match the diff. ## Not verified The patch changes eight files, all included in the prepared review folder. I inspected portions of `X509.cpp`, `Api.hpp`, and `tests/X509.cpp`, plus `CMakeLists.txt`, `Export.cpp`, and the debt entry. I did not read all changed lines in those files or inspect the changed lines in `tests/Oracle.cpp` and `tests/OracleReference.cpp`; therefore the decoder implementation, oracle changes, and their coverage remain unverified. No tests were run. Windows, title, and console behavior were not confirmed. ## To get this to a good state Nothing is required. Optional: clarify the description’s scope relative to the full diff.
MarcZX10 commented 2026-11-21 06:33:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T06:33:31Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the free path and its exercised reference-count and cleanup behavior appear consistent with the stated scope.

What I ran

Reviewed head fa53f6a94380d2a65f5aa80ab00a032e8734924b using repo_read.py to inspect the prepared diff and pinned source. No build or tests were run.

Results

Check Result Note
Diff and source review passed Free path and tests inspected
Build and tests not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Not verified

Build and test results were not independently verified. The author reports 38 passing tests, registration and convention checks, and 3,000 oracle cases. Windows, title, and console behavior were not tested. Read: description.md, commits.md, manifest.json, diff.patch; changed source inspected: Api.hpp, X509.cpp, and tests/X509.cpp. All changed files in the manifest are marked included; the remaining changed-file contents and full test suite were not inspected.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003539674 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13547#pullrequestreview-6003539674). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T06:33:31Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the free path and its exercised reference-count and cleanup behavior appear consistent with the stated scope. ## What I ran Reviewed head `fa53f6a94380d2a65f5aa80ab00a032e8734924b` using `repo_read.py` to inspect the prepared diff and pinned source. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | Free path and tests inspected | | Build and tests | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Build and test results were not independently verified. The author reports 38 passing tests, registration and convention checks, and 3,000 oracle cases. Windows, title, and console behavior were not tested. Read: `description.md`, `commits.md`, `manifest.json`, `diff.patch`; changed source inspected: `Api.hpp`, `X509.cpp`, and `tests/X509.cpp`. All changed files in the manifest are marked included; the remaining changed-file contents and full test suite were not inspected. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-22 13:07:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T13:07:18Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 07cea365b24d0857c904b01b6cd6ffb89ad2c60c from the prepared diff and source reader. No commands or tests were run.

Results

Check Result Note
Source review passed Inspected the X509_INFO_free implementation and focused tests
Automated checks not run Test results in the description are author reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

The PR includes stacked decoder and support changes beyond the stated X509_INFO_free scope. Those changes were not fully reviewed, so approval is not justified. Windows, title, and console behavior were also not tested by this review. The description reports those environments were not tested by the author.

Reviewed file paths: core/libs/prx/libSceLibreSsl/src/X509.cpp (targeted implementation range), and the relevant changed hunks in review/diff.patch, plus review/description.md, review/commits.md, and review/manifest.json. Excluded from full source review: other changed paths and the remainder of the large stacked decoder/support changes.

To get this to a good state

Nothing is required. Optional: submit the stacked decoder and support changes in a separately reviewable scope, or provide a complete review of those changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6012414687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13547#pullrequestreview-6012414687). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T13:07:18Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `07cea365b24d0857c904b01b6cd6ffb89ad2c60c` from the prepared diff and source reader. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Inspected the `X509_INFO_free` implementation and focused tests | | Automated checks | not run | Test results in the description are author reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The PR includes stacked decoder and support changes beyond the stated `X509_INFO_free` scope. Those changes were not fully reviewed, so approval is not justified. Windows, title, and console behavior were also not tested by this review. The description reports those environments were not tested by the author. Reviewed file paths: `core/libs/prx/libSceLibreSsl/src/X509.cpp` (targeted implementation range), and the relevant changed hunks in `review/diff.patch`, plus `review/description.md`, `review/commits.md`, and `review/manifest.json`. Excluded from full source review: other changed paths and the remainder of the large stacked decoder/support changes. ## To get this to a good state Nothing is required. Optional: submit the stacked decoder and support changes in a separately reviewable scope, or provide a complete review of those changes.
ligmaSec commented 2026-12-03 16:00:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:00:52Z.

Review: COMMENTED


On Linux, CTest passed guest_libressl_x509_der and guest_libressl_x509_der_allocator with this revision integrated. The focused run covers the X509_INFO_free ownership and release checks, including the separately invoked allocator case.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6173429919 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13547#pullrequestreview-6173429919). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T16:00:52Z. **Review:** COMMENTED --- On Linux, CTest passed `guest_libressl_x509_der` and `guest_libressl_x509_der_allocator` with this revision integrated. The focused run covers the `X509_INFO_free` ownership and release checks, including the separately invoked allocator case. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/13547:upstream-pr/13547'
git switch 'upstream-pr/13547'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/13547'
git switch 'upstream-pr/13547'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/13547'
git switch 'upstream-pr/13547'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/13547'
git switch 'main'
git merge --squash 'upstream-pr/13547'
git switch 'main'
git merge --ff-only 'upstream-pr/13547'
git switch 'main'
git merge 'upstream-pr/13547'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13547
No description provided.