Skip to content

Commit

Permalink
Merge pull request #81 from realtimeregister/ssl
Browse files Browse the repository at this point in the history
Add SSL support
  • Loading branch information
glenn1001 authored Jul 15, 2024
2 parents dc08213 + a358a40 commit 923ae0a
Show file tree
Hide file tree
Showing 31 changed files with 883 additions and 36 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This SDK currently supports these APIs:
* [Providers API](https://dm.realtimeregister.com/docs/api/providers)
* [TLDs API](https://dm.realtimeregister.com/docs/api/tlds)
* [Processes API](https://dm.realtimeregister.com/docs/api/processes)
* [Certificates API](https://dm.realtimeregister.com/docs/api/ssl)

Are you missing functionality? Feel free to create an issue, or hit us up with a pull request.

Expand Down
10 changes: 6 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="clover.xml"/>
</report>
Expand All @@ -14,4 +11,9 @@
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
149 changes: 132 additions & 17 deletions src/Api/CertificatesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use DateTimeImmutable;
use SandwaveIo\RealtimeRegister\Domain\Certificate;
use SandwaveIo\RealtimeRegister\Domain\CertificateCollection;
use SandwaveIo\RealtimeRegister\Domain\CertificateInfoProcess;
use SandwaveIo\RealtimeRegister\Domain\DomainControlValidationCollection;
use SandwaveIo\RealtimeRegister\Domain\Enum\DownloadFormatEnum;
use SandwaveIo\RealtimeRegister\Domain\Product;
use SandwaveIo\RealtimeRegister\Domain\ProductCollection;
Expand Down Expand Up @@ -60,9 +62,10 @@ public function downloadCertificate(int $certificateId, string $format = 'CRT'):
}

/* @see https://dm.realtimeregister.com/docs/api/ssl/dcvemailaddresslist */
public function listDcvEmailAddresses(string $domainName): array
public function listDcvEmailAddresses(string $domainName, string $product = null): array
{
$response = $this->client->get('/v2/ssl/dcvemailaddresslist/' . $domainName);

$response = $this->client->get('/v2/ssl/dcvemailaddresslist/' . $domainName . ($product ? '?product=' . $product : ''));

return $response->json();
}
Expand Down Expand Up @@ -119,10 +122,14 @@ public function requestCertificate(
?string $city = null,
?string $coc = null,
?string $saEmail = null,
?string $saLanguage = null,
?array $approver = null,
?array $dcv = null
): int {
?string $country = null,
?string $language = null,
?array $dcv = null,
?string $domainName = null,
?string $authKey = null,
?string $state = null,
): CertificateInfoProcess {
$payload = [
'customer' => $customer,
'product' => $product,
Expand Down Expand Up @@ -154,6 +161,10 @@ public function requestCertificate(
$payload['city'] = $city;
}

if (! is_null($country)) {
$payload['country'] = $country;
}

if (! is_null($coc)) {
$payload['coc'] = $coc;
}
Expand All @@ -162,8 +173,8 @@ public function requestCertificate(
$payload['saEmail'] = $saEmail;
}

if (! is_null($saLanguage)) {
$payload['saLanguage'] = $saLanguage;
if (! is_null($language)) {
$payload['language'] = $language;
}

if (! is_null($approver)) {
Expand All @@ -174,9 +185,21 @@ public function requestCertificate(
$payload['dcv'] = $dcv;
}

if (! is_null($domainName)) {
$payload['domainName'] = $domainName;
}

if (! is_null($authKey)) {
$payload['authKey'] = $authKey;
}

if (! is_null($state)) {
$payload['state'] = $state;
}

$response = $this->client->post('/v2/ssl/certificates', $payload);

return (int) $response->headers()['x-process-id'][0];
return CertificateInfoProcess::fromArray(array_merge($response->json(), ['headers' => $response->headers()]));
}

/* @see https://dm.realtimeregister.com/docs/api/ssl/renew */
Expand All @@ -192,10 +215,15 @@ public function renewCertificate(
?string $city = null,
?string $coc = null,
?string $saEmail = null,
?string $saLanguage = null,
?array $approver = null,
?array $dcv = null
): int {
?string $country = null,
?string $language = null,
?array $dcv = null,
?string $domainName = null,
?string $authKey = null,
?string $state = null,
?string $product = null,
): CertificateInfoProcess {
$payload = [
'period' => $period,
'csr' => $csr,
Expand All @@ -213,6 +241,10 @@ public function renewCertificate(
$payload['department'] = $department;
}

if (! is_null($country)) {
$payload['country'] = $country;
}

if (! is_null($address)) {
$payload['address'] = $address;
}
Expand All @@ -233,8 +265,8 @@ public function renewCertificate(
$payload['saEmail'] = $saEmail;
}

if (! is_null($saLanguage)) {
$payload['saLanguage'] = $saLanguage;
if (! is_null($language)) {
$payload['language'] = $language;
}

if (! is_null($approver)) {
Expand All @@ -245,9 +277,25 @@ public function renewCertificate(
$payload['dcv'] = $dcv;
}

if (! is_null($domainName)) {
$payload['domainName'] = $domainName;
}

if (! is_null($authKey)) {
$payload['authKey'] = $authKey;
}

if (! is_null($state)) {
$payload['state'] = $state;
}

if (! is_null($product)) {
$payload['product'] = $product;
}

$response = $this->client->post('/v2/ssl/certificates/' . $certificateId . '/renew', $payload);

return (int) $response->headers()['x-process-id'][0];
return CertificateInfoProcess::fromArray(array_merge($response->json(), ['headers' => $response->headers()]));
}

/** @see https://dm.realtimeregister.com/docs/api/ssl/reissue */
Expand All @@ -262,8 +310,13 @@ public function reissueCertificate(
?string $city = null,
?string $coc = null,
?array $approver = null,
?array $dcv = null
): int {
?string $country = null,
?string $language = null,
?array $dcv = null,
?string $domainName = null,
?string $authKey = null,
?string $state = null,
): CertificateInfoProcess {
$payload = [
'csr' => $csr,
];
Expand All @@ -280,6 +333,10 @@ public function reissueCertificate(
$payload['department'] = $department;
}

if (! is_null($country)) {
$payload['country'] = $country;
}

if (! is_null($address)) {
$payload['address'] = $address;
}
Expand All @@ -296,6 +353,10 @@ public function reissueCertificate(
$payload['coc'] = $coc;
}

if (! is_null($language)) {
$payload['language'] = $language;
}

if (! is_null($approver)) {
$payload['approver'] = $approver;
}
Expand All @@ -304,9 +365,21 @@ public function reissueCertificate(
$payload['dcv'] = $dcv;
}

if (! is_null($domainName)) {
$payload['domainName'] = $domainName;
}

if (! is_null($authKey)) {
$payload['authKey'] = $authKey;
}

if (! is_null($state)) {
$payload['state'] = $state;
}

$response = $this->client->post('/v2/ssl/certificates/' . $certificateId . '/reissue', $payload);

return (int) $response->headers()['x-process-id'][0];
return CertificateInfoProcess::fromArray(array_merge($response->json(), ['headers' => $response->headers()]));
}

/* @see https://dm.realtimeregister.com/docs/api/ssl/revoke */
Expand Down Expand Up @@ -354,6 +427,15 @@ public function scheduleValidationCall(int $processId, DateTimeImmutable $date):
$this->client->post('/v2/processes/' . $processId . '/schedule-validation-call', $payload);
}

/** @see https://dm.realtimeregister.com/docs/api/processes/info */
public function info(int $processId): CertificateInfoProcess
{
$response = $this->client->get('/v2/processes/' . $processId . '/info');

return CertificateInfoProcess::fromArray(array_merge($response->json(), ['headers' => $response->headers()]));

}

/** @see https://dm.realtimeregister.com/docs/api/ssl/import */
public function importCertificate(string $customer, string $certificate, ?string $csr, ?string $coc): void
{
Expand All @@ -372,4 +454,37 @@ public function importCertificate(string $customer, string $certificate, ?string

$this->client->post('/v2/ssl/import', $payload);
}

/** @see https://dm.realtimeregister.com/docs/api/ssl/decocdecsr */
public function decodeCsr(string $csr): array
{
$response = $this->client->post('/v2/ssl/decodecsr', ['csr' => $csr]);

return $response->json();
}

/** @see https://dm.realtimeregister.com/docs/api/ssl/generate-authkey */
public function generateAuthKey(string $product, string $csr): array
{
$payload = [
'product' => $product,
'csr' => $csr,
];

$response = $this->client->post('/v2/ssl/authkey', $payload);

return $response->json();
}

/** @see https://dm.yoursrs-ote.com/docs/api/ssl/resenddcv */
public function resendDcv(int $processId, DomainControlValidationCollection $domainControlValidationCollection): array
{
$payload = [
'dcv' => $domainControlValidationCollection,
];

$response = $this->client->post('/v2/processes/' . $processId . '/resend', $payload);

return $response->json();
}
}
27 changes: 27 additions & 0 deletions src/Domain/AuthKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace SandwaveIo\RealtimeRegister\Domain;

use DateTime;

class AuthKey implements DomainObjectInterface
{
public function __construct(
public readonly string $authKey,
public readonly DateTime $validity
) {
}

public function toArray(): array
{
return [
'authKey' => $this->authKey,
'validity' => $this->validity->format('Y-m-d\TH:i:s\Z'),
];
}

public static function fromArray(array $json): AuthKey
{
return new AuthKey($json['authKey'], new DateTime($json['validity']));
}
}
46 changes: 46 additions & 0 deletions src/Domain/CertificateInfoProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types = 1);

namespace SandwaveIo\RealtimeRegister\Domain;

class CertificateInfoProcess implements DomainObjectInterface
{
public function __construct(
public string $commonName,
public bool $requiresAttention,
public ?int $certificateId,
public ?CertificateValidation $validations,
public ?int $processId
) {
}

public function toArray(): array
{
return array_filter([
'commonName' => $this->commonName,
'requiresAttention' => $this->requiresAttention,
'certificateId' => $this->certificateId,
'validations' => $this->validations?->toArray(),
'processId' => $this->processId,
], function ($x) {
return ! is_null($x);
});
}

public static function fromArray(array $json): CertificateInfoProcess
{
return new CertificateInfoProcess(
$json['commonName'],
$json['requiresAttention'],
$json['certificateId'],
CertificateValidation::fromArray($json['validations']),
array_key_exists('headers', $json) ? self::getProcessId($json['headers']) : null
);
}

private static function getProcessId(array $json): ?int
{
return array_key_exists('x-process-id', $json) ? (int) $json['x-process-id'][0] : null;
}
}
Loading

0 comments on commit 923ae0a

Please sign in to comment.