1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LE_ACME2\Request\Order; |
4
|
|
|
|
5
|
|
|
use LE_ACME2\Response; |
6
|
|
|
use LE_ACME2\Request\AbstractRequest; |
7
|
|
|
|
8
|
|
|
use LE_ACME2\Connector; |
9
|
|
|
use LE_ACME2\Cache; |
10
|
|
|
use LE_ACME2\Exception; |
11
|
|
|
use LE_ACME2\Struct; |
12
|
|
|
use LE_ACME2\Utilities; |
13
|
|
|
|
14
|
|
|
class RevokeCertificate extends AbstractRequest { |
15
|
|
|
|
16
|
|
|
protected $_certificateBundle; |
17
|
|
|
protected $_reason; |
18
|
|
|
|
19
|
|
|
public function __construct(Struct\CertificateBundle $certificateBundle, $reason) { |
20
|
|
|
|
21
|
|
|
$this->_certificateBundle = $certificateBundle; |
22
|
|
|
$this->_reason = $reason; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @throws Exception\InvalidResponse |
27
|
|
|
* @throws Exception\RateLimitReached |
28
|
|
|
* @throws Exception\ServiceUnavailable |
29
|
|
|
*/ |
30
|
|
|
public function getResponse() : Response\Order\RevokeCertificate { |
31
|
|
|
|
32
|
|
|
$certificate = file_get_contents($this->_certificateBundle->path . $this->_certificateBundle->certificate); |
33
|
|
|
preg_match('~-----BEGIN\sCERTIFICATE-----(.*)-----END\sCERTIFICATE-----~s', $certificate, $matches); |
34
|
|
|
$certificate = trim(Utilities\Base64::UrlSafeEncode(base64_decode(trim($matches[1])))); |
35
|
|
|
|
36
|
|
|
$payload = [ |
37
|
|
|
'certificate' => $certificate, |
38
|
|
|
'reason' => $this->_reason |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
$jwk = Utilities\RequestSigner::JWKString( |
42
|
|
|
$payload, |
43
|
|
|
Cache\DirectoryResponse::getInstance()->get()->getRevokeCert(), |
|
|
|
|
44
|
|
|
Cache\NewNonceResponse::getInstance()->get()->getNonce(), |
45
|
|
|
$this->_certificateBundle->path, |
46
|
|
|
$this->_certificateBundle->private |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$result = Connector\Connector::getInstance()->request( |
|
|
|
|
50
|
|
|
Connector\Connector::METHOD_POST, |
51
|
|
|
Cache\DirectoryResponse::getInstance()->get()->getRevokeCert(), |
52
|
|
|
$jwk |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
return new Response\Order\RevokeCertificate($result); |
56
|
|
|
} |
57
|
|
|
} |