1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ocsp; |
4
|
|
|
|
5
|
|
|
use Ocsp\Exception\RequestException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Contains the data to be included in the OCSP request. |
9
|
|
|
*/ |
10
|
|
|
class Request |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The serial number of the certificate. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $certificateSerialNumber; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The DER-encoded data of the issuer. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $issuerNameDer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The bytes of the public key of the subject included in the certificate. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $issuerPublicKeyBytes; |
32
|
|
|
|
33
|
2 |
|
protected function __construct() |
34
|
|
|
{ |
35
|
2 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create a new instance. |
39
|
|
|
* |
40
|
|
|
* @param string $certificateSerialNumber |
41
|
|
|
* @param string $issuerNameDer |
42
|
|
|
* @param string $issuerPublicKeyBytes |
43
|
|
|
|
44
|
|
|
* |
45
|
|
|
* @throws \Ocsp\Exception\RequestException when there's some invalid value |
46
|
|
|
* |
47
|
|
|
* @return static |
48
|
|
|
*/ |
49
|
2 |
|
public static function create($certificateSerialNumber, $issuerNameDer, $issuerPublicKeyBytes) |
50
|
|
|
{ |
51
|
2 |
|
$result = new static(); |
52
|
|
|
|
53
|
2 |
|
$certificateSerialNumber = (string) $certificateSerialNumber; |
54
|
2 |
|
if ($certificateSerialNumber === '') { |
55
|
|
|
throw RequestException::create('Missing the certificate serial number'); |
56
|
|
|
} |
57
|
2 |
|
$result->certificateSerialNumber = $certificateSerialNumber; |
58
|
|
|
|
59
|
2 |
|
$issuerNameDer = (string) $issuerNameDer; |
60
|
2 |
|
if ($issuerNameDer === '') { |
61
|
|
|
throw RequestException::create('Missing the issuer details from the certificate'); |
62
|
|
|
} |
63
|
2 |
|
$result->issuerNameDer = $issuerNameDer; |
64
|
|
|
|
65
|
2 |
|
$issuerPublicKeyBytes = (string) $issuerPublicKeyBytes; |
66
|
2 |
|
if ($issuerPublicKeyBytes === '') { |
67
|
|
|
throw RequestException::create('Missing the issuer public key from the issuer certificate'); |
68
|
|
|
} |
69
|
2 |
|
$result->issuerPublicKeyBytes = $issuerPublicKeyBytes; |
70
|
|
|
|
71
|
2 |
|
return $result; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get tThe serial number of the certificate. |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
2 |
|
public function getCertificateSerialNumber() |
80
|
|
|
{ |
81
|
2 |
|
return $this->certificateSerialNumber; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the DER-encoded data of the issuer. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
2 |
|
public function getIssuerNameDer() |
90
|
|
|
{ |
91
|
2 |
|
return $this->issuerNameDer; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get the bytes of the public key of the subject included in the certificate. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
2 |
|
public function getIssuerPublicKeyBytes() |
100
|
|
|
{ |
101
|
2 |
|
return $this->issuerPublicKeyBytes; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|