1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWizard\WebAuthn\Server; |
4
|
|
|
|
5
|
|
|
use MadWizard\WebAuthn\Extension\ExtensionInputInterface; |
6
|
|
|
use MadWizard\WebAuthn\Format\ByteBuffer; |
7
|
|
|
use MadWizard\WebAuthn\Format\SerializableTrait; |
8
|
|
|
use MadWizard\WebAuthn\Web\Origin; |
9
|
|
|
|
10
|
|
|
abstract class AbstractContext |
11
|
|
|
{ |
12
|
|
|
use SerializableTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var ByteBuffer |
16
|
|
|
*/ |
17
|
|
|
private $challenge; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $rpId; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private $userVerificationRequired = false; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
private $userPresenceRequired = true; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Origin |
36
|
|
|
*/ |
37
|
|
|
private $origin; |
38
|
17 |
|
|
39
|
|
|
/** |
40
|
17 |
|
* @var ExtensionInputInterface[] |
41
|
17 |
|
*/ |
42
|
17 |
|
private $extensionInputs = []; |
43
|
17 |
|
|
44
|
|
|
public function __construct(ByteBuffer $challenge, Origin $origin, string $rpId) |
45
|
12 |
|
{ |
46
|
|
|
$this->challenge = $challenge; |
47
|
12 |
|
$this->origin = $origin; |
48
|
|
|
$this->rpId = $rpId; |
49
|
|
|
} |
50
|
7 |
|
|
51
|
|
|
public function getChallenge(): ByteBuffer |
52
|
7 |
|
{ |
53
|
|
|
return $this->challenge; |
54
|
|
|
} |
55
|
5 |
|
|
56
|
|
|
public function getRpId(): string |
57
|
5 |
|
{ |
58
|
|
|
return $this->rpId; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function isUserVerificationRequired(): bool |
62
|
|
|
{ |
63
|
|
|
return $this->userVerificationRequired; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function setUserVerificationRequired(bool $required): void |
67
|
|
|
{ |
68
|
|
|
$this->userVerificationRequired = $required; |
69
|
|
|
} |
70
|
2 |
|
|
71
|
|
|
public function isUserPresenceRequired(): bool |
72
|
2 |
|
{ |
73
|
2 |
|
return $this->userPresenceRequired; |
74
|
|
|
} |
75
|
10 |
|
|
76
|
|
|
public function setUserPresenceRequired(bool $required): void |
77
|
10 |
|
{ |
78
|
|
|
$this->userPresenceRequired = $required; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getOrigin(): Origin |
82
|
|
|
{ |
83
|
|
|
return $this->origin; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function addExtensionInput(ExtensionInputInterface $input) |
87
|
|
|
{ |
88
|
|
|
$this->extensionInputs[] = $input; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return ExtensionInputInterface[] |
93
|
|
|
*/ |
94
|
|
|
public function getExtensionInputs(): array |
95
|
|
|
{ |
96
|
|
|
return $this->extensionInputs; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function __serialize(): array |
100
|
|
|
{ |
101
|
|
|
return [ |
102
|
|
|
'challenge' => $this->challenge, |
103
|
|
|
'rpId' => $this->rpId, |
104
|
|
|
'userVerificationRequired' => $this->userVerificationRequired, |
105
|
|
|
'origin' => $this->origin, |
106
|
|
|
'userPresenceRequired' => $this->userPresenceRequired, |
107
|
|
|
'extensionInputs' => $this->extensionInputs, |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function __unserialize(array $data): void |
112
|
|
|
{ |
113
|
|
|
$this->challenge = $data['challenge']; |
114
|
|
|
$this->rpId = $data['rpId']; |
115
|
|
|
$this->userVerificationRequired = $data['userVerificationRequired']; |
116
|
|
|
$this->origin = $data['origin']; |
117
|
|
|
$this->userPresenceRequired = $data['userPresenceRequired']; |
118
|
|
|
$this->extensionInputs = $data['extensionInputs']; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|