Skip to content
Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.
Branch: master
Clone or download
Seldaek Merge pull request #37 from alcohol/update-testing-matrix
testing matrix: add 5.3 again, drop hhvm
Latest commit dd3f738 Mar 26, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Initial commit Apr 11, 2016
res
src copy CA bundle to a temporary file when it is bundled in a PHAR file Nov 24, 2017
tests Improve tests Dec 15, 2017
.gitattributes
.gitignore Undo .gitignore Jul 28, 2016
.php_cs Update file header Aug 26, 2016
.travis.yml testing matrix: add 5.3 again, drop hhvm Mar 21, 2019
LICENSE Initial commit Apr 11, 2016
README.md
composer.json tested with phpunit 7 and 8 Mar 22, 2019
phpunit.xml.dist

README.md

composer/ca-bundle

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 fallback
  • CaBundle::getBundledCaBundlePath(): Returns the path to the bundled CA file
  • CaBundle::validateCaFile($filename): Validates a CA file using opensl_x509_parse only if it is safe to use
  • CaBundle::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) || (is_link($caPathOrFile) && is_dir(readlink($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) || (is_link($caPathOrFile) && is_dir(readlink($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.

You can’t perform that action at this time.