1composer/ca-bundle
2==================
3
4Small utility library that lets you find a path to the system CA bundle,
5and includes a fallback to the Mozilla CA bundle.
6
7Originally written as part of [composer/composer](https://github.com/composer/composer),
8now extracted and made available as a stand-alone library.
9
10
11Installation
12------------
13
14Install the latest version with:
15
16```bash
17$ composer require composer/ca-bundle
18```
19
20
21Requirements
22------------
23
24* PHP 5.3.2 is required but using the latest version of PHP is highly recommended.
25
26
27Basic usage
28-----------
29
30### `Composer\CaBundle\CaBundle`
31
32- `CaBundle::getSystemCaRootBundlePath()`: Returns the system CA bundle path, or a path to the bundled one as fallback
33- `CaBundle::getBundledCaBundlePath()`: Returns the path to the bundled CA file
34- `CaBundle::validateCaFile($filename)`: Validates a CA file using openssl_x509_parse only if it is safe to use
35- `CaBundle::isOpensslParseSafe()`: Test if it is safe to use the PHP function openssl_x509_parse()
36- `CaBundle::reset()`: Resets the static caches
37
38
39#### To use with curl
40
41```php
42$curl = curl_init("https://example.org/");
43
44$caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
45if (is_dir($caPathOrFile)) {
46    curl_setopt($curl, CURLOPT_CAPATH, $caPathOrFile);
47} else {
48    curl_setopt($curl, CURLOPT_CAINFO, $caPathOrFile);
49}
50
51$result = curl_exec($curl);
52```
53
54#### To use with php streams
55
56```php
57$opts = array(
58    'http' => array(
59        'method' => "GET"
60    )
61);
62
63$caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
64if (is_dir($caPathOrFile)) {
65    $opts['ssl']['capath'] = $caPathOrFile;
66} else {
67    $opts['ssl']['cafile'] = $caPathOrFile;
68}
69
70$context = stream_context_create($opts);
71$result = file_get_contents('https://example.com', false, $context);
72```
73
74#### To use with Guzzle
75
76```php
77$client = new \GuzzleHttp\Client([
78    \GuzzleHttp\RequestOptions::VERIFY => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath()
79]);
80```
81
82License
83-------
84
85composer/ca-bundle is licensed under the MIT License, see the LICENSE file for details.
86