mirror of
https://github.com/anikeen-com/yaac.git
synced 2026-03-20 17:16:06 +00:00
Add ability to set custom key length
This commit is contained in:
@@ -138,6 +138,11 @@ class Client
|
|||||||
$this->init();
|
$this->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getKeyLength(): int
|
||||||
|
{
|
||||||
|
return $config['key_length'] ?? 4096;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an existing order by ID
|
* Get an existing order by ID
|
||||||
*
|
*
|
||||||
@@ -316,7 +321,7 @@ class Client
|
|||||||
*/
|
*/
|
||||||
public function getCertificate(Order $order): Certificate
|
public function getCertificate(Order $order): Certificate
|
||||||
{
|
{
|
||||||
$privateKey = Helper::getNewKey();
|
$privateKey = Helper::getNewKey($this->getKeyLength());
|
||||||
$csr = Helper::getCsr($order->getDomains(), $privateKey);
|
$csr = Helper::getCsr($order->getDomains(), $privateKey);
|
||||||
$der = Helper::toDer($csr);
|
$der = Helper::toDer($csr);
|
||||||
|
|
||||||
@@ -493,7 +498,7 @@ class Client
|
|||||||
{
|
{
|
||||||
//Make sure a private key is in place
|
//Make sure a private key is in place
|
||||||
if ($this->getFilesystem()->has($this->getPath('account.pem')) === false) {
|
if ($this->getFilesystem()->has($this->getPath('account.pem')) === false) {
|
||||||
$this->getFilesystem()->write($this->getPath('account.pem'), Helper::getNewKey());
|
$this->getFilesystem()->write($this->getPath('account.pem'), Helper::getNewKey($this->getKeyLength()));
|
||||||
}
|
}
|
||||||
$privateKey = $this->getFilesystem()->read($this->getPath('account.pem'));
|
$privateKey = $this->getFilesystem()->read($this->getPath('account.pem'));
|
||||||
$privateKey = openssl_pkey_get_private($privateKey);
|
$privateKey = openssl_pkey_get_private($privateKey);
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ class Helper
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getNewKey(): string
|
public static function getNewKey(int $keyLength): string
|
||||||
{
|
{
|
||||||
|
|
||||||
$key = openssl_pkey_new([
|
$key = openssl_pkey_new([
|
||||||
'private_key_bits' => 2048,
|
'private_key_bits' => $keyLength,
|
||||||
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||||
]);
|
]);
|
||||||
openssl_pkey_export($key, $pem);
|
openssl_pkey_export($key, $pem);
|
||||||
|
|||||||
Reference in New Issue
Block a user