feat(libSceLibreSsl3): implement SSL_set_alpn_protos #16980

Merged
GalaxyGamingFR merged 2 commits from upstream-pr/16980 into main 2026-11-12 23:16:41 +00:00
GalaxyGamingFR commented 2026-11-08 03:55:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GalaxyGamingFR on 2026-11-08T03:55:28Z.


What

Implement SSL_set_alpn_protos in libSceLibreSsl3, replacing its parameterless throwing placeholder in AdditionalExports.cpp.

  • Source: LibreSSL 4.0.0 at ce488b78 ssl_lib.c, the revision the library's debt file already uses, with tlsext_alpn_check_format and CBS_stow. The behaviour follows them:
    • A null list is treated as length 0.
    • A non-empty list must be a sequence of 1-byte length-prefixed names, each non-empty and inside the buffer. Otherwise it returns 1 and the SSL is unchanged.
    • Otherwise the old alpn_client_proto_list is freed and the fields are cleared. A length of 0 stops there and returns 0. A non-empty list is copied into a new malloc buffer and stored with its length, and the call returns 0. A failed allocation returns 1 with the list cleared, as upstream does.
    • As upstream notes, 0 means success here, the reverse of most of the API.
  • The list and its length are at offsets 264 and 272 of LibreSsl3Ssl, the layout #16979 extends to 320 bytes. That is why this PR depends on #16979.
  • Api.hpp now declares it as int SSL_set_alpn_protos(LibreSsl3Ssl* ssl, const std::uint8_t* protos, std::uint32_t protosLength), matching upstream's unsigned int length.
  • Memory goes through libc's malloc_nid_postfix and free_nid_postfix, as Asn1Values.cpp already does.
  • A null SSL throws std::invalid_argument, where upstream would dereference it.

The gap is recorded in docs/dev/debt/libSceLibreSsl3.md: no handshake runs here, so the list is never sent, an SSL whose list came from another allocator cannot be passed, and the console layout is not measured. The export inventory is updated (137 exports, 127 named).

No title's trace or disassembly was used, and the export was not measured on a PS5.

Tested

Windows 11, WinLibs GCC 15.2.0 UCRT. This is not a full CMake build. I compiled tests/GuestLibreSsl3Ssl.cpp with libSceLibreSsl3's Ssl.cpp, Key.cpp, X509.cpp, Asn1Values.cpp and IntegerDecoder.cpp and libSceLibreSsl's Error.cpp into one executable, with APS5_VABI defined empty, a one-line NotImplementedAt_nid_no_patch that throws, and malloc/calloc/free shims over the C runtime. No title or homebrew, and not built on Linux or macOS.

  • The test passes. The new CheckAlpnProtos fills a guarded SSL with 0x5A (list pointer null) and checks, after each call, that only the 16 bytes at offsets 264 and 272 changed:
    • h2 + http/1.1 is copied (a new buffer with the same bytes) and returns 0, and a second list replaces it.
    • A truncated name, a zero-length name and a truncated last name each return 1 and leave the stored list as it was.
    • A length of 0 and a null list each return 0 and clear the list.
    • A null SSL throws.
  • Three deliberate bugs make the test fail: a format check that accepts zero-length and truncated names, returning early on a null list without clearing, and storing the caller's pointer instead of a copy.
  • -Wall -Wextra is clean for the changed files, and python tools/check_conventions.py --base origin/main passes.

I searched open and merged pull requests for alpn_protos just before opening this one, and none implements it. SSL_CTX_set_alpn_protos is forwarded to libSceLibreSsl and is not changed here. #16586, #16588, #16589, #16848, #16918 and #16977 change the same export inventory count, so whichever lands later needs a one-line rebase.

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: #16979 (this branch contains its commit; the diff to review is the last commit)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5208446605 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16980). Originally posted by [GalaxyGamingFR](https://github.com/GalaxyGamingFR) on 2026-11-08T03:55:28Z. --- ### What Implement `SSL_set_alpn_protos` in `libSceLibreSsl3`, replacing its parameterless throwing placeholder in `AdditionalExports.cpp`. - Source: LibreSSL 4.0.0 at [`ce488b78` `ssl_lib.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libssl/ssl_lib.c#L1921-L1947), the revision the library's debt file already uses, with [`tlsext_alpn_check_format`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libssl/ssl_tlsext.c#L68-L86) and [`CBS_stow`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libssl/bs_cbs.c#L86-L103). The behaviour follows them: - A null list is treated as length 0. - A non-empty list must be a sequence of 1-byte length-prefixed names, each non-empty and inside the buffer. Otherwise it returns 1 and the SSL is unchanged. - Otherwise the old `alpn_client_proto_list` is freed and the fields are cleared. A length of 0 stops there and returns 0. A non-empty list is copied into a new `malloc` buffer and stored with its length, and the call returns 0. A failed allocation returns 1 with the list cleared, as upstream does. - As upstream notes, 0 means success here, the reverse of most of the API. - The list and its length are at offsets 264 and 272 of `LibreSsl3Ssl`, the layout #16979 extends to 320 bytes. That is why this PR depends on #16979. - `Api.hpp` now declares it as `int SSL_set_alpn_protos(LibreSsl3Ssl* ssl, const std::uint8_t* protos, std::uint32_t protosLength)`, matching upstream's `unsigned int` length. - Memory goes through libc's `malloc_nid_postfix` and `free_nid_postfix`, as `Asn1Values.cpp` already does. - A null SSL throws `std::invalid_argument`, where upstream would dereference it. The gap is recorded in `docs/dev/debt/libSceLibreSsl3.md`: no handshake runs here, so the list is never sent, an SSL whose list came from another allocator cannot be passed, and the console layout is not measured. The export inventory is updated (137 exports, 127 named). No title's trace or disassembly was used, and the export was not measured on a PS5. ### Tested Windows 11, WinLibs GCC 15.2.0 UCRT. This is not a full CMake build. I compiled `tests/GuestLibreSsl3Ssl.cpp` with libSceLibreSsl3's `Ssl.cpp`, `Key.cpp`, `X509.cpp`, `Asn1Values.cpp` and `IntegerDecoder.cpp` and libSceLibreSsl's `Error.cpp` into one executable, with `APS5_VABI` defined empty, a one-line `NotImplementedAt_nid_no_patch` that throws, and `malloc`/`calloc`/`free` shims over the C runtime. No title or homebrew, and not built on Linux or macOS. - The test passes. The new `CheckAlpnProtos` fills a guarded SSL with `0x5A` (list pointer null) and checks, after each call, that only the 16 bytes at offsets 264 and 272 changed: - `h2` + `http/1.1` is copied (a new buffer with the same bytes) and returns 0, and a second list replaces it. - A truncated name, a zero-length name and a truncated last name each return 1 and leave the stored list as it was. - A length of 0 and a null list each return 0 and clear the list. - A null SSL throws. - Three deliberate bugs make the test fail: a format check that accepts zero-length and truncated names, returning early on a null list without clearing, and storing the caller's pointer instead of a copy. - `-Wall -Wextra` is clean for the changed files, and `python tools/check_conventions.py --base origin/main` passes. I searched open and merged pull requests for `alpn_protos` just before opening this one, and none implements it. `SSL_CTX_set_alpn_protos` is forwarded to libSceLibreSsl and is not changed here. #16586, #16588, #16589, #16848, #16918 and #16977 change the same export inventory count, so whichever lands later needs a one-line rebase. ### 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: #16979 (this branch contains its commit; the diff to review is the last commit) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!16980
No description provided.