feat(libSceLibreSsl): implement the X509_STORE_CTX error, depth, current certificate and chain accessors #10447

Merged
alvaroelpob merged 7 commits from upstream-pr/10447 into main 2026-10-27 23:03:34 +00:00
alvaroelpob commented 2026-10-24 00:51:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-24T00:51:55Z.


What

Implements X509_STORE_CTX_get_error, X509_STORE_CTX_set_error, X509_STORE_CTX_get_error_depth, X509_STORE_CTX_get_current_cert and X509_STORE_CTX_get_chain in libSceLibreSsl, which threw and were declared without parameters.

The module is LibreSSL 2.5.4 (firmware 13.40 measurements in #8981). Signatures, the X509_STORE_CTX layout and the results follow that release's x509_vfy.h and x509_vfy.c:

Export Behaviour
int X509_STORE_CTX_get_error(X509_STORE_CTX*) error
void X509_STORE_CTX_set_error(X509_STORE_CTX*, int) stores the value in error and touches nothing else
int X509_STORE_CTX_get_error_depth(X509_STORE_CTX*) error_depth
X509* X509_STORE_CTX_get_current_cert(X509_STORE_CTX*) current_cert
STACK_OF(X509)* X509_STORE_CTX_get_chain(X509_STORE_CTX*) chain, without copying or taking a reference

The struct is 240 bytes on LP64 (chain at 160, error_depth at 180, error at 184, current_cert at 192, ex_data at 232; 2.5.4's CRYPTO_EX_DATA holds only the stack pointer). static_asserts check it. LibreSSL dereferences the context without checking it, so a null context throws. No export of this module creates or fills a context yet, so for now only contexts the caller builds reach these functions.

The debt entry records the source and what is unverified, and the pending-export count drops from 357 to 352.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON on main e2b9700a9. There is one commit per function, in the order get_error, set_error, get_error_depth, get_current_cert, get_chain. Each commit adds that function with its test block and debt update, and each was built and its guest_libressl_x509_store_context test and check_conventions.py run on its own.

  • New guest_libressl_x509_store_context test: on a 240-byte buffer filled with 0xAA, each getter reads its own offset; set_error writes only the 4 bytes at 184 and doesn't change error_depth; the pointer getters return null and non-null values as stored; a null context throws for all five. On main the first call throws.
  • Full ctest -j16 at the last commit: 2003/2004 pass. agc_driver_multisample_retirement fails the same way on main on this machine. On main, agc_driver_sgpr_pattern_fill_keys also failed once under -j16 and passes on its own.
  • Not tested: Windows, a title.
  • Rebased on main 1e740a23a3 (after #9033), head f59ce38328: the conflicts were only the add_library source list, the end of the test block, the pending-export count and the last debt entry; both sides are kept and the count is 357 minus this PR's exports. Full build and ctest -j16: 2043/2044 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main e7e3e9c198, head 835eb4d04d, to resolve the conflict from #9529 on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 353 minus this PR's exports. 835eb4d04d (refactor(libSceLibreSsl): declare the X509_STORE_CTX exports in the public header) puts the real signatures and their structs in libSceLibreSsl/include/Api.hpp and drops the test's redeclarations, which public_headers requires since #10706. 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 ae7d59258e (after #9949), head 9d3827f68f, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 342 minus this PR's exports. Full build and ctest -j16: 2275/2276 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 2dbe9b99f5 (after #9745, #9870 and #11111), head 3d1542748e, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 340 minus this PR's exports. Full build and ctest -j16: 2370/2371 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main c7b4878fa8 (after #10373, #10376 and #10449), head d0927e2302, to resolve the conflicts with main on the shared CMakeLists.txt, Api.hpp and debt-file lines; both sides are kept and the count is 319 minus this PR's exports. Full build and ctest -j16: 2394/2395 pass; agc_driver_multisample_retirement fails the same way on that main. 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: #9448, #9571, #10078, #10395, #10418
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4991129896 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10447). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-24T00:51:55Z. --- ### What Implements `X509_STORE_CTX_get_error`, `X509_STORE_CTX_set_error`, `X509_STORE_CTX_get_error_depth`, `X509_STORE_CTX_get_current_cert` and `X509_STORE_CTX_get_chain` 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, the `X509_STORE_CTX` layout and the results follow that release's [`x509_vfy.h` and `x509_vfy.c`](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/x509): | Export | Behaviour | |---|---| | `int X509_STORE_CTX_get_error(X509_STORE_CTX*)` | `error` | | `void X509_STORE_CTX_set_error(X509_STORE_CTX*, int)` | stores the value in `error` and touches nothing else | | `int X509_STORE_CTX_get_error_depth(X509_STORE_CTX*)` | `error_depth` | | `X509* X509_STORE_CTX_get_current_cert(X509_STORE_CTX*)` | `current_cert` | | `STACK_OF(X509)* X509_STORE_CTX_get_chain(X509_STORE_CTX*)` | `chain`, without copying or taking a reference | The struct is 240 bytes on LP64 (`chain` at 160, `error_depth` at 180, `error` at 184, `current_cert` at 192, `ex_data` at 232; 2.5.4's `CRYPTO_EX_DATA` holds only the stack pointer). `static_assert`s check it. LibreSSL dereferences the context without checking it, so a null context throws. No export of this module creates or fills a context yet, so for now only contexts the caller builds reach these functions. The debt entry records the source and what is unverified, and the pending-export count drops from 357 to 352. ### 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` e2b9700a9. There is one commit per function, in the order `get_error`, `set_error`, `get_error_depth`, `get_current_cert`, `get_chain`. Each commit adds that function with its test block and debt update, and each was built and its `guest_libressl_x509_store_context` test and `check_conventions.py` run on its own. - New `guest_libressl_x509_store_context` test: on a 240-byte buffer filled with 0xAA, each getter reads its own offset; `set_error` writes only the 4 bytes at 184 and doesn't change `error_depth`; the pointer getters return null and non-null values as stored; a null context throws for all five. On `main` the first call throws. - Full `ctest -j16` at the last commit: 2003/2004 pass. `agc_driver_multisample_retirement` fails the same way on `main` on this machine. On `main`, `agc_driver_sgpr_pattern_fill_keys` also failed once under `-j16` and passes on its own. - Not tested: Windows, a title. - Rebased on `main` 1e740a23a3 (after #9033), head f59ce38328: the conflicts were only the `add_library` source list, the end of the test block, the pending-export count and the last debt entry; both sides are kept and the count is 357 minus this PR's exports. Full build and `ctest -j16`: 2043/2044 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` e7e3e9c198, head 835eb4d04d, to resolve the conflict from #9529 on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 353 minus this PR's exports. 835eb4d04d (`refactor(libSceLibreSsl): declare the X509_STORE_CTX exports in the public header`) puts the real signatures and their structs in `libSceLibreSsl/include/Api.hpp` and drops the test's redeclarations, which `public_headers` requires since #10706. 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` ae7d59258e (after #9949), head 9d3827f68f, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 342 minus this PR's exports. Full build and `ctest -j16`: 2275/2276 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 2dbe9b99f5 (after #9745, #9870 and #11111), head 3d1542748e, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 340 minus this PR's exports. Full build and `ctest -j16`: 2370/2371 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` c7b4878fa8 (after #10373, #10376 and #10449), head d0927e2302, to resolve the conflicts with `main` on the shared `CMakeLists.txt`, `Api.hpp` and debt-file lines; both sides are kept and the count is 319 minus this PR's exports. Full build and `ctest -j16`: 2394/2395 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `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: #9448, #9571, #10078, #10395, #10418 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-24 00:52:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-24T00:52:05Z.

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:5635917447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10447#pullrequestreview-5635917447). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-24T00:52:05Z. **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 01:37:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T01:37:03Z.

Review: APPROVED


Reviewed exact head 0a5955af46bea727c08a0bb1f436f7d8daed4282. The 240-byte X509_STORE_CTX layout and offsets match the pinned LibreSSL 2.5.4 x509_vfy.h; x509_vfy.c confirms these accessors read or write only the named fields and return the stored chain/current certificate pointers without changing ownership. I found no open PR for the same five exports.

I compiled the exact changed implementation and supplied test with GCC 12.2, C++20, -Wall -Wextra -Werror; the focused test passed. This direct build used a temporary NotImplemented_nid_no_patch shim and does not validate full project linkage or exception integration. Exact-head conventions passed. Hosted eligibility, conventions, intake, labels and report checks pass; full Linux/Windows product jobs are skipped under repository policy. The PR declares its LibreSSL dependency ordering. No blocking behavior issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636205979 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10447#pullrequestreview-5636205979). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T01:37:03Z. **Review:** APPROVED --- Reviewed exact head 0a5955af46bea727c08a0bb1f436f7d8daed4282. The 240-byte X509_STORE_CTX layout and offsets match the pinned LibreSSL 2.5.4 x509_vfy.h; x509_vfy.c confirms these accessors read or write only the named fields and return the stored chain/current certificate pointers without changing ownership. I found no open PR for the same five exports. I compiled the exact changed implementation and supplied test with GCC 12.2, C++20, -Wall -Wextra -Werror; the focused test passed. This direct build used a temporary NotImplemented_nid_no_patch shim and does not validate full project linkage or exception integration. Exact-head conventions passed. Hosted eligibility, conventions, intake, labels and report checks pass; full Linux/Windows product jobs are skipped under repository policy. The PR declares its LibreSSL dependency ordering. No blocking behavior issue found.
ahmadmuj commented 2026-10-25 18:55:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T18:55:06Z.

Review: APPROVED


Reviewed head 0f8367b2 (base main 6e775f45). Ubuntu 24.04, GCC 13.3, Release, real build with no shim.

What I ran:

  • Exact head: built libSceLibreSsl.prx and all 10 guest_libressl_* tests; all pass. check_conventions.py passes. I got the same result on the previous head fd3ea94 merged onto main a7a2eece. The PR's code is identical between the two heads; only the debt-file context moved.
  • Layout: printed offsetof for all 33 members of 2.5.4's x509_store_ctx_st and of LibreSslX509StoreContext. All match, size 240. That fits BunnyFl's 13.42 offsets.
  • Real objects: built LibreSSL 2.5.4 libcrypto and ran X509_verify_cert in 4 cases: missing issuer, valid chain, set_error(23) after a failure, expired CA. I dumped the 240-byte ctx each time and fed the bytes to this PR's exports from the built prx. error, depth, current_cert and chain match 2.5.4's own getters in all 4. Example: in the expired-CA case both give error 10, depth 1, and current_cert = the CA, not the leaf. set_error on those dumps changes only bytes 184-187. With error and error_depth swapped in a probe copy of the struct, 3 of the 4 cases differ, so the comparison isn't vacuous.
  • Mutations against the PR's test: get_error_depth reading error, set_error writing errorDepth, get_chain reading currentCert. Each one fails the test (lines 80, 67, 105).

Optional nit: TestGetErrorDepth skips the OnlyChanged check that the other blocks do.

Heads up: #9949 merged after your rebase, so this conflicts again in CMakeLists.txt (the add_library source list and the test block) and in the debt file.

Not checked: Windows, the console (I have no dumps).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644740953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10447#pullrequestreview-5644740953). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T18:55:06Z. **Review:** APPROVED --- Reviewed head 0f8367b2 (base main 6e775f45). Ubuntu 24.04, GCC 13.3, Release, real build with no shim. What I ran: - Exact head: built `libSceLibreSsl.prx` and all 10 `guest_libressl_*` tests; all pass. `check_conventions.py` passes. I got the same result on the previous head fd3ea94 merged onto main a7a2eece. The PR's code is identical between the two heads; only the debt-file context moved. - Layout: printed `offsetof` for all 33 members of 2.5.4's `x509_store_ctx_st` and of `LibreSslX509StoreContext`. All match, size 240. That fits BunnyFl's 13.42 offsets. - Real objects: built LibreSSL 2.5.4 libcrypto and ran `X509_verify_cert` in 4 cases: missing issuer, valid chain, `set_error(23)` after a failure, expired CA. I dumped the 240-byte ctx each time and fed the bytes to this PR's exports from the built prx. error, depth, current_cert and chain match 2.5.4's own getters in all 4. Example: in the expired-CA case both give error 10, depth 1, and current_cert = the CA, not the leaf. `set_error` on those dumps changes only bytes 184-187. With error and error_depth swapped in a probe copy of the struct, 3 of the 4 cases differ, so the comparison isn't vacuous. - Mutations against the PR's test: get_error_depth reading `error`, set_error writing `errorDepth`, get_chain reading `currentCert`. Each one fails the test (lines 80, 67, 105). Optional nit: `TestGetErrorDepth` skips the `OnlyChanged` check that the other blocks do. Heads up: #9949 merged after your rebase, so this conflicts again in `CMakeLists.txt` (the `add_library` source list and the test block) and in the debt file. Not checked: Windows, the console (I have no dumps).
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!10447
No description provided.