Completed
Push — master ( 74a36c...b50a3c )
by Chris
03:40 queued 57s
created

ComodoDecodeCSR::getCSR()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
* @author Chris Hilsdon <[email protected]>
4
*/
5
namespace Xigen;
6
7
use GuzzleHttp\Client;
8
9
class ComodoDecodeCSR
10
{
11
    protected $md5;
12
    protected $sha1;
13
    protected $Endpoint = "https://secure.comodo.net/products/!decodeCSR";
14
    protected $Form = [
15
        'responseFormat' => 'N',
16
        'showErrorCodes' => 'N',
17
        'showErrorMessages' => 'N',
18
        'showFieldNames' => 'N',
19
        'showEmptyFields' => 'N',
20
        'showCN' => 'N',
21
        'showAddress' => 'N',
22
        'showPublicKey' => 'N',
23
        'showKeySize' => 'N',
24
        'showSANDNSNames' => 'Y',
25
        'showCSR' => 'N',
26
        'showCSRHashes' => 'Y',
27
        'showSignatureAlgorithm' => 'N',
28
        'product' => '',
29
        'countryNameType' => 'TWOCHAR'
30
    ];
31
    protected $CSR;
32
    private $request;
33
34
    public function setCSR($CSR)
35
    {
36
        //TODO Check that this is a valid CSR
37
        $this->CSR = $CSR;
38
        $this->Form['csr'] = $CSR;
39
    }
40
41
    public function getCSR()
42
    {
43
        return $this->CSR;
44
    }
45
46
    public function getHashes()
47
    {
48
        $client = new Client();
49
50
        $this->request = $client->request('POST', $this->Endpoint, [
51
            'form_params' => $this->Form
52
        ]);
53
54
        return $this->processResponce();
55
    }
56
57
    private function processResponce()
58
    {
59
        $Responce = $this->request->getBody();
60
        $lines = explode("\n", $Responce);
61
        $data = array();
62
63
        foreach ($lines as $v) {
64
            if (!empty($v)) {
65
                $value = explode("=", $v);
66
                $data[$value[0]] = $value[1];
67
            }
68
        }
69
70
        $this->md5 = $data["md5"];
71
        $this->sha1 = $data["sha1"];
72
73
        return $data ? $data : false;
74
    }
75
}
76