|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LE_ACME2\Request\Account; |
|
4
|
|
|
|
|
5
|
|
|
use LE_ACME2\Request\AbstractRequest; |
|
6
|
|
|
use LE_ACME2\Response; |
|
7
|
|
|
|
|
8
|
|
|
use LE_ACME2\Connector; |
|
9
|
|
|
use LE_ACME2\Cache; |
|
10
|
|
|
use LE_ACME2\Utilities; |
|
11
|
|
|
use LE_ACME2\Exception; |
|
12
|
|
|
|
|
13
|
|
|
use LE_ACME2\Account; |
|
14
|
|
|
|
|
15
|
|
|
class ChangeKeys extends AbstractRequest { |
|
16
|
|
|
|
|
17
|
|
|
protected $_account; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(Account $account) { |
|
20
|
|
|
$this->_account = $account; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @throws Exception\InvalidResponse |
|
25
|
|
|
* @throws Exception\RateLimitReached |
|
26
|
|
|
* @throws Exception\ServiceUnavailable |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getResponse() : Response\Account\ChangeKeys { |
|
29
|
|
|
|
|
30
|
|
|
$currentPrivateKey = openssl_pkey_get_private( |
|
31
|
|
|
file_get_contents($this->_account->getKeyDirectoryPath() . 'private.pem') |
|
32
|
|
|
); |
|
33
|
|
|
$currentPrivateKeyDetails = openssl_pkey_get_details($currentPrivateKey); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* draft-13 Section 7.3.6 |
|
37
|
|
|
* "newKey" is deprecated after August 23rd 2018 |
|
38
|
|
|
*/ |
|
39
|
|
|
$newPrivateKey = openssl_pkey_get_private( |
|
40
|
|
|
file_get_contents($this->_account->getKeyDirectoryPath() . 'private-replacement.pem') |
|
41
|
|
|
); |
|
42
|
|
|
$newPrivateKeyDetails = openssl_pkey_get_details($newPrivateKey); |
|
43
|
|
|
|
|
44
|
|
|
$innerPayload = [ |
|
45
|
|
|
'account' => Cache\AccountResponse::getInstance()->get($this->_account)->getLocation(), |
|
|
|
|
|
|
46
|
|
|
'oldKey' => [ |
|
47
|
|
|
"kty" => "RSA", |
|
48
|
|
|
"n" => Utilities\Base64::UrlSafeEncode($currentPrivateKeyDetails["rsa"]["n"]), |
|
49
|
|
|
"e" => Utilities\Base64::UrlSafeEncode($currentPrivateKeyDetails["rsa"]["e"]) |
|
50
|
|
|
], |
|
51
|
|
|
'newKey' => [ |
|
52
|
|
|
"kty" => "RSA", |
|
53
|
|
|
"n" => Utilities\Base64::UrlSafeEncode($newPrivateKeyDetails["rsa"]["n"]), |
|
54
|
|
|
"e" => Utilities\Base64::UrlSafeEncode($newPrivateKeyDetails["rsa"]["e"]) |
|
55
|
|
|
] |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
$outerPayload = Utilities\RequestSigner::JWK( |
|
59
|
|
|
$innerPayload, |
|
60
|
|
|
Cache\DirectoryResponse::getInstance()->get()->getKeyChange(), |
|
61
|
|
|
Cache\NewNonceResponse::getInstance()->get()->getNonce(), |
|
62
|
|
|
$this->_account->getKeyDirectoryPath(), |
|
63
|
|
|
'private-replacement.pem' |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$data = Utilities\RequestSigner::KID( |
|
67
|
|
|
$outerPayload, |
|
68
|
|
|
Cache\AccountResponse::getInstance()->get($this->_account)->getLocation(), |
|
69
|
|
|
Cache\DirectoryResponse::getInstance()->get()->getKeyChange(), |
|
70
|
|
|
Cache\NewNonceResponse::getInstance()->get()->getNonce(), |
|
71
|
|
|
$this->_account->getKeyDirectoryPath(), |
|
72
|
|
|
'private.pem' |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$result = Connector\Connector::getInstance()->request( |
|
|
|
|
|
|
76
|
|
|
Connector\Connector::METHOD_POST, |
|
77
|
|
|
Cache\DirectoryResponse::getInstance()->get()->getKeyChange(), |
|
78
|
|
|
$data |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
return new Response\Account\ChangeKeys($result); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|