Skip to content

Commit

Permalink
Update README for 1.0, add example
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed Sep 16, 2012
1 parent b9c65e6 commit cbf8698
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 7 deletions.
77 changes: 70 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,59 @@
# Sslurp

v0.1 by Evan Coury
v1.0 by Evan Coury

[![Build Status](https://secure.travis-ci.org/EvanDotPro/Sslurp.png?branch=master)](https://travis-ci.org/EvanDotPro/Sslurp)

## Introduction

**WARNING:** This library is currently undergoing review and should not yet be
considered stable or secure. Proceed with caution...

Dealing with SSL properly in PHP is a pain in the ass. Sslurp
aims to make it suck less. Sslurp can be used as a stand-alone library or a ZF2
module.
Dealing with SSL properly in PHP is a pain in the ass. Sslurp aims to make it
suck less. Sslurp can be used as a stand-alone library or a ZF2 module.

**Note:** This library requires PHP with OpenSSL support. This is standard in
most Linux distributions' PHP packages, else you need to ensure you compile
using --with-openssl[=DIR].

## Installation

### Composer / Packagist

```
./composer.phar require evandotpro/sslurp
```

### Normal

The `./bin/update-ca-bundle` CLI tool will "just work" out of the box.

Sslurp can _easily_ be used in any existing project, framework, or library.

To use Sslurp as a library in your project, the easiest method is to simply
include the `autoload\_register.php` file:

```php
require_once 'vendor/Sslurp/autoload_register.php';
```

Alternatively, if you project supports loading classmap arrays, you may fetch
the classmap without registering an additional SPL autoloader:

```php
$classmap = include 'vendor/Sslurp/autoload_classmap.php';
// Register $classmap with your project's existing classmap autoloader
```

If you have an existing SPL autoloader that allows adding a callable to a stack
instead of directly registering the classmap array, you have the option of
simply getting a closure which can autoload the Sslurp classes:

```php
$sslurpLoader = include 'vendor/Sslurp/autoload_function.php';
// $sslurpLoader is a closure that can be registered with an existing autoloader
```

## Usage


### CLI root CA bundle updater

[update-ca-bundle](https://github.com/EvanDotPro/Sslurp/blob/master/bin/update-ca-bundle)
Expand All @@ -41,6 +78,32 @@ Options
-o Path/filename to the file to (over)write he update root CA bundle. Default to stdout.
```

### Using Sslurp as a library

In addition to the CLI tool, Sslurp can be used as a library through the OOP
interface. The
[source](https://github.com/EvanDotPro/Sslurp/tree/master/src/Sslurp) _is_ the
API documentation.

```php
<?php
require_once 'autoload_register.php';

$bundle = new \Sslurp\CaRootPemBundle(file_get_contents('ca-bundle.pem'));

if ($bundle->isLatest()) {
echo 'Your CA root bundle is up to date!' . PHP_EOL;
} else {
echo 'WARNING! Your CA root bundle is out of date!' . PHP_EOL
. 'Local CA root bundle is version ' . $bundle->getVersion() . '. '
. 'Latest version is version ' . $bundle->getMozillaCertData()->getVersion() . '.' . PHP_EOL;

echo 'Updating...';
file_put_contents('ca-bundle.pem', $bundle->getUpdatedCaRootBundle());
echo "\tDone!" . PHP_EOL;
}
```

## License

Sslurp is released under the BSD license. See the included LICENSE file.
12 changes: 12 additions & 0 deletions src/Sslurp/CaRootPemBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ class CaRootPemBundle extends AbstractCaRootData
*/
private $pemContent = null;

/**
* @var MozillaCertData
*/
private $mozCertData = null;

/**
* Override for unit testing
*
* @var string
*/
public static $overrideDateTime = null;

Expand All @@ -46,6 +53,11 @@ public function getContent($until = false)
return $this->pemContent;
}

public function getMozillaCertData()
{
return $this->mozCertData;
}

public function isLatest()
{
return $this->getVersion() === $this->mozCertData->getVersion();
Expand Down
1 change: 1 addition & 0 deletions test/SslurpTest/CaRootPemBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ public function testWillFetchMozillaCertData()
require_once __DIR__ . '/TestAsset/MockMozillaCertData.php';
$bundle = new CaRootPemBundle(null, new TestAsset\MockMozillaCertData);
$this->assertNotNull($bundle->getContent());
$this->assertInstanceOf('Sslurp\MozillaCertData', $bundle->getMozillaCertData());
}
}

0 comments on commit cbf8698

Please sign in to comment.