HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

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|bool

Parameters

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);
��Z9*�΢�g�����[P���u$�f�D��J�Y;�^{�x�`��j�5�^�õ����г���~�:B�:7�G9r��^�cEZ��J܍qpy��9&��啒:�!�t�V?DI��OY:�W$$L���o6q_�:ے�ٲ���7�q����Hv �y�F%'z�r�y2W�k�.��
۹��qۯK��Q    ��<�Ly��'�r��/wWO��x��M����x�)5�����s ��\l�h�X���S�xYxL��Q%�IֿL�͒k=-`�5(�슒.&5��3ڗ������z���%@���K����1��yb�1��bu�EA��|U�j+�U7    O�˱����1��q�����
� M�C��8+��?c*��n�M=�s9�y��v4JZ>d#��+�0[�m�}��0���O�:�5@�:&��"�    K�����j\Bs[!�Sv��r�趝\aL�b�
dQ�k�<{%���/��2ٗI�;+5��*����ORx><ILO����?B�]�����~@���'T(�"��
�3c���)$QcFRm˞�?�9��.���jnȟ�b�    �ݚ?�rp0��V�wa5ˊ�5�I6<���ZX��T��_�c��6/Z����C~��J�Տ�C��k�' �޶��CO��KQ��-6LK
E���m�t����|�x��\\f�I�Q�Q\�LE9I�E��$}�n��tl\��ZNKOg�K���2l    ��f,}Ug��8�P�?���gpwtֱ�a9n`*3�V�}� ��t�,��d�/G���F�ǂ�
�
�º=�e��l�6_��Ȱ@��}nE[��u�x$1+�l�;�z�����
�l��+�%�u    ����������-�d���p����)�
��'\Y�    ���h��������I5���0��y%tF�0և]ץJ�5�F��n��`�wf��H�l�$�    �;���n����ɀZ��0�C��S=
و\�cy��O�0F�Iʺ����c\6���T���p�
ɶ�9Lwx��������]�i���"C!��ޡ��/s�K���+�Q&�n�ˆ���rs��p_�D3�[�<̚��C
V�z��b�T�%�>�4%��cNeu��ll���Q�c8DŽ0��0���ۢ��=x�.�ۜ���[�"�3���v�n��4�j1x��t罕���,����BV��ڌ}�5e���
��z[���藟�ne�����    N�e0��$?�m���Z�C��_L���T<�s)(��A�4���ڂ3ơJ���g�Qr�8
zz��˦�#
"z�~�������@*�ZB�qj6�|.��C��V��UǞu1e"�F���gDm�M�ChAU�B��Y}���S�X%��.E�z��O��n�UT�$r#"�    C{�|[�9���