|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2019 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\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\JWKSource; |
|
15
|
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource; |
|
17
|
|
|
use Jose\Component\KeyManagement\JWKFactory; |
|
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
22
|
|
|
|
|
23
|
|
|
class P12 extends AbstractSource implements JWKSource |
|
24
|
|
|
{ |
|
25
|
|
|
public function createDefinition(ContainerBuilder $container, array $config): Definition |
|
26
|
|
|
{ |
|
27
|
|
|
$definition = new Definition(JWK::class); |
|
28
|
|
|
$definition->setFactory([ |
|
29
|
|
|
new Reference(JWKFactory::class), |
|
30
|
|
|
'createFromPKCS12CertificateFile', |
|
31
|
|
|
]); |
|
32
|
|
|
$definition->setArguments([ |
|
33
|
|
|
$config['path'], |
|
34
|
|
|
$config['password'], |
|
35
|
|
|
$config['additional_values'], |
|
36
|
|
|
]); |
|
37
|
|
|
$definition->addTag('jose.jwk'); |
|
38
|
|
|
|
|
39
|
|
|
return $definition; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getKey(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return 'p12'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function addConfiguration(NodeDefinition $node): void |
|
48
|
|
|
{ |
|
49
|
|
|
parent::addConfiguration($node); |
|
50
|
|
|
$node |
|
51
|
|
|
->children() |
|
52
|
|
|
->scalarNode('path') |
|
53
|
|
|
->info('Path of the key file.') |
|
54
|
|
|
->isRequired() |
|
55
|
|
|
->end() |
|
56
|
|
|
->scalarNode('password') |
|
57
|
|
|
->info('Password used to decrypt the key (optional).') |
|
58
|
|
|
->defaultNull() |
|
59
|
|
|
->end() |
|
60
|
|
|
->arrayNode('additional_values') |
|
61
|
|
|
->info('Additional values to be added to the key.') |
|
62
|
|
|
->defaultValue([]) |
|
63
|
|
|
->useAttributeAsKey('key') |
|
64
|
|
|
->variablePrototype()->end() |
|
65
|
|
|
->end() |
|
66
|
|
|
->end() |
|
67
|
|
|
; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|