|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MadWizard\WebAuthn\Attestation\Registry; |
|
4
|
|
|
|
|
5
|
|
|
use MadWizard\WebAuthn\Attestation\AttestationObject; |
|
6
|
|
|
use MadWizard\WebAuthn\Attestation\Statement\AttestationStatementInterface; |
|
7
|
|
|
use MadWizard\WebAuthn\Attestation\Statement\UnsupportedAttestationStatement; |
|
8
|
|
|
use MadWizard\WebAuthn\Attestation\Verifier\AttestationVerifierInterface; |
|
9
|
|
|
use MadWizard\WebAuthn\Attestation\Verifier\UnsupportedAttestationVerifier; |
|
10
|
|
|
use MadWizard\WebAuthn\Exception\FormatNotSupportedException; |
|
11
|
|
|
|
|
12
|
|
|
final class AttestationFormatRegistry implements AttestationFormatRegistryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var AttestationFormatInterface[] |
|
16
|
|
|
*/ |
|
17
|
|
|
private $formats = []; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var bool |
|
21
|
|
|
*/ |
|
22
|
|
|
private $strictSupportedFormats = true; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function addFormat(AttestationFormatInterface $format): void |
|
29
|
28 |
|
{ |
|
30
|
|
|
$this->formats[$format->getFormatId()] = $format; |
|
31
|
28 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function createStatement(AttestationObject $attestationObject): AttestationStatementInterface |
|
34
|
|
|
{ |
|
35
|
|
|
$formatId = $attestationObject->getFormat(); |
|
36
|
|
|
$format = $this->formats[$formatId] ?? null; |
|
37
|
|
|
if ($format === null) { |
|
38
|
22 |
|
if ($this->strictSupportedFormats) { |
|
39
|
|
|
throw new FormatNotSupportedException(sprintf('Format "%s" is not supported.', $formatId)); |
|
40
|
22 |
|
} |
|
41
|
22 |
|
return new UnsupportedAttestationStatement($attestationObject); |
|
42
|
|
|
} |
|
43
|
3 |
|
return $format->createStatement($attestationObject); |
|
44
|
|
|
} |
|
45
|
3 |
|
|
|
46
|
3 |
|
public function getVerifier(string $formatId): AttestationVerifierInterface |
|
47
|
3 |
|
{ |
|
48
|
1 |
|
$format = $this->formats[$formatId] ?? null; |
|
49
|
1 |
|
if ($format === null) { |
|
50
|
|
|
if ($this->strictSupportedFormats) { |
|
51
|
|
|
throw new FormatNotSupportedException(sprintf('Format "%s" is not supported.', $formatId)); |
|
52
|
|
|
} |
|
53
|
2 |
|
return new UnsupportedAttestationVerifier(); |
|
54
|
|
|
} |
|
55
|
|
|
return $format->getVerifier(); |
|
56
|
3 |
|
} |
|
57
|
|
|
|
|
58
|
3 |
|
public function strictSupportedFormats(bool $strict): void |
|
59
|
3 |
|
{ |
|
60
|
1 |
|
$this->strictSupportedFormats = $strict; |
|
61
|
1 |
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|