composer / ca-bundle
Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.
Fund package maintenance!
packagist.com
Tidelift
composer
Installs: 270 366 646
Dependents: 190
Suggesters: 14
Security: 0
Stars: 2 945
Watchers: 15
Forks: 39
Open Issues: 1
Requires
- php: ^7.2 || ^8.0
- ext-openssl: *
- ext-pcre: *
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^8 || ^9
- psr/log: ^1.0 || ^2.0 || ^3.0
- symfony/process: ^4.0 || ^5.0 || ^6.0 || ^7.0
- dev-main / 1.x-dev
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.x-dev
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.11
- 1.2.10
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-cacert-update/1.4
- dev-cacert-update/main
This package is auto-updated.
Last update: 2024-11-28 00:31:20 UTC
README
Small utility library that lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.
Originally written as part of composer/composer, now extracted and made available as a stand-alone library.
Installation
Install the latest version with:
$ composer require composer/ca-bundle
Requirements
- PHP 5.3.2 is required but using the latest version of PHP is highly recommended.
Basic usage
Composer\CaBundle\CaBundle
CaBundle::getSystemCaRootBundlePath()
: Returns the system CA bundle path, or a path to the bundled one as fallbackCaBundle::getBundledCaBundlePath()
: Returns the path to the bundled CA fileCaBundle::validateCaFile($filename)
: Validates a CA file using openssl_x509_parse only if it is safe to useCaBundle::isOpensslParseSafe()
: Test if it is safe to use the PHP function openssl_x509_parse()CaBundle::reset()
: Resets the static caches
To use with curl
$curl = curl_init("https://example.org/"); $caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(); if (is_dir($caPathOrFile)) { curl_setopt($curl, CURLOPT_CAPATH, $caPathOrFile); } else { curl_setopt($curl, CURLOPT_CAINFO, $caPathOrFile); } $result = curl_exec($curl);
To use with php streams
$opts = array( 'http' => array( 'method' => "GET" ) ); $caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(); if (is_dir($caPathOrFile)) { $opts['ssl']['capath'] = $caPathOrFile; } else { $opts['ssl']['cafile'] = $caPathOrFile; } $context = stream_context_create($opts); $result = file_get_contents('https://example.com', false, $context);
To use with Guzzle
$client = new \GuzzleHttp\Client([ \GuzzleHttp\RequestOptions::VERIFY => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath() ]);
License
composer/ca-bundle is licensed under the MIT License, see the LICENSE file for details.