1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ocsp; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Contains the response about the revocation of a certificate. |
9
|
|
|
*/ |
10
|
|
|
class Response |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Certificate revocation reason: unspecified. |
14
|
|
|
* |
15
|
|
|
* @var int |
16
|
|
|
*/ |
17
|
|
|
const REVOCATIONREASON_UNSPECIFIED = 0; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Certificate revocation reason: key compromise. |
21
|
|
|
* |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
const REVOCATIONREASON_KEYCOMPROMISE = 1; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Certificate revocation reason: CA Compromise. |
28
|
|
|
* |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
const REVOCATIONREASON_CACOMPROMISE = 2; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Certificate revocation reason: affiliation changed. |
35
|
|
|
* |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
const REVOCATIONREASON_AFFILIATIONCHANGED = 3; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Certificate revocation reason: superseded. |
42
|
|
|
* |
43
|
|
|
* @var int |
44
|
|
|
*/ |
45
|
|
|
const REVOCATIONREASON_SUPERSEDED = 4; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Certificate revocation reason: cessation of operation. |
49
|
|
|
* |
50
|
|
|
* @var int |
51
|
|
|
*/ |
52
|
|
|
const REVOCATIONREASON_CESSATIONOFOPERATION = 5; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Certificate revocation reason: certificate hold. |
56
|
|
|
* |
57
|
|
|
* @var int |
58
|
|
|
*/ |
59
|
|
|
const REVOCATIONREASON_CERTIFICATEHOLD = 6; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Certificate revocation reason: remove from CRL. |
63
|
|
|
* |
64
|
|
|
* @var int |
65
|
|
|
*/ |
66
|
|
|
const REVOCATIONREASON_REMOVEFROMCRL = 8; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Certificate revocation reason: privilege withdrawn. |
70
|
|
|
* |
71
|
|
|
* @var int |
72
|
|
|
*/ |
73
|
|
|
const REVOCATIONREASON_PRIVILEGEWITHDRAWN = 9; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Certificate revocation reason: AA compromise. |
77
|
|
|
* |
78
|
|
|
* @var int |
79
|
|
|
*/ |
80
|
|
|
const REVOCATIONREASON_AACOMPROMISE = 10; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* The most recent time at which the status being indicated is known by the responder to have been correct. |
84
|
|
|
* |
85
|
|
|
* @var \DateTimeImmutable |
86
|
|
|
*/ |
87
|
|
|
private $thisUpdate; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* The most recent time at which the status being indicated is known by the responder to have been correct. |
91
|
|
|
* |
92
|
|
|
* @var \DateTimeImmutable|null |
93
|
|
|
*/ |
94
|
|
|
private $nextUpdate; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* The serial number of the certificate. |
98
|
|
|
* |
99
|
|
|
* @var string |
100
|
|
|
*/ |
101
|
|
|
private $certificateSerialNumber; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Is the certificate revoked (NULL: unknown)? |
105
|
|
|
* |
106
|
|
|
* @var bool|null |
107
|
|
|
*/ |
108
|
|
|
private $revoked; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* The date/time when the revocation occurred. |
112
|
|
|
* |
113
|
|
|
* @var \DateTimeImmutable|null |
114
|
|
|
*/ |
115
|
|
|
private $revokedOn; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* The revocation reason (if revoked). |
119
|
|
|
* |
120
|
|
|
* @var int|null |
121
|
2 |
|
*/ |
122
|
|
|
private $revocationReason; |
123
|
2 |
|
|
124
|
2 |
|
/** |
125
|
|
|
* @param \DateTimeImmutable $thisUpdate |
126
|
|
|
* @param string $certificateSerialNumber |
127
|
|
|
*/ |
128
|
|
|
protected function __construct(DateTimeImmutable $thisUpdate, ?DateTimeImmutable $nextUpdate, $certificateSerialNumber) |
129
|
|
|
{ |
130
|
|
|
$this->thisUpdate = $thisUpdate; |
131
|
|
|
$this->nextUpdate = $nextUpdate; |
132
|
|
|
$this->certificateSerialNumber = $certificateSerialNumber; |
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
/** |
136
|
|
|
* Create a new instance when the certificate is good. |
137
|
1 |
|
* |
138
|
1 |
|
* @param \DateTimeImmutable $thisUpdate |
139
|
|
|
* @param string $certificateSerialNumber |
140
|
1 |
|
* |
141
|
|
|
* @return static |
142
|
|
|
*/ |
143
|
|
|
public static function good(DateTimeImmutable $thisUpdate, ?DateTimeImmutable $nextUpdate, $certificateSerialNumber) |
144
|
|
|
{ |
145
|
|
|
$result = new static($thisUpdate, $nextUpdate, $certificateSerialNumber); |
146
|
|
|
$result->revoked = false; |
147
|
|
|
|
148
|
|
|
return $result; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
1 |
|
* Create a new instance when the certificate is revoked. |
153
|
|
|
* |
154
|
1 |
|
* @param \DateTimeImmutable $thisUpdate |
155
|
1 |
|
* @param string $certificateSerialNumber |
156
|
1 |
|
* @param \DateTimeImmutable $revokedOn |
157
|
1 |
|
* |
158
|
|
|
* @return static |
159
|
1 |
|
*/ |
160
|
|
|
public static function revoked(DateTimeImmutable $thisUpdate, ?DateTimeImmutable $nextUpdate, $certificateSerialNumber, DateTimeImmutable $revokedOn, $revocationReason = self::REVOCATIONREASON_UNSPECIFIED) |
161
|
|
|
{ |
162
|
|
|
$result = new static($thisUpdate, $nextUpdate, $certificateSerialNumber); |
163
|
|
|
$result->revoked = true; |
164
|
|
|
$result->revokedOn = $revokedOn; |
165
|
|
|
$result->revocationReason = (int) $revocationReason; |
166
|
|
|
|
167
|
|
|
return $result; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Create a new instance when the certificate revocation is unknown. |
172
|
|
|
* |
173
|
|
|
* @param \DateTimeImmutable $thisUpdate |
174
|
|
|
* @param string $certificateSerialNumber |
175
|
|
|
* |
176
|
|
|
* @return static |
177
|
|
|
*/ |
178
|
|
|
public static function unknown(DateTimeImmutable $thisUpdate, ?DateTimeImmutable $nextUpdate, $certificateSerialNumber) |
179
|
|
|
{ |
180
|
|
|
$result = new static($thisUpdate, $nextUpdate, $certificateSerialNumber); |
181
|
|
|
|
182
|
|
|
return $result; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Get the most recent time at which the status being indicated is known by the responder to have been correct. |
187
|
|
|
* |
188
|
|
|
* @return \DateTimeImmutable |
189
|
|
|
*/ |
190
|
|
|
public function getThisUpdate() |
191
|
|
|
{ |
192
|
|
|
return $this->thisUpdate; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Get the serial number of the certificate. |
197
|
|
|
* |
198
|
|
|
* @return string |
199
|
|
|
*/ |
200
|
|
|
public function getCertificateSerialNumber() |
201
|
|
|
{ |
202
|
2 |
|
return $this->certificateSerialNumber; |
203
|
|
|
} |
204
|
2 |
|
|
205
|
|
|
/** |
206
|
|
|
* Is the certificate revoked (NULL: unknown)? |
207
|
|
|
* |
208
|
|
|
* @return bool|null |
209
|
|
|
*/ |
210
|
|
|
public function isRevoked() |
211
|
|
|
{ |
212
|
|
|
return $this->revoked; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Get the revocation date/time (not null only if the certificate is revoked). |
217
|
|
|
* |
218
|
|
|
* @return \DateTimeImmutable|null |
219
|
|
|
*/ |
220
|
|
|
public function getRevokedOn() |
221
|
|
|
{ |
222
|
|
|
return $this->revokedOn; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Get the revocation reason (if revoked). |
227
|
|
|
* |
228
|
|
|
* @return int|null |
229
|
|
|
*/ |
230
|
|
|
public function getRevocationReason() |
231
|
|
|
{ |
232
|
|
|
return $this->revocationReason; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* The most recent time at which the status being indicated is known by the responder to have been correct. |
237
|
|
|
* |
238
|
|
|
* @var \DateTimeImmutable|null |
239
|
|
|
*/ |
240
|
|
|
public function getNextUpdate() |
241
|
|
|
{ |
242
|
|
|
return $this->nextUpdate; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
} |
246
|
|
|
|