feat(libSceLibreSsl): implement SSL_set_verify, SSL_get0_alpn_selected, SSL_set_connect_state and SSL_ctrl #11143

Merged
ahmadmuj merged 58 commits from upstream-pr/11143 into main 2026-11-05 18:02:32 +00:00
ahmadmuj commented 2026-10-25 19:31:49 +00:00 (Migrated from github.com)

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


What

Implements SSL_set_verify, SSL_get0_alpn_selected, SSL_set_connect_state and SSL_ctrl in libSceLibreSsl, which threw and were declared without parameters.

Parent #10481 has merged. This branch uses its LibreSslSsl / LibreSslSslInternal layouts. The parent functions stay unchanged; the internal padding is split into the named fields these calls need (rwstate and shutdown stay where they were).

Behaviour follows LibreSSL 2.5.4 ssl_lib.c, ssl_locl.h and d1_both.c, the version in the firmware 13.40 measurements:

Export Behaviour
void SSL_set_verify(SSL*, int mode, cb) verify_mode = mode; internal->verify_callback = cb only when cb isn't null
void SSL_get0_alpn_selected(const SSL*, const unsigned char**, unsigned*) null/0 without s3, else s3->internal->alpn_selected and its length
void SSL_set_connect_state(SSL*) server = 0, shutdown = 0, state = SSL_ST_CONNECT|SSL_ST_BEFORE, handshake_func = method->internal->ssl_connect
long SSL_ctrl(SSL*, int, long, void*) the 12 commands SSL_ctrl handles itself: read ahead (int, so set truncates and get sign-extends), msg callback arg, options / mode set and clear (64-bit), max cert list, SET_MTU (signed compare against 228, DTLS only), max send fragment (512..16384), RI support

Offsets: options 8, mode 16, handshake_func 56, msg_callback_arg 72, verify_callback 88, read_ahead 212, the cipher and hash contexts 240-264, max_cert_list 296 and state 412 in ssl_internal_st; s3->internal 136 with alpn_selected 1024 and send_connection_binding 1012; method->internal 40 with ssl_connect 40; d1->internal 32 with mtu 636. All are static_asserted, and I checked them against offsetof from the 2.5.4 headers built on x86-64.

What throws instead of matching:

  • SSL_ctrl commands that 2.5.4 sends on to ssl3_ctrl / dtls1_ctrl (that includes SSL_set_tlsext_host_name); the message names the command.
  • SSL_set_connect_state when one of the six cipher or hash contexts is still set. LibreSSL frees those, and we can't do that yet. They're null until a handshake has run. It checks before writing anything.
  • Null pointers that LibreSSL dereferences.

Nothing here creates an SSL or an SSL_METHOD yet (SSL_new, TLS_client_method still throw), so for now only structures the caller builds reach these. The debt entry records these limits.

Left out on purpose: SSL_get_ex_data / SSL_set_ex_data (set allocates the stack on its first call; get alone isn't useful while set throws). Other SSL exports remain outside this PR.

Tested

Ubuntu 24.04 on WSL2, GCC 13.3, Release. Head 1d7fa6ebac59 merges main d893997f1a6f, which includes #10481. Its entire LibreSSL source, header and build tree, plus the relevant tests, match the tested d708a2573e6a exactly. The following fresh checks ran at that unchanged tree before the parent merged; they are not repeated for this history-only alignment. The fresh focused build passes. All 5 selected tests pass: guest_libressl_ssl, guest_libressl_ssl_settings, guest_libressl_ssl_ctx, guest_libressl_ssl_ctx_fields and guest_libressl_error. All 65 public-header checks pass. Conventions and whitespace checks pass.

The merge preserves the SSL feature source and tests, plus main's SSL context source and tests, byte for byte. It combines their build and header entries. The prior 60-test LibreSSL run at 485e945c38dd remains earlier evidence; this update runs the five integration tests above. Merged parent #10481 preserves the same SSL accessor source and test.

The parent now calls the SSL type LibreSslSsl. This branch adopts that name in the child declarations, implementation and test. It resolves the clash with main's namespace LibreSsl. The guest layout and behavior stay unchanged. The old-header syntax failure reproduces before the rename and passes after it. Earlier differential and mutation checks are not repeated.

  • New guest_libressl_ssl_settings test. It fills the structs with byte patterns and compares the whole struct after each call, so a write to a neighbour field fails. It covers each SSL_ctrl command's boundaries (227/228 and -1 / INT64_MIN for MTU, 511/512/16384/16385 and 0x100000200 for the fragment size, read-ahead truncation 0x123456789ABCDEF0 -> -1698898192, options/mode with -1 and bits above 32), ssl_connect vs ssl_accept picked from the method, and every null path. The refused live-context and forwarded-command cases aren't pinned by the test, so they can be implemented later without touching it.
  • 2.5.4 reference: a small C driver linked against libssl 2.5.4 ran each call on a real SSL_new object and printed the field bytes before and after. The test's expected values match its output.
  • 44 single mutations of the implementation (one or more per export and per SSL_ctrl command) all failed the test as first pushed. With the two loops gone, mutations on the refused paths no longer fail it. On #10481's base the test doesn't compile, since the stubs take no parameters.
  • guest_libressl_ssl (#10481's test) still passes. public_headers passes, and so does check_conventions.py --base origin/main.
  • Not tested: Windows, a title, the 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
  • 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 (#10481 merged)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007956561 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11143). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T19:31:49Z. --- ### What Implements `SSL_set_verify`, `SSL_get0_alpn_selected`, `SSL_set_connect_state` and `SSL_ctrl` in libSceLibreSsl, which threw and were declared without parameters. Parent #10481 has merged. This branch uses its `LibreSslSsl` / `LibreSslSslInternal` layouts. The parent functions stay unchanged; the internal padding is split into the named fields these calls need (`rwstate` and `shutdown` stay where they were). Behaviour follows LibreSSL 2.5.4 [`ssl_lib.c`, `ssl_locl.h` and `d1_both.c`](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libssl), the version in the [firmware 13.40 measurements](https://github.com/boykopovar/AnyPS5/discussions/8981#discussioncomment-19111214): | Export | Behaviour | |---|---| | `void SSL_set_verify(SSL*, int mode, cb)` | `verify_mode = mode`; `internal->verify_callback = cb` only when `cb` isn't null | | `void SSL_get0_alpn_selected(const SSL*, const unsigned char**, unsigned*)` | null/0 without `s3`, else `s3->internal->alpn_selected` and its length | | `void SSL_set_connect_state(SSL*)` | `server = 0`, `shutdown = 0`, `state = SSL_ST_CONNECT\|SSL_ST_BEFORE`, `handshake_func = method->internal->ssl_connect` | | `long SSL_ctrl(SSL*, int, long, void*)` | the 12 commands `SSL_ctrl` handles itself: read ahead (int, so set truncates and get sign-extends), msg callback arg, options / mode set and clear (64-bit), max cert list, `SET_MTU` (signed compare against 228, DTLS only), max send fragment (512..16384), RI support | Offsets: `options` 8, `mode` 16, `handshake_func` 56, `msg_callback_arg` 72, `verify_callback` 88, `read_ahead` 212, the cipher and hash contexts 240-264, `max_cert_list` 296 and `state` 412 in `ssl_internal_st`; `s3->internal` 136 with `alpn_selected` 1024 and `send_connection_binding` 1012; `method->internal` 40 with `ssl_connect` 40; `d1->internal` 32 with `mtu` 636. All are `static_assert`ed, and I checked them against `offsetof` from the 2.5.4 headers built on x86-64. What throws instead of matching: - `SSL_ctrl` commands that 2.5.4 sends on to `ssl3_ctrl` / `dtls1_ctrl` (that includes `SSL_set_tlsext_host_name`); the message names the command. - `SSL_set_connect_state` when one of the six cipher or hash contexts is still set. LibreSSL frees those, and we can't do that yet. They're null until a handshake has run. It checks before writing anything. - Null pointers that LibreSSL dereferences. Nothing here creates an `SSL` or an `SSL_METHOD` yet (`SSL_new`, `TLS_client_method` still throw), so for now only structures the caller builds reach these. The debt entry records these limits. Left out on purpose: `SSL_get_ex_data` / `SSL_set_ex_data` (set allocates the stack on its first call; get alone isn't useful while set throws). Other SSL exports remain outside this PR. ### Tested Ubuntu 24.04 on WSL2, GCC 13.3, Release. Head `1d7fa6ebac59` merges main `d893997f1a6f`, which includes #10481. Its entire LibreSSL source, header and build tree, plus the relevant tests, match the tested `d708a2573e6a` exactly. The following fresh checks ran at that unchanged tree before the parent merged; they are not repeated for this history-only alignment. The fresh focused build passes. All 5 selected tests pass: `guest_libressl_ssl`, `guest_libressl_ssl_settings`, `guest_libressl_ssl_ctx`, `guest_libressl_ssl_ctx_fields` and `guest_libressl_error`. All 65 public-header checks pass. Conventions and whitespace checks pass. The merge preserves the SSL feature source and tests, plus main's SSL context source and tests, byte for byte. It combines their build and header entries. The prior 60-test LibreSSL run at `485e945c38dd` remains earlier evidence; this update runs the five integration tests above. Merged parent #10481 preserves the same SSL accessor source and test. The parent now calls the SSL type `LibreSslSsl`. This branch adopts that name in the child declarations, implementation and test. It resolves the clash with main's `namespace LibreSsl`. The guest layout and behavior stay unchanged. The old-header syntax failure reproduces before the rename and passes after it. Earlier differential and mutation checks are not repeated. - New `guest_libressl_ssl_settings` test. It fills the structs with byte patterns and compares the whole struct after each call, so a write to a neighbour field fails. It covers each `SSL_ctrl` command's boundaries (227/228 and -1 / `INT64_MIN` for MTU, 511/512/16384/16385 and 0x100000200 for the fragment size, read-ahead truncation 0x123456789ABCDEF0 -> -1698898192, options/mode with -1 and bits above 32), `ssl_connect` vs `ssl_accept` picked from the method, and every null path. The refused live-context and forwarded-command cases aren't pinned by the test, so they can be implemented later without touching it. - 2.5.4 reference: a small C driver linked against libssl 2.5.4 ran each call on a real `SSL_new` object and printed the field bytes before and after. The test's expected values match its output. - 44 single mutations of the implementation (one or more per export and per `SSL_ctrl` command) all failed the test as first pushed. With the two loops gone, mutations on the refused paths no longer fail it. On #10481's base the test doesn't compile, since the stubs take no parameters. - `guest_libressl_ssl` (#10481's test) still passes. `public_headers` passes, and so does `check_conventions.py --base origin/main`. - Not tested: Windows, a title, the 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) - [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 (#10481 merged) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 19:34:19 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed the PR-specific Ssl.cpp implementation against LibreSSL 2.5.4's ssl_lib.c and the declared #10481 structure dependency. The setter/getter field accesses, non-null verify-callback rule, ALPN null-state outputs, connect-state assignments, and the directly handled SSL_ctrl commands match the pinned source. SET_MTU preserves the source's minimum check, DTLS-only dispatch, stored-width conversion and return value; the unsupported delegated commands are explicitly recorded rather than partially implemented.

Local checks:

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

The author reports a field-by-field differential against LibreSSL 2.5.4, 44 mutation checks, and the prior #10481 focused test passing. Hosted eligibility, conventions, intake, labels and report pass; product/library jobs are skipped. I did not independently run the LibreSSL differential or Windows/console tests. The dependency on #10481 remains in the stated stack order. No blocking issue found in this PR-specific diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644895294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11143#pullrequestreview-5644895294). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T19:34:19Z. **Review:** APPROVED --- Reviewed the PR-specific `Ssl.cpp` implementation against LibreSSL 2.5.4's `ssl_lib.c` and the declared #10481 structure dependency. The setter/getter field accesses, non-null verify-callback rule, ALPN null-state outputs, connect-state assignments, and the directly handled `SSL_ctrl` commands match the pinned source. `SET_MTU` preserves the source's minimum check, DTLS-only dispatch, stored-width conversion and return value; the unsupported delegated commands are explicitly recorded rather than partially implemented. Local checks: - GCC 12.2 syntax-only compilation of `Ssl.cpp`, `GuestLibreSslSsl.cpp`, and `GuestLibreSslSslSettings.cpp`: passed. - `python3 tools/check_conventions.py --base upstream/main --head HEAD`: passed. The author reports a field-by-field differential against LibreSSL 2.5.4, 44 mutation checks, and the prior #10481 focused test passing. Hosted eligibility, conventions, intake, labels and report pass; product/library jobs are skipped. I did not independently run the LibreSSL differential or Windows/console tests. The dependency on #10481 remains in the stated stack order. No blocking issue found in this PR-specific diff.
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!11143
No description provided.