Skip to content

Commit

Permalink
[8.0] Remove deprecated defaultCaBundle method (#3212)
Browse files Browse the repository at this point in the history
* Remove deprecated `defaultCaBundle` method

* Remove old tests
  • Loading branch information
GrahamCampbell committed Mar 31, 2024
1 parent 5b5a290 commit e37fdb8
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 87 deletions.
71 changes: 0 additions & 71 deletions src/Utils.php
Expand Up @@ -116,77 +116,6 @@ public static function defaultUserAgent(): string
return sprintf('GuzzleHttp/%d', ClientInterface::MAJOR_VERSION);
}

/**
* Returns the default cacert bundle for the current system.
*
* First, the openssl.cafile and curl.cainfo php.ini settings are checked.
* If those settings are not configured, then the common locations for
* bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
* and Windows are checked. If any of these file locations are found on
* disk, they will be utilized.
*
* Note: the result of this function is cached for subsequent calls.
*
* @throws \RuntimeException if no bundle can be found.
*
* @deprecated Utils::defaultCaBundle will be removed in guzzlehttp/guzzle:8.0. This method is not needed in PHP 5.6+.
*/
public static function defaultCaBundle(): string
{
static $cached = null;
static $cafiles = [
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
'/etc/pki/tls/certs/ca-bundle.crt',
// Ubuntu, Debian (provided by the ca-certificates package)
'/etc/ssl/certs/ca-certificates.crt',
// FreeBSD (provided by the ca_root_nss package)
'/usr/local/share/certs/ca-root-nss.crt',
// SLES 12 (provided by the ca-certificates package)
'/var/lib/ca-certificates/ca-bundle.pem',
// OS X provided by homebrew (using the default path)
'/usr/local/etc/openssl/cert.pem',
// Google app engine
'/etc/ca-certificates.crt',
// Windows?
'C:\\windows\\system32\\curl-ca-bundle.crt',
'C:\\windows\\curl-ca-bundle.crt',
];

if ($cached) {
return $cached;
}

if ($ca = \ini_get('openssl.cafile')) {
return $cached = $ca;
}

if ($ca = \ini_get('curl.cainfo')) {
return $cached = $ca;
}

foreach ($cafiles as $filename) {
if (\file_exists($filename)) {
return $cached = $filename;
}
}

throw new \RuntimeException(
<<< EOT
No system CA bundle could be found in any of the the common system locations.
PHP versions earlier than 5.6 are not properly configured to use the system's
CA bundle by default. In order to verify peer certificates, you will need to
supply the path on disk to a certificate bundle to the 'verify' request
option: https://docs.guzzlephp.org/en/latest/request-options.html#verify. If
you do not need a specific certificate bundle, then Mozilla provides a commonly
used CA bundle which can be downloaded here (provided by the maintainer of
cURL): https://curl.haxx.se/ca/cacert.pem. Once you have a CA bundle available
on disk, you can set the 'openssl.cafile' PHP ini setting to point to the path
to the file, allowing you to omit the 'verify' request option. See
https://curl.haxx.se/docs/sslcerts.html for more information.
EOT
);
}

/**
* Creates an associative array of lowercase header names to the actual
* header casing.
Expand Down
11 changes: 0 additions & 11 deletions tests/Handler/StreamHandlerTest.php
Expand Up @@ -354,17 +354,6 @@ public function testVerifiesCertIfValidPath()
$this->getSendResult(['cert' => '/does/not/exist']);
}

public function testVerifyCanBeSetToPath()
{
$path = Utils::defaultCaBundle();
$res = $this->getSendResult(['verify' => $path]);
$opts = \stream_context_get_options($res->getBody()->detach());
self::assertTrue($opts['ssl']['verify_peer']);
self::assertTrue($opts['ssl']['verify_peer_name']);
self::assertSame($path, $opts['ssl']['cafile']);
self::assertFileExists($opts['ssl']['cafile']);
}

public function testUsesSystemDefaultBundle()
{
$res = $this->getSendResult(['verify' => true]);
Expand Down
5 changes: 0 additions & 5 deletions tests/UtilsTest.php
Expand Up @@ -90,11 +90,6 @@ public function testReturnsDebugResource()
self::assertIsResource(Utils::debugResource());
}

public function testProvidesDefaultCaBundler()
{
self::assertFileExists(Utils::defaultCaBundle());
}

public function testNormalizeHeaderKeys()
{
$input = ['HelLo' => 'foo', 'WORld' => 'bar'];
Expand Down

0 comments on commit e37fdb8

Please sign in to comment.