feat(libSceLibreSsl3): implement PEM_read_RSAPrivateKey #23155

Merged
MarrasFederico merged 1 commit from upstream-pr/23155 into main 2026-11-18 20:00:46 +00:00
MarrasFederico commented 2026-11-18 19:28:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-18T19:28:27Z.


What

Implement the native libSceLibreSsl3 PEM_read_RSAPrivateKey export (psMmvmdPKds). Wrap the guest FILE in a non-closing BIO, use the native PEM decoder, and retain the RSA key independently of the temporary EVP_PKEY. Replace an existing output only after successful RSA decoding. Traditional and PKCS#8 unencrypted RSA keys are covered. Encrypted and DSA inputs retain the existing unsupported paths.

The test covers native reference ownership, replacement and preservation on error, the error queue for malformed and non-RSA inputs, and the caller's ability to continue reading and close the guest FILE. Each fixture uses its own directory.

Source: LibreSSL 4.0.0 pem_all.c. #22476 concerns the parent libSceLibreSsl implementation. #23029 removes adjacent SSL_CTX stubs and #16654 shares the pending-export count. If either lands first, preserve both implementations and recount the remaining stubs.

Tested

  • Linux GCC 15.2 and Windows MinGW GCC 16.2, Release: guest_libressl3_pem_keys passed three consecutive runs per host at b3a492fe3e6163dd715ab68095396219d87800b3.
  • On Linux, suppressing the release of the previous RSA reference failed the refcount assertion. Byte-exact restoration, rebuild and rerun passed.
  • Conventions, LibreSSL3 debt folding, diff whitespace and merge simulation checked. Console behavior remains unverified.

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:5382666347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23155). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-11-18T19:28:27Z. --- ### What Implement the native libSceLibreSsl3 `PEM_read_RSAPrivateKey` export (`psMmvmdPKds`). Wrap the guest FILE in a non-closing BIO, use the native PEM decoder, and retain the RSA key independently of the temporary EVP_PKEY. Replace an existing output only after successful RSA decoding. Traditional and PKCS#8 unencrypted RSA keys are covered. Encrypted and DSA inputs retain the existing unsupported paths. The test covers native reference ownership, replacement and preservation on error, the error queue for malformed and non-RSA inputs, and the caller's ability to continue reading and close the guest FILE. Each fixture uses its own directory. Source: [LibreSSL 4.0.0 pem_all.c](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/pem/pem_all.c#L266-L291). #22476 concerns the parent libSceLibreSsl implementation. #23029 removes adjacent SSL_CTX stubs and #16654 shares the pending-export count. If either lands first, preserve both implementations and recount the remaining stubs. ### Tested - Linux GCC 15.2 and Windows MinGW GCC 16.2, Release: `guest_libressl3_pem_keys` passed three consecutive runs per host at `b3a492fe3e6163dd715ab68095396219d87800b3`. - On Linux, suppressing the release of the previous RSA reference failed the refcount assertion. Byte-exact restoration, rebuild and rerun passed. - Conventions, LibreSSL3 debt folding, diff whitespace and merge simulation checked. Console behavior remains unverified. ### 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 19:43:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T19:43:49Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libressl3_pem_keys_tests built cleanly.
  • CTest (guest_libressl3_pem_keys):
    1/1 Test #4468: guest_libressl3_pem_keys .........   Passed    1.28 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/PemKeys.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified PEM_read_RSAPrivateKey_nid_disambig1_nid_postfix handles null stream by throwing std::invalid_argument according to debt documentation and OpenSSL/LibreSSL conventions.
    • Verified BIO creation failure queues ErrRBufLib (ERR_R_BUF_LIB) and returns nullptr without leaking resources.
    • Verified decoded EVP_PKEY and LibreSsl3Rsa ownership management using std::unique_ptr with custom deleters, ensuring no leak occurs if EVP_PKEY_get1_RSA returns nullptr or on early exit.
    • Verified rsa out-parameter semantics: if rsa != nullptr, guest input is checked, any existing *rsa is freed via RSA_free_nid_disambig1_nid_postfix only after decoding succeeds, and new pointer is written via CopyGuestOutPreservingErrno.
    • Verified debt fragment docs/dev/debt/changes/feat-libressl3-pem-rsa-file.md and pending export inventory decrement in libressl3-20171-inventory.md match AGENTS.md rules.
    • Verified unit tests in core/libs/prx/libSceLibreSsl3/tests/PemKeys.cpp thoroughly exercise traditional PEM, PKCS#8 PEM, replacement and refcounting, invalid input, non-RSA key error queues, and null stream validation.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5963808304 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23155#pullrequestreview-5963808304). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T19:43:49Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b3a492fe3e`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libressl3_pem_keys_tests` built cleanly. - **CTest** (`guest_libressl3_pem_keys`): ``` 1/1 Test #4468: guest_libressl3_pem_keys ......... Passed 1.28 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/PemKeys.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified PEM_read_RSAPrivateKey_nid_disambig1_nid_postfix handles null stream by throwing std::invalid_argument according to debt documentation and OpenSSL/LibreSSL conventions. - Verified BIO creation failure queues ErrRBufLib (ERR_R_BUF_LIB) and returns nullptr without leaking resources. - Verified decoded EVP_PKEY and LibreSsl3Rsa ownership management using std::unique_ptr with custom deleters, ensuring no leak occurs if EVP_PKEY_get1_RSA returns nullptr or on early exit. - Verified rsa out-parameter semantics: if rsa != nullptr, guest input is checked, any existing *rsa is freed via RSA_free_nid_disambig1_nid_postfix only after decoding succeeds, and new pointer is written via CopyGuestOutPreservingErrno. - Verified debt fragment docs/dev/debt/changes/feat-libressl3-pem-rsa-file.md and pending export inventory decrement in libressl3-20171-inventory.md match AGENTS.md rules. - Verified unit tests in core/libs/prx/libSceLibreSsl3/tests/PemKeys.cpp thoroughly exercise traditional PEM, PKCS#8 PEM, replacement and refcounting, invalid input, non-RSA key error queues, and null stream validation. Looks Good To Me
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!23155
No description provided.