feat(libSceLibreSsl): parse cipher rule strings in SSL_CTX_set_cipher_list #17813

Merged
MarrasFederico merged 3 commits from upstream-pr/17813 into main 2026-11-12 18:12:07 +00:00
MarrasFederico commented 2026-11-09 16:57:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-09T16:57:27Z.


What

SSL_CTX_set_cipher_list parses real cipher rule strings, as LibreSSL 2.5.4 does. It used to throw on every call.

This follows up on #16724, which only handled a null rule string and was closed with a request for a version that parses real strings.

  • Cipher table: the 87 entries of 2.5.4's ssl3_ciphers[] (s3_lib.c), in the 88-byte layout that SSL_CIPHER_get_name, SSL_CIPHER_get_bits and SSL_CIPHER_get_version already read.
  • Rule parser: a port of ssl_create_cipher_list (ssl_ciph.c). It covers:
    • the 53 aliases (ALL, HIGH, kEECDH, AESGCM, …), including combined ones such as kEECDH+AESGCM;
    • the +, - and ! operators, @STRENGTH, and the : , ; and space separators;
    • the DEFAULT prefix (ALL:!aNULL:!eNULL:!SSLv2);
    • the default preference order, and the masks that drop ciphers whose algorithms are unavailable.
  • Export: SSL_CTX_set_cipher_list installs the ordered list and the id-sorted list into the context and frees the previous ones.
    • Both are guest stacks laid out like 2.5.4's _STACK; the sorted one has a guest-callable comparator.
    • It returns 0 with SSL_R_NO_CIPHER_MATCH when nothing matches, and reports SSL_R_INVALID_COMMAND the way LibreSSL does.
    • A null context, or one without its internal block, throws.

Reviewer points addressed (oneandonlydean):

  1. Verbatim licence notices: Preambles from LibreSSL 2.5.4 ssl_ciph.c (v1.96, including the Nokia block) and s3_lib.c (v1.138) have been added verbatim byte-for-byte at the top of core/libs/prx/libSceLibreSsl/src/CipherList.cpp, followed by attribution lines with pinned permalinks to 2.5.4 (https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libssl/ssl_ciph.c and .../src/lib/libssl/s3_lib.c). include/CipherList.hpp contains only AnyPS5-specific helper declarations and no ported code.
  2. Merge upstream main keeping both sides: Merged upstream/main (919e4ee48a) into the published head (2b15fc50e3) with merge commit chore: merge upstream main. All conflicts in Export.cpp, Oracle.cpp, and OracleReference.cpp were resolved by taking main's full code/tests and cleanly re-applying PR #17813's additions. No functions or structs are duplicated.
  3. Debt count: Verified that docs/dev/debt/libSceLibreSsl.md has no summary numeric count line on main. Verified actual NotImplemented_nid_no_patch occurrences in core/libs/prx/libSceLibreSsl/Export.cpp: 93 on main -> 92 in this branch (SSL_CTX_set_cipher_list_nid_postfix removed). Technical debt entry for SSL_CTX_set_cipher_list updated.

Final head: 1f77cc7be2

Debt: the console's build choices are assumed, not measured:

  • every algorithm 2.5.4 enables by default is available, IDEA excluded;
  • the default order puts AES before ChaCha20, as 2.5.4 does on a CPU with AES-NI, like the PS5's Zen 2.

Tested

Ubuntu 26.04.1 LTS, kernel 7.0.0-43-generic, GCC 15.2.0, Release, BUILD_TESTING=ON, CMake 4.4.4 with Ninja 1.13 from a virtualenv. Merged upstream/main into the published head 2b15fc50e3 with normal merge commits 20070ce24a (main 919e4ee48a); the published history was not rebased, squashed or force-pushed. On top of the merges the branch adds local commit(s): 1f77cc7be2 (docs(libSceLibreSsl): keep LibreSSL 2.5.4 licence notices in CipherList.cpp). No console or title was run. Final head: 1f77cc7be2 (full 1f77cc7be287502a3d23b664c1e5a05c0a609967). Windows and macOS were not compiled here; no game title was run.

  • guest_libressl_cipher_list: checks the table, ssl3_get_cipher index order, lookup by id and bit counts. It also covers errors and their codes, ordering rules, DEFAULT, @STRENGTH, stack shapes and the comparator, and replacing a list.
  • guest_libressl_cipher_list_allocator: checks that each failed guest allocation returns 0, keeps the previous lists and frees everything it allocated. It also checks that a failed growth during a push silently drops that cipher, as in 2.5.4.
  • LibreSSL oracle (-DANYPS5_LIBRESSL_ORACLE=ON, built against the official libressl-2.5.4 tarball):
    • all 87 table entries are byte-identical;
    • 3,500 rule strings give the same result, error codes and cipher list: about 250 hand-picked strings, variants of every cipher and alias name, and 2,500 random ones.
    • The oracle also reports 6 differences in AES_set_encrypt_key and AES_set_decrypt_key; those are on main without this PR too.
  • Negative control: with the ! rule disabled, the unit test fails and the oracle reports 515 of 3,500 lists differing. Restoring the code makes both pass.
  • ctest -R '^guest_libressl_cipher' --output-on-failure --repeat until-fail:3: 100% tests passed out of 3, 3 runs each, Not Run = 0 (exit 0).
  • Not executed here: guest_libressl_oracle_tests is behind option(ANYPS5_LIBRESSL_ORACLE ... OFF) and needs a LibreSSL 2.5.4 checkout, so the oracle evidence stays the one produced on the contributor's machine.
  • Checks: python3 tools/check_conventions.py --base upstream/main passed (0 errors); git diff --check upstream/main...HEAD passed cleanly.

Publication checks: head 1f77cc7be287502a3d23b664c1e5a05c0a609967 passed an independent conventions/diff check and a clean merge-tree check against upstream main fa289273974bb03ffcf6c6432f0b15a2cb65f46d. Linux execution results above come from the recorded verification runs, reviewed rather than rerun during publication.

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:5227740685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17813). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-11-09T16:57:27Z. --- ### What `SSL_CTX_set_cipher_list` parses real cipher rule strings, as LibreSSL 2.5.4 does. It used to throw on every call. This follows up on #16724, which only handled a null rule string and was closed with a request for a version that parses real strings. - **Cipher table:** the 87 entries of 2.5.4's `ssl3_ciphers[]` (`s3_lib.c`), in the 88-byte layout that `SSL_CIPHER_get_name`, `SSL_CIPHER_get_bits` and `SSL_CIPHER_get_version` already read. - **Rule parser:** a port of `ssl_create_cipher_list` (`ssl_ciph.c`). It covers: - the 53 aliases (`ALL`, `HIGH`, `kEECDH`, `AESGCM`, …), including combined ones such as `kEECDH+AESGCM`; - the `+`, `-` and `!` operators, `@STRENGTH`, and the `:` `,` `;` and space separators; - the `DEFAULT` prefix (`ALL:!aNULL:!eNULL:!SSLv2`); - the default preference order, and the masks that drop ciphers whose algorithms are unavailable. - **Export:** `SSL_CTX_set_cipher_list` installs the ordered list and the id-sorted list into the context and frees the previous ones. - Both are guest stacks laid out like 2.5.4's `_STACK`; the sorted one has a guest-callable comparator. - It returns 0 with `SSL_R_NO_CIPHER_MATCH` when nothing matches, and reports `SSL_R_INVALID_COMMAND` the way LibreSSL does. - A null context, or one without its internal block, throws. Reviewer points addressed (oneandonlydean): 1. **Verbatim licence notices:** Preambles from LibreSSL 2.5.4 `ssl_ciph.c` (v1.96, including the Nokia block) and `s3_lib.c` (v1.138) have been added verbatim byte-for-byte at the top of `core/libs/prx/libSceLibreSsl/src/CipherList.cpp`, followed by attribution lines with pinned permalinks to 2.5.4 (`https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libssl/ssl_ciph.c` and `.../src/lib/libssl/s3_lib.c`). `include/CipherList.hpp` contains only AnyPS5-specific helper declarations and no ported code. 2. **Merge upstream main keeping both sides:** Merged `upstream/main` (`919e4ee48a`) into the published head (`2b15fc50e3`) with merge commit `chore: merge upstream main`. All conflicts in `Export.cpp`, `Oracle.cpp`, and `OracleReference.cpp` were resolved by taking main's full code/tests and cleanly re-applying PR #17813's additions. No functions or structs are duplicated. 3. **Debt count:** Verified that `docs/dev/debt/libSceLibreSsl.md` has no summary numeric count line on main. Verified actual `NotImplemented_nid_no_patch` occurrences in `core/libs/prx/libSceLibreSsl/Export.cpp`: 93 on main -> 92 in this branch (`SSL_CTX_set_cipher_list_nid_postfix` removed). Technical debt entry for `SSL_CTX_set_cipher_list` updated. Final head: `1f77cc7be2` Debt: the console's build choices are assumed, not measured: - every algorithm 2.5.4 enables by default is available, IDEA excluded; - the default order puts AES before ChaCha20, as 2.5.4 does on a CPU with AES-NI, like the PS5's Zen 2. ### Tested Ubuntu 26.04.1 LTS, kernel 7.0.0-43-generic, GCC 15.2.0, Release, `BUILD_TESTING=ON`, CMake 4.4.4 with Ninja 1.13 from a virtualenv. Merged `upstream/main` into the published head `2b15fc50e3` with normal merge commits `20070ce24a` (main `919e4ee48a`); the published history was not rebased, squashed or force-pushed. On top of the merges the branch adds local commit(s): `1f77cc7be2` (docs(libSceLibreSsl): keep LibreSSL 2.5.4 licence notices in CipherList.cpp). No console or title was run. Final head: `1f77cc7be2` (full `1f77cc7be287502a3d23b664c1e5a05c0a609967`). Windows and macOS were not compiled here; no game title was run. - **`guest_libressl_cipher_list`:** checks the table, `ssl3_get_cipher` index order, lookup by id and bit counts. It also covers errors and their codes, ordering rules, `DEFAULT`, `@STRENGTH`, stack shapes and the comparator, and replacing a list. - **`guest_libressl_cipher_list_allocator`:** checks that each failed guest allocation returns 0, keeps the previous lists and frees everything it allocated. It also checks that a failed growth during a push silently drops that cipher, as in 2.5.4. - **LibreSSL oracle** (`-DANYPS5_LIBRESSL_ORACLE=ON`, built against the official libressl-2.5.4 tarball): - all 87 table entries are byte-identical; - 3,500 rule strings give the same result, error codes and cipher list: about 250 hand-picked strings, variants of every cipher and alias name, and 2,500 random ones. - The oracle also reports 6 differences in `AES_set_encrypt_key` and `AES_set_decrypt_key`; those are on `main` without this PR too. - **Negative control:** with the `!` rule disabled, the unit test fails and the oracle reports 515 of 3,500 lists differing. Restoring the code makes both pass. - `ctest -R '^guest_libressl_cipher' --output-on-failure --repeat until-fail:3`: **100% tests passed out of 3**, 3 runs each, `Not Run` = 0 (exit 0). - Not executed here: `guest_libressl_oracle_tests` is behind `option(ANYPS5_LIBRESSL_ORACLE ... OFF)` and needs a LibreSSL 2.5.4 checkout, so the oracle evidence stays the one produced on the contributor's machine. - **Checks:** `python3 tools/check_conventions.py --base upstream/main` passed (0 errors); `git diff --check upstream/main...HEAD` passed cleanly. Publication checks: head `1f77cc7be287502a3d23b664c1e5a05c0a609967` passed an independent conventions/diff check and a clean merge-tree check against upstream main `fa289273974bb03ffcf6c6432f0b15a2cb65f46d`. Linux execution results above come from the recorded verification runs, reviewed rather than rerun during publication. ### Checklist - [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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!17813
No description provided.