feat(libSceLibreSsl): implement SSL_set_session #23336
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23336"
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 Callimann8 on 2026-11-18T22:00:33Z.
What
Implements
SSL_set_sessionin libSceLibreSsl. It threw on every call. Clients call it to hand a session they kept withSSL_get1_sessionto a new connection for resumption.This builds on #23139 (
SSL_get1_sessionand the reference-droppingSSL_SESSION_free), whose two commits are included until it merges.SSL_set_session(src/SslSession.cpp) follows LibreSSL 2.5.4ssl_sess.c:ssl_version. No method queuesSSL_R_UNABLE_TO_FIND_SSL_METHOD(240) and returns 0.SSL_set_ssl_methoddoes: the same protocol version only swaps the pointer, another creates the new connection state before freeing the old one (a failed allocation returns 0 and leaves the old state and method in place), and a handshake function set to the old connect or accept moves to the new one.verify_resultto the connection.get_ssl_method(src/SslMethod.cpp) threw for every method. It now returns the TLS 1.0, 1.1 and 1.2 client or server methods oft1_clnt.candt1_srvr.c, or the DTLS 1.0 method, and null for any other version. The six TLS methods are not exported. Each has one version, theSSL3_ENC_METHODflags of its version and thessl3_renegotiateslots, which throw like the other unimplemented slots.LibreSslSessionmapsssl_version(offset 0) andverify_result(offset 136) from thessl_session_stlayout on LP64.SSL_get1_sessionandSSL_set_sessionshare one checked reference increment.Setting a session while the connection holds the last reference to its old session still throws through
SSL_SESSION_free(#23139). The connection keeps its old session and the new session's count is restored, but the method switch has already happened. A null connection or context throws where LibreSSL dereferences it. Debt fragmentdocs/dev/debt/changes/feat-libressl-ssl-set-session.mdadds the entry and updates the method entry.Tested
Linux (Ubuntu 24.04), GCC 13, Release. Unit tests only; nothing checked on a console or in a title.
core/libs/tests/GuestLibreSslSslLifecycle.cppaddsTestSetSessionon a realTLS_client_methodconnection:get_ssl_methodmaps back to itself), takes a reference and copiesverify_result; setting it again leaves the count alone;SSL_set_connect_state, a TLS 1.0 session recreates the connection state at version 0x0301, moves the handshake function to the new connect slot and drops the old session's reference;get_ssl_methodresults.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 PrivacyOnion on 2026-11-18T22:03:47Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
03ec1a0ad7:tools/check_conventions.pypassed.guest_libressl_ssl_lifecycle_tests,guest_libressl_ssl_session_testsbuilt cleanly.guest_libressl_ssl_session,guest_libressl_ssl_lifecycle):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/include/SslInternal.hpp,core/libs/prx/libSceLibreSsl/src/SslMethod.cpp,core/libs/prx/libSceLibreSsl/src/SslSession.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T23:55:18Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make TLS state recreation failure-safe so a failed allocation does not leave the connection switched to a method with no state.
What I ran
Reviewed head
03ec1a0ad777cb53f7f7b18e2a2106775f4fbbb6and the prepared patch. No commands or tests were run;repo_read.pywas unavailable as an executable tool, so I read the changed source at the pinned head directly.Files read:
SslSession.cpp,SslMethod.cpp,Api.hpp, and the prepareddiff.patch,description.md,commits.md, andmanifest.json. All eight files markedreviewedinmanifest.jsonwere included in the prepared material, but I did not read all eight full texts.Results
Findings
Blocking
core/libs/prx/libSceLibreSsl/src/SslSession.cpp:111:SetMethodcan returnfalseaftersslFreehas released the current TLS state andsslNewfails; it has already assigned the new method.SSL_set_sessionthen returns immediately without restoring the prior method or state, leaving the connection with no state and potentially leaking its prior session reference. Keep method/state consistent on allocation failure before returning.Non-blocking
None.
Not verified
The contents of
Export.cpp, both changed test files, and both debt fragments were not independently read at head. The author-reported test run was not reproduced. Console/title behavior was not checked.To get this to a good state
Make method switching preserve a valid connection on state allocation failure, then rerun the lifecycle tests and review the affected change.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T00:42:57Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
22538e3974:tools/check_conventions.pypassed.guest_libressl_ssl_lifecycle_tests,guest_libressl_ssl_session_testsbuilt cleanly.guest_libressl_ssl_session,guest_libressl_ssl_lifecycle):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/include/SslInternal.hpp,core/libs/prx/libSceLibreSsl/src/SslMethod.cpp,core/libs/prx/libSceLibreSsl/src/SslSession.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T02:00:57Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: none; the implementation appears consistent with its documented behavior, but I could not verify the complete set of changed files or run the reported checks.
What I ran
22538e39740b00d27c31c00d4c4afbf47868865eusing the prepared review artifacts andrepo_read.pyreader tools.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
review/files.jsonwas unavailable through the reader, so I could not establish which changes were excluded or confirm that every file classified as reviewed was read. I inspected the prepared diff, plus the relevant sections ofSslSession.cpp,SslMethod.cpp,Api.hpp, andExport.cpp.SslInternal.hpp,GuestLibreSslSslLifecycle.cpp,GuestLibreSslSslSession.cpp, or either debt fragment.To get this to a good state
Nothing is required. Optional: provide the review file manifest and run the reported unit test command on this head to support a complete review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T12:11:02Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: method switching can leave connection state invalid when allocation or old-state cleanup fails.
What I ran
6a9e89c7f1b172d82db1d57da142f5a46aa10057; basemainwas not merged for a preview.repo_read.pyto inspect session handling, method switching, TLS state allocation, and the relevant layouts.Results
Findings
Blocking
core/libs/prx/libSceLibreSsl/src/SslSession.cpp:61: Afternext.sslNewsucceeds,SetMethodswaps in the new state and callscurrent.sslFree(&ssl)whilessl.methodis temporarily restored to the old method. If freeing the old state throws, the function exits before restoringssl.methodtomethod, and the connection has already lost its old state. The caller then propagates the exception, leaving the connection with the new state but the old method pointer. Make the transition exception-safe so all exits preserve a consistent method/state pair.Non-blocking
Not verified
ctest -R guest_libressloutput are from the PR description.files.jsonwas not available through the reader.To get this to a good state
Make the method/state switch preserve a consistent connection if freeing the previous state fails, then rerun the lifecycle tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:52:24Z.
Review: COMMENTED
Built the branch’s changed sources and ran GuestLibreSslSslLifecycle and GuestLibreSslSslSession on Linux against the existing runtime libraries. The test run passed and covered SSL session assignment and the existing lifecycle cases.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.