openssl: Introduce TLS PSK support#22057
Open
bukka wants to merge 1 commit into
Open
Conversation
Add stream context options psk_client_cb and psk_server_cb that let clients and servers negotiate pre-shared key authentication on both TLS 1.2 and TLS 1.3. Callbacks return an Openssl\Psk instance carrying the key and, on clients, the identity, or null to refuse PSK. A new final Openssl\Psk class is added for that purpose, with readonly $psk and $identity properties and MAX_PSK_LEN / MAX_IDENTITY_LEN constants.
devnexen
reviewed
May 15, 2026
| pefree(sslsock->psk_callbacks, php_stream_is_persistent(stream)); | ||
| } | ||
|
|
||
| if (sslsock->psk_identity_buf) { |
Member
There was a problem hiding this comment.
question, can an OPENSSL_cleanse() be useful for security concern here ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds pre-shared key authentication for OpenSSL streams, covering both TLS 1.2 (PSK ciphersuites) and TLS 1.3 (PSK as an external resumed session).
The
Openssl\Pskclass is following:Two new options under the
sslcontext:psk_client_cb:callable(resource $stream): ?Openssl\PskCalled on the client during the handshake to obtain the PSK and identity. Return
nullto decline PSK. The returnedPskmust have a non-null identity.psk_server_cb:callable(resource $stream, string $identity): ?Openssl\PskCalled on the server with the identity offered by the client. Return
nullto reject the identity. Only the key is read from the returnedPsk.For TLS 1.3 servers a default
session_id_contextis installed when the user does not supply one, since OpenSSL processes PSK as session resumption and would otherwise reject the constructedSSL_SESSIONwithSSL_R_SESSION_ID_CONTEXT_UNINITIALIZEDunder the defaultSSL_VERIFY_PEERconfiguration. An explicitsession_id_contextstill takes precedence.The RFC is not planned unless there are objections as it mirrors the previous Session proposal including all API decisions from it.