|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License (MIT) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
|
7
|
|
|
* |
|
8
|
|
|
* This software may be modified and distributed under the terms |
|
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jose\Object; |
|
13
|
|
|
|
|
14
|
|
|
use Assert\Assertion; |
|
15
|
|
|
use Base64Url\Base64Url; |
|
16
|
|
|
use Jose\Factory\JWKFactory; |
|
17
|
|
|
use Webmozart\Assert\Assert; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class RotatableJWK. |
|
21
|
|
|
*/ |
|
22
|
|
|
final class RotatableJWK implements JWKInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var \Jose\Object\JWKInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $jwk; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
private $filename; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var int |
|
36
|
|
|
*/ |
|
37
|
|
|
private $ttl; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private $parameters; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* RotatableJWK constructor. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $filename |
|
48
|
|
|
* @param array $parameters |
|
49
|
|
|
* @param int $ttl |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct($filename, array $parameters, $ttl = 0) |
|
52
|
|
|
{ |
|
53
|
|
|
Assertion::directory(basename($filename), 'The selected directory does not exist.'); |
|
54
|
|
|
$this->filename = $filename; |
|
55
|
|
|
$this->parameters = $parameters; |
|
56
|
|
|
$this->ttl = $ttl; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return \Jose\Object\JWKInterface |
|
61
|
|
|
*/ |
|
62
|
|
|
private function getJWK() |
|
63
|
|
|
{ |
|
64
|
|
|
if (null === $this->jwk) { |
|
65
|
|
|
$this->createJWK(); |
|
66
|
|
|
} |
|
67
|
|
|
return $this->jwk; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private function loadJWK() |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private function createJWK() |
|
75
|
|
|
{ |
|
76
|
|
|
$jwk = JWKFactory::createKey($this->parameters); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getAll() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->getJWK()->getAll(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritdoc} |
|
89
|
|
|
*/ |
|
90
|
|
|
public function get($key) |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->getJWK()->get($key); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* {@inheritdoc} |
|
97
|
|
|
*/ |
|
98
|
|
|
public function has($key) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getJWK()->has($key); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* {@inheritdoc} |
|
105
|
|
|
*/ |
|
106
|
|
|
public function thumbprint($hash_algorithm) |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->getJWK()->thumbprint($hash_algorithm); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* {@inheritdoc} |
|
113
|
|
|
*/ |
|
114
|
|
|
public function toPublic() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->getJWK()->toPublic(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* {@inheritdoc} |
|
121
|
|
|
*/ |
|
122
|
|
|
public function jsonSerialize() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->getJWK()->jsonSerialize(); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|