Skip to content

Commit 43e85cf

Browse files
committed
Key Management Bundle updated.
Dependency to the Http Client and Psr7 enhanced.
1 parent dedff14 commit 43e85cf

File tree

25 files changed

+761
-43
lines changed

25 files changed

+761
-43
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@
4343
"require-dev": {
4444
"ext-curl": "*",
4545
"bjeavons/zxcvbn-php": "^0.3.0",
46-
"php-http/guzzle6-adapter": "^1.1.1",
47-
"php-http/httplug": "^1.1",
46+
"guzzlehttp/psr7": "^1.4",
4847
"php-http/httplug-bundle": "^1.7",
49-
"php-http/message-factory": "^1.0",
5048
"php-http/mock-client": "^1.0",
5149
"phpbench/phpbench": "^0.13.0",
5250
"phpunit/phpunit": "^6.0",

src/Bundle/KeyManagement/DependencyInjection/Source/JKUSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getNodeDefinition(ArrayNodeDefinition $node)
6262
->defaultNull()
6363
->end()
6464
->scalarNode('request_factory')
65-
->defaultValue('Http\Message\MessageFactory\GuzzleMessageFactory')
65+
->isRequired()
6666
->end()
6767
->end()
6868
->end()
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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\Bundle\KeyManagement\DependencyInjection\Source\JWKSetSource;
15+
16+
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource;
17+
use Jose\Component\KeyManagement\JKUFactory;
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+
/**
24+
* Class JKU.
25+
*/
26+
final class JKU extends AbstractSource implements JWKSetSource
27+
{
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function createDefinition(ContainerBuilder $container, array $config): Definition
32+
{
33+
$definition = new Definition(\Jose\Component\Core\JWKSet::class);
34+
$definition->setFactory([
35+
new Reference(JKUFactory::class),
36+
'loadFromUrl',
37+
]);
38+
$definition->setArguments([
39+
$config['url'],
40+
// $config['headers'],
41+
]);
42+
$definition->addTag('jose.jwkset');
43+
44+
return $definition;
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function getKeySet(): string
51+
{
52+
return 'jku';
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function addConfiguration(NodeDefinition $node)
59+
{
60+
parent::addConfiguration($node);
61+
$node
62+
->children()
63+
->scalarNode('url')->isRequired()->end()
64+
->end();
65+
}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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\Bundle\KeyManagement\DependencyInjection\Source\JWKSetSource;
15+
16+
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource;
17+
use Jose\Component\KeyManagement\X5UFactory;
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+
/**
24+
* Class X5U.
25+
*/
26+
final class X5U extends AbstractSource implements JWKSetSource
27+
{
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function createDefinition(ContainerBuilder $container, array $config): Definition
32+
{
33+
$definition = new Definition(\Jose\Component\Core\JWKSet::class);
34+
$definition->setFactory([
35+
new Reference(X5UFactory::class),
36+
'loadFromUrl',
37+
]);
38+
$definition->setArguments([
39+
$config['url'],
40+
// $config['headers'],
41+
]);
42+
$definition->addTag('jose.jwkset');
43+
44+
return $definition;
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function getKeySet(): string
51+
{
52+
return 'x5u';
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function addConfiguration(NodeDefinition $node)
59+
{
60+
parent::addConfiguration($node);
61+
$node
62+
->children()
63+
->scalarNode('url')->isRequired()->end()
64+
->end();
65+
}
66+
}

src/Bundle/KeyManagement/DependencyInjection/Source/JWKSource/X5C.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function createDefinition(ContainerBuilder $container, array $config): De
3737
]);
3838
$definition->setArguments([
3939
$config['value'],
40+
$config['additional_values'],
4041
]);
4142
$definition->addTag('jose.jwk');
4243

@@ -60,6 +61,11 @@ public function addConfiguration(NodeDefinition $node)
6061
$node
6162
->children()
6263
->scalarNode('value')->isRequired()->end()
64+
->arrayNode('additional_values')
65+
->defaultValue([])
66+
->useAttributeAsKey('key')
67+
->prototype('variable')->end()
68+
->end()
6369
->end();
6470
}
6571
}

src/Bundle/KeyManagement/Resources/config/jku_source.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@ services:
1414
- '@Jose\Component\Core\Converter\JsonConverter'
1515
- '@jose.http_client'
1616
- '@jose.request_factory'
17-
18-
Http\Message\MessageFactory\GuzzleMessageFactory: ~
19-
Http\Message\MessageFactory\DiactorosMessageFactory: ~
20-
Http\Message\MessageFactory\SlimMessageFactory: ~

src/Bundle/KeyManagement/Resources/config/jwkset_sources.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ services:
44
class: 'Jose\Bundle\KeyManagement\DependencyInjection\Source\JWKSetSource\JWKSet'
55
tags:
66
- {'name': 'jose.jwkset_source'}
7+
jose.jwk_set_source.jku:
8+
public: false
9+
class: 'Jose\Bundle\KeyManagement\DependencyInjection\Source\JWKSetSource\JKU'
10+
tags:
11+
- {'name': 'jose.jwkset_source'}
12+
jose.jwk_set_source.x5u:
13+
public: false
14+
class: 'Jose\Bundle\KeyManagement\DependencyInjection\Source\JWKSetSource\X5U'
15+
tags:
16+
- {'name': 'jose.jwkset_source'}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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\Bundle\KeyManagement\Tests;
15+
16+
use Jose\Component\Core\JWK;
17+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
18+
19+
/**
20+
* @group Bundle
21+
* @group Functional
22+
* @group KeyManagement
23+
*/
24+
final class JWKLoaderTest extends WebTestCase
25+
{
26+
/**
27+
* @test
28+
*/
29+
public function aJWKCanBeDefinedInTheConfiguration()
30+
{
31+
$client = static::createClient();
32+
33+
$container = $client->getContainer();
34+
self::assertTrue($container->has('jose.key.jwk1'));
35+
self::assertInstanceOf(JWK::class, $container->get('jose.key.jwk1'));
36+
}
37+
38+
/**
39+
* @test
40+
*/
41+
public function aJWKCanBeDefinedFromAnotherBundle()
42+
{
43+
$client = static::createClient();
44+
45+
$container = $client->getContainer();
46+
self::assertTrue($container->has('jose.key.jwk2'));
47+
self::assertInstanceOf(JWK::class, $container->get('jose.key.jwk2'));
48+
}
49+
50+
/**
51+
* @test
52+
*/
53+
public function aX509InFileCanBeDefinedInTheConfiguration()
54+
{
55+
$client = static::createClient();
56+
57+
$container = $client->getContainer();
58+
self::assertTrue($container->has('jose.key.certificate1'));
59+
self::assertInstanceOf(JWK::class, $container->get('jose.key.certificate1'));
60+
}
61+
62+
/**
63+
* @test
64+
*/
65+
public function aDirectX509InputCanBeDefinedInTheConfiguration()
66+
{
67+
$client = static::createClient();
68+
69+
$container = $client->getContainer();
70+
self::assertTrue($container->has('jose.key.x5c1'));
71+
self::assertInstanceOf(JWK::class, $container->get('jose.key.x5c1'));
72+
}
73+
74+
/**
75+
* @test
76+
*/
77+
public function anEncryptedKeyFileCanBeLoadedInTheConfiguration()
78+
{
79+
$client = static::createClient();
80+
81+
$container = $client->getContainer();
82+
self::assertTrue($container->has('jose.key.file1'));
83+
self::assertInstanceOf(JWK::class, $container->get('jose.key.file1'));
84+
}
85+
86+
/**
87+
* @test
88+
*/
89+
public function aJWKCanBeLoadedFromAJwkSetInTheConfiguration()
90+
{
91+
$client = static::createClient();
92+
93+
$container = $client->getContainer();
94+
self::assertTrue($container->has('jose.key.jwkset1'));
95+
self::assertInstanceOf(JWK::class, $container->get('jose.key.jwkset1'));
96+
}
97+
}

0 commit comments

Comments
 (0)