feat(libSceLibreSsl3): implement the X509 extension stack #17147

Merged
fishingpvalues merged 27 commits from upstream-pr/17147 into main 2026-11-15 12:26:58 +00:00
fishingpvalues commented 2026-11-08 11:21:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fishingpvalues on 2026-11-08T11:21:43Z.


What

Implements X509_add_ext and the non-null path of X509_EXTENSION_free in libSceLibreSsl3.

  • X509_add_ext duplicates the 24-byte extension — its object with dynamic names and data, the critical flag and the octet value — creates the certificate-info extension stack when absent, appends the copy through the existing stack helper and moves it to the requested position. A null certificate or extension returns 0.
  • X509_EXTENSION_free releases a null or non-null extension through the object and octet-string destructors. Open PR #16689 only makes the null path a no-op; this adds the non-null release and will rebase if that lands first.

src/X509ExtensionStack.cpp holds both exports, tests/X509ExtensionStack.cpp is registered as guest_libressl3_x509_extension_stack, and the stubs leave AdditionalExports.cpp while the declarations gain their real signatures in include/Api.hpp. docs/dev/debt/libSceLibreSsl3.md loses two rows (125 to 123 callable exports, 116 to 114 named) and gains one Functional entry for the unverified PS5 layouts.

Tested

Linux x86-64 (Debian 13, glibc 2.41, GCC 14.2.0), Release, BUILD_TESTING=ON, base main f9c2d92b91:

  • cmake --build build --target guest_libressl3_x509_extension_stack_tests --parallel 8: passed.
  • ctest --test-dir build -R '^guest_libressl3_x509_extension_stack$' --output-on-failure: 1/1 passed.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.
  • Merged main f9c2d92b91 and resolved the technical-debt inventory conflicts; rebuilt and reran the test.
  • Not run: Windows, a console or a title.

Checklist

  • Based on current main; #16689 also touches X509_EXTENSION_free for the null path only, so whichever merges second rebases
  • 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)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (alternate to #16689 for X509_EXTENSION_free)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5210882423 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17147). Originally posted by [fishingpvalues](https://github.com/fishingpvalues) on 2026-11-08T11:21:43Z. --- ### What Implements `X509_add_ext` and the non-null path of `X509_EXTENSION_free` in `libSceLibreSsl3`. - `X509_add_ext` duplicates the 24-byte extension — its object with dynamic names and data, the critical flag and the octet value — creates the certificate-info extension stack when absent, appends the copy through the existing stack helper and moves it to the requested position. A null certificate or extension returns 0. - `X509_EXTENSION_free` releases a null or non-null extension through the object and octet-string destructors. Open PR #16689 only makes the null path a no-op; this adds the non-null release and will rebase if that lands first. `src/X509ExtensionStack.cpp` holds both exports, `tests/X509ExtensionStack.cpp` is registered as `guest_libressl3_x509_extension_stack`, and the stubs leave `AdditionalExports.cpp` while the declarations gain their real signatures in `include/Api.hpp`. `docs/dev/debt/libSceLibreSsl3.md` loses two rows (125 to 123 callable exports, 116 to 114 named) and gains one Functional entry for the unverified PS5 layouts. ### Tested Linux x86-64 (Debian 13, glibc 2.41, GCC 14.2.0), Release, `BUILD_TESTING=ON`, base `main` `f9c2d92b91`: - `cmake --build build --target guest_libressl3_x509_extension_stack_tests --parallel 8`: passed. - `ctest --test-dir build -R '^guest_libressl3_x509_extension_stack$' --output-on-failure`: 1/1 passed. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - Merged `main` `f9c2d92b91` and resolved the technical-debt inventory conflicts; rebuilt and reran the test. - Not run: Windows, a console or a title. ### Checklist - [x] Based on current `main`; #16689 also touches `X509_EXTENSION_free` for the null path only, so whichever merges second rebases - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (alternate to #16689 for `X509_EXTENSION_free`) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
coptergui-ops commented 2026-11-08 12:57:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coptergui-ops on 2026-11-08T12:57:46Z.

Review: APPROVED


Reviewed at current head (291de49). Implements X509_add_ext and the full (non-null) X509_EXTENSION_free: deep-copies the 24-byte extension (object with dynamic names/data, critical flag, octet value) through guest calloc/malloc with rollback on partial allocation failure, creates the cert-info extension stack when absent, appends via the existing stack helper and moves to the requested position; null x509 or extension returns 0; FreeExtension releases null and non-null through the object and octet-string destructors. Stubs removed from AdditionalExports.cpp, Api.hpp declarations gain real signatures (void X509_EXTENSION_free(void*), int X509_add_ext(void*, const void*, int)). New src/X509ExtensionStack.cpp + tests/X509ExtensionStack.cpp registered as guest_libressl3_x509_extension_stack; debt loses the two NotImplemented rows (138->136 callable, 128->126 named) and gains one Functional entry documenting the unverified PS5 layouts. Tests pin deep-copy independence, front insertion, null arguments and recorded full release. Overlap verdicts: (vs PR 16689, 'Same exports X509_EXTENSION_free') 16689 (open) only converts the stub to a null no-op (non-null still throws) - this PR implements the export completely and also covers the null path, so after 17147 lands, 16689's X509_EXTENSION_free declaration/stub-move work becomes redundant: 16689 must rebase keeping only AUTHORITY_KEYID_free/X509_CRL_free (merge-tree confirms textual conflict on the same Api.hpp L248 line and AdditionalExports stub). Not a duplicate of functionality - 17147 is strictly more complete. (vs PR 15770, debt md L70) 15770 edits the X509Validity/ASN1_TIME_diff entries around L53, this PR edits the NotImplemented/Functional tables at L217+ - different entries, no shared lines. Conventions checker: baseline warnings only, no new findings from this diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5817972950 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17147#pullrequestreview-5817972950). Originally posted by [coptergui-ops](https://github.com/coptergui-ops) on 2026-11-08T12:57:46Z. **Review:** APPROVED --- Reviewed at current head (291de49). Implements X509_add_ext and the full (non-null) X509_EXTENSION_free: deep-copies the 24-byte extension (object with dynamic names/data, critical flag, octet value) through guest calloc/malloc with rollback on partial allocation failure, creates the cert-info extension stack when absent, appends via the existing stack helper and moves to the requested position; null x509 or extension returns 0; FreeExtension releases null and non-null through the object and octet-string destructors. Stubs removed from AdditionalExports.cpp, Api.hpp declarations gain real signatures (void X509_EXTENSION_free(void*), int X509_add_ext(void*, const void*, int)). New src/X509ExtensionStack.cpp + tests/X509ExtensionStack.cpp registered as guest_libressl3_x509_extension_stack; debt loses the two NotImplemented rows (138->136 callable, 128->126 named) and gains one Functional entry documenting the unverified PS5 layouts. Tests pin deep-copy independence, front insertion, null arguments and recorded full release. Overlap verdicts: (vs PR 16689, 'Same exports X509_EXTENSION_free') 16689 (open) only converts the stub to a null no-op (non-null still throws) - this PR implements the export completely and also covers the null path, so after 17147 lands, 16689's X509_EXTENSION_free declaration/stub-move work becomes redundant: 16689 must rebase keeping only AUTHORITY_KEYID_free/X509_CRL_free (merge-tree confirms textual conflict on the same Api.hpp L248 line and AdditionalExports stub). Not a duplicate of functionality - 17147 is strictly more complete. (vs PR 15770, debt md L70) 15770 edits the X509Validity/ASN1_TIME_diff entries around L53, this PR edits the NotImplemented/Functional tables at L217+ - different entries, no shared lines. Conventions checker: baseline warnings only, no new findings from this diff.
gabichuuuuu commented 2026-11-08 13:07:22 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Windows run of head 291de49ae5, merged onto main 57c0f6a48d. GitHub shows this branch as conflicting, and the local merge stops in docs/dev/debt/libSceLibreSsl3.md, so for the run I took main's version of that file. Setup: Windows 11, WinLibs GCC 15.2 (x86_64-ucrt-posix-seh), Release, BUILD_TESTING=ON.

guest_libressl3_x509_extension_stack passes as pushed.

The copy drops the OID bytes of an object that isn't DynamicData. DuplicateObject_nid_no_patch sets copy->data = nullptr and copy->length = 0, and copies the bytes only when the source has flag 0x08. Objects from the static OID table (OBJ_nid2obj and friends) have flags == 0 and point their data at static bytes. In LibreSSL, X509_add_ext → X509v3_add_ext → X509_EXTENSION_dup is an ASN1_item_dup, an encode followed by a decode. The copy's object therefore always carries the OID bytes, and for a known OID it's the table object itself.

The test builds every object with 0x01 | 0x04 | 0x08, so it never takes that path. I added a local, unpushed case to the test with a static keyUsage object: {"keyUsage", "X509v3 Key Usage", 83, 3, {55 1D 0F}, flags 0}. After X509_add_ext, the stored copy has nid 83, length 0, data null and flags 0x1. This module's own OBJ_cmp(copy, source) returns -3 where LibreSSL gives 0. Anything that later matches the extension by its object, such as OBJ_cmp or a lookup by OID, or that encodes the certificate, sees an empty OID.

A fix would be to always copy length bytes of data when source->data is set, and set DynamicData on the copy, whatever the source's flags are. The alternative is to reuse the source object when it isn't ObjectDynamic, as the decode path does for known OIDs. A test row with a static object would cover it.

A smaller difference: when the certificate has no extension stack yet, this sets certificate->extensions before duplicating. If the duplicate fails, the certificate keeps an empty stack, where LibreSSL frees the new stack and leaves extensions null.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5818001740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17147#pullrequestreview-5818001740). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T13:07:22Z. **Review:** COMMENTED --- Windows run of head `291de49ae5`, merged onto `main` `57c0f6a48d`. GitHub shows this branch as conflicting, and the local merge stops in `docs/dev/debt/libSceLibreSsl3.md`, so for the run I took `main`'s version of that file. Setup: Windows 11, WinLibs GCC 15.2 (`x86_64-ucrt-posix-seh`), Release, `BUILD_TESTING=ON`. `guest_libressl3_x509_extension_stack` passes as pushed. **The copy drops the OID bytes of an object that isn't `DynamicData`.** `DuplicateObject_nid_no_patch` sets `copy->data = nullptr` and `copy->length = 0`, and copies the bytes only when the source has flag `0x08`. Objects from the static OID table (`OBJ_nid2obj` and friends) have `flags == 0` and point their `data` at static bytes. In LibreSSL, `X509_add_ext` → `X509v3_add_ext` → `X509_EXTENSION_dup` is an `ASN1_item_dup`, an encode followed by a decode. The copy's object therefore always carries the OID bytes, and for a known OID it's the table object itself. The test builds every object with `0x01 | 0x04 | 0x08`, so it never takes that path. I added a local, unpushed case to the test with a static keyUsage object: `{"keyUsage", "X509v3 Key Usage", 83, 3, {55 1D 0F}, flags 0}`. After `X509_add_ext`, the stored copy has `nid 83`, `length 0`, `data null` and flags `0x1`. This module's own `OBJ_cmp(copy, source)` returns `-3` where LibreSSL gives 0. Anything that later matches the extension by its object, such as `OBJ_cmp` or a lookup by OID, or that encodes the certificate, sees an empty OID. A fix would be to always copy `length` bytes of `data` when `source->data` is set, and set `DynamicData` on the copy, whatever the source's flags are. The alternative is to reuse the source object when it isn't `ObjectDynamic`, as the decode path does for known OIDs. A test row with a static object would cover it. A smaller difference: when the certificate has no extension stack yet, this sets `certificate->extensions` before duplicating. If the duplicate fails, the certificate keeps an empty stack, where LibreSSL frees the new stack and leaves `extensions` null.
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!17147
No description provided.