feat(libSceLibreSsl): implement the method getters and SSL_CTX and SSL lifecycle #12729
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12729"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by AdnanKhan-ak47 on 2026-10-29T05:51:56Z.
What
Implements the LibreSSL 2.5.4 method getters and the
SSL_CTX/SSLlifecycle in libSceLibreSsl, on top of theSSL_CTXlayout from #11138 and theSSLlayout from #11143, both now inmain. These are the objectsSSL_connect/SSL_read/SSL_writeneed; those follow in a separate PR.Since #10481, #10483, #11138 and #11143 landed, the branch is one commit,
1bea86bbe7, plus two merges ofmain: 11 files, +2,319/−70 (581 of them the test). It squashes the original change (a5119c3e7d), the review fixes and the adaptation tomain's memory BIO: theSSLstruct isLibreSslSsl, as inmain, and the socketBIOusesmain'sLibreSsl::Biotypes and is released through itsBIO_free.Exports (11):
SSLv23_client_method,SSLv23_server_method,TLS_client_method,DTLSv1_client_method,DTLSv1_server_method,SSL_CTX_new,SSL_CTX_free,SSL_new,SSL_free,SSL_set_fd,SSL_get_fd.src/SslMethod.cpp): four static guestSSL_METHODobjects in the 2.5.4 public layout (48 bytes) with their internal blocks: TLS client and server (version 0x0303, range 0x0301-0x0303) and DTLS client and server (0xFEFF).SSLv23_client_methodreturns the same object asTLS_client_method, asssl/methods.cdoes.ssl_new,ssl_clearandssl_freeallocate and free the 144-bytessl3_stateand 1040-byte internal block;ssl_accept/ssl_connecton the wrong side point at anssl_undefined_functionequivalent that queues error 66;ssl_renegotiate_checkisssl_ok;get_timeoutreturns 7200;ssl3_encpoints at a 16-byte block with flags 0x17 (TLS) or 0x01 (DTLS). Slots a guest cannot legitimately call (dispatch_alert, the cipher getters,enc,get_message,read_bytes,write_bytes,get_ssl_method) throw on call, and so do connect, accept, read, peek, write, shutdown and pending until the I/O PR wires them.src/SslLifecycle.cpp):SSL_CTX_newandSSL_newfollowssl_lib.c: defaults, a reference on the context, a freshX509_VERIFY_PARAMinherited from the context, the ALPN, EC point format and supported group lists copied, ticket keys from host entropy, and the ex_data new callbacks run (src/ExData.cppgains the hooks).SSL_CTX_free/SSL_freedrop references, run the ex_data free callbacks with the valuesSSL_CTX_set_ex_data/SSL_set_ex_datastored, and release everything the object owns, the ex_data stack included.SSL_newwith a DTLS method throws and leaves the context's reference count unchanged, because noDTLS1_STATEis modelled.src/SslBio.cpp):SSL_set_fdcreates a socket BIO (104 bytes, staticBIO_METHODtype 0x505, init 1,BIO_NOCLOSE, num = fd) and accepts any integer, asbss_sock.cdoes.SSL_get_fdwalks the read BIO and returns -1 when there is none.BIO_new_socketis not exported here becauseSSL_set_bio,BIO_freeandBIO_ctrlare still stubs.docs/dev/debt/libSceLibreSsl.md: inheriting DH/ECDH parameters, a certificate or key, or verify policies/hosts/e-mail/IP inSSL_new; freeing an object that holds a session, the session table, stored certificates or keys, a buffering BIO, an engine, SRTP profiles or live cipher/hash contexts; closing a BIO that owns its descriptor;SSLerrorfor handshake states other than 0/BEFORE/OK.cipher_list,cipher_list_by_id, the session table and theCERTdigests are left null. The internal-block offsets and sizes are from LibreSSL 2.5.4 built for x86-64, not measured on a console.Tested
The review changes and their test results are in https://github.com/boykopovar/AnyPS5/pull/12729#issuecomment-6493189345. The paragraph below describes the first version.
Head
8a5dd67984(onmaine64c194c43): macOS 27.2 (M4), x86-64 build under Rosetta, with the LibreSSL sources on the macOS integration tree becausemainalone does not build on macOS. The LibreSSL tests pass 54/57, includingguest_libressl_ssl_lifecycle; the other 3 (guest_libressl_protocol_nid,guest_libressl_bio_patched,guest_libressl_cmac_patched) fail identically onmainalone there, where the macOS NID patcher rejects_sceNetRecv. Linux not rerun for this update.tools/check_conventions.py --base origin/mainpasses.Current head
44b98337f3mergesmainec7878b6f9on top of oneandonlydean's merge ofmain(693c81aee5), which resolved theExport.cppstubs besideRSA_generate_key_ex(#18396). The only conflict this time was indocs/dev/debt/changes/fix-libc-ld80-inverse-hyperbolic.md, amainfile that693c81aee5had folded thehypotlfragment into before #22579 did it onmain; it now matchesmain, so this PR's diff is again exactly its own 11 files, line for line as before.1bea86bbe7is the same change rebased without conflicts ontomain050cdf95ad, which has the fix for thepatched_librariesfailure of the previous Windows run (libSceVideoOut.prxandlibSceGnmDriver.prxfailing to load with error 127;main0694c4c, the base of that run, failed it the same way, and the revert in #21466 fixed it).The rebase before it,
784499ab90ontomain55bfc4aad3:mainhad implementedSSL_CTX_get_ex_data(#15281) beside this PR'sSSL_CTX_freestub, and MarrasFederico'sSSL_CTX_set_cipher_list(#17813) now installs real cipher lists into a context. Changes:SSL_CTX_freealready releases both lists with the guest allocator their stacks use. New test stepTestInstalledCipherListsReleasedsets two lists and frees the context under the tracking heap; with thecipher_list_by_idfree removed it fails the per-step leak check, restored it passes.SSL_CTX_newstill leaves both lists null. Its debt entry now says LibreSSL installsALL:!aNULL:!eNULL:!SSLv2there, instead of saying no export builds a cipher table.SSL_get_ex_datathrows.mainhad reworded theSSL_get_SSL_CTXandSSL_set_verifydebt entries this PR edits; git's merge kept both copies and re-added an oldOCSP_RESPONSE_freeline without a conflict. I removed the copies, so the debt diff touches the same entries as before.Earlier rebases:
ace8525a57ontomainc959605c79(only stubs besideSSL_CTX_add_client_CA, #16688, andSSL_get_peer_cert_chain, #16694; no code change).The previous rebase,
230a4607d6ontomain016db0480e:mainhad gained MarrasFederico'sSSL_CTX_set_ex_dataandSSL_set_ex_data(#16678, #16680) andSSL_CTX_check_private_key(#16682), whose stubs sat beside this PR's; both sides are kept. SinceSSL_set_ex_datacan now fill theex_datastack this PR'sSSL_freereleases, three small changes:SSL_new/SSL_freeusemain's newLibreSslSslInternal::exDatafield instead of a raw offset (the same 272).TestStoredExDataReachesRelease: it stores a value with each setter, frees, and requires the free callbacks to get that value; the tracking heap checks the stack is freed. With the free path changed to pass null, the test fails at the callback check; restored, it passes.SSL_set_ex_datathrows.On macOS 27.2 (M4, x86-64 under Rosetta),
44b98337f3with #12730 on top, onmainec7878b6f9: 177 of the 181 LibreSSL tests pass,guest_libressl_ssl_lifecycleincluded.guest_libressl_protocol,guest_libressl_protocol_nid,guest_libressl3_ecdsa_sigandguest_libressl3_rsa_gettersare not built there, becauselibcurl.prxdoes not link on that Mac.Arch Linux x86-64, GCC 16.2.1, branch head
f7e5b79806(main2960e9a6e7merged in):ctest --test-dir build -R libressl37/37 pass; the newguest_libressl_ssl_lifecycle20/20 in a loop;ctest -R ^public_headers65/65. The new test runs against a tracking guest heap and fails on any leak. It covers method identity and version fields, the undefined slots queueing error 66, the throwing slots, context defaults and distinct ticket keys, reference counts (through the ex_data free callbacks), SSL defaults copied atSSL_new, the DTLS refusal and its unwind, the list copies, and the fd round-trip including -1, 0 andINT_MAX. Ten deliberate mutations (wrong reference counts, flags, skipped frees and callbacks, among others) each make it abort.tools/check_conventions.py --base origin/mainpasses. Not tested on a console or with a title.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:01Z.
Review: COMMENTED
It is also +4.2k lines that cannot do anything on its own: there is no handshake or I/O until #12730 (+8.7k, cumulative) lands, so the first point at which a title could benefit is the second PR. Is there a reason these are not one reviewable unit?