skyzyx / signer
Cryptographically sign data to prevent tampering.
Installs: 32 887
Dependents: 1
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=5.4.0
- ext-mcrypt: *
- psr/log: ^1.0
Requires (Dev)
- codeclimate/php-test-reporter: *@dev
- phpunit/phpcov: ~2.0
- phpunit/phpunit: ~4.3
- satooshi/php-coveralls: *@dev
Suggests
README
The Signer class is designed for those who are signing data on behalf of a public-private keypair.
In principle, the "client party" has public key (i.e., client_id
) and a matching private key (i.e., client_secret
) that can be verified by both the signer and the client (but nobody else as we don't want to make forgeries possible).
The "signing party" has a simple identifier which acts as an additional piece of entropy in the algorithm, and can help differentiate between multiple signing parties if the client party does something like try to use the same public-private keypair independently of a signing party (as is common with GPG signing).
Based on a simplified version of the AWS Signature v4.
Examples
use Skyzyx\Signer\Signer; $self_key = 'Skyzyx'; $client_id = 'k3qDQy0Tr56v1ceo'; $client_secret = 'O5j@pG@Jt%AzyiJTEfo!£LSz8yqSj)JX)S6FvW%58KjlS9bc%Fi7&&C4KSCT8hxd'; $signer = new Signer($self_key, $client_id, $client_secret, 'sha512'); $signature = $signer->sign([ 'ClientID' => $client_id, 'Domain' => 'foo.com', 'Path' => '/', 'Expires' => 'Wed, 13 Jan 2021 22:23:01 GMT', 'Secure' => null, 'HttpOnly' => null, ]); $signature = wordwrap($signature, 64, "\n", true); #=> dfbffab5b6f7156402da8147886bba3eba67bd5baf2e780ba9d39e8437db7c47 #=> 35e9a0b834aa21ac76f98da8c52a2a0cd1b0192d0f0df5c98e3848b1b2e1a037
Installation
Using Composer:
composer require skyzyx/signer=^1.0.0
And include it in your scripts:
require_once 'vendor/autoload.php';
Testing
Firstly, run composer install -o
to download and install the dependencies.
You can run the tests as follows:
bin/phpunit
Debug Logging
NOTE: You should only use logging during development — never in production.
Signer implements the PSR-3 Psr\Log\LoggerAwareInterface
. Because of this,
you can inject any PSR-3-compatible logging package, and Signer will use it to log DEBUG
-level messages.
use Monolog\Logger; use Monolog\Handler\StreamHandler; use Skyzyx\Signer\Signer; // create a log channel $log = new Logger('name'); $log->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG)); // inject a logger $signer = new Signer(); $signer->setLogger($log); $signer->sign( ... );
API Reference
The API Reference is generated by a tool called phpDocumentor 2.x. You should install it locally on your system with:
cd /usr/local/bin && wget http://phpdoc.org/phpDocumentor.phar && chmod +x phpDocumentor.phar && mv phpDocumentor.phar phpdoc
Once it's installed, you can generate updated documentation by running the following command in the root of the repository.
phpdoc
Contributing
Here's the process for contributing:
- Fork Signer to your GitHub account.
- Clone your GitHub copy of the repository into your local workspace.
- Write code, fix bugs, and add tests with 100% code coverage.
- Commit your changes to your local workspace and push them up to your GitHub copy.
- You submit a GitHub pull request with a description of what the change is.
- The contribution is reviewed. Maybe there will be some banter back-and-forth in the comments.
- If all goes well, your pull request will be accepted and your changes are merged in.
Authors, Copyright & Licensing
- Copyright (c) 2011-2014 Amazon Web Services, Inc.
- Copyright (c) 2014 Ryan Parman.
See also the list of contributors who participated in this project.
Licensed for use under the terms of the Apache 2.0 license.
Coding Standards
PSR-0/1/2 are a solid foundation, but are not an entire coding style by themselves. I have taken the time to document all of the nitpicky patterns and nuances of my personal coding style. It goes well-beyond brace placement and tabs vs. spaces to cover topics such as docblock annotations, ternary operations and which variation of English to use. It aims for thoroughness and pedanticism over hoping that we can all get along.