Skip to content

feat(libSceLibreSsl): implement SSL_get_session, SSL_get_current_cipher, SSL_get_certificate and SSL_get_privatekey - #10482

Merged
oneandonlydean merged 8 commits into
boykopovar:mainfrom
alvaroelpob:feat/libscelibressl-ssl-session
Nov 5, 2026
Merged

oneandonlydean merged 8 commits into
boykopovar:mainfrom
alvaroelpob:feat/libscelibressl-ssl-session

Conversation

@alvaroelpob

@alvaroelpob alvaroelpob commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements SSL_get_session, SSL_get_current_cipher, SSL_get_certificate and SSL_get_privatekey in libSceLibreSsl, which threw and were declared without parameters.

The module is LibreSSL 2.5.4 (firmware 13.40 measurements in #8981). Signatures, layouts and results follow that release's ssl.h, ssl_locl.h, ssl_lib.c and ssl_sess.c:

Export Behaviour
SSL_SESSION* SSL_get_session(const SSL*) session
const SSL_CIPHER* SSL_get_current_cipher(const SSL*) session->cipher, or null without a session
X509* SSL_get_certificate(const SSL*) cert->key->x509, or null without a cert
EVP_PKEY* SSL_get_privatekey(SSL*) cert->key->privatekey, or null without a cert

The layouts are 232 bytes for SSL (cert at 80, session at 128), 232 for SSL_SESSION (cipher at 168), 256 for CERT (key at 0) and 24 for CERT_PKEY (x509, privatekey, digest). They were checked with static_asserts and against offsetof from the 2.5.4 headers compiled on x86-64. LibreSSL dereferences the connection, and a cert without a current key, without checking them, so those throw. No export of this module creates a connection yet, so for now only connections built by the caller reach these functions.

#10481 reads other fields of the same SSL layout. This PR uses its own file and struct names, so the two don't overlap.

The debt entry records the source and what is unverified, and the pending-export count drops from 357 to 353.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON on main 379b1dc. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its guest_libressl_ssl_session test and check_conventions.py run on its own.

Checklist

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Progress report (151a2cb → a6ec924)

📈 System libraries: 27.08% (+0.01%, +4 implemented functions)

✅ 4 implemented
Library Name
libSceLibreSsl SSL_get_certificate_nid_postfix
libSceLibreSsl SSL_get_current_cipher_nid_postfix
libSceLibreSsl SSL_get_privatekey_nid_postfix
libSceLibreSsl SSL_get_session_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl 225/435 (51.72%) 229/435 (52.64%) +0.92%

@alvaroelpob
alvaroelpob marked this pull request as ready for review October 24, 2026 02:59
Copilot AI balanced review requested due to automatic review settings October 24, 2026 02:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 15827 core/libs/prx/libSceLibreSsl/CMakeLists.txt L273

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 10508 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10570 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10878 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11128 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11359 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11466 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 12729 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 12730 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13266 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13285 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13486 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13546 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13547 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13860 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13877 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 14115 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 14212 docs/dev/debt/libSceLibreSsl.md
PR 15480 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15481 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15482 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15483 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15737 docs/dev/debt/libSceLibreSsl.md
PR 15994 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md

@github-actions github-actions Bot added build docs prx needs rebase Conflicts with main, rebase needed labels Oct 24, 2026
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-ssl-session branch from 0c5b52a to 6019901 Compare October 24, 2026 15:32
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 1e740a2 (head 6019901) to resolve the conflict from #9033 on the shared CMakeLists.txt and debt-file lines. Full suite 2043/2044, with the same failure on main. Depends on drops #9033 and adds #9949.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the four accessors against the cited LibreSSL 2.5.4 structures. The current session, cipher and key fields/offsets match the static assertions; getters handle absent session/cert as null and the current-key path as described. The head merges cleanly with current upstream main, and conventions/diff checks pass. I compiled and ran GuestLibreSslSslSession.cpp with SslSession.cpp directly using GCC 12.2.0; it passed. The full build/test results are author-reported; hosted product jobs are skipped.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 25, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 25, 2026
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-ssl-session branch from 6019901 to 22e3528 Compare October 25, 2026 05:32
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main e7e3e9c, head 22e3528, to resolve the conflict from #9529 on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 353 minus this PR's exports. #10706 now requires each export to be declared once in include/Api.hpp, so 22e3528 moves these signatures and their structs there and drops the test's redeclarations. Full suite 2202/2203, with the same failure on main. Depends on drops the merged #9529.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 25, 2026

@ahmadmuj ahmadmuj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 57dc6f7977be9f2e4d3b559ba5814b32f163bf9b, merged locally onto main a7a2eece499ef8925c93765dbbcc9f4d9461a2f0. The merge conflicts only in the debt file's first lines (the count next to main's updated Digest line); I took main's lines with 341 to build. Main has since moved to 58c9977e3b, which only adds an unrelated NpTrophy test, same conflict.

What I ran, Linux x86-64, GCC 13.3, Release:

  • Built the libSceLibreSsl test targets on the merged tree: all 10 guest_libressl_* tests pass, including guest_libressl_ssl_session. check_conventions.py --base origin/main, the conventions_*/pr_overlap* ctests (47) and public_headers* (65) pass.
  • Red controls: a null cert->key returning null instead of throwing, SSL_get_certificate returning privatekey, the cipher getter always returning null, and a null ssl not throwing each fail the test (lines 86, 93, 74, 58). Restored, it passes.
  • offsetof probe against the compiled LibreSSL 2.5.4 ssl.h and ssl/ssl_locl.h: SSL 232 (cert 80, session 128), SSL_SESSION 232 (cipher 168), CERT 256 (key 0), CERT_PKEY 24 (x509 0, privatekey 8). All your static_asserts agree.
  • Differential: I compiled SslSession.cpp as is and linked it with the 2.5.4 libssl.a. Then I called your 4 getters and the real ones on 13 real connection states, on both the live SSL and a 232-byte copy of it. The states included a fresh SSL_new, RSA cert+key, a session with and without a cipher, RSA then EC (so key is slot 5 while pkeys[0] still holds RSA), an EC cert from the SSL_CTX, SSL_set_SSL_CTX, SSL_dup and set_session(NULL). All 52 results are identical.
  • Null handling matches ssl_lib.c and ssl_sess.c. The two throws are where 2.5.4 dereferences without a check.

Two small things, neither blocks:

  • The test's TestCert doesn't match the real cert_st. In 2.5.4, pkeys starts at 80 and has 7 slots (SSL_PKEY_NUM is 7, after valid, the masks and the DH/ECDH fields). The test puts 8 slots at offset 8, and it reaches 256 only by coincidence. The getters only follow key, so the results are unaffected, but the test describes a layout that doesn't exist. Something like TestCertKey* key; unsigned char beforePkeys[72]; TestCertKey pkeys[7]; int references; with static_assert(offsetof(TestCert, pkeys) == 80) would match.
  • LibreSslSessionConnection and #10481's LibreSsl are two views of the same ssl_st, with the same size and the same cert and session offsets. You already note that in the body. Like on #10485, whichever lands second could switch to the other's type, so Api.hpp keeps a single SSL.

Approving. Not checked: console behaviour, Windows, and a title, since nothing creates an SSL in this module yet, as the debt entry says.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-ssl-session branch from 57dc6f7 to 1899090 Compare October 25, 2026 18:51
@alvaroelpob

alvaroelpob commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased on main ae7d592 (after #9949; head 3490c64) to resolve the conflicts on the shared CMakeLists.txt and debt-file lines; no change to this PR's functions. Full ctest -j16 2275/2276, agc_driver_multisample_retirement fails the same way on main. Depends on drops the merged #9949, #10005, #10071 and #10484.

@BunnyFl

BunnyFl commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

The layout matches firmware 13.42's libSceLibreSsl.sprx for SSL_get_session. I ran the 13.42 versions in an emulator on structures filled with offset markers (every 4-byte word holds its own offset), so a getter's result names the field it read. Two runs gave identical results.

SSL_get_session reads +0x80 (128), the session offset in your static_assert. The other asserted fields (cert at 80, cipher at 168, the sizes) aren't touched by this call, so I can't confirm those.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-ssl-session branch from 1899090 to 3490c64 Compare October 25, 2026 20:08
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 3, 2026
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 9ab6a28 to resolve the conflicts with #10395 on the shared CMakeLists.txt, Api.hpp and debt lines; the pending-export count is recomputed from Export.cpp. Head 25aeb6f. Full Linux suite: 3898/3898; check_conventions.py passes.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-ssl-session branch from 2d52a50 to 25aeb6f Compare November 4, 2026 19:43
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 4, 2026
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Rebased on main d63781e to resolve the conflicts on the shared CMakeLists.txt, Api.hpp and debt lines (#10395 and #11662); the pending-export count is recomputed from Export.cpp. Head 7efb1fc. Full Linux suite on that head: 3935/3936; the one failure was guest_poll under the background run, which passes when rerun in the foreground; check_conventions.py passes. The implementation and debt changes are unchanged apart from the count.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-ssl-session branch from 25aeb6f to 7efb1fc Compare November 5, 2026 13:22
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 5, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @alvaroelpob, thanks for keeping this branch current. #10481 has now landed, and main has one shared view of the guest SSL object: LibreSslSsl in include/Api.hpp, with static_asserts in src/Ssl.cpp (size 232, cert at 80, session at 128).

This branch adds a second view of the same object, LibreSslSessionConnection, with the same size and the same two offsets, and takes it as the parameter type of SSL_get_session, SSL_get_current_cipher, SSL_get_certificate and SSL_get_privatekey. The two agree today, but two layouts of one guest object can drift apart later, and the exports in src/Ssl.cpp and src/SslSession.cpp would then disagree about which bytes they read.

Could you switch these four to const LibreSslSsl* and read cert and session from it (they are void* there, so a static_cast to LibreSslCert* / LibreSslSession*), then drop LibreSslSessionConnection and its static_asserts? LibreSslCert, LibreSslCertKey and LibreSslSession can stay as they are. The behaviour and tests should not need to change.

@alvaroelpob

alvaroelpob commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Done in b190203: SSL_get_session, SSL_get_current_cipher, SSL_get_certificate and SSL_get_privatekey now take const LibreSslSsl* and read cert and session through static_cast to LibreSslCert* / LibreSslSession*. LibreSslSessionConnection and its static_asserts are gone, and the test only switched its cast to the shared type. LibreSslCert, LibreSslCertKey and LibreSslSession are unchanged.

To pick up #10481 the branch is rebased on main d48f11a. That rebase replaces your merge of main (bcbce32), which brought no changes of its own beyond main and the branch. Rebasing put the pending-export count back to main's 170, so da87403 sets it to the 166 stubs left in Export.cpp. Full Linux suite on b190203: 4085/4085; check_conventions.py passes.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-ssl-session branch from bcbce32 to b190203 Compare November 5, 2026 18:29
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl-ssl-session branch from b190203 to 6aa4750 Compare November 5, 2026 19:36
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Rebased on main ce69412 to resolve the new conflicts. This also picks up the latest main; the LibreSslSsl change from my previous comment is unchanged. The rebase left the pending-export count wrong, so 503b810 recounts it from Export.cpp. Head 6aa4750. Full Linux suite: 4087/4087. check_conventions.py passes.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @alvaroelpob, main moved on and #11553 removed the LibreSsl pending-exports count line your PR also edited, so I merged main into your branch and kept main's line. Nothing else changed.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 5, 2026
@oneandonlydean
oneandonlydean dismissed MarcZX10’s stale review November 5, 2026 21:20

Addressed: the branch now has current main merged in (a6ec924, main 08e7317). The implementation is unchanged, and the pending-exports count line was removed on main by #11553, so the merge keeps main's version. Windows is green on this head and the LibreSSL tests pass (54/54).

@oneandonlydean
oneandonlydean merged commit c5a9823 into boykopovar:main Nov 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants