gnu-social/vendor/composer/ca-bundle/README.md

86 lines
2.0 KiB
Markdown
Raw Normal View History

2019-07-15 01:41:55 +01:00
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](https://github.com/composer/composer),
now extracted and made available as a stand-alone library.
Installation
------------
Install the latest version with:
```bash
$ composer require composer/ca-bundle
```
Requirements
------------
* PHP 5.3.2 is required but using the latest version of PHP is highly recommended.
Basic usage
-----------
2019-11-16 16:51:01 +00:00
### `Composer\CaBundle\CaBundle`
2019-07-15 01:41:55 +01:00
- `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
2019-11-16 16:51:01 +00:00
- `CaBundle::validateCaFile($filename)`: Validates a CA file using openssl_x509_parse only if it is safe to use
2019-07-15 01:41:55 +01:00
- `CaBundle::isOpensslParseSafe()`: Test if it is safe to use the PHP function openssl_x509_parse()
- `CaBundle::reset()`: Resets the static caches
2019-11-16 16:51:01 +00:00
#### To use with curl
2019-07-15 01:41:55 +01:00
```php
$curl = curl_init("https://example.org/");
$caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
2019-11-16 16:51:01 +00:00
if (is_dir($caPathOrFile)) {
2019-07-15 01:41:55 +01:00
curl_setopt($curl, CURLOPT_CAPATH, $caPathOrFile);
} else {
curl_setopt($curl, CURLOPT_CAINFO, $caPathOrFile);
}
$result = curl_exec($curl);
```
2019-11-16 16:51:01 +00:00
#### To use with php streams
2019-07-15 01:41:55 +01:00
```php
$opts = array(
'http' => array(
'method' => "GET"
)
);
$caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
2019-11-16 16:51:01 +00:00
if (is_dir($caPathOrFile)) {
2019-07-15 01:41:55 +01:00
$opts['ssl']['capath'] = $caPathOrFile;
} else {
$opts['ssl']['cafile'] = $caPathOrFile;
}
$context = stream_context_create($opts);
$result = file_get_contents('https://example.com', false, $context);
```
2019-11-16 16:51:01 +00:00
#### To use with Guzzle
2019-07-15 01:41:55 +01:00
```php
$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.