feat(libSceLibreSsl): implement X509_LOOKUP_file and X509_STORE_add_lookup #11105

Merged
JaceTheBlu merged 18 commits from upstream-pr/11105 into main 2026-10-28 14:35:23 +00:00
JaceTheBlu commented 2026-10-25 17:41:07 +00:00 (Migrated from github.com)

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


What

Implements X509_LOOKUP_file and X509_STORE_add_lookup in libSceLibreSsl, which threw and were declared without parameters, and lets X509_STORE_free free the store's lookups. It stacks on #11100, which carries #11089.

Export Behaviour
X509_LOOKUP_METHOD* X509_LOOKUP_file(void) returns the static 80-byte file method: name "Load file into cache", only ctrl set, as x509_file_lookup in by_file.c
X509_LOOKUP* X509_STORE_add_lookup(X509_STORE*, X509_LOOKUP_METHOD*) returns the store's lookup whose method is the given one; otherwise mallocs a 32-byte lookup as X509_LOOKUP_new leaves it (init and skip 0, no method data), sets its store_ctx to the store and pushes it on the store's methods, doubling the element array with realloc when num_alloc <= num + 1 as sk_insert does; a failed push frees the new lookup and returns null

X509_STORE_free now shuts down and frees each listed lookup as x509_lu.c does, instead of throwing when a lookup is listed.

These follow LibreSSL 2.5.4 by_file.c and x509_lu.c and stack.c, which are unchanged in 2.7 (OPENBSD_6_3, whose X509_VERIFY_PARAM_set1_host the module also exports). Layouts are checked with static_asserts on LP64.

What is not modelled throws instead of being guessed: the file method's ctrl (loading PEM certificates and CRLs needs a certificate model this module does not have yet), and the new_item, shutdown and free callbacks of a guest-supplied method, which are not called. A null store, method or listed lookup throws where LibreSSL faults. The debt entry records this, and the pending-export count in docs/dev/debt/libSceLibreSsl.md drops by two.

Tested

Debian trixie container, GCC 14.2, full Release build of this branch. ctest -R 'libressl|crypto_memcmp': all pass (18 of 18 on the stacked head), including the new guest_libressl_x509_lookup (the static method and its fields, a new lookup's fields and owner, finding a lookup again, five more methods growing the stack from 4 to 8 slots, the throwing cases) and guest_libressl_x509_lookup_allocator (one malloc per lookup, one realloc on the fourth push, every lookup freed with the store, a failed realloc and a store without a method stack freeing the new lookup), and guest_libressl_x509_store. 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).

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: #11100
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007082403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11105). Originally posted by [JaceTheBlu](https://github.com/JaceTheBlu) on 2026-10-25T17:41:07Z. --- ### What Implements `X509_LOOKUP_file` and `X509_STORE_add_lookup` in libSceLibreSsl, which threw and were declared without parameters, and lets `X509_STORE_free` free the store's lookups. It stacks on #11100, which carries #11089. | Export | Behaviour | |---|---| | `X509_LOOKUP_METHOD* X509_LOOKUP_file(void)` | returns the static 80-byte file method: name `"Load file into cache"`, only `ctrl` set, as `x509_file_lookup` in `by_file.c` | | `X509_LOOKUP* X509_STORE_add_lookup(X509_STORE*, X509_LOOKUP_METHOD*)` | returns the store's lookup whose `method` is the given one; otherwise `malloc`s a 32-byte lookup as `X509_LOOKUP_new` leaves it (`init` and `skip` 0, no method data), sets its `store_ctx` to the store and pushes it on the store's methods, doubling the element array with `realloc` when `num_alloc <= num + 1` as `sk_insert` does; a failed push frees the new lookup and returns null | `X509_STORE_free` now shuts down and frees each listed lookup as `x509_lu.c` does, instead of throwing when a lookup is listed. These follow LibreSSL 2.5.4 [`by_file.c` and `x509_lu.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), which are unchanged in 2.7 (`OPENBSD_6_3`, whose `X509_VERIFY_PARAM_set1_host` the module also exports). Layouts are checked with `static_assert`s on LP64. What is not modelled throws instead of being guessed: the file method's `ctrl` (loading PEM certificates and CRLs needs a certificate model this module does not have yet), and the `new_item`, `shutdown` and `free` callbacks of a guest-supplied method, which are not called. A null store, method or listed lookup throws where LibreSSL faults. The debt entry records this, and the pending-export count in `docs/dev/debt/libSceLibreSsl.md` drops by two. ### Tested Debian trixie container, GCC 14.2, full Release build of this branch. `ctest -R 'libressl|crypto_memcmp'`: all pass (18 of 18 on the stacked head), including the new `guest_libressl_x509_lookup` (the static method and its fields, a new lookup's fields and owner, finding a lookup again, five more methods growing the stack from 4 to 8 slots, the throwing cases) and `guest_libressl_x509_lookup_allocator` (one `malloc` per lookup, one `realloc` on the fourth push, every lookup freed with the store, a failed `realloc` and a store without a method stack freeing the new lookup), and `guest_libressl_x509_store`. `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`). ### 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: #11100 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 18:08:19 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Reviewed exact head e8d6c3fb477fe583c554efd13b6ba88752eecb91.

X509_STORE_add_lookup_nid_postfix allocates lookup at line 227 before rejecting a null method or a method with an unsupported newItem callback. Both checks throw before the lookup is added to store->lookupMethods, so the store cannot reclaim that block. tests/X509Lookup.cpp::Unsupported catches both exceptions and confirms the store remains unchanged, but it does not check allocator balance; repeated caught calls therefore leak one guest-heap allocation each.

Please validate method and method->newItem before allocating, or explicitly free the local lookup before throwing. Extend the allocator test to assert these rejected cases do not leave an allocation outstanding. This is limited to the two already-tested error paths; the normal lookup allocation and cleanup tests can remain as they are.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644562646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11105#pullrequestreview-5644562646). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T18:08:19Z. **Review:** CHANGES_REQUESTED --- Reviewed exact head `e8d6c3fb477fe583c554efd13b6ba88752eecb91`. `X509_STORE_add_lookup_nid_postfix` allocates `lookup` at line 227 before rejecting a null `method` or a method with an unsupported `newItem` callback. Both checks throw before the lookup is added to `store->lookupMethods`, so the store cannot reclaim that block. `tests/X509Lookup.cpp::Unsupported` catches both exceptions and confirms the store remains unchanged, but it does not check allocator balance; repeated caught calls therefore leak one guest-heap allocation each. Please validate `method` and `method->newItem` before allocating, or explicitly free the local lookup before throwing. Extend the allocator test to assert these rejected cases do not leave an allocation outstanding. This is limited to the two already-tested error paths; the normal lookup allocation and cleanup tests can remain as they are.
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!11105
No description provided.