1 | <?php |
||
16 | class ComodoDecodeCSR |
||
17 | { |
||
18 | use Traits\GetSetUnset; |
||
19 | |||
20 | protected $MD5; |
||
21 | protected $SHA1; |
||
22 | protected $Endpoint = "https://secure.comodo.net/products/!decodeCSR"; |
||
23 | protected $CSR; |
||
24 | /** |
||
25 | * An array of warnings that can be show after the test |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $warnings = []; |
||
29 | protected $Form = [ |
||
30 | 'responseFormat' => 'N', |
||
31 | 'showErrorCodes' => 'N', |
||
32 | 'showErrorMessages' => 'N', |
||
33 | 'showFieldNames' => 'N', |
||
34 | 'showEmptyFields' => 'N', |
||
35 | 'showCN' => 'N', |
||
36 | 'showAddress' => 'N', |
||
37 | 'showPublicKey' => 'N', |
||
38 | 'showKeySize' => 'N', |
||
39 | 'showSANDNSNames' => 'Y', |
||
40 | 'showCSR' => 'N', |
||
41 | 'showCSRHashes' => 'Y', |
||
42 | 'showSignatureAlgorithm' => 'N', |
||
43 | 10 | 'product' => '', |
|
44 | 'countryNameType' => 'TWOCHAR' |
||
45 | 10 | ]; |
|
46 | private $request; |
||
47 | 10 | ||
48 | 10 | private $forceSSL = false; |
|
49 | 10 | ||
50 | public function getCN() |
||
51 | 10 | { |
|
52 | $CSRInfo = $this->decodeCSR(); |
||
53 | return $CSRInfo['subject']['CN']; |
||
54 | 10 | } |
|
55 | |||
56 | 2 | public function setCSR($csr) |
|
57 | 2 | { |
|
58 | $this->CSR = $csr; |
||
59 | 2 | //Check that this is a valid CSR |
|
60 | $this->decodeCSR(); |
||
61 | $this->Form['csr'] = $csr; |
||
62 | 2 | } |
|
63 | 2 | ||
64 | 1 | protected function addWarning($code, $message) |
|
65 | 10 | { |
|
66 | $this->warnings[] = [ |
||
67 | 1 | $code => $message |
|
68 | 1 | ]; |
|
69 | } |
||
70 | |||
71 | 7 | public function fetchHashes() |
|
72 | { |
||
73 | 7 | $client = new Client(); |
|
74 | 7 | ||
75 | $this->request = $client->request('POST', $this->getEndpoint(), [ |
||
76 | 7 | 'form_params' => $this->Form |
|
77 | ]); |
||
78 | |||
79 | 7 | return $this->processResponse(); |
|
80 | } |
||
81 | 7 | ||
82 | public function checkInstalled() |
||
83 | { |
||
84 | 7 | ||
85 | 2 | try { |
|
86 | $domain = $this->getCN(); |
||
87 | } catch (\Exception $e) { |
||
88 | return false; |
||
89 | 5 | } |
|
90 | 1 | ||
91 | 1 | $response = $this->fetchDVCFile($domain); |
|
92 | if ($response == false) { |
||
93 | return false; |
||
94 | 5 | } |
|
95 | |||
96 | 2 | $check = $this->checkDVC($response); |
|
|
|||
97 | 2 | if ($check === true) { |
|
98 | return $check; |
||
99 | } |
||
100 | 5 | ||
101 | 2 | //Try again but this time use https:// |
|
102 | $this->forceSSL = true; |
||
103 | |||
104 | 3 | $response = $this->fetchDVCFile($domain); |
|
105 | if ($response == false) { |
||
106 | return false; |
||
107 | 2 | } |
|
108 | |||
109 | 2 | $check = $this->checkDVC($response); |
|
110 | 2 | if ($check === true) { |
|
111 | 2 | //TODO Add a message to say then you will need to select 'HTTPS CSR |
|
112 | 2 | //Hash' |
|
113 | return $check; |
||
114 | } |
||
115 | 2 | ||
116 | return false; |
||
117 | 2 | } |
|
118 | |||
119 | public function generateDVC() |
||
126 | |||
127 | 10 | /** |
|
128 | * |
||
129 | 10 | * @param GuzzleHttp\Psr7\Response $response |
|
130 | 10 | * @return bool |
|
131 | 10 | */ |
|
132 | 10 | public function checkDVC(Response $response) |
|
167 | |||
168 | private function decodeCSR() |
||
184 | |||
185 | private function processResponse() |
||
206 | |||
207 | private function fetchDVCFile($domain) |
||
229 | } |
||
230 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.