|
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 Jose\Component\Core\JWKSet; |
|
17
|
|
|
use Jose\Component\KeyManagement\JWKFactory; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class OkpKeysetGeneratorCommand. |
|
24
|
|
|
*/ |
|
25
|
|
|
final class OkpKeysetGeneratorCommand extends AbstractGeneratorCommand |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function configure() |
|
31
|
|
|
{ |
|
32
|
|
|
parent::configure(); |
|
33
|
|
|
$this |
|
34
|
|
|
->setName('keyset:generate:okp') |
|
35
|
|
|
->setDescription('Generate a key set with Octet Key Pairs keys (JWKSet format)') |
|
36
|
|
|
->addArgument('quantity', InputArgument::REQUIRED, 'Quantity of keys in the key set.') |
|
37
|
|
|
->addArgument('curve', InputArgument::REQUIRED, 'Curve of the keys.'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
44
|
|
|
{ |
|
45
|
|
|
$quantity = (int) $input->getArgument('quantity'); |
|
46
|
|
|
$curve = $input->getArgument('curve'); |
|
47
|
|
|
$args = $this->getOptions($input); |
|
48
|
|
|
|
|
49
|
|
|
$keyset = JWKSet::createFromKeys([]); |
|
50
|
|
|
for ($i = 0; $i < $quantity; ++$i) { |
|
51
|
|
|
$keyset = $keyset->with(JWKFactory::createOKPKey($curve, $args)); |
|
52
|
|
|
} |
|
53
|
|
|
$this->prepareJsonOutput($input, $output, $keyset); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|