1 | <?php |
||
28 | class Certificate implements ICertificate { |
||
29 | protected $name; |
||
30 | |||
31 | protected $commonName; |
||
32 | |||
33 | protected $organization; |
||
34 | |||
35 | protected $serial; |
||
36 | |||
37 | protected $issueDate; |
||
38 | |||
39 | protected $expireDate; |
||
40 | |||
41 | protected $issuerName; |
||
42 | |||
43 | protected $issuerOrganization; |
||
44 | |||
45 | /** |
||
46 | * @param string $data base64 encoded certificate |
||
47 | * @param string $name |
||
48 | * @throws \Exception If the certificate could not get parsed |
||
49 | */ |
||
50 | 13 | public function __construct($data, $name) { |
|
51 | 13 | $this->name = $name; |
|
52 | 13 | $gmt = new \DateTimeZone('GMT'); |
|
53 | |||
54 | // If string starts with "file://" ignore the certificate |
||
55 | 13 | $query = 'file://'; |
|
56 | 13 | if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
57 | 1 | throw new \Exception('Certificate could not get parsed.'); |
|
58 | } |
||
59 | |||
60 | 13 | $info = openssl_x509_parse($data); |
|
61 | 13 | if(!is_array($info)) { |
|
62 | 2 | throw new \Exception('Certificate could not get parsed.'); |
|
63 | } |
||
64 | |||
65 | 12 | $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
66 | 12 | $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
67 | 12 | $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
68 | 12 | $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
69 | 12 | $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
70 | 12 | $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
71 | 12 | } |
|
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | 3 | public function getName() { |
|
79 | |||
80 | /** |
||
81 | * @return string|null |
||
82 | */ |
||
83 | 1 | public function getCommonName() { |
|
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | 1 | public function getOrganization() { |
|
93 | |||
94 | /** |
||
95 | * @return \DateTime |
||
96 | */ |
||
97 | 1 | public function getIssueDate() { |
|
100 | |||
101 | /** |
||
102 | * @return \DateTime |
||
103 | */ |
||
104 | 1 | public function getExpireDate() { |
|
105 | 1 | return $this->expireDate; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * @return bool |
||
110 | */ |
||
111 | 1 | public function isExpired() { |
|
112 | 1 | $now = new \DateTime(); |
|
113 | 1 | return $this->issueDate > $now or $now > $this->expireDate; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * @return string|null |
||
118 | */ |
||
119 | 1 | public function getIssuerName() { |
|
122 | |||
123 | /** |
||
124 | * @return string|null |
||
125 | */ |
||
126 | 1 | public function getIssuerOrganization() { |
|
129 | } |
||
130 |