ChangeKeys   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 37
dl 0
loc 67
ccs 0
cts 28
cp 0
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getResponse() 0 54 1
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(),
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
            'account' => Cache\AccountResponse::getInstance()->/** @scrutinizer ignore-call */ get($this->_account)->getLocation(),
Loading history...
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(
0 ignored issues
show
Bug introduced by
It seems like request() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
        $result = Connector\Connector::getInstance()->/** @scrutinizer ignore-call */ request(
Loading history...
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