Coder Social home page Coder Social logo

nicolas-grekas / composer-ca-bundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from composer/ca-bundle

0.0 1.0 0.0 714 KB

Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.

License: MIT License

PHP 100.00%

composer-ca-bundle's Introduction

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 openssl_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)) {
    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.

composer-ca-bundle's People

Contributors

seldaek avatar exussum12 avatar github-actions[bot] avatar garas avatar dependabot[bot] avatar peter279k avatar grahamcampbell avatar janpettermg avatar carusogabriel avatar johnstevenson avatar tgalopin avatar stotev avatar alcohol avatar 1ma avatar bytestream avatar jyggen avatar andreybolonin avatar rhukster avatar anrdaemon avatar stof avatar darenas31415 avatar glensc avatar iandenh avatar deuchnord avatar reedy avatar sjorek avatar fuzzfree avatar someniatko avatar thecaliskan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.