|
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\Base64; |
|
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
|
|
|
$digest = $this->createDigest(); |
|
41
|
|
|
|
|
42
|
|
|
return [ |
|
43
|
|
|
'type' => 'http', |
|
44
|
|
|
'identifier' => $domainValidation->identifier['value'], |
|
45
|
|
|
'filename' => $domainValidation->file['token'], |
|
46
|
|
|
'content' => $domainValidation->file['token'] . '.' . $digest, |
|
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
|
|
|
$digest = $this->createDigest(); |
|
58
|
|
|
|
|
59
|
|
|
$payload = [ |
|
60
|
|
|
'keyAuthorization' => $domainValidation->file['token'] . '.' . $digest, |
|
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
|
|
|
private function createDigest(): string |
|
69
|
|
|
{ |
|
70
|
|
|
$privateKeyContent = file_get_contents($this->client->getAccountKeysPath() . 'private.pem'); |
|
71
|
|
|
$privateKey = openssl_pkey_get_private($privateKeyContent); |
|
72
|
|
|
|
|
73
|
|
|
$details = openssl_pkey_get_details($privateKey); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$header = [ |
|
76
|
|
|
'e' => Base64::urlSafeEncode($details['rsa']['e']), |
|
77
|
|
|
'kty' => 'RSA', |
|
78
|
|
|
'n' => Base64::urlSafeEncode($details['rsa']['n']), |
|
79
|
|
|
]; |
|
80
|
|
|
|
|
81
|
|
|
return Base64::urlSafeEncode(hash('sha256', json_encode($header), true)); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.