Skip to content

Commit f71138b

Browse files
committed
First release
0 parents  commit f71138b

12 files changed

+381
-0
lines changed

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* text=auto
2+
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/box.json.dist export-ignore
6+
/README.md export-ignore

.github/CONTRIBUTING.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Contributing
2+
3+
First of all, **thank you** for contributing.
4+
5+
Bugs or feature requests can be posted online on the GitHub issues section of the project.
6+
7+
Few rules to ease code reviews and merges:
8+
9+
- You MUST follow the [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-4](http://www.php-fig.org/psr/psr-4/) coding standards.
10+
- You MUST run the test suite.
11+
- You MUST write (or update) unit tests when bugs are fixed or features are added.
12+
- You SHOULD write documentation.
13+
14+
We use [Git-Flow](http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/) to automate our git branching workflow.
15+
16+
To contribute use [Pull Requests](https://help.github.com/articles/using-pull-requests), please, write commit messages that make sense, and rebase your branch before submitting your PR.
17+
18+
May be asked to squash your commits too. This is used to "clean" your Pull Request before merging it, avoiding commits such as fix tests, fix 2, fix 3, etc.
19+
20+
Run test suite
21+
------------
22+
23+
* install composer: `curl -s http://getcomposer.org/installer | php`
24+
* install dependencies: `php composer.phar install`
25+
* run tests: `vendor/bin/behat`

.github/ISSUE_TEMPLATE.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
| Q | A
2+
| -------------------- | -----
3+
| Bug report? | yes/no
4+
| Feature request? | yes/no
5+
| BC Break report? | yes/no
6+
| RFC? / Specification | yes/no
7+
| Version | x.y(.z)
8+
9+
<!--
10+
Fill in this template according to your issue.
11+
Otherwise, replace this comment by the description of your issue.
12+
13+
Please consider the following requirements
14+
* You MUST never send security issues here. If you think that your issue is a security one then contact Spomky in private at https://gitter.im/Spomky/
15+
* You should not post many lines of source code or console logs. Small inputs (approx 5 lines) are acceptable otherwize you should use a third party service (e.g. Pastebin, Chop...).
16+
-->

.github/PULL_REQUEST_TEMPLATE.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| Q | A
2+
| ------------- | ---
3+
| Branch? | master
4+
| Bug fix? | yes/no
5+
| New feature? | yes/no
6+
| BC breaks? | yes/no
7+
| Deprecations? | yes/no
8+
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
9+
| License | MIT
10+
| Tests added | <!--highly recommended for new features-->
11+
| Doc PR | <!--highly recommended for new features-->
12+
13+
<!--
14+
Fill in this template according to the PR you're about to submit.
15+
Replace this comment by a description of what your PR is solving.
16+
17+
Please consider the following requirement:
18+
* Modification of existing tests should be avoided unless deemed necessary.
19+
* You MUST never open a PR related to a security issue. Contact Spomky in private at https://gitter.im/Spomky/
20+
-->

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.travis/phar-private.pem
2+
jose.phar
3+
jose.phar.pubkey
4+
jose.phar.version
5+
.travis/build-key.pem
6+
.travis/secrets.tar
7+
composer.lock

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014-2017 Spomky-Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
PHP JOSE Application
2+
==================
3+
4+
If you really love that project, then you can help me out for a couple of :beers:!
5+
6+
[![Beerpay](https://beerpay.io/Spomky-Labs/jose/badge.svg?style=beer-square)](https://beerpay.io/Spomky-Labs/jose) [![Beerpay](https://beerpay.io/Spomky-Labs/jose/make-wish.svg?style=flat-square)](https://beerpay.io/Spomky-Labs/jose?focus=wish)
7+
8+
---
9+
10+
# Installation
11+
12+
# Contributing
13+
14+
Requests for new features, bug fixed and all other ideas to make this framework useful are welcome.
15+
If you feel comfortable writing code, you could try to fix [opened issues where help is wanted](https://github.com/Spomky-Labs/jose/labels/help+wanted) or [those that are easy to fix](https://github.com/Spomky-Labs/jose/labels/easy-pick).
16+
17+
Do not forget to [follow these best practices](.github/CONTRIBUTING.md).
18+
19+
**If you think you have found a security issue, DO NOT open an issue**. You should submit your issue here.
20+
21+
# Licence
22+
23+
This software is release under [MIT licence](LICENSE).

bin/jose

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
require __DIR__.'/../vendor/autoload.php';
7+
8+
use Jose\Component\Console;
9+
use Symfony\Component\Console\Application;
10+
use Jose\Component\Core\Converter\StandardJsonConverter;
11+
use Jose\Component\KeyManagement\KeyAnalyzer;
12+
use Jose\Component\KeyManagement\X5UFactory;
13+
use Jose\Component\KeyManagement\JKUFactory;
14+
use Jose\Component\KeyManagement\KeyAnalyzer\JWKAnalyzerManager;
15+
use Http\Adapter\Guzzle6\Client;
16+
use GuzzleHttp\Psr7\Request;
17+
use GuzzleHttp\Psr7\Response;
18+
use Http\Message\MessageFactory as Psr7MessageFactory;
19+
20+
/**
21+
* Class MessageFactory.
22+
*/
23+
final class MessageFactory implements Psr7MessageFactory
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
29+
{
30+
return new Request($method, $uri, $headers, $body, $protocolVersion);
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $protocolVersion = '1.1')
37+
{
38+
return new Response($statusCode, $headers, $body, $protocolVersion, $reasonPhrase);
39+
}
40+
}
41+
42+
$jsonConverter = new StandardJsonConverter();
43+
$httpClient = new Client();
44+
$messageFactory = new MessageFactory();
45+
$jwkAnalyzerManager = new JWKAnalyzerManager();
46+
$jwkAnalyzerManager
47+
->add(new KeyAnalyzer\AlgorithmAnalyzer())
48+
->add(new KeyAnalyzer\UsageAnalyzer())
49+
->add(new KeyAnalyzer\KeyIdentifierAnalyzer())
50+
->add(new KeyAnalyzer\NoneAnalyzer())
51+
->add(new KeyAnalyzer\OctAnalyzer())
52+
->add(new KeyAnalyzer\RsaAnalyzer())
53+
;
54+
55+
$application = new Application('Jose', '@package_version@');
56+
$application->add(new Console\OctKeyGeneratorCommand($jsonConverter));
57+
$application->add(new Console\RsaKeyGeneratorCommand($jsonConverter));
58+
$application->add(new Console\EcKeyGeneratorCommand($jsonConverter));
59+
$application->add(new Console\OkpKeyGeneratorCommand($jsonConverter));
60+
$application->add(new Console\KeyFileLoaderCommand($jsonConverter));
61+
$application->add(new Console\P12CertificateLoaderCommand($jsonConverter));
62+
$application->add(new Console\X509CertificateLoaderCommand($jsonConverter));
63+
64+
$application->add(new Console\EcKeysetGeneratorCommand($jsonConverter));
65+
$application->add(new Console\OkpKeysetGeneratorCommand($jsonConverter));
66+
$application->add(new Console\OctKeysetGeneratorCommand($jsonConverter));
67+
$application->add(new Console\RsaKeysetGeneratorCommand($jsonConverter));
68+
$application->add(new Console\MergeKeysetCommand($jsonConverter));
69+
$application->add(new Console\PublicKeysetCommand($jsonConverter));
70+
$application->add(new Console\RotateKeysetCommand($jsonConverter));
71+
$application->add(new Console\AddKeyIntoKeysetCommand($jsonConverter));
72+
73+
$application->add(new Console\OptimizeRsaKeyCommand($jsonConverter));
74+
$application->add(new Console\KeyAnalyzerCommand($jwkAnalyzerManager, $jsonConverter));
75+
$application->add(new Console\KeysetAnalyzerCommand($jwkAnalyzerManager, $jsonConverter));
76+
$application->add(new Console\X5ULoaderCommand(new X5UFactory($jsonConverter, $httpClient, $messageFactory), $jsonConverter));
77+
$application->add(new Console\JKULoaderCommand(new JKUFactory($jsonConverter, $httpClient, $messageFactory), $jsonConverter));
78+
79+
$application->add(new Console\PemConverterCommand($jsonConverter));
80+
81+
$application->add(new Console\GetThumbprintCommand($jsonConverter));
82+
83+
$application->add(new Console\UpdateCommand());
84+
$application->add(new Console\RollbackCommand());
85+
86+
$application->run();

box.json.dist

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"algorithm": "OPENSSL",
3+
"chmod": "0755",
4+
"compression": "GZ",
5+
"files": [
6+
"LICENSE"
7+
],
8+
"finder": [
9+
{
10+
"name": "*.php",
11+
"exclude": [
12+
"tests",
13+
"Tests",
14+
"test",
15+
"Test"
16+
],
17+
"in": ["src","vendor"]
18+
}
19+
],
20+
"git-version": "package_version",
21+
"intercept": true,
22+
"key": ".travis/phar-private.pem",
23+
"main": "bin/jose",
24+
"output": "jose.phar",
25+
"stub": true
26+
}

composer.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "web-token/jwt-app",
3+
"description": "JWT Application.",
4+
"type": "application",
5+
"license": "MIT",
6+
"keywords": ["JWS", "JWT", "JWE", "JWA", "JWK", "JWKSet", "Jot", "Jose", "RFC7515", "RFC7516", "RFC7517", "RFC7518", "RFC7519", "RFC7520", "Bundle", "Symfony"],
7+
"homepage": "https://github.com/web-token/jwt-app",
8+
"authors": [
9+
{
10+
"name": "Florent Morselli",
11+
"homepage": "https://github.com/Spomky"
12+
},{
13+
"name": "All contributors",
14+
"homepage": "https://github.com/web-token/jwt-app/contributors"
15+
}
16+
],
17+
"autoload": {
18+
"psr-4": {
19+
"Jose\\Component\\Console\\": "src/"
20+
}
21+
},
22+
"require": {
23+
"php": "^7.1",
24+
"web-token/jwt-framework": "^1.0@dev",
25+
"php-http/guzzle6-adapter": "^1.1.1",
26+
"bjeavons/zxcvbn-php": "^0.3"
27+
},
28+
"extra": {
29+
"branch-alias": {
30+
"dev-master": "1.0.x-dev"
31+
}
32+
},
33+
"config": {
34+
"sort-packages": true
35+
}
36+
}

src/RollbackCommand.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2017 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Jose\Component\Console;
15+
16+
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Output\OutputInterface;
19+
use Humbug\SelfUpdate\Updater;
20+
21+
/**
22+
* Class RollbackCommand.
23+
*/
24+
final class RollbackCommand extends Command
25+
{
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
protected function configure()
30+
{
31+
$this
32+
->setName('rollback')
33+
->setDescription('Rollback current version.')
34+
;
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
protected function execute(InputInterface $input, OutputInterface $output)
41+
{
42+
$updater = new Updater();
43+
44+
try {
45+
if (!$updater->rollback()) {
46+
$output->write('Failure!');
47+
} else {
48+
$output->write('Success!');
49+
}
50+
} catch (\Exception $e) {
51+
$output->write('Well, something happened! Either an oopsie or something involving hackers.');
52+
}
53+
}
54+
}

src/UpdateCommand.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2017 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Jose\Component\Console;
15+
16+
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Output\OutputInterface;
19+
use Humbug\SelfUpdate\Updater;
20+
21+
/**
22+
* Class UpdateCommand.
23+
*/
24+
final class UpdateCommand extends Command
25+
{
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
protected function configure()
30+
{
31+
$this
32+
->setName('selfupdate')
33+
->setDescription('Update the application if needed.')
34+
;
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
protected function execute(InputInterface $input, OutputInterface $output)
41+
{
42+
$updater = new Updater();
43+
$updater->setStrategy(Updater::STRATEGY_GITHUB);
44+
$updater->getStrategy()->setPackageName('web-token/jwt-framework');
45+
$updater->getStrategy()->setPharName('jose');
46+
$updater->getStrategy()->setCurrentLocalVersion('1.0.0');
47+
48+
try {
49+
$result = $updater->update();
50+
if ($result) {
51+
$new = $updater->getNewVersion();
52+
$old = $updater->getOldVersion();
53+
$output->write(sprintf('Updated from %s to %s', $old, $new));
54+
} else {
55+
$output->write('Already up-to-date.');
56+
}
57+
} catch (\Exception $e) {
58+
$output->write('Something went wrong during the update.');
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)