feat(libSceLibreSsl3): implement d2i_RSA_PUBKEY #22845

Merged
Callimann8 merged 1 commit from upstream-pr/22845 into main 2026-11-18 13:17:07 +00:00
Callimann8 commented 2026-11-18 12:28:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Callimann8 on 2026-11-18T12:28:12Z.


What

Implements d2i_RSA_PUBKEY in libSceLibreSsl3, following d2i_RSA_PUBKEY and pubkey_ex_d2i in LibreSSL 4.0.0 (x_pubkey.c) and the extern path of tasn_dec.c (both at ce488b78e0bd).

  • The SubjectPublicKeyInfo is decoded with this module's d2i_PUBKEY, the RSA key is taken with EVP_PKEY_get1_RSA and the temporary EVP_PKEY is freed, as upstream does.
  • Only a decoded RSA key frees and replaces *out and advances *in past the SPKI; on failure both are left untouched.
  • A non-RSA key (for example P-256) returns null with EVP_R_EXPECTING_AN_RSA_KEY; an RSA-PSS key is accepted, as EVP_PKEY_get1_RSA does.
  • A negative length returns null without an error, as ASN1_item_ex_d2i does. A null in, which upstream dereferences, throws.
  • Builds on RSA_free and RSA_new from the native LibreSSL3 RSA work (merged), which is what the old debt entry waited for. The import keeps binding to libSceLibreSsl3 (guest_libressl3_import_binding).
  • The debt fragment adds the entry, updates the KeyComponents.cpp entry that still listed d2i_RSA_PUBKEY as throwing, and drops it from the pending-exports count in the inventory fragment.

Tested

Linux (Ubuntu 24.04, GCC 13.3, Release). A new case in guest_libressl3_key_der decodes the RSA-2048 SPKI fixture with trailing bytes and checks the cursor, the reference count, that no private exponent is set and that n and e match d2i_PUBKEY's key. It also checks replacement of *out, a P-256 SPKI (EVP_R_EXPECTING_AN_RSA_KEY, output and cursor untouched), a truncated SPKI (ASN1_R_TOO_LONG), a negative length (no error queued) and a null in (throws). All 87 libSceLibreSsl3 tests pass on current main. tools/check_conventions.py and tools/debt_fold.py --check pass. Not tested on a console.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5375937578 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22845). Originally posted by [Callimann8](https://github.com/Callimann8) on 2026-11-18T12:28:12Z. --- ### What Implements `d2i_RSA_PUBKEY` in libSceLibreSsl3, following `d2i_RSA_PUBKEY` and `pubkey_ex_d2i` in LibreSSL 4.0.0 (`x_pubkey.c`) and the extern path of `tasn_dec.c` (both at `ce488b78e0bd`). - The SubjectPublicKeyInfo is decoded with this module's `d2i_PUBKEY`, the RSA key is taken with `EVP_PKEY_get1_RSA` and the temporary `EVP_PKEY` is freed, as upstream does. - Only a decoded RSA key frees and replaces `*out` and advances `*in` past the SPKI; on failure both are left untouched. - A non-RSA key (for example P-256) returns null with `EVP_R_EXPECTING_AN_RSA_KEY`; an RSA-PSS key is accepted, as `EVP_PKEY_get1_RSA` does. - A negative length returns null without an error, as `ASN1_item_ex_d2i` does. A null `in`, which upstream dereferences, throws. - Builds on `RSA_free` and `RSA_new` from the native LibreSSL3 RSA work (merged), which is what the old debt entry waited for. The import keeps binding to libSceLibreSsl3 (`guest_libressl3_import_binding`). - The debt fragment adds the entry, updates the `KeyComponents.cpp` entry that still listed `d2i_RSA_PUBKEY` as throwing, and drops it from the pending-exports count in the inventory fragment. ### Tested Linux (Ubuntu 24.04, GCC 13.3, Release). A new case in `guest_libressl3_key_der` decodes the RSA-2048 SPKI fixture with trailing bytes and checks the cursor, the reference count, that no private exponent is set and that `n` and `e` match `d2i_PUBKEY`'s key. It also checks replacement of `*out`, a P-256 SPKI (`EVP_R_EXPECTING_AN_RSA_KEY`, output and cursor untouched), a truncated SPKI (`ASN1_R_TOO_LONG`), a negative length (no error queued) and a null `in` (throws). All 87 libSceLibreSsl3 tests pass on current `main`. `tools/check_conventions.py` and `tools/debt_fold.py --check` pass. Not tested on a console. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
PrivacyOnion commented 2026-11-18 12:30:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T12:30:00Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 0799fa7a0a:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libressl3_key_der_tests built cleanly.
  • CTest (guest_libressl3_key_der):
    1/1 Test #4453: guest_libressl3_key_der ..........   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/Export.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/KeyDer.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified d2i_RSA_PUBKEY_nid_disambig1_nid_postfix argument validation in KeyDer.cpp: null input throws via APS5_INVALID_ARG_EX and negative length immediately returns nullptr without modifying input or output.
    • Verified LibreSSL 4.0.0 semantics: SubjectPublicKeyInfo decoded with d2i_PUBKEY_nid_postfix, key extracted with EVP_PKEY_get1_RSA_nid_disambig1_nid_postfix, temporary EVP_PKEY freed cleanly.
    • Verified output replacement via ReplaceOutput: caller pointer output is freed with RSA_free and updated only on successful RSA decode, with *input advanced past SPKI; on failure neither *output nor *input is modified.
    • Verified non-RSA rejection (e.g. EC P-256) returns nullptr and sets EVP_R_EXPECTING_AN_RSA_KEY on error queue.
    • Verified technical debt documentation in docs/dev/debt/changes/feat-libressl3-d2i-rsa-pubkey.md, inventory count update in libressl3-20171-inventory.md, and Export.cpp / Api.hpp header sync.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5956559077 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22845#pullrequestreview-5956559077). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T12:30:00Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `0799fa7a0a`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libressl3_key_der_tests` built cleanly. - **CTest** (`guest_libressl3_key_der`): ``` 1/1 Test #4453: guest_libressl3_key_der .......... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/Export.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/KeyDer.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified d2i_RSA_PUBKEY_nid_disambig1_nid_postfix argument validation in KeyDer.cpp: null `input` throws via APS5_INVALID_ARG_EX and negative length immediately returns nullptr without modifying input or output. - Verified LibreSSL 4.0.0 semantics: SubjectPublicKeyInfo decoded with d2i_PUBKEY_nid_postfix, key extracted with EVP_PKEY_get1_RSA_nid_disambig1_nid_postfix, temporary EVP_PKEY freed cleanly. - Verified output replacement via ReplaceOutput: caller pointer `output` is freed with RSA_free and updated only on successful RSA decode, with `*input` advanced past SPKI; on failure neither `*output` nor `*input` is modified. - Verified non-RSA rejection (e.g. EC P-256) returns nullptr and sets EVP_R_EXPECTING_AN_RSA_KEY on error queue. - Verified technical debt documentation in docs/dev/debt/changes/feat-libressl3-d2i-rsa-pubkey.md, inventory count update in libressl3-20171-inventory.md, and Export.cpp / Api.hpp header sync. Looks Good To Me
MarcZX10 commented 2026-11-18 12:41:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T12:41:41Z.

Review: COMMENTED


Reviewed — comments

The review bundle and pinned repository could not be inspected because the required reader command is unavailable in this session.

What I ran

No repository checks were run; repo_read.py could not be invoked.

Results

Check Result Note
Review bundle inspection not run Reader unavailable
Changed code audit not run Files not inspected

Findings

Blocking

None verified.

Non-blocking

None verified.

Not verified

The description, commits, diff, manifest, changed files, and repository context were not read. Review completeness and merge suitability cannot be determined.

To get this to a good state

Nothing is required based on verified findings. The change needs a complete review before a formal approval or change request is justified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5956718971 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22845#pullrequestreview-5956718971). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T12:41:41Z. **Review:** COMMENTED --- # Reviewed — comments The review bundle and pinned repository could not be inspected because the required reader command is unavailable in this session. ## What I ran No repository checks were run; `repo_read.py` could not be invoked. ## Results | Check | Result | Note | |---|---|---| | Review bundle inspection | not run | Reader unavailable | | Changed code audit | not run | Files not inspected | ## Findings ### Blocking None verified. ### Non-blocking None verified. ## Not verified The description, commits, diff, manifest, changed files, and repository context were not read. Review completeness and merge suitability cannot be determined. ## To get this to a good state Nothing is required based on verified findings. The change needs a complete review before a formal approval or change request is justified.
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!22845
No description provided.