fix(libSceLibreSsl3): report mismatched key types through the error queue #15601

Closed
MarrasFederico wants to merge 0 commits from upstream-pr/15601 into main
MarrasFederico commented 2026-11-03 21:18:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-03T21:18:22Z.


What

A mismatched key type previously threw std::runtime_error. LibreSSL 4.0.0 instead returns null and queues an EVP error: RSA, DSA, and DH. The adapted accessor implementation now appends that error to the calling thread's existing parent-library queue.

RSA accepts types 6 and 912, DSA accepts 116, and DH accepts 28. Other types return null and queue library 6, function 0xfff, and reasons 127, 129, or 128 respectively. Matching keys return their borrowed inner pointer, including null, without changing references or clearing existing errors. The source file retains the original notices and pinned provenance.

  • The existing 32-byte key layout and use of the parent error queue remain unmeasured on PS5.
  • A null outer key retains the existing invalid_argument exception; upstream dereferences it.
  • The library debt entry records these limits. No constructor, destructor, or ownership behavior is added.

Neither path was measured on a console.

Tested

Ubuntu 26.04.1, kernel 7.0.0-42-generic, GCC 15, Release, BUILD_TESTING=ON, on main 04a9eb4fa2, then again after merging main 4741457fed. Windows and macOS were not compiled here. No title was run.

  • Rebuilt guest_libressl3_pkey_getters_tests separately for every control. The test covers recognized and unknown key types, the mismatch cross-product, empty matching keys, borrowed pointers, reference and field preservation, errno, and thread isolation. Ordered queue draining checks that older errors survive subsequent mismatches and successful calls.
  • Main implementation with the extended test: CTest exit 8, reporting the existing mismatched-type exception. Fixed implementation: exit 0. Removing error publication: exit 8 (assertion abort). Clearing the queue before publication: exit 8 (FIFO assertion abort). Restoring the fix: exit 0.
  • Rebuilt the relevant library targets and ran ctest --test-dir build -R 'libressl3|crypto_memcmp|libressl_errors|public_headers' -j6 --output-on-failure: 77/77 passed, including all 65 public-header tests.
  • After merging main 4741457fed: all 13 LibreSSL3 tests pass, including guest_libressl3_pkey_getters. The only conflict was in the debt file: main's newer entries are kept, and this PR's getter entry replaces the old one.
  • python3 tools/check_conventions.py --base origin/main and git diff --check origin/main passed after rebase. Repeated open/closed PR searches for all three symbols and PkeyGetters.cpp; the closed accessor implementations are already represented in main, and the open component accessors do not implement this mismatch fix.
  • pr_overlap.py examined 1775 open PRs and exited 2. It reported debt-line overlaps with #10395 (EC keys), #10960 (digest operations), #12945 (BIO/SSL retains), and #14366 (RSA component getters). I compared their diffs: their debt edits require reconciliation, but none changes these three mismatch paths.

Each comparison the tool could not complete was inspected manually:

  • #10461 adds ASN1_OBJECT_free and its test registration; shared CMake/debt edits need reconciliation.
  • #10631 adds OBJ_cmp and its test registration; shared CMake/debt edits need reconciliation.
  • #11146 adds EC private-key access/lifetime support and updates retain debt; it does not change these accessors.
  • #12754 adds SSL/X509 retains, protocol bounds, and random access; its CMake/debt edits concern separate functions.
  • #12928 adds file/socket BIO support and error-queue forwarding; its shared debt changes do not alter getter mismatch handling.
  • #13486 carries stack-test registration and inventory changes in the shared CMake/debt files; it does not change these getters.
  • #14212 changes debt spacing and the pending-export inventory; those edits must be retained when resolving the debt file.
  • #14483 adds SSL_CIPHER_get_id; its shared debt entry concerns a separate export.
  • #14499 adds EVP_PKEY_get0_EC_KEY in src/Key.cpp and EC assertions in tests/PkeyGetters.cpp. Its test/debt edits must be combined with this PR; it does not change RSA/DSA/DH mismatch errors.
  • #14612 adds AES_unwrap_key and its test registration; its CMake/debt edits concern a separate export.

These are shared-file conflicts, not dependencies on unmerged implementations.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5144663091 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15601). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-11-03T21:18:22Z. --- ### What A mismatched key type previously threw `std::runtime_error`. LibreSSL 4.0.0 instead returns null and queues an EVP error: [RSA](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/evp/p_lib.c#L630-L639), [DSA](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/evp/p_lib.c#L670-L679), and [DH](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/evp/p_lib.c#L741-L751). The adapted accessor implementation now appends that error to the calling thread's existing parent-library queue. RSA accepts types 6 and 912, DSA accepts 116, and DH accepts 28. Other types return null and queue library 6, function `0xfff`, and reasons 127, 129, or 128 respectively. Matching keys return their borrowed inner pointer, including null, without changing references or clearing existing errors. The source file retains the original notices and pinned provenance. - The existing 32-byte key layout and use of the parent error queue remain unmeasured on PS5. - A null outer key retains the existing `invalid_argument` exception; upstream dereferences it. - The library debt entry records these limits. No constructor, destructor, or ownership behavior is added. Neither path was measured on a console. ### 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.1, kernel 7.0.0-42-generic, GCC 15, Release, BUILD_TESTING=ON, on main `04a9eb4fa2`, then again after merging main `4741457fed`. Windows and macOS were not compiled here. No title was run. - Rebuilt `guest_libressl3_pkey_getters_tests` separately for every control. The test covers recognized and unknown key types, the mismatch cross-product, empty matching keys, borrowed pointers, reference and field preservation, errno, and thread isolation. Ordered queue draining checks that older errors survive subsequent mismatches and successful calls. - Main implementation with the extended test: CTest exit 8, reporting the existing mismatched-type exception. Fixed implementation: exit 0. Removing error publication: exit 8 (assertion abort). Clearing the queue before publication: exit 8 (FIFO assertion abort). Restoring the fix: exit 0. - Rebuilt the relevant library targets and ran `ctest --test-dir build -R 'libressl3|crypto_memcmp|libressl_errors|public_headers' -j6 --output-on-failure`: 77/77 passed, including all 65 public-header tests. - After merging main `4741457fed`: all 13 LibreSSL3 tests pass, including `guest_libressl3_pkey_getters`. The only conflict was in the debt file: main's newer entries are kept, and this PR's getter entry replaces the old one. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check origin/main` passed after rebase. Repeated open/closed PR searches for all three symbols and `PkeyGetters.cpp`; the closed accessor implementations are already represented in main, and the open component accessors do not implement this mismatch fix. - `pr_overlap.py` examined 1775 open PRs and exited 2. It reported debt-line overlaps with #10395 (EC keys), #10960 (digest operations), #12945 (BIO/SSL retains), and #14366 (RSA component getters). I compared their diffs: their debt edits require reconciliation, but none changes these three mismatch paths. Each comparison the tool could not complete was inspected manually: - #10461 adds `ASN1_OBJECT_free` and its test registration; shared CMake/debt edits need reconciliation. - #10631 adds `OBJ_cmp` and its test registration; shared CMake/debt edits need reconciliation. - #11146 adds EC private-key access/lifetime support and updates retain debt; it does not change these accessors. - #12754 adds SSL/X509 retains, protocol bounds, and random access; its CMake/debt edits concern separate functions. - #12928 adds file/socket BIO support and error-queue forwarding; its shared debt changes do not alter getter mismatch handling. - #13486 carries stack-test registration and inventory changes in the shared CMake/debt files; it does not change these getters. - #14212 changes debt spacing and the pending-export inventory; those edits must be retained when resolving the debt file. - #14483 adds `SSL_CIPHER_get_id`; its shared debt entry concerns a separate export. - #14499 adds `EVP_PKEY_get0_EC_KEY` in `src/Key.cpp` and EC assertions in `tests/PkeyGetters.cpp`. Its test/debt edits must be combined with this PR; it does not change RSA/DSA/DH mismatch errors. - #14612 adds `AES_unwrap_key` and its test registration; its CMake/debt edits concern a separate export. These are shared-file conflicts, not dependencies on unmerged implementations. ### 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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->

Pull request closed

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!15601
No description provided.