Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed May 13, 2023
1 parent c7b8d64 commit 8a0fda0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
22 changes: 22 additions & 0 deletions docs/request-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,28 @@ connect_timeout
handler.


.. _crypto_method-option:

crypto_method
---------------

:Summary: A value describing the minimum TLS protocol version to use.
:Types: int
:Default: None
:Constant: ``GuzzleHttp\RequestOptions::CRYPTO_METHOD``

.. code-block:: php
$client->request('GET', '/foo', ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT]);
.. note::

This setting must be set to one of the ``STREAM_CRYPTO_METHOD_TLS*_CLIENT``
constants. PHP 7.4 or higher is required in order to use TLS 1.3, and cURL
7.34.0 or higher is required in order to specify a crypto method, with cURL
7.52.0 or higher being required to use TLS 1.3.


.. _debug-option:

debug
Expand Down
10 changes: 5 additions & 5 deletions src/Handler/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,26 +455,26 @@ private function applyHandlerOptions(EasyHandle $easy, array &$conf): void
if (isset($options['crypto_method'])) {
if (\STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT === $options['crypto_method']) {
if (!defined('CURL_SSLVERSION_TLSv1_0')) {
throw new InvalidArgumentException('Setting `crypto_method` to TLS 1.0 not supported by your version of cURL.');
throw new \InvalidArgumentException('Setting `crypto_method` to TLS 1.0 not supported by your version of cURL.');
}
$conf[\CURLOPT_SSLVERSION] = \CURL_SSLVERSION_TLSv1_0;
} elseif (\STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT === $options['crypto_method']) {
if (!defined('CURL_SSLVERSION_TLSv1_1')) {
throw new InvalidArgumentException('Setting `crypto_method` to TLS 1.1 not supported by your version of cURL.');
throw new \InvalidArgumentException('Setting `crypto_method` to TLS 1.1 not supported by your version of cURL.');
}
$conf[\CURLOPT_SSLVERSION] = \CURL_SSLVERSION_TLSv1_1;
} elseif (\STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT === $options['crypto_method']) {
if (!defined('CURL_SSLVERSION_TLSv1_2')) {
throw new InvalidArgumentException('Setting `crypto_method` to TLS 1.2 not supported by your version of cURL.');
throw new \InvalidArgumentException('Setting `crypto_method` to TLS 1.2 not supported by your version of cURL.');
}
$conf[\CURLOPT_SSLVERSION] = \CURL_SSLVERSION_TLSv1_2;
} elseif (defined('STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT') && \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT === $options['crypto_method']) {
if (!defined('CURL_SSLVERSION_TLSv1_3')) {
throw new InvalidArgumentException('Setting `crypto_method` to TLS 1.3 not supported by your version of cURL.');
throw new \InvalidArgumentException('Setting `crypto_method` to TLS 1.3 not supported by your version of cURL.');
}
$conf[\CURLOPT_SSLVERSION] = \CURL_SSLVERSION_TLSv1_3;
} else {
throw new InvalidArgumentException('An invalid `crypto_method` value was supplied.');
throw new \InvalidArgumentException('An invalid `crypto_method` value was supplied.');
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/RequestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ final class RequestOptions
*/
public const CONNECT_TIMEOUT = 'connect_timeout';

/**
* crypto_method: (int) A value describing the minimum TLS protocol
* version to use.
*
* This setting must be set to one of the
* ``STREAM_CRYPTO_METHOD_TLS*_CLIENT`` constants. PHP 7.4 or higher is
* required in order to use TLS 1.3, and cURL 7.34.0 or higher is required
* in order to specify a crypto method, with cURL 7.52.0 or higher being
* required to use TLS 1.3.
*/
public const CRYPTO_METHOD = 'crypto_method';

/**
* debug: (bool|resource) Set to true or set to a PHP stream returned by
* fopen() enable debug output with the HTTP handler used to send a
Expand Down

0 comments on commit 8a0fda0

Please sign in to comment.