Skip to content

Commit 3f2d594

Browse files
committed
first commit
0 parents  commit 3f2d594

File tree

8 files changed

+210
-0
lines changed

8 files changed

+210
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# PHP CertCentral
2+
PHP client for the DigiCert cert-central API.
3+
4+
# Usage
5+
```php
6+
<?php
7+
require_once 'vendor/autoload.php';
8+
9+
use Wahyuief\PhpCertcentral\Client;
10+
use Wahyuief\PhpCertcentral\Product;
11+
12+
// Config X-DC-DEVKEY
13+
new Client('YOUR_X_DC_DEVKEY');
14+
15+
// Print JSON Output
16+
echo Product::get();
17+
```

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "wahyuief/phpcertcentral",
3+
"description": "PHP Client for the DigiCert cert-central API.",
4+
"keywords": ["digicert", "certcentral", "ssl"],
5+
"license": "MIT",
6+
"require": {
7+
"php": "^8.1",
8+
"rmccue/requests": "^2.0"
9+
},
10+
"autoload": {
11+
"psr-4": {
12+
"Wahyuief\\PhpCertcentral\\": "src/"
13+
}
14+
},
15+
"authors": [
16+
{
17+
"name": "wahyuief",
18+
"email": "wahyuief@pm.me"
19+
}
20+
]
21+
}

src/Certificate.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace wahyuief\phpcertcentral;
4+
5+
use Wahyuief\PhpCertcentral\Util;
6+
use Wahyuief\PhpCertcentral\Client;
7+
8+
class Certificate {
9+
10+
public static function download($cert_id, $cert_format)
11+
{
12+
return Client::request('get', Util::base_url('certificate', $cert_id, 'download/format', $cert_format));
13+
}
14+
15+
public static function download_by_order($order_id, $cert_format)
16+
{
17+
return Client::request('get', Util::base_url('certificate', 'download/order', $order_id, 'format', $cert_format));
18+
}
19+
20+
public static function chain($cert_id)
21+
{
22+
return Client::request('get', Util::base_url('certificate', $cert_id, 'chain'));
23+
}
24+
25+
public static function revoke($cert_id)
26+
{
27+
return Client::request('put', Util::base_url('certificate', $cert_id, 'revoke'));
28+
}
29+
30+
}

src/Client.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace wahyuief\phpcertcentral;
4+
5+
use Wahyuief\PhpCertcentral\Util;
6+
use WpOrg\Requests\Requests;
7+
8+
class Client {
9+
10+
public static $digicert_token;
11+
public static $content_type;
12+
13+
public function __construct($digicert_token)
14+
{
15+
self::$digicert_token = $digicert_token;
16+
self::$content_type = 'application/json';
17+
}
18+
19+
public static function request(...$param)
20+
{
21+
$headers = array(
22+
'X-DC-DEVKEY' => self::$digicert_token,
23+
'Connection' => 'keep-alive',
24+
'Accept' => self::$content_type,
25+
'Content-Type' => self::$content_type,
26+
);
27+
28+
$options = array(
29+
'useragent' => 'wahyuief/phpcertcentral',
30+
'verify' => true,
31+
);
32+
33+
$method = $param[0];
34+
$response = (isset($param[2]) ? Requests::$method($param[1], $headers, $param[2], $options) : Requests::$method($param[1], $headers, $options));
35+
36+
return $response->body;
37+
}
38+
39+
}

src/Domain.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace wahyuief\phpcertcentral;
4+
5+
use Wahyuief\PhpCertcentral\Util;
6+
use Wahyuief\PhpCertcentral\Client;
7+
8+
class Domain {
9+
10+
public static function get($param = '')
11+
{
12+
return Client::request('get', Util::base_url('domain', $param));
13+
}
14+
15+
public static function get_by_name($name)
16+
{
17+
$datas = json_decode(self::get(), true);
18+
$data = array();
19+
$data['domains'] = array_filter($datas['domains'], function ($key) use ($name) {
20+
return str_contains(strtolower($key['name']), strtolower($name));
21+
});
22+
23+
return json_encode($data);
24+
}
25+
26+
}

src/Organization.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace wahyuief\phpcertcentral;
4+
5+
use Wahyuief\PhpCertcentral\Util;
6+
use Wahyuief\PhpCertcentral\Client;
7+
8+
class Organization {
9+
10+
public static function get($param = '')
11+
{
12+
return Client::request('get', Util::base_url('organization', $param));
13+
}
14+
15+
public static function get_by_name($name)
16+
{
17+
$datas = json_decode(self::get(), true);
18+
$data = array();
19+
$data['organizations'] = array_filter($datas['organizations'], function ($key) use ($name) {
20+
return str_contains(strtolower($key['name']), strtolower($name));
21+
});
22+
23+
return json_encode($data);
24+
}
25+
26+
}

src/Product.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace wahyuief\phpcertcentral;
4+
5+
use Wahyuief\PhpCertcentral\Util;
6+
use Wahyuief\PhpCertcentral\Client;
7+
8+
class Product {
9+
10+
public static function get($param = '')
11+
{
12+
return Client::request('get', Util::base_url('product', $param));
13+
}
14+
15+
public static function get_by_name($name)
16+
{
17+
$datas = json_decode(self::get(), true);
18+
$data = array();
19+
$data['products'] = array_filter($datas['products'], function ($key) use ($name) {
20+
return str_contains(strtolower($key['name']), strtolower($name));
21+
});
22+
23+
return json_encode($data);
24+
}
25+
26+
}

src/Util.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace wahyuief\phpcertcentral;
4+
5+
define('BASE_URL', 'https://www.digicert.com/services/v2');
6+
define('SEPARATOR', '/');
7+
8+
class Util {
9+
10+
public static function base_url(...$url) {
11+
return (str_ends_with(BASE_URL, SEPARATOR) ? BASE_URL : BASE_URL . SEPARATOR) . self::normalize($url);
12+
}
13+
14+
public static function normalize($url) {
15+
$normalized = array();
16+
foreach ($url as $key => $value) {
17+
if ($value) {
18+
$value = ltrim($value, SEPARATOR);
19+
$value = rtrim($value, SEPARATOR);
20+
$normalized[$key] = $value;
21+
}
22+
}
23+
return join(SEPARATOR, $normalized);
24+
}
25+
}

0 commit comments

Comments
 (0)