Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8.1k
openssl: Introduce TLS PSK support#22057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --TEST-- | ||
| TLS PSK callback option must be a valid callable | ||
| --EXTENSIONS-- | ||
| openssl | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!function_exists("proc_open")) die("skip no proc_open"); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| $serverCode = <<<'CODE' | ||
| $serverCtx = stream_context_create(['ssl' => [ | ||
| 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER, | ||
| 'ciphers' => 'PSK', | ||
| 'psk_server_cb' => function ($stream, string $identity): ?Openssl\Psk { | ||
| return new Openssl\Psk("k", "id"); | ||
| }, | ||
| ]]); | ||
| $server = stream_socket_server('tls://127.0.0.1:0', $errno, $errstr, | ||
| STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $serverCtx); | ||
| phpt_notify_server_start($server); | ||
| @stream_socket_accept($server, 3); | ||
| CODE; | ||
| $clientCode = <<<'CODE' | ||
| $clientCtx = stream_context_create(['ssl' => [ | ||
| 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, | ||
| 'ciphers' => 'PSK', | ||
| 'verify_peer' => false, | ||
| 'psk_client_cb' => 'php_openssl_no_such_function', | ||
| ]]); | ||
| try { | ||
| @stream_socket_client('tls://{{ ADDR }}', $errno, $errstr, | ||
| 5, STREAM_CLIENT_CONNECT, $clientCtx); | ||
| echo "no exception\n"; | ||
| } catch (TypeError $e) { | ||
| echo "caught: ", $e->getMessage(), "\n"; | ||
| } | ||
| CODE; | ||
| include __DIR__ . '/ServerClientTestCase.inc'; | ||
| ServerClientTestCase::getInstance()->run($clientCode, $serverCode); | ||
| ?> | ||
| --EXPECTF-- | ||
| caught: psk_client_cb must be a valid callback, %s | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --TEST-- | ||
| TLS PSK client callback returning wrong type raises TypeError | ||
| --EXTENSIONS-- | ||
| openssl | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!function_exists("proc_open")) die("skip no proc_open"); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| $serverCode = <<<'CODE' | ||
| $serverCtx = stream_context_create(['ssl' => [ | ||
| 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER, | ||
| 'ciphers' => 'PSK', | ||
| 'psk_server_cb' => function ($stream, string $identity): ?Openssl\Psk { | ||
| return new Openssl\Psk("k", "id"); | ||
| }, | ||
| ]]); | ||
| $server = stream_socket_server('tls://127.0.0.1:0', $errno, $errstr, | ||
| STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $serverCtx); | ||
| phpt_notify_server_start($server); | ||
| @stream_socket_accept($server, 3); | ||
| CODE; | ||
| $clientCode = <<<'CODE' | ||
| $clientCtx = stream_context_create(['ssl' => [ | ||
| 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, | ||
| 'ciphers' => 'PSK', | ||
| 'verify_peer' => false, | ||
| 'psk_client_cb' => function ($stream) { | ||
| /* Returning a string instead of Openssl\Psk|null. */ | ||
| return "not a Psk object"; | ||
| }, | ||
| ]]); | ||
| try { | ||
| @stream_socket_client('tls://{{ ADDR }}', $errno, $errstr, | ||
| 5, STREAM_CLIENT_CONNECT, $clientCtx); | ||
| echo "no exception\n"; | ||
| } catch (TypeError $e) { | ||
| echo "caught: ", $e->getMessage(), "\n"; | ||
| } | ||
| CODE; | ||
| include __DIR__ . '/ServerClientTestCase.inc'; | ||
| ServerClientTestCase::getInstance()->run($clientCode, $serverCode); | ||
| ?> | ||
| --EXPECT-- | ||
| caught: PSK callback must return Openssl\Psk or null |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --TEST-- | ||
| TLS 1.2 PSK: client callback returning null aborts handshake (no shared cipher) | ||
| --EXTENSIONS-- | ||
| openssl | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!function_exists("proc_open")) die("skip no proc_open"); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| $serverCode = <<<'CODE' | ||
| $serverCtx = stream_context_create(['ssl' => [ | ||
| 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER, | ||
| 'ciphers' => 'PSK', | ||
| 'psk_server_cb' => function ($stream, string $identity): ?Openssl\Psk { | ||
| return new Openssl\Psk("doesnotmatter", null); | ||
| }, | ||
| ]]); | ||
| $server = stream_socket_server('tls://127.0.0.1:0', $errno, $errstr, | ||
| STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $serverCtx); | ||
| phpt_notify_server_start($server); | ||
| @stream_socket_accept($server, 3); | ||
| CODE; | ||
| $clientCode = <<<'CODE' | ||
| $clientCtx = stream_context_create(['ssl' => [ | ||
| 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, | ||
| 'ciphers' => 'PSK', | ||
| 'verify_peer' => false, | ||
| 'psk_client_cb' => function ($stream): ?Openssl\Psk { | ||
| /* Reject: no PSK to use, no other ciphers offered. */ | ||
| return null; | ||
| }, | ||
| ]]); | ||
| $client = @stream_socket_client('tls://{{ ADDR }}', $errno, $errstr, | ||
| 5, STREAM_CLIENT_CONNECT, $clientCtx); | ||
| var_dump($client); | ||
| CODE; | ||
| include __DIR__ . '/ServerClientTestCase.inc'; | ||
| ServerClientTestCase::getInstance()->run($clientCode, $serverCode); | ||
| ?> | ||
| --EXPECT-- | ||
| bool(false) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be done in the follow up PR as well as you are picking it up