1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace U2FAuthentication\Fido2; |
15
|
|
|
|
16
|
|
|
use U2FAuthentication\Fido2\AuthenticationExtensions\AuthenticationExtensionsClientOutputs; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @see https://www.w3.org/TR/webauthn/#sec-authenticator-data |
20
|
|
|
*/ |
21
|
|
|
class AuthenticatorData |
22
|
|
|
{ |
23
|
|
|
private $authData; |
24
|
|
|
|
25
|
|
|
private $rpIdHash; |
26
|
|
|
|
27
|
|
|
private $flags; |
28
|
|
|
|
29
|
|
|
private $signCount; |
30
|
|
|
|
31
|
|
|
private $attestedCredentialData; |
32
|
|
|
|
33
|
|
|
private $extensions; |
34
|
|
|
|
35
|
|
|
private const FLAG_UP = 0b00000001; |
36
|
|
|
private const FLAG_RFU1 = 0b00000010; |
37
|
|
|
private const FLAG_UV = 0b00000100; |
38
|
|
|
private const FLAG_RFU2 = 0b00111000; |
39
|
|
|
private const FLAG_AT = 0b01000000; |
40
|
|
|
private const FLAG_ED = 0b10000000; |
41
|
|
|
|
42
|
|
|
public function __construct(string $authData, string $rpIdHash, string $flags, int $signCount, ?AttestedCredentialData $attestedCredentialData, ?AuthenticationExtensionsClientOutputs $extensions) |
43
|
|
|
{ |
44
|
|
|
$this->rpIdHash = $rpIdHash; |
45
|
|
|
$this->flags = $flags; |
46
|
|
|
$this->signCount = $signCount; |
47
|
|
|
$this->attestedCredentialData = $attestedCredentialData; |
48
|
|
|
$this->extensions = $extensions; |
49
|
|
|
$this->authData = $authData; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getAuthData(): string |
53
|
|
|
{ |
54
|
|
|
return $this->authData; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getRpIdHash(): string |
58
|
|
|
{ |
59
|
|
|
return $this->rpIdHash; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function isUserPresent(): bool |
63
|
|
|
{ |
64
|
|
|
return \ord($this->flags) & self::FLAG_UP ? true : false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function isUserVerified(): bool |
68
|
|
|
{ |
69
|
|
|
return \ord($this->flags) & self::FLAG_UV ? true : false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function hasAttestedCredentialData(): bool |
73
|
|
|
{ |
74
|
|
|
return \ord($this->flags) & self::FLAG_AT ? true : false; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function hasExtensions(): bool |
78
|
|
|
{ |
79
|
|
|
return \ord($this->flags) & self::FLAG_ED ? true : false; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getReservedForFutureUse1(): int |
83
|
|
|
{ |
84
|
|
|
return \ord($this->flags) & self::FLAG_RFU1; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getReservedForFutureUse2(): int |
88
|
|
|
{ |
89
|
|
|
return \ord($this->flags) & self::FLAG_RFU2; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getSignCount(): int |
93
|
|
|
{ |
94
|
|
|
return $this->signCount; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getAttestedCredentialData(): ?AttestedCredentialData |
98
|
|
|
{ |
99
|
|
|
return $this->attestedCredentialData; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getExtensions(): ?AuthenticationExtensionsClientOutputs |
103
|
|
|
{ |
104
|
|
|
return $this->extensions; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|