@@ -88,7 +88,7 @@ |
||
88 | 88 | * |
89 | 89 | * Do not return false in case a specific user disabeld this module, |
90 | 90 | * OR if the user is unable to use this specific module. |
91 | - * @return boolean |
|
91 | + * @return boolean|null |
|
92 | 92 | */ |
93 | 93 | public function is_enabled() |
94 | 94 | { |
@@ -20,7 +20,6 @@ |
||
20 | 20 | use phpbb\template\template; |
21 | 21 | use phpbb\user; |
22 | 22 | use phpbrowscap\Browscap; |
23 | -use ReflectionObject; |
|
24 | 23 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
25 | 24 | use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
26 | 25 |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * |
|
4 | - * 2FA extension for the phpBB Forum Software package. |
|
5 | - * |
|
6 | - * @copyright (c) 2015 Paul Sohier |
|
7 | - * @license GNU General Public License, version 2 (GPL-2.0) |
|
8 | - * |
|
9 | - */ |
|
3 | + * |
|
4 | + * 2FA extension for the phpBB Forum Software package. |
|
5 | + * |
|
6 | + * @copyright (c) 2015 Paul Sohier |
|
7 | + * @license GNU General Public License, version 2 (GPL-2.0) |
|
8 | + * |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | namespace paul999\tfa\modules; |
12 | 12 | |
@@ -27,456 +27,456 @@ discard block |
||
27 | 27 | class u2f implements module_interface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var driver_interface |
|
32 | - */ |
|
33 | - private $db; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var user |
|
37 | - */ |
|
38 | - private $user; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var request_interface |
|
42 | - */ |
|
43 | - private $request; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var template |
|
47 | - */ |
|
48 | - private $template; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - private $registration_table; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var \paul999\u2f\U2F |
|
57 | - */ |
|
58 | - private $u2f; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - private $reg_data; |
|
64 | - |
|
65 | - /** |
|
66 | - * u2f constructor. |
|
67 | - * @param driver_interface $db |
|
68 | - * @param user $user |
|
69 | - * @param request_interface $request |
|
70 | - * @param template $template |
|
71 | - * @param string $registration_table |
|
72 | - */ |
|
73 | - public function __construct(driver_interface $db, user $user, request_interface $request, template $template, $registration_table) |
|
74 | - { |
|
75 | - $this->db = $db; |
|
76 | - $this->user = $user; |
|
77 | - $this->request = $request; |
|
78 | - $this->template = $template; |
|
79 | - |
|
80 | - $this->registration_table = $registration_table; |
|
81 | - |
|
82 | - $this->u2f = new \paul999\u2f\U2F('https://' . $this->request->server('HTTP_HOST')); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Return if this module is enabled by the admin |
|
87 | - * (And all server requirements are met). |
|
88 | - * |
|
89 | - * Do not return false in case a specific user disabeld this module, |
|
90 | - * OR if the user is unable to use this specific module. |
|
91 | - * @return boolean |
|
92 | - */ |
|
93 | - public function is_enabled() |
|
94 | - { |
|
95 | - // TODO: Implement is_enabled() method. |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Check if the current user is able to use this module. |
|
100 | - * |
|
101 | - * This means that the user enabled it in the UCP, |
|
102 | - * And has it setup up correctly. |
|
103 | - * This method will be called during login, not during registration/ |
|
104 | - * |
|
105 | - * @param int $user_id |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public function is_usable($user_id) |
|
109 | - { |
|
110 | - $browscap = new Browscap(); |
|
111 | - $info = $browscap->getBrowser(); |
|
112 | - if ($info['Browser'] !== 'chrome') |
|
113 | - { |
|
114 | - return false; // u2f is currently only supported in chrome! |
|
115 | - } |
|
116 | - $sql = 'SELECT COUNT(registration_id) as reg_id FROM ' . $this->registration_table . ' WHERE user_id = ' . (int) $user_id; |
|
117 | - $result = $this->db->sql_query($sql); |
|
118 | - $row = $this->db->sql_fetchrow($result); |
|
119 | - $this->db->sql_freeresult($result); |
|
120 | - |
|
121 | - return $row && $row['reg_id'] > 0; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Check if the user can potentially use this. |
|
126 | - * This method is called at registration page. |
|
127 | - * |
|
128 | - * You can, for example, check if the current browser is suitable. |
|
129 | - * |
|
130 | - * @param int $user_id |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function is_potentially_usable($user_id) |
|
134 | - { |
|
135 | - $browsercap = new Browscap(); |
|
136 | - $info = $browsercap->getBrowser(); |
|
137 | - return $info['Browser'] === 'chrome'; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Get the priority for this module. |
|
142 | - * A lower priority means more chance it gets selected as default option |
|
143 | - * |
|
144 | - * There can be only one module with a specific priority! |
|
145 | - * If there is already a module registered with this priority, |
|
146 | - * a Exception might be thrown |
|
147 | - * |
|
148 | - * @param int $user_id If set, the priority can depend on the current user |
|
149 | - * @return int |
|
150 | - */ |
|
151 | - public function get_priority($user_id = 0) |
|
152 | - { |
|
153 | - return 10; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Start of the login procedure. |
|
158 | - * @param int $user_id |
|
159 | - * @return void |
|
160 | - * @throws BadRequestHttpException |
|
161 | - */ |
|
162 | - public function login_start($user_id) |
|
163 | - { |
|
164 | - $registrations = json_encode($this->u2f->getAuthenticateData($this->getRegistrations($user_id)), JSON_UNESCAPED_SLASHES); |
|
165 | - |
|
166 | - $sql_ary = array( |
|
167 | - 'u2f_request' => $registrations |
|
168 | - ); |
|
169 | - |
|
170 | - $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' |
|
30 | + /** |
|
31 | + * @var driver_interface |
|
32 | + */ |
|
33 | + private $db; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var user |
|
37 | + */ |
|
38 | + private $user; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var request_interface |
|
42 | + */ |
|
43 | + private $request; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var template |
|
47 | + */ |
|
48 | + private $template; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + private $registration_table; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var \paul999\u2f\U2F |
|
57 | + */ |
|
58 | + private $u2f; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + private $reg_data; |
|
64 | + |
|
65 | + /** |
|
66 | + * u2f constructor. |
|
67 | + * @param driver_interface $db |
|
68 | + * @param user $user |
|
69 | + * @param request_interface $request |
|
70 | + * @param template $template |
|
71 | + * @param string $registration_table |
|
72 | + */ |
|
73 | + public function __construct(driver_interface $db, user $user, request_interface $request, template $template, $registration_table) |
|
74 | + { |
|
75 | + $this->db = $db; |
|
76 | + $this->user = $user; |
|
77 | + $this->request = $request; |
|
78 | + $this->template = $template; |
|
79 | + |
|
80 | + $this->registration_table = $registration_table; |
|
81 | + |
|
82 | + $this->u2f = new \paul999\u2f\U2F('https://' . $this->request->server('HTTP_HOST')); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Return if this module is enabled by the admin |
|
87 | + * (And all server requirements are met). |
|
88 | + * |
|
89 | + * Do not return false in case a specific user disabeld this module, |
|
90 | + * OR if the user is unable to use this specific module. |
|
91 | + * @return boolean |
|
92 | + */ |
|
93 | + public function is_enabled() |
|
94 | + { |
|
95 | + // TODO: Implement is_enabled() method. |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Check if the current user is able to use this module. |
|
100 | + * |
|
101 | + * This means that the user enabled it in the UCP, |
|
102 | + * And has it setup up correctly. |
|
103 | + * This method will be called during login, not during registration/ |
|
104 | + * |
|
105 | + * @param int $user_id |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public function is_usable($user_id) |
|
109 | + { |
|
110 | + $browscap = new Browscap(); |
|
111 | + $info = $browscap->getBrowser(); |
|
112 | + if ($info['Browser'] !== 'chrome') |
|
113 | + { |
|
114 | + return false; // u2f is currently only supported in chrome! |
|
115 | + } |
|
116 | + $sql = 'SELECT COUNT(registration_id) as reg_id FROM ' . $this->registration_table . ' WHERE user_id = ' . (int) $user_id; |
|
117 | + $result = $this->db->sql_query($sql); |
|
118 | + $row = $this->db->sql_fetchrow($result); |
|
119 | + $this->db->sql_freeresult($result); |
|
120 | + |
|
121 | + return $row && $row['reg_id'] > 0; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Check if the user can potentially use this. |
|
126 | + * This method is called at registration page. |
|
127 | + * |
|
128 | + * You can, for example, check if the current browser is suitable. |
|
129 | + * |
|
130 | + * @param int $user_id |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function is_potentially_usable($user_id) |
|
134 | + { |
|
135 | + $browsercap = new Browscap(); |
|
136 | + $info = $browsercap->getBrowser(); |
|
137 | + return $info['Browser'] === 'chrome'; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Get the priority for this module. |
|
142 | + * A lower priority means more chance it gets selected as default option |
|
143 | + * |
|
144 | + * There can be only one module with a specific priority! |
|
145 | + * If there is already a module registered with this priority, |
|
146 | + * a Exception might be thrown |
|
147 | + * |
|
148 | + * @param int $user_id If set, the priority can depend on the current user |
|
149 | + * @return int |
|
150 | + */ |
|
151 | + public function get_priority($user_id = 0) |
|
152 | + { |
|
153 | + return 10; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Start of the login procedure. |
|
158 | + * @param int $user_id |
|
159 | + * @return void |
|
160 | + * @throws BadRequestHttpException |
|
161 | + */ |
|
162 | + public function login_start($user_id) |
|
163 | + { |
|
164 | + $registrations = json_encode($this->u2f->getAuthenticateData($this->getRegistrations($user_id)), JSON_UNESCAPED_SLASHES); |
|
165 | + |
|
166 | + $sql_ary = array( |
|
167 | + 'u2f_request' => $registrations |
|
168 | + ); |
|
169 | + |
|
170 | + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' |
|
171 | 171 | WHERE |
172 | 172 | session_id = \'' . $this->db->sql_escape($this->user->data['session_id']) . '\' AND |
173 | 173 | session_user_id = ' . (int) $this->user->data['user_id']; |
174 | - $this->db->sql_query($sql); |
|
175 | - $count = $this->db->sql_affectedrows(); |
|
176 | - |
|
177 | - if ($count != 1) |
|
178 | - { |
|
179 | - if ($count > 1) |
|
180 | - { |
|
181 | - // Reset sessions table. We had multiple sessions with same ID!!! |
|
182 | - $sql_ary['u2f_request'] = ''; |
|
183 | - $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' |
|
174 | + $this->db->sql_query($sql); |
|
175 | + $count = $this->db->sql_affectedrows(); |
|
176 | + |
|
177 | + if ($count != 1) |
|
178 | + { |
|
179 | + if ($count > 1) |
|
180 | + { |
|
181 | + // Reset sessions table. We had multiple sessions with same ID!!! |
|
182 | + $sql_ary['u2f_request'] = ''; |
|
183 | + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' |
|
184 | 184 | WHERE |
185 | 185 | session_id = \'' . $this->db->sql_escape($this->user->data['session_id']) . '\' AND |
186 | 186 | session_user_id = ' . (int) $this->user->data['user_id']; |
187 | - $this->db->sql_query($sql); |
|
188 | - } |
|
189 | - throw new BadRequestHttpException('TFA_UNABLE_TO_UPDATE_SESSION'); |
|
190 | - } |
|
191 | - |
|
192 | - $this->template->assign_var('U2F_REQ', $registrations); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Actual login procedure |
|
197 | - * @param int $user_id |
|
198 | - * @throws AccessDeniedHttpException |
|
199 | - */ |
|
200 | - public function login($user_id) |
|
201 | - { |
|
202 | - try { |
|
203 | - $sql = 'SELECT u2f_request FROM ' . SESSIONS_TABLE . ' WHERE |
|
187 | + $this->db->sql_query($sql); |
|
188 | + } |
|
189 | + throw new BadRequestHttpException('TFA_UNABLE_TO_UPDATE_SESSION'); |
|
190 | + } |
|
191 | + |
|
192 | + $this->template->assign_var('U2F_REQ', $registrations); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Actual login procedure |
|
197 | + * @param int $user_id |
|
198 | + * @throws AccessDeniedHttpException |
|
199 | + */ |
|
200 | + public function login($user_id) |
|
201 | + { |
|
202 | + try { |
|
203 | + $sql = 'SELECT u2f_request FROM ' . SESSIONS_TABLE . ' WHERE |
|
204 | 204 | session_id = \'' . $this->db->sql_escape($this->user->data['session_id']) . '\' AND |
205 | 205 | session_user_id = ' . (int)$this->user->data['user_id']; |
206 | - $result = $this->db->sql_query($sql); |
|
207 | - $row = $this->db->sql_fetchrow($result); |
|
208 | - $this->db->sql_freeresult($result); |
|
209 | - |
|
210 | - if (!$row || empty($row['u2f_request'])) { |
|
211 | - throw new AccessDeniedHttpException($this->user->lang('TFA_NO_ACCESS')); |
|
212 | - } |
|
213 | - |
|
214 | - $response = json_decode(htmlspecialchars_decode($this->request->variable('authenticate', ''))); |
|
215 | - |
|
216 | - if (property_exists($response, 'errorCode')) { |
|
217 | - if ($response->errorCode == 4) // errorCode 4 means that this device wasn't registered |
|
218 | - { |
|
219 | - throw new AccessDeniedHttpException($this->user->lang('TFA_NOT_REGISTERED')); |
|
220 | - } |
|
221 | - throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG')); |
|
222 | - } |
|
223 | - $result = new AuthenticationResponse($response->signatureData, $response->clientData, $response->keyHandle, $response->errorCode); |
|
224 | - |
|
225 | - /** @var \paul999\tfa\helper\registration_helper $reg */ |
|
226 | - $reg = $this->u2f->doAuthenticate($this->convertRequests(json_decode($row['u2f_request'])), $this->getRegistrations($user_id), $result); |
|
227 | - $sql_ary = array( |
|
228 | - 'counter' => $reg->getCounter(), |
|
229 | - 'last_used' => time(), |
|
230 | - ); |
|
231 | - |
|
232 | - $sql = 'UPDATE ' . $this->registration_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE registration_id = ' . (int)$reg->id; |
|
233 | - $this->db->sql_query($sql); |
|
234 | - } |
|
235 | - catch (U2fError $error) |
|
206 | + $result = $this->db->sql_query($sql); |
|
207 | + $row = $this->db->sql_fetchrow($result); |
|
208 | + $this->db->sql_freeresult($result); |
|
209 | + |
|
210 | + if (!$row || empty($row['u2f_request'])) { |
|
211 | + throw new AccessDeniedHttpException($this->user->lang('TFA_NO_ACCESS')); |
|
212 | + } |
|
213 | + |
|
214 | + $response = json_decode(htmlspecialchars_decode($this->request->variable('authenticate', ''))); |
|
215 | + |
|
216 | + if (property_exists($response, 'errorCode')) { |
|
217 | + if ($response->errorCode == 4) // errorCode 4 means that this device wasn't registered |
|
218 | + { |
|
219 | + throw new AccessDeniedHttpException($this->user->lang('TFA_NOT_REGISTERED')); |
|
220 | + } |
|
221 | + throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG')); |
|
222 | + } |
|
223 | + $result = new AuthenticationResponse($response->signatureData, $response->clientData, $response->keyHandle, $response->errorCode); |
|
224 | + |
|
225 | + /** @var \paul999\tfa\helper\registration_helper $reg */ |
|
226 | + $reg = $this->u2f->doAuthenticate($this->convertRequests(json_decode($row['u2f_request'])), $this->getRegistrations($user_id), $result); |
|
227 | + $sql_ary = array( |
|
228 | + 'counter' => $reg->getCounter(), |
|
229 | + 'last_used' => time(), |
|
230 | + ); |
|
231 | + |
|
232 | + $sql = 'UPDATE ' . $this->registration_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE registration_id = ' . (int)$reg->id; |
|
233 | + $this->db->sql_query($sql); |
|
234 | + } |
|
235 | + catch (U2fError $error) |
|
236 | 236 | { |
237 | - $this->createError($error); |
|
238 | - } |
|
237 | + $this->createError($error); |
|
238 | + } |
|
239 | 239 | catch (\InvalidArgumentException $invalid) |
240 | 240 | { |
241 | - throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG') . '<br />' . $invalid->getMessage(), $invalid); |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * @param array $requests |
|
247 | - * @return array |
|
248 | - */ |
|
249 | - private function convertRequests($requests) |
|
250 | - { |
|
251 | - $result = array(); |
|
252 | - foreach($requests as $request) |
|
253 | - { |
|
254 | - $result[] = new SignRequest($request->challenge, $request->keyHandle, $request->appId); |
|
255 | - } |
|
256 | - return $result; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Start of registration |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - public function register_start() |
|
264 | - { |
|
265 | - $data = $this->u2f->getRegisterData($this->reg_data); |
|
266 | - |
|
267 | - $sql_ary = array( |
|
268 | - 'u2f_request' => json_encode($data[0], JSON_UNESCAPED_SLASHES), |
|
269 | - ); |
|
270 | - |
|
271 | - $count = $this->update_session($sql_ary); |
|
272 | - |
|
273 | - if ($count == 0) |
|
274 | - { |
|
275 | - trigger_error('TFA_UNABLE_TO_UPDATE_SESSION'); |
|
276 | - } |
|
277 | - else if ($count > 1) |
|
278 | - { |
|
279 | - // Reset sessions table. We had multiple sessions with same ID!!! |
|
280 | - $sql_ary['u2f_request'] = ''; |
|
281 | - $this->update_session($sql_ary); |
|
282 | - |
|
283 | - trigger_error('TFA_UNABLE_TO_UPDATE_SESSION'); |
|
284 | - } |
|
285 | - |
|
286 | - $this->template->assign_vars(array( |
|
287 | - 'U2F_REG' => true, |
|
288 | - 'U2F_SIGN_REQUEST' => json_encode($data[0], JSON_UNESCAPED_SLASHES), |
|
289 | - 'U2F_SIGN' => json_encode($data[1], JSON_UNESCAPED_SLASHES), |
|
290 | - )); |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Actual registration |
|
295 | - * @return void |
|
296 | - */ |
|
297 | - public function register() |
|
298 | - { |
|
299 | - try |
|
300 | - { |
|
301 | - $reg = $this->u2f->doRegister(json_decode($this->user->data['u2f_request']), json_decode(htmlspecialchars_decode($this->request->variable('register', '')))); |
|
302 | - |
|
303 | - $sql_ary = array( |
|
304 | - 'user_id' => $this->user->data['user_id'], |
|
305 | - 'key_handle' => $reg->getKeyHandle(), |
|
306 | - 'public_key' => $reg->getPublicKey(), |
|
307 | - 'certificate' => $reg->getCertificate(), |
|
308 | - 'counter' => ($reg->getCounter() > 0) ? $reg->getCounter() : 0, |
|
309 | - 'registered' => time(), |
|
310 | - 'last_used' => time(), |
|
311 | - ); |
|
312 | - |
|
313 | - $sql = 'INSERT INTO ' . $this->registration_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); |
|
314 | - $this->db->sql_query($sql); |
|
315 | - |
|
316 | - $sql_ary = array( |
|
317 | - 'u2f_request' => '', |
|
318 | - ); |
|
319 | - |
|
320 | - $this->update_session($sql_ary); |
|
321 | - } |
|
322 | - catch (U2fError $err) |
|
323 | - { |
|
324 | - $this->createError($err); |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * This method is called to show the UCP page. |
|
330 | - * You can assign template variables to the template, or do anything else here. |
|
331 | - */ |
|
332 | - public function show_ucp() |
|
333 | - { |
|
334 | - $sql = 'SELECT * |
|
241 | + throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG') . '<br />' . $invalid->getMessage(), $invalid); |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * @param array $requests |
|
247 | + * @return array |
|
248 | + */ |
|
249 | + private function convertRequests($requests) |
|
250 | + { |
|
251 | + $result = array(); |
|
252 | + foreach($requests as $request) |
|
253 | + { |
|
254 | + $result[] = new SignRequest($request->challenge, $request->keyHandle, $request->appId); |
|
255 | + } |
|
256 | + return $result; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Start of registration |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + public function register_start() |
|
264 | + { |
|
265 | + $data = $this->u2f->getRegisterData($this->reg_data); |
|
266 | + |
|
267 | + $sql_ary = array( |
|
268 | + 'u2f_request' => json_encode($data[0], JSON_UNESCAPED_SLASHES), |
|
269 | + ); |
|
270 | + |
|
271 | + $count = $this->update_session($sql_ary); |
|
272 | + |
|
273 | + if ($count == 0) |
|
274 | + { |
|
275 | + trigger_error('TFA_UNABLE_TO_UPDATE_SESSION'); |
|
276 | + } |
|
277 | + else if ($count > 1) |
|
278 | + { |
|
279 | + // Reset sessions table. We had multiple sessions with same ID!!! |
|
280 | + $sql_ary['u2f_request'] = ''; |
|
281 | + $this->update_session($sql_ary); |
|
282 | + |
|
283 | + trigger_error('TFA_UNABLE_TO_UPDATE_SESSION'); |
|
284 | + } |
|
285 | + |
|
286 | + $this->template->assign_vars(array( |
|
287 | + 'U2F_REG' => true, |
|
288 | + 'U2F_SIGN_REQUEST' => json_encode($data[0], JSON_UNESCAPED_SLASHES), |
|
289 | + 'U2F_SIGN' => json_encode($data[1], JSON_UNESCAPED_SLASHES), |
|
290 | + )); |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Actual registration |
|
295 | + * @return void |
|
296 | + */ |
|
297 | + public function register() |
|
298 | + { |
|
299 | + try |
|
300 | + { |
|
301 | + $reg = $this->u2f->doRegister(json_decode($this->user->data['u2f_request']), json_decode(htmlspecialchars_decode($this->request->variable('register', '')))); |
|
302 | + |
|
303 | + $sql_ary = array( |
|
304 | + 'user_id' => $this->user->data['user_id'], |
|
305 | + 'key_handle' => $reg->getKeyHandle(), |
|
306 | + 'public_key' => $reg->getPublicKey(), |
|
307 | + 'certificate' => $reg->getCertificate(), |
|
308 | + 'counter' => ($reg->getCounter() > 0) ? $reg->getCounter() : 0, |
|
309 | + 'registered' => time(), |
|
310 | + 'last_used' => time(), |
|
311 | + ); |
|
312 | + |
|
313 | + $sql = 'INSERT INTO ' . $this->registration_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); |
|
314 | + $this->db->sql_query($sql); |
|
315 | + |
|
316 | + $sql_ary = array( |
|
317 | + 'u2f_request' => '', |
|
318 | + ); |
|
319 | + |
|
320 | + $this->update_session($sql_ary); |
|
321 | + } |
|
322 | + catch (U2fError $err) |
|
323 | + { |
|
324 | + $this->createError($err); |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * This method is called to show the UCP page. |
|
330 | + * You can assign template variables to the template, or do anything else here. |
|
331 | + */ |
|
332 | + public function show_ucp() |
|
333 | + { |
|
334 | + $sql = 'SELECT * |
|
335 | 335 | FROM ' . $this->registration_table . ' |
336 | 336 | WHERE user_id = ' . (int) $this->user->data['user_id'] . ' |
337 | 337 | ORDER BY registration_id ASC'; |
338 | 338 | |
339 | - $result = $this->db->sql_query($sql); |
|
340 | - $this->reg_data = array(); |
|
341 | - |
|
342 | - while ($row = $this->db->sql_fetchrow($result)) |
|
343 | - { |
|
344 | - $this->template->assign_block_vars('keys', array( |
|
345 | - 'ID' => $row['registration_id'], |
|
346 | - 'REGISTERED' => $this->user->format_date($row['registered']), |
|
347 | - 'LAST_USED' => $this->user->format_date($row['last_used']), |
|
348 | - )); |
|
349 | - |
|
350 | - $reg = new registration_helper(); |
|
351 | - $reg->setCounter($row['counter']); |
|
352 | - $reg->setCertificate($row['certificate']); |
|
353 | - $reg->setKeyHandle($row['key_handle']); |
|
354 | - $reg->setPublicKey($row['public_key']); |
|
355 | - $reg->id = $row['registration_id']; |
|
356 | - $this->reg_data = $reg; |
|
357 | - } |
|
358 | - $this->db->sql_freeresult($result); |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Delete a specific row from the UCP. |
|
363 | - * The data is based on the data provided in show_ucp. |
|
364 | - * @param array $data |
|
365 | - * @return mixed |
|
366 | - */ |
|
367 | - public function delete($data) |
|
368 | - { |
|
369 | - if (isset($data['keys'])) |
|
370 | - { |
|
371 | - $sql_where = $this->db->sql_in_set('registration_id', $data['keys']); |
|
372 | - $sql = 'DELETE FROM ' . $this->registration_table . ' |
|
339 | + $result = $this->db->sql_query($sql); |
|
340 | + $this->reg_data = array(); |
|
341 | + |
|
342 | + while ($row = $this->db->sql_fetchrow($result)) |
|
343 | + { |
|
344 | + $this->template->assign_block_vars('keys', array( |
|
345 | + 'ID' => $row['registration_id'], |
|
346 | + 'REGISTERED' => $this->user->format_date($row['registered']), |
|
347 | + 'LAST_USED' => $this->user->format_date($row['last_used']), |
|
348 | + )); |
|
349 | + |
|
350 | + $reg = new registration_helper(); |
|
351 | + $reg->setCounter($row['counter']); |
|
352 | + $reg->setCertificate($row['certificate']); |
|
353 | + $reg->setKeyHandle($row['key_handle']); |
|
354 | + $reg->setPublicKey($row['public_key']); |
|
355 | + $reg->id = $row['registration_id']; |
|
356 | + $this->reg_data = $reg; |
|
357 | + } |
|
358 | + $this->db->sql_freeresult($result); |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Delete a specific row from the UCP. |
|
363 | + * The data is based on the data provided in show_ucp. |
|
364 | + * @param array $data |
|
365 | + * @return mixed |
|
366 | + */ |
|
367 | + public function delete($data) |
|
368 | + { |
|
369 | + if (isset($data['keys'])) |
|
370 | + { |
|
371 | + $sql_where = $this->db->sql_in_set('registration_id', $data['keys']); |
|
372 | + $sql = 'DELETE FROM ' . $this->registration_table . ' |
|
373 | 373 | WHERE user_id = ' . (int)$this->user->data['user_id'] . ' |
374 | 374 | AND ' . $sql_where; |
375 | 375 | |
376 | - $this->db->sql_query($sql); |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Select all registration objects from the database |
|
382 | - * @param integer $user_id |
|
383 | - * @return array |
|
384 | - */ |
|
385 | - private function getRegistrations($user_id) |
|
386 | - { |
|
387 | - $sql = 'SELECT * FROM ' . $this->registration_table . ' WHERE user_id = ' . (int) $user_id; |
|
388 | - $result = $this->db->sql_query($sql); |
|
389 | - $rows = array(); |
|
390 | - |
|
391 | - while ($row = $this->db->sql_fetchrow($result)) |
|
392 | - { |
|
393 | - $reg = new registration_helper(); |
|
394 | - $reg->setCounter($row['counter']); |
|
395 | - $reg->setCertificate($row['certificate']); |
|
396 | - $reg->setKeyHandle($row['key_handle']); |
|
397 | - $reg->setPublicKey($row['public_key']); |
|
398 | - $reg->id = $row['registration_id']; |
|
399 | - $rows[] = $reg; |
|
400 | - } |
|
401 | - |
|
402 | - $this->db->sql_freeresult($result); |
|
403 | - return $rows; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * @param U2fError $error |
|
408 | - * @throws BadRequestHttpException |
|
409 | - */ |
|
410 | - private function createError(U2fError $error) |
|
411 | - { |
|
412 | - switch ($error->getCode()) |
|
413 | - { |
|
414 | - /** Error for the authentication message not matching any outstanding |
|
415 | - * authentication request */ |
|
416 | - case U2fError::ERR_NO_MATCHING_REQUEST: |
|
417 | - throw new BadRequestHttpException($this->user->lang('ERR_NO_MATCHING_REQUEST'), $error); |
|
418 | - |
|
419 | - /** Error for the authentication message not matching any registration */ |
|
420 | - case U2fError::ERR_NO_MATCHING_REGISTRATION: |
|
421 | - throw new BadRequestHttpException($this->user->lang('ERR_NO_MATCHING_REGISTRATION'), $error); |
|
422 | - |
|
423 | - /** Error for the signature on the authentication message not verifying with |
|
424 | - * the correct key */ |
|
425 | - case U2fError::ERR_AUTHENTICATION_FAILURE: |
|
426 | - throw new BadRequestHttpException($this->user->lang('ERR_AUTHENTICATION_FAILURE'), $error); |
|
427 | - |
|
428 | - /** Error for the challenge in the registration message not matching the |
|
429 | - * registration challenge */ |
|
430 | - case U2fError::ERR_UNMATCHED_CHALLENGE: |
|
431 | - throw new BadRequestHttpException($this->user->lang('ERR_UNMATCHED_CHALLENGE'), $error); |
|
432 | - |
|
433 | - /** Error for the attestation signature on the registration message not |
|
434 | - * verifying */ |
|
435 | - case U2fError::ERR_ATTESTATION_SIGNATURE: |
|
436 | - throw new BadRequestHttpException($this->user->lang('ERR_ATTESTATION_SIGNATURE'), $error); |
|
437 | - |
|
438 | - /** Error for the attestation verification not verifying */ |
|
439 | - case U2fError::ERR_ATTESTATION_VERIFICATION: |
|
440 | - throw new BadRequestHttpException($this->user->lang('ERR_ATTESTATION_VERIFICATION'), $error); |
|
441 | - |
|
442 | - /** Error for not getting good random from the system */ |
|
443 | - case U2fError::ERR_BAD_RANDOM: |
|
444 | - throw new BadRequestHttpException($this->user->lang('ERR_BAD_RANDOM'), $error); |
|
445 | - |
|
446 | - /** Error when the counter is lower than expected */ |
|
447 | - case U2fError::ERR_COUNTER_TOO_LOW: |
|
448 | - throw new BadRequestHttpException($this->user->lang('ERR_COUNTER_TOO_LOW'), $error); |
|
449 | - |
|
450 | - /** Error decoding public key */ |
|
451 | - case U2fError::ERR_PUBKEY_DECODE: |
|
452 | - throw new BadRequestHttpException($this->user->lang('ERR_PUBKEY_DECODE'), $error); |
|
453 | - |
|
454 | - /** Error user-agent returned error */ |
|
455 | - case U2fError::ERR_BAD_UA_RETURNING: |
|
456 | - throw new BadRequestHttpException($this->user->lang('ERR_BAD_UA_RETURNING'), $error); |
|
457 | - |
|
458 | - /** Error old OpenSSL version */ |
|
459 | - case U2fError::ERR_OLD_OPENSSL: |
|
460 | - throw new BadRequestHttpException(sprintf($this->user->lang('ERR_OLD_OPENSSL'), OPENSSL_VERSION_TEXT), $error); |
|
461 | - |
|
462 | - default: |
|
463 | - throw new BadRequestHttpException($this->user->lang('TFA_UNKNOWN_ERROR'), $error); |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Update the session with new TFA data |
|
469 | - * @param $sql_ary |
|
470 | - * @return int |
|
471 | - */ |
|
472 | - private function update_session($sql_ary) |
|
473 | - { |
|
474 | - $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' |
|
376 | + $this->db->sql_query($sql); |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Select all registration objects from the database |
|
382 | + * @param integer $user_id |
|
383 | + * @return array |
|
384 | + */ |
|
385 | + private function getRegistrations($user_id) |
|
386 | + { |
|
387 | + $sql = 'SELECT * FROM ' . $this->registration_table . ' WHERE user_id = ' . (int) $user_id; |
|
388 | + $result = $this->db->sql_query($sql); |
|
389 | + $rows = array(); |
|
390 | + |
|
391 | + while ($row = $this->db->sql_fetchrow($result)) |
|
392 | + { |
|
393 | + $reg = new registration_helper(); |
|
394 | + $reg->setCounter($row['counter']); |
|
395 | + $reg->setCertificate($row['certificate']); |
|
396 | + $reg->setKeyHandle($row['key_handle']); |
|
397 | + $reg->setPublicKey($row['public_key']); |
|
398 | + $reg->id = $row['registration_id']; |
|
399 | + $rows[] = $reg; |
|
400 | + } |
|
401 | + |
|
402 | + $this->db->sql_freeresult($result); |
|
403 | + return $rows; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * @param U2fError $error |
|
408 | + * @throws BadRequestHttpException |
|
409 | + */ |
|
410 | + private function createError(U2fError $error) |
|
411 | + { |
|
412 | + switch ($error->getCode()) |
|
413 | + { |
|
414 | + /** Error for the authentication message not matching any outstanding |
|
415 | + * authentication request */ |
|
416 | + case U2fError::ERR_NO_MATCHING_REQUEST: |
|
417 | + throw new BadRequestHttpException($this->user->lang('ERR_NO_MATCHING_REQUEST'), $error); |
|
418 | + |
|
419 | + /** Error for the authentication message not matching any registration */ |
|
420 | + case U2fError::ERR_NO_MATCHING_REGISTRATION: |
|
421 | + throw new BadRequestHttpException($this->user->lang('ERR_NO_MATCHING_REGISTRATION'), $error); |
|
422 | + |
|
423 | + /** Error for the signature on the authentication message not verifying with |
|
424 | + * the correct key */ |
|
425 | + case U2fError::ERR_AUTHENTICATION_FAILURE: |
|
426 | + throw new BadRequestHttpException($this->user->lang('ERR_AUTHENTICATION_FAILURE'), $error); |
|
427 | + |
|
428 | + /** Error for the challenge in the registration message not matching the |
|
429 | + * registration challenge */ |
|
430 | + case U2fError::ERR_UNMATCHED_CHALLENGE: |
|
431 | + throw new BadRequestHttpException($this->user->lang('ERR_UNMATCHED_CHALLENGE'), $error); |
|
432 | + |
|
433 | + /** Error for the attestation signature on the registration message not |
|
434 | + * verifying */ |
|
435 | + case U2fError::ERR_ATTESTATION_SIGNATURE: |
|
436 | + throw new BadRequestHttpException($this->user->lang('ERR_ATTESTATION_SIGNATURE'), $error); |
|
437 | + |
|
438 | + /** Error for the attestation verification not verifying */ |
|
439 | + case U2fError::ERR_ATTESTATION_VERIFICATION: |
|
440 | + throw new BadRequestHttpException($this->user->lang('ERR_ATTESTATION_VERIFICATION'), $error); |
|
441 | + |
|
442 | + /** Error for not getting good random from the system */ |
|
443 | + case U2fError::ERR_BAD_RANDOM: |
|
444 | + throw new BadRequestHttpException($this->user->lang('ERR_BAD_RANDOM'), $error); |
|
445 | + |
|
446 | + /** Error when the counter is lower than expected */ |
|
447 | + case U2fError::ERR_COUNTER_TOO_LOW: |
|
448 | + throw new BadRequestHttpException($this->user->lang('ERR_COUNTER_TOO_LOW'), $error); |
|
449 | + |
|
450 | + /** Error decoding public key */ |
|
451 | + case U2fError::ERR_PUBKEY_DECODE: |
|
452 | + throw new BadRequestHttpException($this->user->lang('ERR_PUBKEY_DECODE'), $error); |
|
453 | + |
|
454 | + /** Error user-agent returned error */ |
|
455 | + case U2fError::ERR_BAD_UA_RETURNING: |
|
456 | + throw new BadRequestHttpException($this->user->lang('ERR_BAD_UA_RETURNING'), $error); |
|
457 | + |
|
458 | + /** Error old OpenSSL version */ |
|
459 | + case U2fError::ERR_OLD_OPENSSL: |
|
460 | + throw new BadRequestHttpException(sprintf($this->user->lang('ERR_OLD_OPENSSL'), OPENSSL_VERSION_TEXT), $error); |
|
461 | + |
|
462 | + default: |
|
463 | + throw new BadRequestHttpException($this->user->lang('TFA_UNKNOWN_ERROR'), $error); |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Update the session with new TFA data |
|
469 | + * @param $sql_ary |
|
470 | + * @return int |
|
471 | + */ |
|
472 | + private function update_session($sql_ary) |
|
473 | + { |
|
474 | + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' |
|
475 | 475 | WHERE |
476 | 476 | session_id = \'' . $this->db->sql_escape($this->user->data['session_id']) . '\' AND |
477 | 477 | session_user_id = ' . (int) $this->user->data['user_id']; |
478 | - $this->db->sql_query($sql); |
|
478 | + $this->db->sql_query($sql); |
|
479 | 479 | |
480 | - return $this->db->sql_affectedrows(); |
|
481 | - } |
|
480 | + return $this->db->sql_affectedrows(); |
|
481 | + } |
|
482 | 482 | } |
483 | 483 | \ No newline at end of file |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $this->request = $request; |
78 | 78 | $this->template = $template; |
79 | 79 | |
80 | - $this->registration_table = $registration_table; |
|
80 | + $this->registration_table = $registration_table; |
|
81 | 81 | |
82 | 82 | $this->u2f = new \paul999\u2f\U2F('https://' . $this->request->server('HTTP_HOST')); |
83 | 83 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | try { |
203 | 203 | $sql = 'SELECT u2f_request FROM ' . SESSIONS_TABLE . ' WHERE |
204 | 204 | session_id = \'' . $this->db->sql_escape($this->user->data['session_id']) . '\' AND |
205 | - session_user_id = ' . (int)$this->user->data['user_id']; |
|
205 | + session_user_id = ' . (int) $this->user->data['user_id']; |
|
206 | 206 | $result = $this->db->sql_query($sql); |
207 | 207 | $row = $this->db->sql_fetchrow($result); |
208 | 208 | $this->db->sql_freeresult($result); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | 'last_used' => time(), |
230 | 230 | ); |
231 | 231 | |
232 | - $sql = 'UPDATE ' . $this->registration_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE registration_id = ' . (int)$reg->id; |
|
232 | + $sql = 'UPDATE ' . $this->registration_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE registration_id = ' . (int) $reg->id; |
|
233 | 233 | $this->db->sql_query($sql); |
234 | 234 | } |
235 | 235 | catch (U2fError $error) |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | private function convertRequests($requests) |
250 | 250 | { |
251 | 251 | $result = array(); |
252 | - foreach($requests as $request) |
|
252 | + foreach ($requests as $request) |
|
253 | 253 | { |
254 | 254 | $result[] = new SignRequest($request->challenge, $request->keyHandle, $request->appId); |
255 | 255 | } |
@@ -347,13 +347,13 @@ discard block |
||
347 | 347 | 'LAST_USED' => $this->user->format_date($row['last_used']), |
348 | 348 | )); |
349 | 349 | |
350 | - $reg = new registration_helper(); |
|
350 | + $reg = new registration_helper(); |
|
351 | 351 | $reg->setCounter($row['counter']); |
352 | 352 | $reg->setCertificate($row['certificate']); |
353 | 353 | $reg->setKeyHandle($row['key_handle']); |
354 | 354 | $reg->setPublicKey($row['public_key']); |
355 | - $reg->id = $row['registration_id']; |
|
356 | - $this->reg_data = $reg; |
|
355 | + $reg->id = $row['registration_id']; |
|
356 | + $this->reg_data = $reg; |
|
357 | 357 | } |
358 | 358 | $this->db->sql_freeresult($result); |
359 | 359 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | { |
371 | 371 | $sql_where = $this->db->sql_in_set('registration_id', $data['keys']); |
372 | 372 | $sql = 'DELETE FROM ' . $this->registration_table . ' |
373 | - WHERE user_id = ' . (int)$this->user->data['user_id'] . ' |
|
373 | + WHERE user_id = ' . (int) $this->user->data['user_id'] . ' |
|
374 | 374 | AND ' . $sql_where; |
375 | 375 | |
376 | 376 | $this->db->sql_query($sql); |
@@ -390,13 +390,13 @@ discard block |
||
390 | 390 | |
391 | 391 | while ($row = $this->db->sql_fetchrow($result)) |
392 | 392 | { |
393 | - $reg = new registration_helper(); |
|
393 | + $reg = new registration_helper(); |
|
394 | 394 | $reg->setCounter($row['counter']); |
395 | 395 | $reg->setCertificate($row['certificate']); |
396 | 396 | $reg->setKeyHandle($row['key_handle']); |
397 | 397 | $reg->setPublicKey($row['public_key']); |
398 | - $reg->id = $row['registration_id']; |
|
399 | - $rows[] = $reg; |
|
398 | + $reg->id = $row['registration_id']; |
|
399 | + $rows[] = $reg; |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | $this->db->sql_freeresult($result); |
@@ -214,10 +214,12 @@ discard block |
||
214 | 214 | $response = json_decode(htmlspecialchars_decode($this->request->variable('authenticate', ''))); |
215 | 215 | |
216 | 216 | if (property_exists($response, 'errorCode')) { |
217 | - if ($response->errorCode == 4) // errorCode 4 means that this device wasn't registered |
|
217 | + if ($response->errorCode == 4) { |
|
218 | + // errorCode 4 means that this device wasn't registered |
|
218 | 219 | { |
219 | 220 | throw new AccessDeniedHttpException($this->user->lang('TFA_NOT_REGISTERED')); |
220 | 221 | } |
222 | + } |
|
221 | 223 | throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG')); |
222 | 224 | } |
223 | 225 | $result = new AuthenticationResponse($response->signatureData, $response->clientData, $response->keyHandle, $response->errorCode); |
@@ -231,12 +233,10 @@ discard block |
||
231 | 233 | |
232 | 234 | $sql = 'UPDATE ' . $this->registration_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE registration_id = ' . (int)$reg->id; |
233 | 235 | $this->db->sql_query($sql); |
234 | - } |
|
235 | - catch (U2fError $error) |
|
236 | + } catch (U2fError $error) |
|
236 | 237 | { |
237 | 238 | $this->createError($error); |
238 | - } |
|
239 | - catch (\InvalidArgumentException $invalid) |
|
239 | + } catch (\InvalidArgumentException $invalid) |
|
240 | 240 | { |
241 | 241 | throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG') . '<br />' . $invalid->getMessage(), $invalid); |
242 | 242 | } |
@@ -273,8 +273,7 @@ discard block |
||
273 | 273 | if ($count == 0) |
274 | 274 | { |
275 | 275 | trigger_error('TFA_UNABLE_TO_UPDATE_SESSION'); |
276 | - } |
|
277 | - else if ($count > 1) |
|
276 | + } else if ($count > 1) |
|
278 | 277 | { |
279 | 278 | // Reset sessions table. We had multiple sessions with same ID!!! |
280 | 279 | $sql_ary['u2f_request'] = ''; |
@@ -318,8 +317,7 @@ discard block |
||
318 | 317 | ); |
319 | 318 | |
320 | 319 | $this->update_session($sql_ary); |
321 | - } |
|
322 | - catch (U2fError $err) |
|
320 | + } catch (U2fError $err) |
|
323 | 321 | { |
324 | 322 | $this->createError($err); |
325 | 323 | } |
@@ -10,11 +10,7 @@ |
||
10 | 10 | |
11 | 11 | namespace paul999\tfa\ucp; |
12 | 12 | |
13 | -use paul999\tfa\helper\registration_helper; |
|
14 | 13 | use paul999\tfa\helper\session_helper; |
15 | -use paul999\u2f\Exceptions\U2fError; |
|
16 | -use paul999\u2f\U2F; |
|
17 | -use phpbb\db\driver\driver_interface; |
|
18 | 14 | use phpbb\request\request_interface; |
19 | 15 | use phpbb\template\template; |
20 | 16 | use phpbb\user; |
@@ -64,10 +64,10 @@ |
||
64 | 64 | */ |
65 | 65 | private function setup(user $user, template $template, request_interface $request, session_helper $session_helper) |
66 | 66 | { |
67 | - $this->user = $user; |
|
67 | + $this->user = $user; |
|
68 | 68 | $this->template = $template; |
69 | 69 | $this->request = $request; |
70 | - $this->session_helper = $session_helper; |
|
70 | + $this->session_helper = $session_helper; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -103,13 +103,11 @@ discard block |
||
103 | 103 | meta_refresh(3, $this->u_action); |
104 | 104 | $message = $this->user->lang['TFA_KEY_ADDED'] . '<br /><br />' . sprintf($this->user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
105 | 105 | trigger_error($message); |
106 | - } |
|
107 | - else |
|
106 | + } else |
|
108 | 107 | { |
109 | 108 | $error[] = $this->user->lang('TFA_MODULE_NOT_FOUND', $class); |
110 | 109 | } |
111 | - } |
|
112 | - catch (\Exception $e) { |
|
110 | + } catch (\Exception $e) { |
|
113 | 111 | $error[] = $e->getMessage(); |
114 | 112 | } |
115 | 113 | } |
@@ -131,8 +129,7 @@ discard block |
||
131 | 129 | if (!check_form_key('ucp_tfa_keys')) |
132 | 130 | { |
133 | 131 | $error[] = 'FORM_INVALID'; |
134 | - } |
|
135 | - else |
|
132 | + } else |
|
136 | 133 | { |
137 | 134 | switch ($mode) |
138 | 135 | { |
@@ -1,99 +1,99 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * |
|
4 | - * 2FA extension for the phpBB Forum Software package. |
|
5 | - * |
|
6 | - * @copyright (c) 2015 Paul Sohier |
|
7 | - * @license GNU General Public License, version 2 (GPL-2.0) |
|
8 | - * |
|
9 | - */ |
|
3 | + * |
|
4 | + * 2FA extension for the phpBB Forum Software package. |
|
5 | + * |
|
6 | + * @copyright (c) 2015 Paul Sohier |
|
7 | + * @license GNU General Public License, version 2 (GPL-2.0) |
|
8 | + * |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | namespace paul999\tfa\modules; |
12 | 12 | |
13 | 13 | interface module_interface |
14 | 14 | { |
15 | - /** |
|
16 | - * Return if this module is enabled by the admin |
|
17 | - * (And all server requirements are met). |
|
18 | - * |
|
19 | - * Do not return false in case a specific user disabeld this module, |
|
20 | - * OR if the user is unable to use this specific module. |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function is_enabled(); |
|
15 | + /** |
|
16 | + * Return if this module is enabled by the admin |
|
17 | + * (And all server requirements are met). |
|
18 | + * |
|
19 | + * Do not return false in case a specific user disabeld this module, |
|
20 | + * OR if the user is unable to use this specific module. |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function is_enabled(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * Check if the current user is able to use this module. |
|
27 | - * |
|
28 | - * This means that the user enabled it in the UCP, |
|
29 | - * And has it setup up correctly. |
|
30 | - * This method will be called during login, not during registration/ |
|
31 | - * |
|
32 | - * @param int $user_id |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - public function is_usable($user_id); |
|
25 | + /** |
|
26 | + * Check if the current user is able to use this module. |
|
27 | + * |
|
28 | + * This means that the user enabled it in the UCP, |
|
29 | + * And has it setup up correctly. |
|
30 | + * This method will be called during login, not during registration/ |
|
31 | + * |
|
32 | + * @param int $user_id |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + public function is_usable($user_id); |
|
36 | 36 | |
37 | - /** |
|
38 | - * Check if the user can potentially use this. |
|
39 | - * This method is called at registration page. |
|
40 | - * |
|
41 | - * You can, for example, check if the current browser is suitable. |
|
42 | - * |
|
43 | - * @param int $user_id |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function is_potentially_usable($user_id); |
|
37 | + /** |
|
38 | + * Check if the user can potentially use this. |
|
39 | + * This method is called at registration page. |
|
40 | + * |
|
41 | + * You can, for example, check if the current browser is suitable. |
|
42 | + * |
|
43 | + * @param int $user_id |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function is_potentially_usable($user_id); |
|
47 | 47 | |
48 | - /** |
|
49 | - * Get the priority for this module. |
|
50 | - * A lower priority means more chance it gets selected as default option |
|
51 | - * |
|
52 | - * There can be only one module with a specific priority! |
|
53 | - * If there is already a module registered with this priority, |
|
54 | - * a Exception might be thrown |
|
55 | - * |
|
56 | - * @param int $user_id If set, the priority can depend on the current user |
|
57 | - * @return int |
|
58 | - */ |
|
59 | - public function get_priority($user_id = 0); |
|
48 | + /** |
|
49 | + * Get the priority for this module. |
|
50 | + * A lower priority means more chance it gets selected as default option |
|
51 | + * |
|
52 | + * There can be only one module with a specific priority! |
|
53 | + * If there is already a module registered with this priority, |
|
54 | + * a Exception might be thrown |
|
55 | + * |
|
56 | + * @param int $user_id If set, the priority can depend on the current user |
|
57 | + * @return int |
|
58 | + */ |
|
59 | + public function get_priority($user_id = 0); |
|
60 | 60 | |
61 | - /** |
|
62 | - * Start of the login procedure. |
|
63 | - * @param int $user_id |
|
64 | - * @return int |
|
65 | - */ |
|
66 | - public function login_start($user_id); |
|
61 | + /** |
|
62 | + * Start of the login procedure. |
|
63 | + * @param int $user_id |
|
64 | + * @return int |
|
65 | + */ |
|
66 | + public function login_start($user_id); |
|
67 | 67 | |
68 | - /** |
|
69 | - * Actual login procedure |
|
70 | - * @param int $user_id |
|
71 | - */ |
|
72 | - public function login($user_id); |
|
68 | + /** |
|
69 | + * Actual login procedure |
|
70 | + * @param int $user_id |
|
71 | + */ |
|
72 | + public function login($user_id); |
|
73 | 73 | |
74 | - /** |
|
75 | - * Start of registration |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public function register_start(); |
|
74 | + /** |
|
75 | + * Start of registration |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public function register_start(); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Actual registration |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function register(); |
|
80 | + /** |
|
81 | + * Actual registration |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function register(); |
|
85 | 85 | |
86 | - /** |
|
87 | - * This method is called to show the UCP page. |
|
88 | - * You can assign template variables to the template, or do anything else here. |
|
89 | - */ |
|
90 | - public function show_ucp(); |
|
86 | + /** |
|
87 | + * This method is called to show the UCP page. |
|
88 | + * You can assign template variables to the template, or do anything else here. |
|
89 | + */ |
|
90 | + public function show_ucp(); |
|
91 | 91 | |
92 | - /** |
|
93 | - * Delete a specific row from the UCP. |
|
94 | - * The data is based on the data provided in show_ucp. |
|
95 | - * @param array $data |
|
96 | - * @return mixed |
|
97 | - */ |
|
98 | - public function delete($data); |
|
92 | + /** |
|
93 | + * Delete a specific row from the UCP. |
|
94 | + * The data is based on the data provided in show_ucp. |
|
95 | + * @param array $data |
|
96 | + * @return mixed |
|
97 | + */ |
|
98 | + public function delete($data); |
|
99 | 99 | } |
100 | 100 | \ No newline at end of file |
@@ -87,15 +87,15 @@ |
||
87 | 87 | */ |
88 | 88 | public function __construct(helper $controller_helper, driver_interface $db, template $template, user $user, request_interface $request, config $config, session_helper_interface $session_helper, $root_path, $php_ext) |
89 | 89 | { |
90 | - $this->controller_helper = $controller_helper; |
|
91 | - $this->template = $template; |
|
92 | - $this->db = $db; |
|
93 | - $this->user = $user; |
|
94 | - $this->request = $request; |
|
95 | - $this->config = $config; |
|
96 | - $this->session_helper = $session_helper; |
|
97 | - $this->root_path = $root_path; |
|
98 | - $this->php_ext = $php_ext; |
|
90 | + $this->controller_helper = $controller_helper; |
|
91 | + $this->template = $template; |
|
92 | + $this->db = $db; |
|
93 | + $this->user = $user; |
|
94 | + $this->request = $request; |
|
95 | + $this->config = $config; |
|
96 | + $this->session_helper = $session_helper; |
|
97 | + $this->root_path = $root_path; |
|
98 | + $this->php_ext = $php_ext; |
|
99 | 99 | |
100 | 100 | } |
101 | 101 |
@@ -127,8 +127,7 @@ |
||
127 | 127 | if (!empty($default)) |
128 | 128 | { |
129 | 129 | $module = $this->session_helper->findModule($class); |
130 | - } |
|
131 | - else |
|
130 | + } else |
|
132 | 131 | { |
133 | 132 | foreach ($modules as $row) |
134 | 133 | { |