1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 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\KeyManagement\JWKFactory; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class SecretKeyGeneratorCommand. |
24
|
|
|
*/ |
25
|
|
|
final class SecretKeyGeneratorCommand extends GeneratorCommand |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
protected function configure() |
31
|
|
|
{ |
32
|
|
|
parent::configure(); |
33
|
|
|
$this |
34
|
|
|
->setName('key:generate:from_secret') |
35
|
|
|
->setDescription('Generate an octet key (JWK format) using an existing secret') |
36
|
|
|
->addArgument('secret', InputArgument::REQUIRED, 'The secret') |
37
|
|
|
->addOption('is_b64', 'b', InputOption::VALUE_NONE, 'Indicates if the secret is Base64 encoded (useful for binary secrets)'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
44
|
|
|
{ |
45
|
|
|
$secret = $input->getArgument('secret'); |
46
|
|
|
if ($input->getOption('is_b64')) { |
47
|
|
|
$secret = base64_decode($secret); |
48
|
|
|
} |
49
|
|
|
$args = $this->getOptions($input); |
50
|
|
|
|
51
|
|
|
$jwk = JWKFactory::createFromSecret($secret, $args); |
52
|
|
|
$this->prepareJsonOutput($input, $output, $jwk); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|