2018-07-16 05:06:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes;
|
|
|
|
|
2020-01-11 11:05:05 +00:00
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
2018-07-16 05:06:43 +00:00
|
|
|
class SSL
|
|
|
|
{
|
|
|
|
// Our CSR
|
|
|
|
private $csr_pem = NULL;
|
|
|
|
// Our Certificate
|
|
|
|
private $crt = [];
|
|
|
|
private $crt_pem = NULL;
|
|
|
|
// Our Key
|
|
|
|
private $key_pem = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $key
|
|
|
|
* @return null
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function __get($key)
|
|
|
|
{
|
|
|
|
switch($key)
|
|
|
|
{
|
|
|
|
case 'cn': return $this->cn();
|
|
|
|
default:
|
|
|
|
throw new \App\Exceptions\SSLUnknownAttribute($key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function cn()
|
|
|
|
{
|
2020-01-11 11:05:05 +00:00
|
|
|
$subject = Arr::get($this->crt,'subject');
|
2018-07-16 05:06:43 +00:00
|
|
|
|
|
|
|
if (! $subject AND $this->csr_pem) {
|
|
|
|
$subject = openssl_csr_get_subject($this->csr_pem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return isset($subject['CN']) ? $subject['CN'] : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add CSR
|
|
|
|
*
|
|
|
|
* @param $value
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function csr($value)
|
|
|
|
{
|
|
|
|
$this->csr_pem = $value;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add certificate
|
|
|
|
*
|
|
|
|
* @param $value
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function crt($value)
|
|
|
|
{
|
|
|
|
$this->crt_pem = $value;
|
|
|
|
$this->crt = openssl_x509_parse($this->crt);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the Key
|
|
|
|
*
|
|
|
|
* @param $value
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function key($value)
|
|
|
|
{
|
|
|
|
$this->key_pem = $value;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|