|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MadWizard\WebAuthn\Attestation\Statement; |
|
4
|
|
|
|
|
5
|
|
|
use MadWizard\WebAuthn\Attestation\AttestationObject; |
|
6
|
|
|
use MadWizard\WebAuthn\Crypto\CoseAlgorithm; |
|
7
|
|
|
use MadWizard\WebAuthn\Exception\DataValidationException; |
|
8
|
|
|
use MadWizard\WebAuthn\Exception\ParseException; |
|
9
|
|
|
use MadWizard\WebAuthn\Format\ByteBuffer; |
|
10
|
|
|
use MadWizard\WebAuthn\Format\DataValidator; |
|
11
|
|
|
use MadWizard\WebAuthn\Pki\X509Certificate; |
|
12
|
|
|
|
|
13
|
|
|
class AndroidKeyAttestationStatement extends AbstractAttestationStatement |
|
14
|
|
|
{ |
|
15
|
|
|
public const FORMAT_ID = 'android-key'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var ByteBuffer |
|
19
|
|
|
*/ |
|
20
|
|
|
private $signature; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var X509Certificate[] |
|
24
|
|
|
*/ |
|
25
|
|
|
private $certificates; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @see CoseAlgorithm enumeration |
|
29
|
|
|
* |
|
30
|
|
|
* @var int |
|
31
|
|
|
*/ |
|
32
|
|
|
private $algorithm; |
|
33
|
|
|
|
|
34
|
3 |
|
public function __construct(AttestationObject $attestationObject) |
|
35
|
|
|
{ |
|
36
|
3 |
|
parent::__construct($attestationObject, self::FORMAT_ID); |
|
37
|
|
|
|
|
38
|
3 |
|
$statement = $attestationObject->getStatement(); |
|
39
|
|
|
|
|
40
|
|
|
try { |
|
41
|
3 |
|
DataValidator::checkMap( |
|
42
|
3 |
|
$statement, |
|
43
|
|
|
[ |
|
44
|
3 |
|
'alg' => 'integer', |
|
45
|
|
|
'x5c' => 'array', |
|
46
|
|
|
'sig' => ByteBuffer::class, |
|
47
|
|
|
] |
|
48
|
|
|
); |
|
49
|
1 |
|
} catch (DataValidationException $e) { |
|
50
|
1 |
|
throw new ParseException('Invalid Android key attestation statement.', 0, $e); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
$this->signature = $statement->get('sig'); |
|
54
|
2 |
|
$this->algorithm = $statement->get('alg'); |
|
55
|
2 |
|
$this->certificates = $this->buildPEMCertificateArray($statement->get('x5c')); |
|
56
|
2 |
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
public function getAlgorithm(): int |
|
59
|
|
|
{ |
|
60
|
2 |
|
return $this->algorithm; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
public function getSignature(): ByteBuffer |
|
64
|
|
|
{ |
|
65
|
2 |
|
return $this->signature; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return X509Certificate[] |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public function getCertificates(): array |
|
72
|
|
|
{ |
|
73
|
2 |
|
return $this->certificates; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|