|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rogierw\RwAcme\Endpoints; |
|
4
|
|
|
|
|
5
|
|
|
use Rogierw\RwAcme\DTO\AccountData; |
|
6
|
|
|
use Rogierw\RwAcme\DTO\DomainValidationData; |
|
7
|
|
|
use Rogierw\RwAcme\DTO\OrderData; |
|
8
|
|
|
use Rogierw\RwAcme\Http\Response; |
|
9
|
|
|
use Rogierw\RwAcme\Support\Arr; |
|
10
|
|
|
use Rogierw\RwAcme\Support\JsonWebKey; |
|
11
|
|
|
|
|
12
|
|
|
class DomainValidation extends Endpoint |
|
13
|
|
|
{ |
|
14
|
|
|
const TYPE_HTTP = 'http-01'; |
|
15
|
|
|
const TYPE_DNS = 'dns-01'; |
|
16
|
|
|
|
|
17
|
|
|
/** @return DomainValidationData[] */ |
|
18
|
|
|
public function status(OrderData $orderData, string $type = 'all'): array |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
$data = []; |
|
21
|
|
|
|
|
22
|
|
|
foreach ($orderData->domainValidationUrls as $domainValidationUrl) { |
|
23
|
|
|
$response = $this->client |
|
24
|
|
|
->getHttpClient() |
|
25
|
|
|
->post( |
|
26
|
|
|
$domainValidationUrl, |
|
27
|
|
|
$this->createKeyId($orderData->accountUrl, $domainValidationUrl) |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
if ($response->getHttpResponseCode() === 200) { |
|
31
|
|
|
$data[] = DomainValidationData::fromResponse($response); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return $data; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getFileValidationData(DomainValidationData $domainValidation): array |
|
39
|
|
|
{ |
|
40
|
|
|
$thumbprint = JsonWebKey::thumbprint(JsonWebKey::compute($this->getAccountPrivateKey())); |
|
41
|
|
|
|
|
42
|
|
|
return [ |
|
43
|
|
|
'type' => self::TYPE_HTTP, |
|
44
|
|
|
'identifier' => $domainValidation->identifier['value'], |
|
45
|
|
|
'filename' => $domainValidation->file['token'], |
|
46
|
|
|
'content' => $domainValidation->file['token'] . '.' . $thumbprint, |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function start(AccountData $accountData, DomainValidationData $domainValidation): Response |
|
51
|
|
|
{ |
|
52
|
|
|
$this->client->logger( |
|
53
|
|
|
'info', |
|
54
|
|
|
'Start HTTP challenge for ' . Arr::get($domainValidation->identifier, 'value', '') |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
$thumbprint = JsonWebKey::thumbprint(JsonWebKey::compute($this->getAccountPrivateKey())); |
|
58
|
|
|
|
|
59
|
|
|
$payload = [ |
|
60
|
|
|
'keyAuthorization' => $domainValidation->file['token'] . '.' . $thumbprint, |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
$data = $this->createKeyId($accountData->url, $domainValidation->file['url'], $payload); |
|
64
|
|
|
|
|
65
|
|
|
return $this->client->getHttpClient()->post($domainValidation->file['url'], $data); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.