feat(libSceLibreSsl): implement SSL_CTX_ctrl, SSL_CTX_callback_ctrl, SSL_CTX_set_msg_callback, SSL_CTX_set_verify and SSL_CTX_set_session_id_context #11138

Merged
ahmadmuj merged 53 commits from upstream-pr/11138 into main 2026-11-05 17:07:03 +00:00
ahmadmuj commented 2026-10-25 19:26:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T19:26:31Z.


What

Implements SSL_CTX_ctrl, SSL_CTX_callback_ctrl, SSL_CTX_set_msg_callback, SSL_CTX_set_verify and SSL_CTX_set_session_id_context in libSceLibreSsl, which threw and were declared without parameters. SSL_CTX_ctrl is what SSL_CTX_set_options, set_mode, set_session_cache_mode, set_read_ahead and friends expand to, so it's the one most TLS setup code hits.

This stacks on #10483 and uses its LibreSslCtx / LibreSslCtxInternal. The diff carries #10483's commits (a local merge with main) until it merges. #10483's functions and test are unchanged; LibreSslCtxInternal goes from beforeQuietShutdown[292] / quietShutdown / rest[168] to every ssl_ctx_internal_st field named at its offset. quietShutdown stays at 292 and the size stays 464. The slots #10485 uses keep its names (newSessionCb 24, appVerifyCallback 48, ... alpnSelectCbArg 408), so its planned move onto #10483's types is a type swap.

Behaviour follows LibreSSL 2.5.4 ssl_lib.c and s3_lib.c (SSL_CTX_ctrl falls through to ssl3_ctx_ctrl, the same for the callback version):

Export Behaviour
long SSL_CTX_ctrl(SSL_CTX*, int cmd, long larg, void* parg) options / mode set and clear (return the new mask), read_ahead, max_cert_list, session cache size and mode (return the old value; read_ahead and cache mode keep the low 32 bits), the 11 session stats, max_send_fragment (512..16384, else 0), msg callback arg, servername arg, status arg, ticket keys get/set (null parg returns 48, a length other than 48 queues 0x14FFF145 and returns 0), extra chain certs get. Commands 2, 5, 6 and 7 queue 0x14FFF042 and return 0; 1 returns 0. Commands not in 2.5.4's switch return 0, as that release does
long SSL_CTX_callback_ctrl(SSL_CTX*, int cmd, void (*)(void)) 15 msg callback, 53 servername, 63 status, 72 ticket key callback (return 1); 5 queues 0x14FFF042, returns 0; anything else 0
void SSL_CTX_set_msg_callback(SSL_CTX*, cb) internal->msg_callback = cb
void SSL_CTX_set_verify(SSL_CTX*, int mode, cb) verify_mode = mode, internal->default_verify_callback = cb
int SSL_CTX_set_session_id_context(SSL_CTX*, const unsigned char*, unsigned int) length > 32 queues 0x14FFF111 and returns 0 with no write; else copies, sets the length, returns 1. Bytes past the new length are kept, as in 2.5.4

Throws: control commands 3, 4, 14, 20, 83, 91, 92, 94, 118 and callback commands 6 and 7 (they use cert, session table, DH, ECDH, stack or group state no export builds yet), a null context, a null internal state (2.5.4 reads ctx->internal->cert on entry for every command), a null output for command 82, and a null session ID with a nonzero length. Errors go through the existing LibreSslPutError_nid_no_patch as SSLerrorx does (lib 20, function 0xfff), and the ERR debt entry lists the three additional SSL_CTX producers.

The debt entry records the source and the throwing commands. The merged branch has 181 pending exports; main has 191.

Tested

Ubuntu 24.04 on WSL2, GCC 13.3, Release. Head 300af5cbcef1 merges main a0a8b1b1733c and #10483 2c6493028f9f.

The selected build passes. Ordinary LibreSSL tests pass: 60/60. Public headers pass: 65/65. Conventions and whitespace checks pass.

SslCtx.cpp and both context tests are byte-identical to the published head. The merge removes duplicate parent layout definitions and keeps the expanded fields. The parent offsets and structure size stay unchanged. Earlier differential and mutation checks are not repeated.

No console, title, Windows or macOS run. No full build, full ctest, patched or oracle run.

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: #10483
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007918714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11138). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T19:26:31Z. --- ### What Implements `SSL_CTX_ctrl`, `SSL_CTX_callback_ctrl`, `SSL_CTX_set_msg_callback`, `SSL_CTX_set_verify` and `SSL_CTX_set_session_id_context` in libSceLibreSsl, which threw and were declared without parameters. `SSL_CTX_ctrl` is what `SSL_CTX_set_options`, `set_mode`, `set_session_cache_mode`, `set_read_ahead` and friends expand to, so it's the one most TLS setup code hits. This stacks on #10483 and uses its `LibreSslCtx` / `LibreSslCtxInternal`. The diff carries #10483's commits (a local merge with `main`) until it merges. #10483's functions and test are unchanged; `LibreSslCtxInternal` goes from `beforeQuietShutdown[292] / quietShutdown / rest[168]` to every `ssl_ctx_internal_st` field named at its offset. `quietShutdown` stays at 292 and the size stays 464. The slots #10485 uses keep its names (`newSessionCb` 24, `appVerifyCallback` 48, ... `alpnSelectCbArg` 408), so its planned move onto #10483's types is a type swap. Behaviour follows [LibreSSL 2.5.4](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libssl) `ssl_lib.c` and `s3_lib.c` (`SSL_CTX_ctrl` falls through to `ssl3_ctx_ctrl`, the same for the callback version): | Export | Behaviour | |---|---| | `long SSL_CTX_ctrl(SSL_CTX*, int cmd, long larg, void* parg)` | options / mode set and clear (return the new mask), read_ahead, max_cert_list, session cache size and mode (return the old value; read_ahead and cache mode keep the low 32 bits), the 11 session stats, max_send_fragment (512..16384, else 0), msg callback arg, servername arg, status arg, ticket keys get/set (null `parg` returns 48, a length other than 48 queues `0x14FFF145` and returns 0), extra chain certs get. Commands 2, 5, 6 and 7 queue `0x14FFF042` and return 0; 1 returns 0. Commands not in 2.5.4's switch return 0, as that release does | | `long SSL_CTX_callback_ctrl(SSL_CTX*, int cmd, void (*)(void))` | 15 msg callback, 53 servername, 63 status, 72 ticket key callback (return 1); 5 queues `0x14FFF042`, returns 0; anything else 0 | | `void SSL_CTX_set_msg_callback(SSL_CTX*, cb)` | `internal->msg_callback = cb` | | `void SSL_CTX_set_verify(SSL_CTX*, int mode, cb)` | `verify_mode = mode`, `internal->default_verify_callback = cb` | | `int SSL_CTX_set_session_id_context(SSL_CTX*, const unsigned char*, unsigned int)` | length > 32 queues `0x14FFF111` and returns 0 with no write; else copies, sets the length, returns 1. Bytes past the new length are kept, as in 2.5.4 | Throws: control commands 3, 4, 14, 20, 83, 91, 92, 94, 118 and callback commands 6 and 7 (they use cert, session table, DH, ECDH, stack or group state no export builds yet), a null context, a null internal state (2.5.4 reads `ctx->internal->cert` on entry for every command), a null output for command 82, and a null session ID with a nonzero length. Errors go through the existing `LibreSslPutError_nid_no_patch` as `SSLerrorx` does (lib 20, function 0xfff), and the ERR debt entry lists the three additional SSL_CTX producers. The debt entry records the source and the throwing commands. The merged branch has 181 pending exports; main has 191. ### Tested Ubuntu 24.04 on WSL2, GCC 13.3, Release. Head `300af5cbcef1` merges main `a0a8b1b1733c` and #10483 `2c6493028f9f`. The selected build passes. Ordinary LibreSSL tests pass: 60/60. Public headers pass: 65/65. Conventions and whitespace checks pass. `SslCtx.cpp` and both context tests are byte-identical to the published head. The merge removes duplicate parent layout definitions and keeps the expanded fields. The parent offsets and structure size stay unchanged. Earlier differential and mutation checks are not repeated. No console, title, Windows or macOS run. No full build, full ctest, patched or oracle run. ### 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: #10483 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 19:30:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:30:35Z.

Review: APPROVED


Reviewed the PR-specific SslCtx.cpp behavior against pinned LibreSSL 2.5.4 ssl_lib.c / s3_lib.c, with #10483 as the declared layout dependency. I checked the command dispatch and return conventions for option/mode masks, read-ahead and cache settings, session counters, fragment bounds, ticket-key buffer length, callback setters, session-id context length, and the explicitly unsupported commands. The source-derived error reasons and the throw-vs-return boundaries are documented in the PR and debt entry. The base SSL_CTX layout dependency #10483 has a current review and remains open as a stack prerequisite.

Local checks on the submitted tree:

  • GCC 12.2 syntax-only compilation of SslCtx.cpp, GuestLibreSslSslCtx.cpp, and GuestLibreSslSslCtxFields.cpp: passed.
  • python3 tools/check_conventions.py --base upstream/main --head HEAD: passed.

The PR reports a byte-for-byte differential against real LibreSSL 2.5.4 for the context and internal layouts, command results, changed bytes and error queue, plus focused regression and mutation tests. Hosted eligibility, conventions, intake, labels and report pass; product/library build jobs are skipped. I did not independently run the LibreSSL runtime differential in this environment. No blocking issue found in this PR-specific change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644883712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11138#pullrequestreview-5644883712). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T19:30:35Z. **Review:** APPROVED --- Reviewed the PR-specific `SslCtx.cpp` behavior against pinned LibreSSL 2.5.4 `ssl_lib.c` / `s3_lib.c`, with #10483 as the declared layout dependency. I checked the command dispatch and return conventions for option/mode masks, read-ahead and cache settings, session counters, fragment bounds, ticket-key buffer length, callback setters, session-id context length, and the explicitly unsupported commands. The source-derived error reasons and the throw-vs-return boundaries are documented in the PR and debt entry. The base `SSL_CTX` layout dependency #10483 has a current review and remains open as a stack prerequisite. Local checks on the submitted tree: - GCC 12.2 syntax-only compilation of `SslCtx.cpp`, `GuestLibreSslSslCtx.cpp`, and `GuestLibreSslSslCtxFields.cpp`: passed. - `python3 tools/check_conventions.py --base upstream/main --head HEAD`: passed. The PR reports a byte-for-byte differential against real LibreSSL 2.5.4 for the context and internal layouts, command results, changed bytes and error queue, plus focused regression and mutation tests. Hosted eligibility, conventions, intake, labels and report pass; product/library build jobs are skipped. I did not independently run the LibreSSL runtime differential in this environment. No blocking issue found in this PR-specific change.
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!11138
No description provided.