1 | <?php |
||
15 | class ComodoDecodeCSR |
||
16 | { |
||
17 | use Traits\ComodoDecodeCSR\Getters; |
||
18 | use Traits\ComodoDecodeCSR\Setters; |
||
19 | |||
20 | protected $MD5; |
||
21 | protected $SHA1; |
||
22 | protected $Endpoint = "https://secure.comodo.net/products/!decodeCSR"; |
||
23 | protected $CSR; |
||
24 | protected $Form = [ |
||
25 | 'responseFormat' => 'N', |
||
26 | 'showErrorCodes' => 'N', |
||
27 | 'showErrorMessages' => 'N', |
||
28 | 'showFieldNames' => 'N', |
||
29 | 'showEmptyFields' => 'N', |
||
30 | 'showCN' => 'N', |
||
31 | 'showAddress' => 'N', |
||
32 | 'showPublicKey' => 'N', |
||
33 | 'showKeySize' => 'N', |
||
34 | 'showSANDNSNames' => 'Y', |
||
35 | 'showCSR' => 'N', |
||
36 | 'showCSRHashes' => 'Y', |
||
37 | 'showSignatureAlgorithm' => 'N', |
||
38 | 'product' => '', |
||
39 | 'countryNameType' => 'TWOCHAR' |
||
40 | ]; |
||
41 | private $request; |
||
42 | |||
43 | 9 | public function fetchHashes() |
|
53 | |||
54 | 9 | public function checkInstalled() |
|
55 | { |
||
56 | 2 | $CSRInfo = $this->decodeCSR(); |
|
57 | 2 | $domain = $CSRInfo['subject']['CN']; |
|
58 | 2 | $URL = 'http://' . $domain . "/" . $this->getmd5() . '.txt'; |
|
59 | |||
60 | 2 | $client = new Client(); |
|
61 | |||
62 | try { |
||
63 | 2 | $request = $client->request('GET', $URL); |
|
64 | 2 | } catch (ClientException $e) { |
|
65 | 9 | return false; |
|
66 | } |
||
67 | |||
68 | 1 | $responce = "" . $request->getBody(); |
|
69 | 1 | return ($responce === $this->generateDVC()); |
|
70 | } |
||
71 | |||
72 | 6 | public function generateDVC() |
|
79 | |||
80 | 5 | public function checkDVC($response) |
|
81 | { |
||
82 | 5 | $DVC = $this->generateDVC(); |
|
83 | |||
84 | //If the response matches the DVC value return true |
||
85 | 5 | if ($response === $DVC) { |
|
86 | 1 | return true; |
|
87 | } |
||
88 | |||
89 | //Check if last character is not a new line |
||
90 | 4 | if (substr($response, -1) !== "\n") { |
|
91 | //Add said new line |
||
92 | 2 | $response = $response . "\n"; |
|
93 | 2 | } |
|
94 | |||
95 | //Check it again |
||
96 | 4 | if ($response === $DVC) { |
|
97 | 1 | return true; |
|
98 | } |
||
99 | |||
100 | 3 | return false; |
|
101 | } |
||
102 | |||
103 | 2 | private function decodeCSR() |
|
115 | |||
116 | 9 | private function processResponse() |
|
117 | { |
||
137 | } |
||
138 |