1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* antibot |
5
|
|
|
* |
6
|
|
|
* @category Jkphl |
7
|
|
|
* @package Jkphl\Antibot |
8
|
|
|
* @subpackage Jkphl\Antibot\Ports\Validators |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2018 Joschi Kuphal <[email protected]> |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Jkphl\Antibot\Ports\Validators; |
38
|
|
|
|
39
|
|
|
use Jkphl\Antibot\Domain\Antibot; |
40
|
|
|
use Jkphl\Antibot\Domain\Exceptions\InvalidRequestMethodOrderException; |
41
|
|
|
use Jkphl\Antibot\Infrastructure\Exceptions\HmacValidationException; |
42
|
|
|
use Jkphl\Antibot\Infrastructure\Factory\HmacFactory; |
43
|
|
|
use Jkphl\Antibot\Infrastructure\Model\AbstractValidator; |
44
|
|
|
use Jkphl\Antibot\Infrastructure\Model\InputElement; |
45
|
|
|
use Jkphl\Antibot\Ports\Exceptions\InvalidArgumentException; |
46
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* HMAC Validator |
50
|
|
|
* |
51
|
|
|
* @package Jkphl\Antibot |
52
|
|
|
* @subpackage Jkphl\Antibot\Ports\Validators |
53
|
|
|
*/ |
54
|
|
|
class HmacValidator extends AbstractValidator |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* Request method vector |
58
|
|
|
* |
59
|
|
|
* @var string[] |
60
|
|
|
*/ |
61
|
|
|
protected $methodVector = null; |
62
|
|
|
/** |
63
|
|
|
* Request submission times |
64
|
|
|
* |
65
|
|
|
* @var float[] |
66
|
|
|
*/ |
67
|
|
|
protected $submissionTimes = null; |
68
|
|
|
/** |
69
|
|
|
* Validation order position |
70
|
|
|
* |
71
|
|
|
* @var int |
72
|
|
|
*/ |
73
|
|
|
const POSITION = 100; |
74
|
|
|
/** |
75
|
|
|
* GET request |
76
|
|
|
* |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
const METHOD_GET = 'GET'; |
80
|
|
|
/** |
81
|
|
|
* POST request |
82
|
|
|
* |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
const METHOD_POST = 'POST'; |
86
|
|
|
/** |
87
|
|
|
* Minimum submission time |
88
|
|
|
* |
89
|
|
|
* @var float |
90
|
|
|
*/ |
91
|
|
|
const MINIMUM_SUBMISSION = 10; |
92
|
|
|
/** |
93
|
|
|
* Minimum submission time for follow-up submissions |
94
|
|
|
* |
95
|
|
|
* @var float |
96
|
|
|
*/ |
97
|
|
|
const MINIMUM_FOLLOWUP_SUBMISSION = 3; |
98
|
|
|
/** |
99
|
|
|
* Maximum submission time |
100
|
|
|
* |
101
|
|
|
* @var float |
102
|
|
|
*/ |
103
|
|
|
const MAXIMUM_SUBMISSION = 3600; |
104
|
|
|
/** |
105
|
|
|
* Block access |
106
|
|
|
* |
107
|
|
|
* @var string |
108
|
|
|
*/ |
109
|
|
|
const BLOCK = 'BLOCK'; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set the request method vector |
113
|
|
|
* |
114
|
|
|
* @param string $previous Previous request |
115
|
|
|
* @param string $current Current request |
116
|
|
|
*/ |
117
|
2 |
|
public function setMethodVector(string $previous = null, string $current = null): void |
118
|
|
|
{ |
119
|
|
|
// If the request method vector should be unset |
120
|
2 |
|
if ($previous === null) { |
121
|
|
|
$this->methodVector = null; |
|
|
|
|
122
|
|
|
|
123
|
|
|
return; |
124
|
|
|
} |
125
|
|
|
|
126
|
2 |
|
$this->methodVector = [$this->validateRequestMethod($previous), $this->validateRequestMethod($current)]; |
127
|
2 |
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Sanitize and validate a request method |
131
|
|
|
* |
132
|
|
|
* @param string $method Request method |
133
|
|
|
* |
134
|
|
|
* @return string Validated request method |
135
|
|
|
* @throws InvalidArgumentException If the request method is invalid |
136
|
|
|
*/ |
137
|
2 |
|
protected function validateRequestMethod(string $method): string |
138
|
|
|
{ |
139
|
2 |
|
$method = strtoupper($method); |
140
|
2 |
|
if ($method !== static::METHOD_GET && $method !== static::METHOD_POST) { |
141
|
|
|
throw new InvalidArgumentException( |
142
|
|
|
sprintf(InvalidArgumentException::INVALID_REQUEST_METHOD_STR, $method), |
143
|
|
|
InvalidArgumentException::INVALID_REQUEST_METHOD |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
2 |
|
return $method; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Sanitize and set the submission times |
152
|
|
|
* |
153
|
|
|
* @param float $max Maximum submission time |
154
|
|
|
* @param float $min Minimum submission time |
155
|
|
|
* @param float|null $minFollowUp Minimum submission time for follow-up submissions |
156
|
|
|
*/ |
157
|
1 |
|
public function setSubmissionTimes(float $max = null, float $min = null, float $minFollowUp = null): void |
158
|
|
|
{ |
159
|
|
|
// If the submission times should be unset |
160
|
1 |
|
if ($max === null) { |
161
|
|
|
$this->submissionTimes = null; |
|
|
|
|
162
|
|
|
|
163
|
|
|
return; |
164
|
|
|
} |
165
|
|
|
|
166
|
1 |
|
$max = min(floatval($max), static::MAXIMUM_SUBMISSION); |
167
|
1 |
|
$min = max(floatval($min), static::MINIMUM_SUBMISSION); |
168
|
1 |
|
$minFollowUp = ($minFollowUp === null) |
169
|
1 |
|
? $min : max(floatval($minFollowUp), static::MINIMUM_FOLLOWUP_SUBMISSION); |
170
|
1 |
|
$this->submissionTimes = [$min, $minFollowUp, $max]; |
|
|
|
|
171
|
1 |
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Validate a request |
175
|
|
|
* |
176
|
|
|
* @param ServerRequestInterface $request Request |
177
|
|
|
* @param Antibot $antibot Antibot instance |
178
|
|
|
* |
179
|
|
|
* @return bool |
180
|
|
|
*/ |
181
|
2 |
|
public function validate(ServerRequestInterface $request, Antibot $antibot): bool |
182
|
|
|
{ |
183
|
2 |
|
$data = $antibot->getData(); |
184
|
|
|
|
185
|
|
|
// If Antibot data has been submitted |
186
|
2 |
|
if ($data !== null) { |
187
|
|
|
// If no HMAC was submitted |
188
|
2 |
|
if (empty($data['hmac'])) { |
189
|
|
|
return false; |
190
|
|
|
} |
191
|
|
|
|
192
|
2 |
|
return $this->validateHmac($data['hmac'], $request, $antibot); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return true; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Create protective form HTML |
200
|
|
|
* |
201
|
|
|
* @param ServerRequestInterface $request Request |
202
|
|
|
* @param Antibot $antibot Antibot instance |
203
|
|
|
* |
204
|
|
|
* @return InputElement[] HMTL input elements |
205
|
|
|
*/ |
206
|
3 |
|
public function armor(ServerRequestInterface $request, Antibot $antibot): array |
207
|
|
|
{ |
208
|
3 |
|
$now = null; |
209
|
3 |
|
$hmac = $this->calculateHmac($request, $antibot, $now); |
210
|
|
|
$armor = [ |
211
|
3 |
|
new InputElement([ |
212
|
3 |
|
'type' => 'hidden', |
213
|
3 |
|
'name' => $antibot->getParameterPrefix().'[hmac]', |
214
|
3 |
|
'value' => $hmac |
215
|
|
|
]) |
216
|
|
|
]; |
217
|
|
|
// Add the timestamp field |
218
|
3 |
|
if ($now !== null) { |
219
|
1 |
|
$armor[] = new InputElement([ |
220
|
1 |
|
'type' => 'hidden', |
221
|
1 |
|
'name' => $antibot->getParameterPrefix().'[ts]', |
222
|
1 |
|
'value' => intval($now) |
223
|
|
|
]); |
224
|
|
|
} |
225
|
|
|
|
226
|
3 |
|
return $armor; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Decrypt and validate an HMAC |
231
|
|
|
* |
232
|
|
|
* @param string $hmac HMAC |
233
|
|
|
* @param ServerRequestInterface $request Request |
234
|
|
|
* @param Antibot $antibot Antibot instance |
235
|
|
|
* |
236
|
|
|
* @return bool HMAC is valid |
237
|
|
|
* @throws HmacValidationException If the request method order is invalid |
238
|
|
|
* @throws HmacValidationException If the request timing is invalid |
239
|
|
|
*/ |
240
|
2 |
|
protected function validateHmac(string $hmac, ServerRequestInterface $request, Antibot $antibot): bool |
241
|
|
|
{ |
242
|
2 |
|
$decrypted = false; |
|
|
|
|
243
|
2 |
|
$previousMethod = null; |
|
|
|
|
244
|
2 |
|
$hmacParams = [$antibot->getUnique()]; |
245
|
|
|
|
246
|
|
|
// Short-circuit blocked HMAC |
247
|
2 |
|
$hmacBlock = $hmacParams; |
248
|
2 |
|
$hmacBlock[] = self::BLOCK; |
249
|
2 |
|
if (HmacFactory::createFromString(serialize($hmacBlock), $antibot->getUnique()) === $hmac) { |
250
|
|
|
return false; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
// If the request method vector should be used |
254
|
2 |
|
if (!empty($this->methodVector)) { |
255
|
1 |
|
$serverParams = $request->getServerParams(); |
256
|
1 |
|
$requestMethod = empty($serverParams['REQUEST_METHOD']) ? 'EMPTY' : $serverParams['REQUEST_METHOD']; |
257
|
1 |
|
if ($requestMethod !== $this->methodVector[1]) { |
258
|
1 |
|
throw new HmacValidationException( |
259
|
1 |
|
HmacValidationException::INVALID_REQUEST_METHOD_ORDER_STR, |
260
|
1 |
|
HmacValidationException::INVALID_REQUEST_METHOD_ORDER |
261
|
|
|
); |
262
|
|
|
} |
263
|
|
|
|
264
|
1 |
|
$hmacParams[] = $this->methodVector[0]; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
// If submission time checks are enabled |
268
|
2 |
|
if (!empty($this->submissionTimes)) { |
269
|
|
|
list($first, $min, $max) = $this->submissionTimes; |
270
|
|
|
$now = time(); |
271
|
|
|
$initial = $now - $first; |
272
|
|
|
$delay = null; |
|
|
|
|
273
|
|
|
$data = $antibot->getData(); |
274
|
|
|
$timestamp = empty($data['ts']) ? null : $data['ts']; |
275
|
|
|
|
276
|
|
|
// If a timestamp has been submitted |
277
|
|
|
if ($timestamp |
278
|
|
|
&& (($timestamp + $min) <= $now) |
279
|
|
|
&& (($timestamp + $max) >= $now) |
280
|
|
|
&& ( |
281
|
|
|
$this->probeTimedHmac($hmac, $antibot, $hmacParams, $timestamp, $timestamp > $initial) |
282
|
|
|
|| (($timestamp <= $initial) ? |
283
|
|
|
$this->probeTimedHmac($hmac, $antibot, $hmacParams, $timestamp, true) : false |
284
|
|
|
) |
285
|
|
|
) |
286
|
|
|
) { |
287
|
|
|
// $delay = $now - $timestamp; |
288
|
|
|
return true; |
289
|
|
|
} else { |
290
|
|
|
// Run through the valid seconds range |
291
|
|
|
for ($time = $now - $min; $time >= $now - $max; --$time) { |
292
|
|
|
// Probe the current timestamp |
293
|
|
|
if ($this->probeTimedHmac($hmac, $antibot, $hmacParams, $time, $time > $initial) |
294
|
|
|
|| (($time <= $initial) |
295
|
|
|
&& $this->probeTimedHMAC($hmac, $antibot, $hmacParams, $time, true) |
296
|
|
|
) |
297
|
|
|
) { |
298
|
|
|
// $delay = $now - $time; |
299
|
|
|
return true; |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
throw new HmacValidationException( |
305
|
|
|
HmacValidationException::INVALID_REQUEST_TIMING_STR, |
306
|
|
|
HmacValidationException::INVALID_REQUEST_TIMING |
307
|
|
|
); |
308
|
|
|
} |
309
|
|
|
|
310
|
2 |
|
$currentHMAC = HmacFactory::createFromString(serialize($hmacParams), $antibot->getUnique()); |
311
|
|
|
|
312
|
2 |
|
return $hmac === $currentHMAC; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Probe a timed HMAC |
317
|
|
|
* |
318
|
|
|
* @param string $hmac HMAC |
319
|
|
|
* @param Antibot $antibot Antibot instance |
320
|
|
|
* @param array $hmacParams HMAC params |
321
|
|
|
* @param int $timestamp Timestamp |
322
|
|
|
* @param bool $followUp Is a follow-up request |
323
|
|
|
* |
324
|
|
|
* @return bool HMAC is valid |
325
|
|
|
*/ |
326
|
|
|
protected function probeTimedHmac( |
327
|
|
|
string $hmac, |
328
|
|
|
Antibot $antibot, |
329
|
|
|
array $hmacParams, |
330
|
|
|
int $timestamp, |
331
|
|
|
bool $followUp = false |
332
|
|
|
): bool { |
333
|
|
|
if ($followUp) { |
334
|
|
|
$hmacParams[] = true; |
335
|
|
|
} |
336
|
|
|
$hmacParams[] = $timestamp; |
337
|
|
|
$currentHMAC = HmacFactory::createFromString(serialize($hmacParams), $antibot->getUnique()); |
338
|
|
|
|
339
|
|
|
echo 'Current HMAC: '.$currentHMAC; |
340
|
|
|
|
341
|
|
|
return $currentHMAC == $hmac; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
public function _decryptHmac($hmac) |
345
|
|
|
{ |
346
|
|
|
// If submission time checks are enabled |
347
|
|
|
if ($this->_submissionTimeEnabled()) { |
|
|
|
|
348
|
|
|
$minimum = intval($this->_settings['time']['minimum']); |
|
|
|
|
349
|
|
|
$maximium = intval($this->_settings['time']['maximum']); |
350
|
|
|
$first = max($minimum, intval($this->_settings['time']['first'])); |
351
|
|
|
$now = time(); |
352
|
|
|
$initial = $now - $first; |
353
|
|
|
// If a timestamp hint has been submitted: Probe this first |
354
|
|
|
if ($this->_timestamp && (($this->_timestamp + $minimum) <= $now) && (($this->_timestamp + $maximium) >= $now) && $this->_info('Probing timestamp hint first') && ( |
|
|
|
|
355
|
|
|
$this->_probeTimedHMAC($hmac, $hmacParams, $this->_timestamp, $this->_timestamp > $initial) || |
|
|
|
|
356
|
|
|
(($this->_timestamp <= $initial) ? $this->_probeTimedHMAC($hmac, $hmacParams, $this->_timestamp, |
|
|
|
|
357
|
|
|
true) : false)) |
|
|
|
|
358
|
|
|
) { |
359
|
|
|
$this->_delay = $now - $this->_timestamp; |
|
|
|
|
360
|
|
|
$decrypted = true; |
361
|
|
|
// Else (or if decryption failed for some reason: Probe the valid time range |
362
|
|
|
} else { |
363
|
|
|
// Run through the valid seconds range |
364
|
|
|
for ($time = $now - $minimum; $time >= $now - $maximium; --$time) { |
365
|
|
|
// Probe the current timestamp |
366
|
|
|
if ($this->_probeTimedHMAC($hmac, $hmacParams, $time, |
|
|
|
|
367
|
|
|
$time > $initial) || (($time <= $initial) && $this->_probeTimedHMAC($hmac, $hmacParams, |
|
|
|
|
368
|
|
|
$time, true)) |
|
|
|
|
369
|
|
|
) { |
370
|
|
|
$this->_delay = $now - $time; |
371
|
|
|
$decrypted = true; |
372
|
|
|
break; |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
// Else: Check for HMAC match |
377
|
|
|
} else { |
378
|
|
|
$currentHMAC = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac(serialize($hmacParams)); |
379
|
|
|
$decrypted = $hmac == $currentHMAC; |
380
|
|
|
$this->_debug('Probing HMAC with parameters', $hmacParams); |
|
|
|
|
381
|
|
|
$this->_debug('Current HMAC:', $currentHMAC); |
|
|
|
|
382
|
|
|
} |
383
|
|
|
// Register the initial HTTP method in case decryption was successfull |
384
|
|
|
if ($decrypted && $previousMethod) { |
|
|
|
|
385
|
|
|
$this->_method = $previousMethod; |
|
|
|
|
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
return $decrypted; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Probe a set of HMAC parameters with timestamp (for both initial or follow-up requests) |
393
|
|
|
* |
394
|
|
|
* @param \string $hmac HMAC |
395
|
|
|
* @param \array $hmacParams HMAC parameters |
396
|
|
|
* @param \int $timestamp Timestamp |
397
|
|
|
* @param \boolean $followUp Follow-up request |
398
|
|
|
* |
399
|
|
|
* @return \boolean HMAC matches |
400
|
|
|
*/ |
401
|
|
|
protected function _probeTimedHMAC($hmac, array $hmacParams, $timestamp, $followUp = false) |
402
|
|
|
{ |
403
|
|
|
if ($followUp) { |
404
|
|
|
$hmacParams[] = true; |
405
|
|
|
} |
406
|
|
|
$hmacParams[] = $timestamp; |
407
|
|
|
$currentHMAC = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac(serialize($hmacParams)); |
408
|
|
|
$this->_debug('Probing HMAC with parameters', $hmacParams); |
|
|
|
|
409
|
|
|
$this->_debug('Current HMAC:', $currentHMAC); |
|
|
|
|
410
|
|
|
|
411
|
|
|
return $currentHMAC == $hmac; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* Create and return the submission HMAC |
416
|
|
|
* |
417
|
|
|
* @param \int $now Current timestamp |
418
|
|
|
* |
419
|
|
|
* @return \string Submission HMAC |
420
|
|
|
*/ |
421
|
|
|
protected function _hmac(&$now = null) |
422
|
|
|
{ |
423
|
|
|
$hmacParams = array($this->_token); |
|
|
|
|
424
|
|
|
// If session token checks are enabled |
425
|
|
|
if ($this->_sessionTokenEnabled()) { |
|
|
|
|
426
|
|
|
$hmacParams[] = session_id(); |
427
|
|
|
} |
428
|
|
|
// If there is an invalid current HMAC |
429
|
|
|
if ($this->_valid === false) { |
|
|
|
|
430
|
|
|
$hmacParams[] = self::BLOCK; |
431
|
|
|
// Else |
432
|
|
|
} else { |
433
|
|
|
// If submission time checks are enabled |
434
|
|
|
if ($this->_submissionMethodOrderEnabled()) { |
|
|
|
|
435
|
|
|
$hmacParams[] = $this->_method ?: strtoupper($_SERVER['REQUEST_METHOD']); |
436
|
|
|
} |
437
|
|
|
// If submission time checks are enabled |
438
|
|
|
if ($this->_submissionTimeEnabled()) { |
|
|
|
|
439
|
|
|
if ($this->_data) { |
|
|
|
|
440
|
|
|
$hmacParams[] = true; |
441
|
|
|
} |
442
|
|
|
$hmacParams[] = |
443
|
|
|
$now = time(); |
444
|
|
|
} |
445
|
|
|
} |
446
|
|
|
$hmac = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac(serialize($hmacParams)); |
447
|
|
|
$this->_debug('Creating HMAC for parameters', $hmacParams); |
|
|
|
|
448
|
|
|
$this->_debug('HMAC:', $hmac); |
|
|
|
|
449
|
|
|
|
450
|
|
|
return $hmac; |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Calculate the HMAC |
455
|
|
|
* |
456
|
|
|
* @param ServerRequestInterface $request Request |
457
|
|
|
* @param Antibot $antibot Antibot instance |
458
|
|
|
* @param int|null $now Current timestamp |
459
|
|
|
* |
460
|
|
|
* @return string HMAC |
461
|
|
|
*/ |
462
|
3 |
|
protected function calculateHmac(ServerRequestInterface $request, Antibot $antibot, int &$now = null): string |
463
|
|
|
{ |
464
|
3 |
|
$hmacParams = [$antibot->getUnique()]; |
465
|
3 |
|
$now = null; |
466
|
|
|
|
467
|
|
|
// Invalidate the HMAC if there's a current, invalid one |
468
|
3 |
|
if (false) { |
|
|
|
|
469
|
|
|
|
470
|
|
|
} else { |
471
|
3 |
|
$serverParams = $request->getServerParams(); |
472
|
|
|
|
473
|
|
|
// If the request method vector should be used |
474
|
3 |
|
if (!empty($this->methodVector)) { |
475
|
2 |
|
$requestMethod = empty($serverParams['REQUEST_METHOD']) ? '' : $serverParams['REQUEST_METHOD']; |
476
|
2 |
|
$hmacParams[] = $this->validateRequestMethod($requestMethod); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
// If submission time checks are enabled |
480
|
3 |
|
if (!empty($this->submissionTimes)) { |
481
|
1 |
|
if (!empty($antibot->getData())) { |
482
|
|
|
$hmacParams[] = true; |
483
|
|
|
} |
484
|
1 |
|
$hmacParams[] = $now = time(); |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
// print_r($hmacParams); |
489
|
|
|
|
490
|
3 |
|
$hmac = HmacFactory::createFromString(serialize($hmacParams), $antibot->getUnique()); |
491
|
|
|
|
492
|
3 |
|
return $hmac; |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..