stream_socket_enable_crypto
Description
The stream_socket_enable_crypto of Stream for PHP turns encryption on/off on an already connected socket.
Syntax
stream_socket_enable_crypto(
resource $stream,
bool $enable,
?int $crypto_method = null,
?resource $session_stream = null
): int|boolParameters
stream
The stream resource.
enable
Enable/disable cryptography on the stream.
crypto_type
Setup encryption on the stream.
| STREAM_CRYPTO_METHOD_SSLv2_CLIENT |
| STREAM_CRYPTO_METHOD_SSLv3_CLIENT |
| STREAM_CRYPTO_METHOD_SSLv23_CLIENT |
| STREAM_CRYPTO_METHOD_ANY_CLIENT |
| STREAM_CRYPTO_METHOD_TLS_CLIENT |
| STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT |
| STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT |
| STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT |
| STREAM_CRYPTO_METHOD_SSLv2_SERVER |
| STREAM_CRYPTO_METHOD_SSLv3_SERVER |
| STREAM_CRYPTO_METHOD_SSLv23_SERVER |
| STREAM_CRYPTO_METHOD_ANY_SERVER |
| STREAM_CRYPTO_METHOD_TLS_SERVER |
| STREAM_CRYPTO_METHOD_TLSv1_0_SERVER |
| STREAM_CRYPTO_METHOD_TLSv1_1_SERVER |
| STREAM_CRYPTO_METHOD_TLSv1_2_SERVER |
If omitted, the crypto_method context option on the stream's SSL context will be used instead.
session_stream
Seed the stream with settings from session_stream.
Return
Returns true on success, false if negotiation has failed or 0 if there isn't enough data and you should try again (only for non-blocking sockets).
Examples
1 · crypto_type
<?
$protocol = "tls";
$host = "osbo.com";
$port = "443";
$remote_socket = $protocol . "://" . $host . ":" . $port;
$timeout = 30;
$stream = stream_socket_client($remote_socket, $errno, $errstr, $timeout);
if(!$stream)
{
exit("$errstr ($errno)");
}
// turn on encryption for login
$enable = true;
$crypto_type = STREAM_CRYPTO_METHOD_SSLv23_CLIENT;
stream_socket_enable_crypto($stream, $enable, $crypto_type);
fwrite($stream, "USER user\r\n");
fwrite($stream, "PASS secret\r\n");
// turn off encryption for the rest
$enable = false;
stream_socket_enable_crypto($stream, $enable);
$string = "GET / HTTP/1.1\r\n";
$string .= "Host: $host\r\n";
$string .= "Connection: close\r\n\r\n";
fwrite($stream, $string);
$length = 1024;
while(!feof($stream))
{
echo fgets($stream, $length);
}
fclose($stream);
�}�ڪ��B(�fԕ�y�,�����p #��w�%5f�v�Be�Y��g$�0)��<kAh�2:�%��>�P6����:��(|��7Ts�r�������t �/'��:�NS0��B���0��A��>`���+/���/��XY� �C��u4���[P�ӭ�͚��x��k�,��uH�^��<a�N����[2&}ȅ���w?�����p��w��g<�KMƟի�~[��GQ 4iZ<"�Y�_�HT]�[�?
֧�k�z�0�r��K_�00^�D��MN��1����ĝ<A*f5q��w�M��>u�aV�Z]:�#��]��*ï����� 7���:I�����r��hy-�y�� �fL'�Q��f�]#�&f^�A���$��F0d�N����L��p�b����$�ѺUw a����:&���k>h�pSe������Fd)T�r�&>��K?I�&d�Bբ��3��=�6�[�R2Q�S�[j=LղDu�w�ĥ �0!�2��K�"��-䜲B4z�Xv�c�%s��,��HK��<��<Bs�b�D ��(��J�FU^���Τ����&���]3�OS9\�iܝ<Eb"5Z����7?k��-���x��h}0�A�����:2�� ���`{�Q+C�&[ G7�R���H�1F��%a�׆�w���-^��yB<����^Wl�Z�˖���Ur�*� &����X`>]PRW�jL�Ԩ�?ٳ��~��y��顏CS���
x*F��O��24����~xf35���8$_�qk��D���ĥv垢7J����f�%�/ݴ���MLp����Ϯ5�Ŵ��������E�U*���vܑ%nX)d�O�`�w�-R�:iQ�iv��k�f���C\|�Z"�p��:#�a!���4�����@{"������5o��P��9u�h���������_��.��
&F�D��H�Y��_���PY�2��DuiH�DgS"������T���VZ|��>r��ln��D3>
l��?�[�����,u�W (�u>��w�f����n���j�*���,��(�tM���i������ͅ�M6=�Jݽ�~= ��1!֕���D��<�+Yي�h� Z�t>��i̽�M�|E����� ��f6���Ɏ�,
� 2_
om[dmb�SKJ�(��1�w�m�x�0�������V �
�cZP�Z��ɵ�uKG�G+�~�� p�M�M^L@�?��Y�D���y �
6�
�p�r-�� %�C�|?w'��[�r�c���9v���4��$�Z2�(
cAѹ]���Ȇ�!|"����7�F7�t��+Z�����q?@����|�-�xmwb;zZ��Ο����h��.�o�^�x>�1�.e+�as:BRYh���.�:F�G���x�o��@n� �Vxu+\W�W�++ˏ