mirror of
https://github.com/anikeen-com/yaac.git
synced 2026-03-21 17:37:42 +00:00
naming changes
readme update
This commit is contained in:
@@ -195,6 +195,12 @@ file_put_contents('certificate.cert', $certificate->getCertificate());
|
|||||||
file_put_contents('private.key', $certificate->getPrivateKey());
|
file_put_contents('private.key', $certificate->getPrivateKey());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
>To get a seperate intermediate certificate and domain certificate:
|
||||||
|
>```php
|
||||||
|
>$domainCertificate = $certificate->getCertificate(false);
|
||||||
|
>$intermediateCertificate = $certificate->getIntermediate();
|
||||||
|
>```
|
||||||
|
|
||||||
### Who is using it?
|
### Who is using it?
|
||||||
|
|
||||||
Are you using this package, would love to know. Please send a PR to enlist your project or company.
|
Are you using this package, would love to know. Please send a PR to enlist your project or company.
|
||||||
|
|||||||
@@ -331,8 +331,8 @@ class Client
|
|||||||
$data['certificate'],
|
$data['certificate'],
|
||||||
$this->signPayloadKid(null, $data['certificate'])
|
$this->signPayloadKid(null, $data['certificate'])
|
||||||
);
|
);
|
||||||
$certificate = $str = preg_replace('/^[ \t]*[\r\n]+/m', '', (string)$certificateResponse->getBody());
|
$chain = $str = preg_replace('/^[ \t]*[\r\n]+/m', '', (string)$certificateResponse->getBody());
|
||||||
return new Certificate($privateKey, $csr, $certificate);
|
return new Certificate($privateKey, $csr, $chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ class Certificate
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $certificate;
|
protected $chain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $certificateNoChain;
|
protected $certificate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
@@ -41,16 +41,16 @@ class Certificate
|
|||||||
* Certificate constructor.
|
* Certificate constructor.
|
||||||
* @param $privateKey
|
* @param $privateKey
|
||||||
* @param $csr
|
* @param $csr
|
||||||
* @param $certificate
|
* @param $chain
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function __construct($privateKey, $csr, $certificate)
|
public function __construct($privateKey, $csr, $chain)
|
||||||
{
|
{
|
||||||
$this->privateKey = $privateKey;
|
$this->privateKey = $privateKey;
|
||||||
$this->csr = $csr;
|
$this->csr = $csr;
|
||||||
$this->certificate = $certificate;
|
$this->chain = $chain;
|
||||||
list($this->certificateNoChain, $this->intermediateCertificate) = Helper::splitCertificate($certificate);
|
list($this->certificate, $this->intermediateCertificate) = Helper::splitCertificate($chain);
|
||||||
$this->expiryDate = Helper::getCertExpiryDate($certificate);
|
$this->expiryDate = Helper::getCertExpiryDate($chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,19 +72,21 @@ class Certificate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the certificate as a multi line string
|
* Return the certificate as a multi line string, by default it includes the intermediate certificate as well
|
||||||
|
*
|
||||||
|
* @param bool $asChain
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCertificate($asChain = true): string
|
public function getCertificate($asChain = true): string
|
||||||
{
|
{
|
||||||
return $asChain ? $this->certificate : $this->certificateNoChain;
|
return $asChain ? $this->chain : $this->certificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the intermediate certificate as a multi line string
|
* Return the intermediate certificate as a multi line string
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getIntermediateCertificate(): string
|
public function getIntermediate(): string
|
||||||
{
|
{
|
||||||
return $this->intermediateCertificate;
|
return $this->intermediateCertificate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,23 +140,27 @@ class Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split a two certificate bundle into separate
|
* Split a two certificate bundle into separate multi line string certificates
|
||||||
* multi line string certificates
|
* @param string $chain
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function splitCertificate(string $certificate): array
|
public static function splitCertificate(string $chain): array
|
||||||
{
|
{
|
||||||
preg_match('/^(?<signed>-----BEGIN CERTIFICATE-----.+?-----END CERTIFICATE-----)\n'
|
preg_match(
|
||||||
|
'/^(?<domain>-----BEGIN CERTIFICATE-----.+?-----END CERTIFICATE-----)\n'
|
||||||
. '(?<intermediate>-----BEGIN CERTIFICATE-----.+?-----END CERTIFICATE-----)$/s',
|
. '(?<intermediate>-----BEGIN CERTIFICATE-----.+?-----END CERTIFICATE-----)$/s',
|
||||||
$certificate, $certificates);
|
$chain,
|
||||||
|
$certificates
|
||||||
|
);
|
||||||
|
|
||||||
$signed = $certificates['signed'] ?? null;
|
$domain = $certificates['domain'] ?? null;
|
||||||
$intermediate = $certificates['intermediate'] ?? null;
|
$intermediate = $certificates['intermediate'] ?? null;
|
||||||
|
|
||||||
if (!$signed || !$intermediate) {
|
if (!$domain || !$intermediate) {
|
||||||
throw new \Exception('Could not parse certificate string');
|
throw new \Exception('Could not parse certificate string');
|
||||||
}
|
}
|
||||||
|
|
||||||
return [$signed, $intermediate];
|
return [$domain, $intermediate];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user