|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MadWizard\WebAuthn\Attestation; |
|
4
|
|
|
|
|
5
|
|
|
use MadWizard\WebAuthn\Exception\CborException; |
|
6
|
|
|
use MadWizard\WebAuthn\Exception\ParseException; |
|
7
|
|
|
use MadWizard\WebAuthn\Exception\WebAuthnException; |
|
8
|
|
|
use MadWizard\WebAuthn\Format\ByteBuffer; |
|
9
|
|
|
use MadWizard\WebAuthn\Format\CborDecoder; |
|
10
|
|
|
use MadWizard\WebAuthn\Format\CborMap; |
|
11
|
|
|
use MadWizard\WebAuthn\Format\DataValidator; |
|
12
|
|
|
|
|
13
|
|
|
final class AttestationObject |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $format; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var CborMap |
|
22
|
|
|
*/ |
|
23
|
|
|
private $statement; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var ByteBuffer |
|
27
|
|
|
*/ |
|
28
|
|
|
private $authData; |
|
29
|
|
|
|
|
30
|
35 |
|
public function __construct(string $format, CborMap $statement, ByteBuffer $authData) |
|
31
|
|
|
{ |
|
32
|
35 |
|
$this->format = $format; |
|
33
|
35 |
|
$this->statement = $statement; |
|
34
|
35 |
|
$this->authData = $authData; |
|
35
|
35 |
|
} |
|
36
|
|
|
|
|
37
|
37 |
|
public static function parse(ByteBuffer $buffer): self |
|
38
|
|
|
{ |
|
39
|
|
|
try { |
|
40
|
37 |
|
$data = CborDecoder::decode($buffer); |
|
41
|
36 |
|
if (!$data instanceof CborMap) { |
|
42
|
1 |
|
throw new WebAuthnException('Expecting attestation object to be a CBOR map.'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
35 |
|
DataValidator::checkMap( |
|
46
|
35 |
|
$data, |
|
47
|
|
|
[ |
|
48
|
35 |
|
'fmt' => 'string', |
|
49
|
|
|
'attStmt' => CborMap::class, |
|
50
|
|
|
'authData' => ByteBuffer::class, |
|
51
|
|
|
] |
|
52
|
|
|
); |
|
53
|
32 |
|
return new self($data->get('fmt'), $data->get('attStmt'), $data->get('authData')); |
|
54
|
5 |
|
} catch (CborException $e) { |
|
55
|
1 |
|
throw new ParseException('Failed to parse CBOR attestation object.', 0, $e); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
34 |
|
public function getFormat(): string |
|
60
|
|
|
{ |
|
61
|
34 |
|
return $this->format; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
31 |
|
public function getStatement(): CborMap |
|
65
|
|
|
{ |
|
66
|
31 |
|
return $this->statement; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
12 |
|
public function getAuthenticatorData(): ByteBuffer |
|
70
|
|
|
{ |
|
71
|
12 |
|
return $this->authData; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|