1 | <?php |
||
32 | class Registration |
||
33 | { |
||
34 | /** |
||
35 | * @ORM\Id |
||
36 | * @ORM\GeneratedValue(strategy="NONE") |
||
37 | * @ORM\Column(type="u2f_key_handle") |
||
38 | * |
||
39 | * @var KeyHandle |
||
40 | */ |
||
41 | private $keyHandle; |
||
42 | |||
43 | /** |
||
44 | * @ORM\Column(type="u2f_public_key") |
||
45 | * |
||
46 | * @var PublicKey |
||
47 | */ |
||
48 | private $publicKey; |
||
49 | |||
50 | /** |
||
51 | * @ORM\Column(type="integer") |
||
52 | * |
||
53 | * @var int |
||
54 | */ |
||
55 | private $signCounter; |
||
56 | |||
57 | /** |
||
58 | * @ORM\Column(type="datetime") |
||
59 | * |
||
60 | * @var DateTime |
||
61 | */ |
||
62 | private $lastUsed; |
||
63 | |||
64 | /** |
||
65 | * @param KeyHandle $keyHandle |
||
66 | * @param PublicKey $publicKey |
||
67 | */ |
||
68 | public function __construct(KeyHandle $keyHandle, PublicKey $publicKey) |
||
69 | { |
||
70 | $this->keyHandle = $keyHandle; |
||
71 | $this->publicKey = $publicKey; |
||
72 | $this->signCounter = 0; |
||
73 | $this->lastUsed = new DateTime(); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param int $newSignCounter |
||
78 | * @throws DomainException |
||
79 | */ |
||
80 | public function authenticationWasVerified($newSignCounter) |
||
81 | { |
||
82 | if (!is_int($newSignCounter)) { |
||
83 | throw InvalidArgumentException::invalidType('int', 'newSignCounter', $newSignCounter); |
||
84 | } |
||
85 | |||
86 | if ($newSignCounter <= $this->signCounter) { |
||
87 | throw new SignCounterTooLowException( |
||
88 | sprintf( |
||
89 | 'An authentication matching this registration was verified, but the sign counter "%d" was lower ' . |
||
90 | 'than or equal to the last known sign counter "%d". This registration must be invalidated.', |
||
91 | $newSignCounter, |
||
92 | $this->signCounter |
||
93 | ) |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | $this->signCounter = $newSignCounter; |
||
98 | $this->lastUsed = new DateTime(); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @return KeyHandle |
||
103 | */ |
||
104 | public function getKeyHandle() |
||
108 | |||
109 | /** |
||
110 | * @return PublicKey |
||
111 | */ |
||
112 | public function getPublicKey() |
||
116 | |||
117 | /** |
||
118 | * @return int |
||
119 | */ |
||
120 | public function getSignCounter() |
||
124 | } |
||
125 |