fix(libSceSsl): follow the codes and defaults measured on a PS5 (13.40) #7756
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7756"
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 frankea on 2026-10-19T06:14:33Z.
What
Every "unverified" and "unknown" sentence #7626 left in
docs/dev/debt/libSceSsl.mdwas measured on a PS5 on system software 13.40 with a ps5-payload-dev payload against a TLS 1.2 test server presenting certificates issued by the test fixture root (the measurement log is the first comment below; the payload, the test server and the raw console logs are attached as files by the author). The code follows the console where it differed:SERVER_VERIFY | CN_CHECK | KNOWN_CA_CHECK(0x25): the console accepts expired and not-yet-valid certificates untilNOT_AFTER_CHECK/NOT_BEFORE_CHECKis enabled. Bits outside 0x3F returnSSL_ERROR_INVALID_VALUEfromsceSslEnableVerifyOption/sceSslDisableVerifyOption.sceSslConnect,sceSslReadandsceSslWrite, each returningSSL_ERROR_APPLICATION_VERIFICATION_CALLBACK_CHECKwhile it refuses.sceSslReadwith flags 0 reads until the requested length or the end of the stream;MsgFlagPartialReadreturns what is available. A stream that ends without close_notify reads as 0 like a close_notify; a reset returnsSCE_NET_ERROR_ECONNRESET(0x80410136) from read and close andSCE_NET_ERROR_EPIPE(0x80410120) from write; a blocking socket's receive timeout returnsSSL_ERROR_WANT_POLLIN, soSSL_ERROR_READ_TIMEOUTis gone; a record that fails its MAC returns 0x80951D55.SSL_ERROR_FATAL_ALERTand ends the transport: later connects return 0, reads 0, writesSSL_ERROR_SOCKET_CLOSED.sceSslClosebefore the handshake is a no-op, the connection stays usable forsceSslConnect(0) andsceSslRead(0) after a close, a close_notify that would block returnsSSL_ERROR_WANT_POLLOUT.sceSslRead/sceSslWritebeforesceSslConnectrun the handshake.sceSslWritewith flags other than 0 returnsSSL_ERROR_INVALID_VALUE.SSL_ERROR_INVALID_IDfrom every connection call;sceSslTermof an unknown context too;sceSslInit(0)returnsSCE_KERNEL_ERROR_EINVAL; a null host returnsSSL_ERROR_INVALID_VALUE; a descriptor that is not a socket failssceSslConnectwithSCE_NET_ERROR_EBADF.sceSslSetMinSslVersionaccepts 2..5 only (SSL_ERROR_INVALID_VALUEotherwise; the console has no TLS 1.3 value and offers TLS 1.2 only, which this build already matches).sceSslSetAlpnsplits on commas, measured on the wire; an empty list returnsSSL_ERROR_BAD_LENGTH.sceSslGetNameEntryInfowrites long attribute names (commonName);sceSslGetSerialNumberleaves*sboLenalone when the buffer is large enough.SSL_ERROR_INVALID_CERTand what the callback gets for it, read/write after a plain verification failure, write aftersceSslClose, client certificates, the callback using its own connection). Disabling 0x1, 0x4 or 0x20 stopped the payload process through the kernel's debug exception path; the emulator keeps clearing them because titles import the call, and the entry records it.Tested
PS5, system software 13.40, ps5-payload-dev elfldr v0.26, payload built from the attached
main.c(ps5-sslprobe) with the SDK built from source on macOS; serverserver.pywith OpenSSL 4.0.3; the attached logs are the console's output.Emulator: Ubuntu 24.04 x86-64 container (GCC 13, Release,
BUILD_TESTING=ON) on2dcc94109+ this commit:guest_ssl,guest_ssl_load,guest_ssl_transport_kernel,guest_ssl_transport_net,guest_ssl_ps5_readerspass, 3 runs each, with the host CPU check of83a268a86bypassed locally for the run because the container runs under Rosetta without AVX2 (the bypass is not in the commit);python3 tools/check_conventions.py --base origin/mainpasses. Not tested: Windows and macOS, a title.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in the technical debt file.mdfiles or images added to the repository (measurement log in the first comment, payload and logs attached to this PR)Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-19T06:14:52Z.
libSceSsl measured on a PS5, system software 13.40 (2026-10-19)
Every number in this file is console output. Nothing here is inferred from an emulator, SharpProspero or KytyPS5; the only inferences are marked as such.
Method
kernel_get_fw_version()= 0x13400002, the SDK version libSceLibcInternal reports), no hardware modification, PLK Payload Manager 0.6.1, ps5-payload-dev elfldr v0.26 listening on port 9021. elfldr runs each payload as a child of its own process (parent SceRedisServer, AuthId 480000001000000e, uid 0,payload.elfinps), so this is not a title process: a result that depends on the caller's process type is flagged below.main.cof the attached ps5-sslprobe folder, built with the ps5-payload-dev SDK compiled from source on macOS with Homebrew llvm@18 (make DESTDIR=~/ps5-payload-dev/ps5-payload-sdk install, no sudo). The SDK'slibSceSsl.sostub makes the loader resolve everysceSsl*import by NID in the console'slibSceSsl.sprx(NIDs computed with the repository's algorithm, the attachednids.txt: sceSslInithdpVEUDFW3s, sceSslConnectzXvd6iNyfgc, sceSslReadjltWpVKtetg, sceSslWriteiNjkt9Poblw, sceSslCloseviRXSHZYd0c, sceSslSetVerifyCallbackE4a-ahM57QQ, sceSslEnableVerifyOptionpo1X86mgHDU, sceSslDisableVerifyOptionPwsHbErG+e8, sceSslSetMinSslVersionQWSxBzf6lAg, sceSslSetAlpnTL86glUrmUw, sceSslGetAlpnSelected4O7+bRkRUe8, sceSslGetSslError0XcZknp7-Wc).sceKernelLoadStartModule("libSceSsl.sprx")returned handle 34 andsceKernelDlsym(34, "sceSslInit")returned 0x80020003 (ENOENT): the console resolves these exports by NID only.nc 192.168.1.125 9021 < sslprobe.elf); raw logs are the attachedrun1.log,run2.log,run3.log,run-opt.log,klog-dis1.log(kernel log) andserver.log(the Mac side).server.pyon this Mac (192.168.1.176, Python 3.15, OpenSSL 4.0.3), one TLS scenario per port, every port TLS 1.2 only unless stated, server certificates issued by the repository's fixture root (core/libs/tests/SslCertificateFixture.hpp, attachedgen_certs.py):good(CN and SANmac.anyps5.test, SAN IP 192.168.1.176, valid 2026-10-18..2036-10-16),cnmismatch(CN/SANother.anyps5.test),expired(valid 2025-09-14..2026-09-19),notyet(valid 2027-11-23..2028-12-27). The server sends leaf + root. Each accepted connection has its ClientHello decoded before the handshake.sceNetSocket("sslprobe", AF_INET, SOCK_STREAM, IPPROTO_TCP),sceNetConnect,sceNetSetsockopt), host stringmac.anyps5.test, twosceSslInit(256 KiB)contexts: ctx 1 with no CA, ctx 2 with the fixture root loaded bysceSslLoadCert(2, 1, [PEM, 680 bytes], NULL, NULL)= 0.What the console sends
ClientHello (144 bytes, every connection): record version 0x0301, client version 0x0303, cipher suites
c030 c02c cca9 cca8 c02f c02b 003d 003c 0035 002f 000a 00ff, groups001d 0017 0018 0019(x25519, P-256, P-384, P-521), signature algorithms0401 0501 0601 0403 0503 0603 0804 0805 0806 0201, extensions0 11 10 13only (SNI, ec_point_formats, supported_groups, signature_algorithms) plus 16 (ALPN) whensceSslSetAlpnwas called. No supported_versions, no extended_master_secret, no session ticket: the library speaks TLS 1.2 at most (a TLS 1.3-only server makessceSslConnectreturn 0x8095F010, see below). The library identifies itself in its own out-of-memory message as[libssl2] libressl_calloc(...), i.e. a LibreSSL build. The negotiated cipher with the ECDSA fixture chain was ECDHE-ECDSA-AES256-GCM-SHA384.SNI is the host string as given (
MAC.ANYPS5.TESTis sent upper-case and still verifies), an empty host sends an empty SNI name, an IP-literal host sends no SNI extension.The first
sceSslConnectof the process took 23.8 s before the ClientHello left the console (the server then completed the handshake in 15 ms); every later connection handshakes in 20-30 ms. Later payload runs in the same elfldr session did not repeat the delay.Handles and pool
sceSslInit(256 KiB)twicesceSslInit(64 KiB)= 3,sceSslInit(16 KiB)= 4,sceSslInit(1)= 5sceSslInit(0)SCE_KERNEL_ERROR_EINVAL)sceSslCreateConnectionsceSslGetMemoryPoolStats(2)after initsceSslLoadCertof the 680-byte rootsceSslGetMemoryPoolStats(4)after a failed connect on the 16 KiB poolsceSslConnecton the 16 KiB pool (root loaded, good cert)SSL_ERROR_OUT_OF_MEMORY); the library printed[libssl2] libressl_calloc(8807d8020, 6144, 1) out of memoryon stdout firstsceSslGetMemoryPoolStats(99999)Initial verify options and
sceSsl{Enable,Disable}VerifyOptionFresh connections, no option call unless stated (
default), blocking socket.sceSslConnectUNKNOWN_CACN_CHECKNOT_AFTER_CHECKNOT_BEFORE_CHECKSo the initial options are
SERVER_VERIFY0x1,CN_CHECK0x4 andKNOWN_CA_CHECK0x20 on,NOT_AFTER_CHECK0x8 andNOT_BEFORE_CHECK0x10 off (the 0x1/0x4/0x20 part is inferred from the failures above plus the disable results below; it was not read back, there is no getter). Whether 0x2 (CLIENT_VERIFYin SharpProspero) starts on or off was not determined.Return codes of the option calls themselves:
sceSslEnableVerifyOption(c, 0x4 / 0x8 / 0x10 / 0x3F / 0)sceSslEnableVerifyOption(c, 0x1000),sceSslDisableVerifyOption(c, 0x40 / 0x100 / 0x1000)INVALID_VALUE(bits outside 0x3F are rejected)sceSslDisableVerifyOption(c, 0x2 / 0x8 / 0x10)sceSslDisableVerifyOption(c, 0x1),(c, 0x4),(c, 0x20)mDBG: Sending signal(pid: N, tid: T, signo: 0xa0020101);psthen shows the payload in state STOP,kill(pid, SIGKILL)returns 0 and does not remove it. Reproduced 6/6 (runs 1, opt, dis-0x1, dis-0x4, dis-0x20 and the klog run), each as the first disable of that bit on a fresh connection beforesceSslConnect; disabling 0x4 after enabling 0x4 on the same connection stops the process too.sceSsl{Enable,Disable}VerifyOption(99999, ...)INVALID_IDThe stop is from an elfldr payload (SceRedisServer lineage). Titles import
sceSslDisableVerifyOption; whether a title process is allowed to clear 0x1/0x4/0x20 was not measured (it needs the homebrew-as-app route). Signal number 0xa0020101 is the console's debug-exception path, not a POSIX signal: asigactionhandler installed for SIGSEGV/SIGBUS/SIGILL/SIGABRT/SIGTRAP/SIGFPE/SIGSYS never ran.Verify callback
int cb(int id, unsigned int err, void** certs, int num, void* userArg)set withsceSslSetVerifyCallback(c, cb, &arg)= 0.sceSslConnectsceSslConnectreturns 0 without calling it againAPPLICATION_VERIFICATION_CALLBACK_CHECKsceSslConnect(-> 0x8095F0FD),sceSslRead(0x8095F0FD, 5 ms),sceSslConnectagain,sceSslRead,sceSslWrite(0x8095F0FD each, 5 callbacks in total);sceSslClose0, twice 0sceSslSetVerifyCallback(c, NULL, NULL)= 0, cnmismatcherris the bitmask of the verify options that failed (0x4 = CN_CHECK, 0x20 = KNOWN_CA_CHECK, 0 when the chain passed), not anSSL_ERROR_*code. The same pair comes back fromsceSslGetSslError.certs[0]is the leaf,certs[1]the root the server sent (num 2 = the chain as received). The elements are certificate handles for the context's readers:sceSslGetSerialNumber(ctx, certs[0], buf[32], &len=32)= 0 writes the serial left-aligned (10 01for serial 0x1001,80 a1for the root) and leaveslenat 32;sceSslGetSubjectName/sceSslGetIssuerName(ctx, cert)return name handles;sceSslGetNameEntryCount= 3;sceSslGetNameEntryInfo(ctx, name, i, oid[64], 64, value[128], 128, &valueLen)= 0 with oid =countryName,organizationName,commonName(long names) and valueLen = exact length (2, 12, 15/17/19);sceSslFreeSslCertName= 0. The first 24 bytes at a handle are three pointers (a struct with a vtable-like layout, not DER). The handles stay valid aftersceSslConnectreturns (re-read successfully) and are freed bysceSslDeleteConnection: the memory read back as zeros andsceSslGetSerialNumberon the stale handle crashed the payload (SIGSEGV at the handle's first pointer), so they must not be used after the delete.Error codes by situation
Root loaded, good certificate unless stated. "read" is
sceSslRead(c, buf, 64, flags).MsgFlagPartialRead)piece) after 126 ms; read 5 flags 1 -> 5 (`-one); read 64 flags 2 -> 10 after 475 ms (piece-twoSSL_ERROR_EOF)APPLICATION_DATA_AFTER_CLOSE_NOTIFY)sceSslConnectagainsceSslClose0, again 0SCE_NET_ERROR_EPIPE) each timesceSslConnectagainsceSslClose-> 0x80410136, second close 0x80410136SO_RCVTIMEO= 2 s (16-byte timeval; a 4-byte int returns 0x80410116 EINVAL), silent serverWANT_POLLINafter 2001 ms each (never 0x80951710READ_TIMEOUT); write afterwards 14,sceSslConnect0,sceSslClose0, read after close 0SO_NBIO0x1200 = 1), nothing pendingsceSslConnectWANT_POLLOUTon each further write; poll(POLLOUT) says writable (kernel buffer) while the library still returns 0x8095F014;sceSslClose-> 0x8095F014sceSslConnectsceSslClose0sceSslConnectFATAL_ALERT;sceSslConnectagain -> 0 after 500 ms; read 0; write -> 0x8095170DSOCKET_CLOSED;sceSslClose0, 0sceSslConnectsceSslConnectagain 0; read 0; write 14; close 0, 0sceSslConnectagainsceSslConnectafter successsceSslClosebefore any connectsceSslConnectafterwards -> 0 with data readable (close before connect is a no-op)sceSslCloseafter success, twicesceSslConnect0, read 0sceSslReadbefore anysceSslConnectsceSslWritebefore connect 15;sceSslConnectafterwards 0sceSslWrite(c, buf, 1, flags=1)INVALID_VALUE(write accepts flags 0 only)sceSslGetSslError(c, &a, &b)(signature guessed asint, int*, int*) after a CN failure returned 0 with a = 0x8095F00A (INVALID_CERT) and b = 0x4 (the failed option bit).ALPN
Server offers h2 and http/1.1 unless stated.
sceSslSetAlpn(c, s)sceSslGetAlpnSelected"h2,http/1.1"h2,http/1.1(two names: the string is split on commas)"h2"after, still"h2"aftersceSslClose"\x02h2\x08http/1.1"(wire format)\x02h2\x08http/1.1"http/1.1"http/1.1"http/1.1""h2,http/1.1"against a server offering http/1.1 only"http/1.1""h2,http/1.1"against a server without ALPN"h2, http/1.1"then"spdy/3,h2"spdy/3,h2(the second call replaces the list)"h2"""BAD_LENGTHsceSslSetAlpn(99999, "h2")sceSslSetMinSslVersionsceSslConnectto the TLS 1.2 serverINVALID_VALUEThere is no TLS 1.3 value: 6 and above are rejected and the library never offers 1.3.
Handles, ordering, invalid arguments
sceSslClose,sceSslConnect,sceSslRead,sceSslDeleteConnection,sceSslSetAlpn,sceSslEnableVerifyOption,sceSslSetMinSslVersion,sceSslSetVerifyCallbackon connection 99999INVALID_IDsceSslCreateConnection(99999, sock, host)sceSslCreateConnection(ctx, -1, host),(ctx, 0, host),(ctx, 1234567, host)sceSslConnecton the 1234567 oneSCE_NET_ERROR_EBADF)sceSslCreateConnection(ctx, sock, "")sceSslConnect-> 0x8095F00B (empty SNI sent, server alerted bad certificate)sceSslCreateConnection(ctx, sock, NULL)INVALID_VALUEsceSslCreateConnection(ctx, sock, "192.168.1.176")sceSslCreateConnection(ctx, sock, "MAC.ANYPS5.TEST")sceSslDeleteConnectionwithout close after a successful connectsceSslDeleteConnection, thensceSslClose,sceSslConnecton itsceSslTerm(ctx3)with a live connectionsceSslClose,sceSslConnect,sceSslDeleteConnectionon that connection 0x8095F006sceSslTerm(ctx3)again,sceSslTerm(99999)sceSslSetVerifyCallback(c, NULL, NULL)Not measured
sceSslDisableVerifyOptionof 0x1/0x4/0x20 (needs a game-type process).SSL_ERROR_READ_TIMEOUT,SSL_ERROR_EOF,SSL_ERROR_INTERNALwere never produced; a situation that returns 0x8095F00AINVALID_CERTfromsceSslConnectwas not found (a chain problem other than CA, CN and dates was not set up).sceSslSetSslVersion,sceSslGetPeerCert,sceSslCheckRecvPending,sceSslRecv/sceSslSend,sceSslReuseConnection,sceSslLoadRootCACert(all exported, not called).AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T06:23:10Z.
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.
docs/dev/debt/libSceSsl.mdcore/libs/tests/GuestSsl.cppcore/libs/tests/GuestSslLoad.cppcore/libs/tests/SslCertificateFixture.hppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T01:33:20Z.
Checked the diff against the debt entries and the measurement log: every changed code, default and flag matches what the entries claim, cases the log does not cover (write after
sceSslClose,SSL_ERROR_INVALID_CERTwith a callback, read/write after a plain verification failure) still throw, and the new tests pin exact return values (expired/future leaves with and without the option, fatal alert, reset on read/write/close, close before handshake); merged.