|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MadWizard\WebAuthn\Attestation\Tpm; |
|
4
|
|
|
|
|
5
|
|
|
use MadWizard\WebAuthn\Exception\ParseException; |
|
6
|
|
|
use MadWizard\WebAuthn\Format\ByteBuffer; |
|
7
|
|
|
|
|
8
|
|
|
final class TpmAttest |
|
9
|
|
|
{ |
|
10
|
|
|
use TpmStructureTrait; |
|
11
|
|
|
|
|
12
|
|
|
private const TPM_GENERATED = "\xFF\x54\x43\x47"; |
|
13
|
|
|
|
|
14
|
|
|
public const TPM_ST_ATTEST_CERTIFY = 0x8017; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var ByteBuffer |
|
18
|
|
|
*/ |
|
19
|
|
|
private $attName; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var ByteBuffer |
|
23
|
|
|
*/ |
|
24
|
|
|
private $extraData; |
|
25
|
|
|
|
|
26
|
6 |
|
public function __construct(ByteBuffer $data) |
|
27
|
|
|
{ |
|
28
|
|
|
// Read magic |
|
29
|
6 |
|
$magic = $data->getBytes(0, 4); |
|
30
|
6 |
|
if ($magic !== self::TPM_GENERATED) { |
|
31
|
1 |
|
throw new ParseException('Magic bytes of TPM attestation are not TPM_GENERATED sequence.'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
// Read type |
|
35
|
5 |
|
$type = $data->getUint16Val(4); |
|
36
|
5 |
|
if ($type !== self::TPM_ST_ATTEST_CERTIFY) { |
|
37
|
1 |
|
throw new ParseException(sprintf('Wrong type for TPMS_ATTEST structure, expecting TPM_ST_ATTEST_CERTIFY, not 0x%04Xd.', $type)); |
|
38
|
|
|
} |
|
39
|
|
|
//$this->objectAttributes = $data->getUint32Val(6); |
|
40
|
|
|
|
|
41
|
4 |
|
$offset = 6; |
|
42
|
|
|
|
|
43
|
|
|
// qualifiedSigner |
|
44
|
4 |
|
self::readLengthPrefixed($data, $offset); |
|
45
|
|
|
|
|
46
|
|
|
// Extra data |
|
47
|
4 |
|
$this->extraData = self::readLengthPrefixed($data, $offset); |
|
48
|
|
|
|
|
49
|
|
|
// Clock info |
|
50
|
4 |
|
self::readFixed($data, $offset, 17); |
|
51
|
|
|
|
|
52
|
|
|
// Firmware version |
|
53
|
4 |
|
self::readFixed($data, $offset, 8); |
|
54
|
|
|
|
|
55
|
|
|
// Attested name |
|
56
|
4 |
|
$this->attName = self::readLengthPrefixed($data, $offset); |
|
57
|
|
|
|
|
58
|
|
|
// Attested qualified name |
|
59
|
4 |
|
self::readLengthPrefixed($data, $offset); |
|
60
|
|
|
|
|
61
|
4 |
|
if ($offset !== $data->getLength()) { |
|
62
|
1 |
|
throw new ParseException('Unexpected bytes after TPMS_ATTEST structure.'); |
|
63
|
|
|
} |
|
64
|
3 |
|
} |
|
65
|
|
|
|
|
66
|
3 |
|
public function getAttName(): ByteBuffer |
|
67
|
|
|
{ |
|
68
|
3 |
|
return $this->attName; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function getExtraData(): ByteBuffer |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->extraData; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|