You are here

public function SiteClient::createCert in Lockr 7.2

Creates a new certificate.

Parameters

array $dn The distinguished name to create the CSR.:

Return value

string[] The private key and signed certificate.

File

vendor/lockr/lockr-client/src/SiteClient.php, line 33

Class

SiteClient
API for site management operations.

Namespace

Lockr

Code

public function createCert(array $dn) {
  $key = openssl_pkey_new(array(
    'private_key_bits' => 2048,
  ));
  if ($key === false) {
    throw new \RuntimeException('Could not create private key.');
  }
  if (!openssl_pkey_export($key, $key_text)) {
    throw new \RuntimeException('Could not export private key.');
  }
  $csr = openssl_csr_new($dn, $key);
  if (!openssl_csr_export($csr, $csr_text)) {
    throw new \RuntimeException('Could not export CSR.');
  }
  $body = $this->client
    ->post('/v1/create-cert', [
    'csr_text' => $csr_text,
  ]);
  return [
    'key_text' => $key_text,
    'cert_text' => $body['cert_text'],
  ];
}