feat(libSceLibreSsl3): implement X509_get0_extensions, X509_get_ext_count and X509_get_ext #10493

Merged
alvaroelpob merged 9 commits from upstream-pr/10493 into main 2026-11-05 20:58:13 +00:00
alvaroelpob commented 2026-10-24 03:24:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-24T03:24:14Z.


What

Implements X509_get0_extensions, X509_get_ext_count and X509_get_ext in libSceLibreSsl3, which threw and were declared without parameters.

The module is LibreSSL 4.0.0 (firmware 13.40 measurements in #8981). Signatures, layouts and results follow that release's x509_local.h, x509_set.c, x509_ext.c, x509_v3.c and stack_local.h, stack.c:

Export Behaviour
const STACK_OF(X509_EXTENSION)* X509_get0_extensions(const X509*) cert_info->extensions
int X509_get_ext_count(const X509*) 0 for a null stack (X509v3_get_ext_count), otherwise num
X509_EXTENSION* X509_get_ext(const X509*, int loc) null for a null stack, a negative loc or loc >= num (sk_value), otherwise data[loc]

The layouts are 216 bytes for X509, 104 for X509_CINF (extensions at 72) and 32 for the stack (num, data, sorted, num_alloc, comp). They were checked with static_asserts and against offsetof from the 4.0.0 headers compiled on x86-64. LibreSSL dereferences the certificate and its cert_info without checking them, and the entry array for an index in range, so a null for any of these throws. No export of this module creates a certificate yet, so for now only certificates built by the caller reach these functions.

#10078 implements the X509_EXTENSION_get_* getters in libSceLibreSsl. This PR is in libSceLibreSsl3 and touches none of them.

The debt entry records the source and what is unverified. The pending-export count drops from 84 to 81, and the three names join the exclusion list.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON on main 379b1dca3. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its guest_libressl3_x509_extensions test and check_conventions.py run on its own.

  • New guest_libressl3_x509_extensions test. X509_get0_extensions returns null and then the stack, not the field before it. X509_get_ext_count returns 0 for a null and for an empty stack, then 3. X509_get_ext returns null without a stack, the first and second entries of a two-entry stack, and null for indexes 2, -1, INT_MIN and INT_MAX and for a null slot. The fixtures are the public LibreSsl3ExtensionsCertInfo and LibreSsl3ExtensionsX509.
  • Full ctest -j16 at the last commit: 2005/2006 pass. agc_driver_multisample_retirement fails the same way on main on this machine.
  • Not tested: Windows, a title.
  • Rebased on main e7e3e9c198, head 6ced24908f. The branch still merged cleanly, but after #10706 public_headers fails on the merge: the exports kept their (void) stubs in include/Api.hpp and the test redeclared them. 6ced24908f (refactor(libSceLibreSsl3): declare the X509 extension exports in the public header) puts the real signatures and their structs in libSceLibreSsl3/include/Api.hpp and drops the test's redeclarations. Full build and ctest -j16: 2202/2203 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 6e775f452a, head 70887669ae, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 84 minus this PR's exports. Review fix 70887669ae drops the throw checks for unsupported inputs and builds the tests on the public structs; guest_libressl3_x509_extensions passes. Full build and ctest -j16: 2268/2269 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Review fix f74d123d74 gives the stack a non-null third slot past num, so bounding on numAlloc fails guest_libressl3_x509_extensions, and the debt entry says a null entry array throws. Full build and ctest -j16 on main 6e775f452a: 2268/2269 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 74acfad65b (after #10948), head b88d2c3a1b, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 83 minus this PR's exports. Full build and ctest -j16: 2431/2432 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main f2d874c1fd (after #10948, #13267, #13831, #13897 and #14171), head 54cd11170e, to resolve the conflicts on the pending-export line of the debt file: the count and the exclusion list keep main's names and add this PR's, and the count, 74, matches the stubs in Export.cpp. Full build and ctest -j16: 3157/3157 pass. check_conventions.py --base upstream/main passes.
  • Rebased on main 4939814d79 (after #9535 and #9970), head c21ce49e51, to resolve the conflicts on the shared Export.cpp, Api.hpp and debt-file lines; both sides are kept. main says 76 pending exports with 74 stubs left, so the count is set to the 71 stubs left in Export.cpp. Full build and ctest -j16: 3538/3538 pass. check_conventions.py --base upstream/main passes.
  • Merged main b11c7bf84f (after #10557), head 7db5eca55c, to resolve the conflicts on the shared CMakeLists.txt, Api.hpp and debt-file lines; both sides are kept, X509_PUBKEY_get0_param stays in the exclusion list, and the count is set to the 70 stubs left in Export.cpp. Full build and ctest -j16: 3883/3883 pass. check_conventions.py --base upstream/main passes.

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: #10452, #10461, #10490, #10491
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4992108734 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10493). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-24T03:24:14Z. --- ### What Implements `X509_get0_extensions`, `X509_get_ext_count` and `X509_get_ext` in libSceLibreSsl3, which threw and were declared without parameters. The module is LibreSSL 4.0.0 ([firmware 13.40 measurements in #8981](https://github.com/boykopovar/AnyPS5/discussions/8981#discussioncomment-19111214)). Signatures, layouts and results follow that release's [`x509_local.h`, `x509_set.c`, `x509_ext.c`, `x509_v3.c`](https://github.com/libressl/openbsd/tree/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/x509) and [`stack_local.h`, `stack.c`](https://github.com/libressl/openbsd/tree/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/stack): | Export | Behaviour | |---|---| | `const STACK_OF(X509_EXTENSION)* X509_get0_extensions(const X509*)` | `cert_info->extensions` | | `int X509_get_ext_count(const X509*)` | 0 for a null stack (`X509v3_get_ext_count`), otherwise `num` | | `X509_EXTENSION* X509_get_ext(const X509*, int loc)` | null for a null stack, a negative `loc` or `loc >= num` (`sk_value`), otherwise `data[loc]` | The layouts are 216 bytes for `X509`, 104 for `X509_CINF` (`extensions` at 72) and 32 for the stack (`num`, `data`, `sorted`, `num_alloc`, `comp`). They were checked with `static_assert`s and against `offsetof` from the 4.0.0 headers compiled on x86-64. LibreSSL dereferences the certificate and its `cert_info` without checking them, and the entry array for an index in range, so a null for any of these throws. No export of this module creates a certificate yet, so for now only certificates built by the caller reach these functions. #10078 implements the `X509_EXTENSION_get_*` getters in libSceLibreSsl. This PR is in libSceLibreSsl3 and touches none of them. The debt entry records the source and what is unverified. The pending-export count drops from 84 to 81, and the three names join the exclusion list. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with `BUILD_TESTING=ON` on `main` 379b1dca3. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its `guest_libressl3_x509_extensions` test and `check_conventions.py` run on its own. - New `guest_libressl3_x509_extensions` test. `X509_get0_extensions` returns null and then the stack, not the field before it. `X509_get_ext_count` returns 0 for a null and for an empty stack, then 3. `X509_get_ext` returns null without a stack, the first and second entries of a two-entry stack, and null for indexes 2, -1, `INT_MIN` and `INT_MAX` and for a null slot. The fixtures are the public `LibreSsl3ExtensionsCertInfo` and `LibreSsl3ExtensionsX509`. - Full `ctest -j16` at the last commit: 2005/2006 pass. `agc_driver_multisample_retirement` fails the same way on `main` on this machine. - Not tested: Windows, a title. - Rebased on `main` e7e3e9c198, head 6ced24908f. The branch still merged cleanly, but after #10706 `public_headers` fails on the merge: the exports kept their `(void)` stubs in `include/Api.hpp` and the test redeclared them. 6ced24908f (`refactor(libSceLibreSsl3): declare the X509 extension exports in the public header`) puts the real signatures and their structs in `libSceLibreSsl3/include/Api.hpp` and drops the test's redeclarations. Full build and `ctest -j16`: 2202/2203 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 6e775f452a, head 70887669ae, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 84 minus this PR's exports. Review fix 70887669ae drops the throw checks for unsupported inputs and builds the tests on the public structs; `guest_libressl3_x509_extensions` passes. Full build and `ctest -j16`: 2268/2269 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Review fix f74d123d74 gives the stack a non-null third slot past `num`, so bounding on `numAlloc` fails `guest_libressl3_x509_extensions`, and the debt entry says a null entry array throws. Full build and `ctest -j16` on `main` 6e775f452a: 2268/2269 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 74acfad65b (after #10948), head b88d2c3a1b, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 83 minus this PR's exports. Full build and `ctest -j16`: 2431/2432 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` f2d874c1fd (after #10948, #13267, #13831, #13897 and #14171), head 54cd11170e, to resolve the conflicts on the pending-export line of the debt file: the count and the exclusion list keep `main`'s names and add this PR's, and the count, 74, matches the stubs in `Export.cpp`. Full build and `ctest -j16`: 3157/3157 pass. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 4939814d79 (after #9535 and #9970), head c21ce49e51, to resolve the conflicts on the shared `Export.cpp`, `Api.hpp` and debt-file lines; both sides are kept. `main` says 76 pending exports with 74 stubs left, so the count is set to the 71 stubs left in `Export.cpp`. Full build and `ctest -j16`: 3538/3538 pass. `check_conventions.py --base upstream/main` passes. - Merged `main` b11c7bf84f (after #10557), head 7db5eca55c, to resolve the conflicts on the shared `CMakeLists.txt`, `Api.hpp` and debt-file lines; both sides are kept, `X509_PUBKEY_get0_param` stays in the exclusion list, and the count is set to the 70 stubs left in `Export.cpp`. Full build and `ctest -j16`: 3883/3883 pass. `check_conventions.py --base upstream/main` passes. ### 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: #10452, #10461, #10490, #10491 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-24 03:25:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-24T03:25:48Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636644669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10493#pullrequestreview-5636644669). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-24T03:25:48Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
MarcZX10 commented 2026-10-24 12:09:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T12:09:09Z.

Review: APPROVED


Reviewed exact head f237ce7d1104be00efc7060b3bdec42423aa5ede against the pinned LibreSSL 4.0.0 source named in the PR. The exported signatures, null-stack/count behavior, negative and out-of-range handling, and unchecked in-range element access match the cited implementation; layout assertions cover the stated x86-64 offsets. The new tests exercise populated/empty stacks, invalid indexes, null elements, and null certificate/info/array cases. The author reports per-commit focused tests and a full build/test run with one unrelated baseline failure; I did not reproduce those runs locally. Hosted conventions, intake, eligibility, labels, and report pass; platform/product jobs were skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638185399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10493#pullrequestreview-5638185399). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T12:09:09Z. **Review:** APPROVED --- Reviewed exact head `f237ce7d1104be00efc7060b3bdec42423aa5ede` against the pinned LibreSSL 4.0.0 source named in the PR. The exported signatures, null-stack/count behavior, negative and out-of-range handling, and unchecked in-range element access match the cited implementation; layout assertions cover the stated x86-64 offsets. The new tests exercise populated/empty stacks, invalid indexes, null elements, and null certificate/info/array cases. The author reports per-commit focused tests and a full build/test run with one unrelated baseline failure; I did not reproduce those runs locally. Hosted conventions, intake, eligibility, labels, and report pass; platform/product jobs were skipped.
ahmadmuj commented 2026-10-25 19:29:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T19:29:00Z.

Review: APPROVED


Reviewed head 70887669ae67 merged onto main ae7d59258e (clean, tree 3f62a47c10). Linux x86-64, GCC 13.3, Release.

What I ran:

  • Built only guest_libressl3_x509_extensions_tests; guest_libressl3_x509_extensions passes 3 of 3 runs. check_conventions.py --base origin/main passes.
  • Red controls, 8 mutations of X509Extensions.cpp: extensions read at offset 64 or 80, count returns numAlloc, count returns -1 for a null stack, loc > num, no negative check, data[loc + 1], non-null for a null stack. All 8 fail the test.
  • Differential against real LibreSSL 2.5.4 libcrypto.a: the same X509* goes to the real functions and to these exports. Cases: a v3 cert with 6 extensions (parsed from DER), a v1 cert (null stack), X509_new with an extension added then deleted (empty stack), a bare X509_new, and X509_new with 1 extension. Count, and get_ext at INT_MIN, -2, -1, 0, 1, n-1, n, n+1, INT_MAX: identical pointers in every case. 2.5.4 has no X509_get0_extensions, so I compared that one against x->cert_info->extensions.
  • offsetof from the 4.0.0 x509_local.h and stack_local.h: X509 216, X509_CINF 104 with extensions at 72, stack 32 with data at 8. All match the static_asserts. 2.5.4 has the same X509_CINF and stack layout, so the 2.5.4 run reads the same fields.
  • Behaviour against 4.0.0 X509_get0_extensions (x509_set.c), X509_get_ext_count / X509_get_ext (x509_ext.c), X509v3_get_ext_count / X509v3_get_ext (x509_v3.c) and sk_value (stack.c): matches.

Two small non-blocking things:

  1. GuestLibreSsl3X509Extensions.cpp:43: slots[2] is null, so a bound on numAlloc instead of num still passes. I tried that mutation and the test stays green. The case is real: sk_delete only does num--, so after X509_delete_ext the deleted pointer stays at data[num]. My 2.5.4 probe saw exactly that: num 0 and the freed extension still in data[0]. A non-null third slot (say &third) makes the X509_get_ext_nid_postfix(&certificate, 2) == nullptr check with num 2 catch it.
  2. The debt line says a stack "with a positive count and null entries" throws. X509Extensions.cpp:37 throws only on a null data array; a null entry returns null, which matches sk_value and what test lines 58-59 check. Maybe "a null entry array".

Not run: Windows, a title, LibreSSL 4.0.0 as a library (its sources and headers only).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644879217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10493#pullrequestreview-5644879217). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T19:29:00Z. **Review:** APPROVED --- Reviewed head `70887669ae67` merged onto `main` `ae7d59258e` (clean, tree `3f62a47c10`). Linux x86-64, GCC 13.3, Release. What I ran: - Built only `guest_libressl3_x509_extensions_tests`; `guest_libressl3_x509_extensions` passes 3 of 3 runs. `check_conventions.py --base origin/main` passes. - Red controls, 8 mutations of `X509Extensions.cpp`: extensions read at offset 64 or 80, count returns `numAlloc`, count returns -1 for a null stack, `loc > num`, no negative check, `data[loc + 1]`, non-null for a null stack. All 8 fail the test. - Differential against real LibreSSL 2.5.4 `libcrypto.a`: the same `X509*` goes to the real functions and to these exports. Cases: a v3 cert with 6 extensions (parsed from DER), a v1 cert (null stack), `X509_new` with an extension added then deleted (empty stack), a bare `X509_new`, and `X509_new` with 1 extension. Count, and `get_ext` at `INT_MIN`, -2, -1, 0, 1, n-1, n, n+1, `INT_MAX`: identical pointers in every case. 2.5.4 has no `X509_get0_extensions`, so I compared that one against `x->cert_info->extensions`. - `offsetof` from the 4.0.0 `x509_local.h` and `stack_local.h`: `X509` 216, `X509_CINF` 104 with `extensions` at 72, stack 32 with `data` at 8. All match the `static_assert`s. 2.5.4 has the same `X509_CINF` and stack layout, so the 2.5.4 run reads the same fields. - Behaviour against 4.0.0 `X509_get0_extensions` (`x509_set.c`), `X509_get_ext_count` / `X509_get_ext` (`x509_ext.c`), `X509v3_get_ext_count` / `X509v3_get_ext` (`x509_v3.c`) and `sk_value` (`stack.c`): matches. Two small non-blocking things: 1. `GuestLibreSsl3X509Extensions.cpp:43`: `slots[2]` is null, so a bound on `numAlloc` instead of `num` still passes. I tried that mutation and the test stays green. The case is real: `sk_delete` only does `num--`, so after `X509_delete_ext` the deleted pointer stays at `data[num]`. My 2.5.4 probe saw exactly that: `num` 0 and the freed extension still in `data[0]`. A non-null third slot (say `&third`) makes the `X509_get_ext_nid_postfix(&certificate, 2) == nullptr` check with `num` 2 catch it. 2. The debt line says a stack "with a positive count and null entries" throws. `X509Extensions.cpp:37` throws only on a null `data` array; a null entry returns null, which matches `sk_value` and what test lines 58-59 check. Maybe "a null entry array". Not run: Windows, a title, LibreSSL 4.0.0 as a library (its sources and headers only).
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!10493
No description provided.