feat(libSceLibreSsl): implement X509_STORE_new, X509_STORE_free and X509_STORE_set_flags #11089

Merged
JaceTheBlu merged 6 commits from upstream-pr/11089 into main 2026-10-28 14:35:25 +00:00
JaceTheBlu commented 2026-10-25 17:24:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JaceTheBlu on 2026-10-25T17:24:38Z.


What

Implements X509_STORE_new, X509_STORE_free and X509_STORE_set_flags in libSceLibreSsl, which threw and were declared without parameters.

The module is LibreSSL 2.5.4 (firmware 13.40 measurements in #8981). Signatures, layouts and results follow that release's x509_vfy.h, vpm_int.h, x509_lu.c and x509_vpm.c and stack.c, checked with static_asserts on LP64:

Export Behaviour
X509_STORE* X509_STORE_new(void) mallocs the 136-byte store; cache 1, references 1, callbacks and ex_data null; the object cache is an empty 32-byte stack (4 null slots) with a comparator, the lookup methods an empty stack without one; the 64-byte X509_VERIFY_PARAM and its 56-byte X509_VERIFY_PARAM_ID are calloced with depth -1. A failed parameter allocation frees what was allocated and returns null, as x509_lu.c does
void X509_STORE_free(X509_STORE*) null is a no-op; drops a reference and returns while others remain; then frees both stacks, the ex_data stack, the verify parameters with their host names, peer name, email and IP, and the store
int X509_STORE_set_flags(X509_STORE*, unsigned long) ORs the 64-bit flags into the verify parameters, adds X509_V_FLAG_POLICY_CHECK (0x80) when any policy flag (mask 0x780) is set, returns 1

Every block comes from the guest malloc, calloc and free, as the module would through libc.

No export of this module adds a certificate, CRL, lookup method or policy object yet, so X509_STORE_free throws when the object cache holds a non-null entry, a lookup method is listed or the verify parameters hold a policy object, instead of freeing objects there is no model for; the object cache's comparator throws for the same reason. A null store or verify parameters in X509_STORE_set_flags, a null parameter identity and a null element array behind a positive count throw where LibreSSL faults. These limits are in docs/dev/debt/libSceLibreSsl.md, and the pending-export count there drops from 345 to 342.

The 32-byte stack layout is declared privately in X509Store.cpp, so this does not depend on #10373, which declares the same layout in Api.hpp for sk_num, sk_value, sk_pop and sk_pop_free; whichever merges second can share that declaration.

Tested

Debian trixie container, GCC 14.2, full Release build. ctest -R 'libressl|crypto_memcmp': 13 of 13 pass, including the new guest_libressl_x509_store (every initial field, flag accumulation and the policy check, all 64 flag bits, shared references, freeing host names, peer name, email, IP and ex_data, and the throwing cases) and guest_libressl_x509_store_allocator (5 mallocs and 2 callocs per store, 7 frees, and both failed callocs releasing everything). tools/check_test_registration.py build and python3 tools/check_conventions.py --base upstream/main pass. Not tested on Windows, on a title or on a console.

tools/pr_overlap.py was not run (no authenticated gh); instead this branch was merged with git merge-tree against the 48 open LibreSSL pull requests. Code only conflicts with #9571 and #9535 (Api.hpp), which already conflict with main; the rest conflict only on the pending-export count in the debt file.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5006958615 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11089). Originally posted by [JaceTheBlu](https://github.com/JaceTheBlu) on 2026-10-25T17:24:38Z. --- ### What Implements `X509_STORE_new`, `X509_STORE_free` and `X509_STORE_set_flags` in libSceLibreSsl, which threw and were declared without parameters. The module is LibreSSL 2.5.4 ([firmware 13.40 measurements in #8981](https://github.com/boykopovar/AnyPS5/discussions/8981#discussioncomment-19111214)). Signatures, layouts and results follow that release's [`x509_vfy.h`, `vpm_int.h`, `x509_lu.c` and `x509_vpm.c`](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/x509) and [`stack.c`](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/stack/stack.c), checked with `static_assert`s on LP64: | Export | Behaviour | |---|---| | `X509_STORE* X509_STORE_new(void)` | `malloc`s the 136-byte store; `cache` 1, `references` 1, callbacks and ex_data null; the object cache is an empty 32-byte stack (4 null slots) with a comparator, the lookup methods an empty stack without one; the 64-byte `X509_VERIFY_PARAM` and its 56-byte `X509_VERIFY_PARAM_ID` are `calloc`ed with `depth` -1. A failed parameter allocation frees what was allocated and returns null, as `x509_lu.c` does | | `void X509_STORE_free(X509_STORE*)` | null is a no-op; drops a reference and returns while others remain; then frees both stacks, the ex_data stack, the verify parameters with their host names, peer name, email and IP, and the store | | `int X509_STORE_set_flags(X509_STORE*, unsigned long)` | ORs the 64-bit flags into the verify parameters, adds `X509_V_FLAG_POLICY_CHECK` (0x80) when any policy flag (mask 0x780) is set, returns 1 | Every block comes from the guest `malloc`, `calloc` and `free`, as the module would through libc. No export of this module adds a certificate, CRL, lookup method or policy object yet, so `X509_STORE_free` throws when the object cache holds a non-null entry, a lookup method is listed or the verify parameters hold a policy object, instead of freeing objects there is no model for; the object cache's comparator throws for the same reason. A null store or verify parameters in `X509_STORE_set_flags`, a null parameter identity and a null element array behind a positive count throw where LibreSSL faults. These limits are in `docs/dev/debt/libSceLibreSsl.md`, and the pending-export count there drops from 345 to 342. The 32-byte stack layout is declared privately in `X509Store.cpp`, so this does not depend on #10373, which declares the same layout in `Api.hpp` for `sk_num`, `sk_value`, `sk_pop` and `sk_pop_free`; whichever merges second can share that declaration. ### Tested Debian trixie container, GCC 14.2, full Release build. `ctest -R 'libressl|crypto_memcmp'`: 13 of 13 pass, including the new `guest_libressl_x509_store` (every initial field, flag accumulation and the policy check, all 64 flag bits, shared references, freeing host names, peer name, email, IP and ex_data, and the throwing cases) and `guest_libressl_x509_store_allocator` (5 `malloc`s and 2 `calloc`s per store, 7 `free`s, and both failed `calloc`s releasing everything). `tools/check_test_registration.py build` and `python3 tools/check_conventions.py --base upstream/main` pass. Not tested on Windows, on a title or on a console. `tools/pr_overlap.py` was not run (no authenticated `gh`); instead this branch was merged with `git merge-tree` against the 48 open LibreSSL pull requests. Code only conflicts with #9571 and #9535 (`Api.hpp`), which already conflict with `main`; the rest conflict only on the pending-export count in the debt file. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 17:29:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T17:29:44Z.

Review: APPROVED


Reviewed the added ABI layouts and allocator paths against LibreSSL 2.5.4 at the cited source revision. X509_STORE_new initializes the fields and four-slot stacks as sk_new does, the policy flag mask matches X509_V_FLAG_POLICY_MASK, and reference decrement/cleanup follow X509_STORE_free. The unsupported nonempty certificate/CRL, lookup-method and policy paths throw before freeing data the project does not model, as the debt entry says.

The PR reports a focused Debian trixie/GCC 14.2 run with 13/13 relevant CTests, including allocation-failure cleanup and the new store tests. Exact-head eligibility, conventions, intake, labels and report checks pass; hosted product jobs are skipped by path policy. Approved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644353104 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11089#pullrequestreview-5644353104). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T17:29:44Z. **Review:** APPROVED --- Reviewed the added ABI layouts and allocator paths against LibreSSL 2.5.4 at the cited source revision. `X509_STORE_new` initializes the fields and four-slot stacks as `sk_new` does, the policy flag mask matches `X509_V_FLAG_POLICY_MASK`, and reference decrement/cleanup follow `X509_STORE_free`. The unsupported nonempty certificate/CRL, lookup-method and policy paths throw before freeing data the project does not model, as the debt entry says. The PR reports a focused Debian trixie/GCC 14.2 run with 13/13 relevant CTests, including allocation-failure cleanup and the new store tests. Exact-head eligibility, conventions, intake, labels and report checks pass; hosted product jobs are skipped by path policy. Approved.
MarcZX10 commented 2026-10-25 18:26:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T18:26:21Z.

Review: APPROVED


Reviewed exact head a2d4d38a1584e6b12e750ebd90df3393cb829661. The pinned LibreSSL 2.5.4 source confirms the X509_STORE initialization fields, verify-parameter defaults (depth = -1), reference decrement/free path, and policy-flag propagation. The implementation preserves the source’s unsupported-object boundaries by throwing for populated stacks without a model. I compiled X509Store.cpp and its test with GCC 12.2 (-std=c++20 -Icore/libs -fsyntax-only); conventions and git diff --check upstream/main...HEAD pass. The author reports a full Release build and 13/13 focused CTests on Debian trixie; hosted product jobs are skipped by path policy, and I did not rerun that full suite here. I also confirmed #10373 has no code conflict with this PR; the shared debt file needs coordinated resolution as noted in my comment.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644644279 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11089#pullrequestreview-5644644279). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T18:26:21Z. **Review:** APPROVED --- Reviewed exact head `a2d4d38a1584e6b12e750ebd90df3393cb829661`. The pinned LibreSSL 2.5.4 source confirms the `X509_STORE` initialization fields, verify-parameter defaults (`depth = -1`), reference decrement/free path, and policy-flag propagation. The implementation preserves the source’s unsupported-object boundaries by throwing for populated stacks without a model. I compiled `X509Store.cpp` and its test with GCC 12.2 (`-std=c++20 -Icore/libs -fsyntax-only`); conventions and `git diff --check upstream/main...HEAD` pass. The author reports a full Release build and 13/13 focused CTests on Debian trixie; hosted product jobs are skipped by path policy, and I did not rerun that full suite here. I also confirmed #10373 has no code conflict with this PR; the shared debt file needs coordinated resolution as noted in my comment.
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!11089
No description provided.