feat(libSceLibreSsl): implement SSL_connect, SSL_read, SSL_write and the rest of TLS I/O over mbedtls #12730
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12730"
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:52:23Z.
What
Implements the LibreSSL 2.5.4 TLS connection exports in libSceLibreSsl over an mbedtls engine on guest sockets, on top of #12729 (methods and
SSL_CTX/SSLlifecycle), which is now merged.With #12729 merged, the branch is
mainplus this PR's two commits: 14 files, +4,501/−60 (2,615 of them tests).c6931c2d5fsquashes the engine (5a82bb22b6), the exports on it (982bff5d57) and the review fixes;0aa621cf84is a test-only fix from ahmadmuj's review.Exports (8):
SSL_connect,SSL_accept,SSL_read,SSL_peek,SSL_write,SSL_pending,SSL_shutdown,SSL_get_error. The TLS method slots for connect, accept, read, peek, write, shutdown and pending now point at the same implementation; the DTLS slots still throw, sinceSSL_newrefuses DTLS.SSL_ctrl(from #11143) gains case 55,SSL_CTRL_SET_TLSEXT_HOSTNAME, followings3_lib.c: a guest-heap copy of the name, error 319 for a name over 255 bytes and 320 for a type other than 0. The handshake writes the resultSSL_get_verify_result(#11143) returns.include/TlsEngine.hpp,src/TlsEngine.cpp, commit5a82bb22b6):LibreSslTls::Connectionruns an mbedtls TLS 1.2 client or server on a guest socket, looked up throughKernelLookupSocketNative_nid_no_patchas libSceSsl does. It reports Done, WantRead, WantWrite, ZeroReturn, Syscall or Ssl, keeps peeked bytes, follows thessl3_write_bytesloop for fragment size, partial writes and moving buffers, sends SNI without hostname verification (2.5.4 only checks a hostname set on the verify param), records the peer chain shape and verify flags, and classifies failures.CMakeLists.txtlinksmbedtlsandmbedx509and hides their symbols, as libSceSsl's build does.src/SslIo.cpp): a host-side map from each guestSSLto its engine connection, created at the first handshake from the server flag, the read BIO's descriptor, the verify mode and the SNI name, and released inSSL_freeandSSL_clear. No guest layout field is added. After every call it setsrwstate, the BIO retry flags, BIO byte counts, theshutdownbits,warn_alert, the handshake state (soSSLerrorfunction codes match 2.5.4) and guesterrnofor syscall failures.SSL_get_errorfollowsssl_lib.c: the error queue first, thenrwstate, then ZERO_RETURN only after a received close_notify.SSL_shutdownfollowsssl3_shutdown(0 after sending close_notify, 1 once both are seen; 1 without sending anything while the handshake has not finished). A repeatedSSL_connectafter a finished handshake restarts withSSL_clearon the same socket, as 2.5.4 does.X509_verify_certstops at the first chain error and the result is 18, 19 or 20 depending on the chain shape (single self-signed, chain ending in self-signed, issuer not found). The defaultSSL_VERIFY_NONEclient completes the handshake and records it.docs/dev/debt/libSceLibreSsl.md: an SSL with no BIO, separate read and write BIOs or a descriptor that is not a guest socket; message, info, verify or certificate-verify callbacks, ALPN lists, status requests, anSSL_SESSION, a verification depth, trusted certificates or store lookups; TLS 1.2 disabled by options or version limits; a server withSSL_VERIFY_PEER; a peer fatal alert; any other engine failure (with the mbedtls code); any call after a failed handshake. The engine is TLS 1.2 only, because the repository's mbedtls configuration compiles TLS 1.3 out, and it has no renegotiation.SSL_acceptcannot complete a handshake until a certificate can be loaded: it fails the first ClientHello with -1,SSL_ERROR_SSLand reason 193 (no shared cipher).Tested
The review changes and their test results, including per-entry times and the run combined with #12688, are in https://github.com/boykopovar/AnyPS5/pull/12730#issuecomment-6493190140. The paragraph below describes the first version.
Head
fd576439d7(#127298a5dd67984onmaine64c194c43): 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 fourguest_libressl_ssl_io_*, threeguest_libressl_tls_engine_*andguest_libressl_ssl_lifecycletests pass, 5 runs each in a loop; the rest of the LibreSSL tests match #12729. Linux not rerun for this update.tools/check_conventions.py --base origin/mainpasses.e00c95553b(now0aa621cf84) changes onlyWriteBackPressureintests/TlsEngine.cpp: the moving-buffer retry keeps its buffer and its result drives the rest of the write loop. Old and new test with a pause forced before that retry, macOS as above: the old one fails 3 of 3 with the assertion from the review, the new one passes 5 of 5, and bothWantWriteandDoneoutcomes of the retry were seen passing. Linux not rerun.Current head
0aa621cf84is the same two commits rebased ontomain0aca3f0d7b. The only conflicts were the stubs besideSSL_get_ex_data, whichmainimplemented (326e51d8e3): its stub sat next to this PR'sSSL_get_errorstub inExport.cpp, and both declarations changed inApi.hpp; both are kept, and this PR's own lines are unchanged. On macOS (same setup), 190 of the 194 LibreSSL tests pass,guest_libressl_ex_dataand this PR's tests included;guest_libressl_protocol,guest_libressl_protocol_nid,guest_libressl3_ecdsa_sigandguest_libressl3_rsa_gettersare not built there, becauselibcurl.prxdoes not link on that Mac.bff386ea9dwas the same two commits onmain50f2772c6b, which contains #12729; its Windows check passed, withguest_libressl_tls_engine_transportin 1.81 s. The Windows check of the head before it6d663c1d82timed out inguest_libressl_tls_engine_transportafter 30 s with no output, where the same commits passed in 1.67 s on5145f29443. On macOS (same setup) that test passed 40 times in a row and 40 times with 8 copies running at once, and all 186 LibreSSL tests that build there pass; if the timeout comes back on Windows I will look for the blocking call.6d663c1d82was the same two commits on #12729's head44b98337f3, which mergesmainec7878b6f9; their content is unchanged.5145f29443was the same change on #127291bea86bbe7andmain050cdf95ad, to rerun the Windows check aftermain'spatched_librariesfailure (see #12729). The rebase before it,13cb16cd25onmain55bfc4aad3:mainimplementedSSL_check_private_key(#16683) beside this PR'sSSL_accept/SSL_connectstubs; both are kept. Two debt changes: theSSL_connect and SSL_acceptentry now says mbedtls's default suites replace any cipher list, including one set withSSL_CTX_set_cipher_list(#17813, now inmain), and a second copy of the method entry that git's merge left without a conflict is removed. On macOS (same setup), the fourguest_libressl_ssl_io_*, threeguest_libressl_tls_engine_*andguest_libressl_ssl_lifecycleentries pass; the rest of the LibreSSL tests match #12729.Arch Linux x86-64, GCC 16.2.1, branch head
648916e2df(main2960e9a6e7merged in through #12729):ctest --test-dir build -R libressl39/39 pass; the newguest_libressl_ssl_io20/20 and the engine testguest_libressl_tls_engine10/10 in a loop;ctest -R ^public_headers65/65.guest_libressl_ssl_iodrives a client through the exports against a server engine thread over 127.0.0.1 guest sockets, on a tracking heap that fails on leaks: handshake and verify result 18 for the self-signed test certificate, 64 KiB echoed both ways,SSL_peekthenSSL_readreturning the same bytes,SSL_pendingafter a partial read, a non-blocking socket returning -1 withSSL_ERROR_WANT_READand then succeeding, partial-write mode andmax_send_fragment, peer close_notify giving 0 andSSL_ERROR_ZERO_RETURN, an abrupt close givingSSL_ERROR_SYSCALLwith errno,SSL_shutdownreturning 0 then 1, quiet shutdown, the SNI the server received, andSSL_VERIFY_PEERfailing against an untrusted certificate. Seventeen deliberate mutations (wrong chain code, dropped shutdown bit, dropped retry flags or errno, ignored partial write,SSL_get_errorignoring the queue, unreleased connection, missing BIO accounting,SSL_shutdownalways 1, SNI not sent, verify mode forced to PEER,SSL_pendingalways 0, ignored fragment size, among others) each make it fail.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:02Z.
Review: COMMENTED
The diff is cumulative with #12729 (+8.7k lines), so the Files tab does not show which part is this PR. For a handshake engine that is difficult to review; please state the commits that are new.
Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-05T17:21:21Z.
Review: COMMENTED
Checked head
740b4ea1e4387230e08a459339cf53c5ea53662f; PR base1e24993fa3a7da25e8fc27152af654687ba64552.On Linux/WSL2, the exact-head build passes.
ctest -R libresslfails twice, with 66/67 passing; the transport entry passes alone. The inline finding explains its intermittent failure.A separate guest-export probe against Python's OpenSSL 3.0.13 peer passes TLS 1.2, verify result 18, exact 64 KiB echo, peer close_notify/ZERO_RETURN, and client shutdown 0 then 1.
Current main
dab11d4569e99119a8561457dbb6891c361136eeconflicts in CMakeLists.txt, Api.hpp and the debt file, so integration remains untested. Scope is this author's TLS I/O; this does not approve the embedded SSL context/fields work.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T06:01:05Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review found no verified blocking defects.
What I ran
Reviewed head
bff386ea9d0c1edfa54d26c3100417544c330a95throughrepo_read.py. No tests or build checks were run. The description’s test results are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, test, convention check, console run, or title run was performed here. All 14 changed files listed in the manifest were included and readable; the full text of each was not read. The review covered the TLS engine, SSL I/O paths, API wiring, build entries, and relevant test cases. Remaining changed-file details and behavior outside those targeted ranges were not verified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:51:37Z.
Review: COMMENTED
Reviewed — no blocking findings
The diff and selected implementation paths at head
0aa621cf8464f0f2af53d13b59266b0c279ed309show no verified defect; tests were not run during this review.What I ran
No commands were run. I read the prepared description, commits, manifest, diff, and selected changed source files using
repo_read.py.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
The review did not inspect every changed file or the complete implementations of
SslIo.cpp,TlsEngine.cpp, and the test files. No tests or builds were run. These files were listed as changed but not read:core/libs/prx/libSceLibreSsl/CMakeLists.txt,core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/include/SslInternal.hpp,core/libs/prx/libSceLibreSsl/include/TlsEngine.hpp,core/libs/prx/libSceLibreSsl/src/Ssl.cpp,core/libs/prx/libSceLibreSsl/src/SslIo.cpp,core/libs/prx/libSceLibreSsl/src/SslLifecycle.cpp,core/libs/prx/libSceLibreSsl/src/SslMethod.cpp,core/libs/prx/libSceLibreSsl/src/TlsEngine.cpp,core/libs/prx/libSceLibreSsl/tests/FakeSocket.hpp,core/libs/prx/libSceLibreSsl/tests/TlsEngine.cpp,core/libs/tests/GuestLibreSslSslIo.cpp, anddocs/dev/debt/libSceLibreSsl.md. No files were excluded by the manifest's listing.To get this to a good state
Nothing is required. Optional: complete the implementation and test review before relying on this review as a merge assessment.