1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupU2fBundle\Validator\Constraints; |
20
|
|
|
|
21
|
|
|
use Surfnet\StepupU2fBundle\Exception\LogicException; |
22
|
|
|
use Symfony\Component\Validator\Constraint; |
23
|
|
|
use Symfony\Component\Validator\ConstraintValidator; |
24
|
|
|
|
25
|
|
|
final class SignatureDataConstraintValidator extends ConstraintValidator |
26
|
|
|
{ |
27
|
|
|
const STRICT = true; |
28
|
|
|
|
29
|
|
|
public function validate($value, Constraint $constraint) |
30
|
|
|
{ |
31
|
|
|
if (!$constraint instanceof SignatureDataConstraint) { |
32
|
|
|
throw new LogicException('SignatureDataConstraintValidator can only validate SignatureDataConstraints'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (!is_string($value)) { |
36
|
|
|
$this->context->addViolation($constraint->message, ['%reason%' => 'Not a string'], $value); |
|
|
|
|
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$decoded = base64_decode(strtr($value, '-_', '+/'), self::STRICT); |
41
|
|
|
|
42
|
|
View Code Duplication |
if ($decoded === false) { |
|
|
|
|
43
|
|
|
$this->context->addViolation($constraint->message, ['%reason%' => 'Not base64 decodable'], $value); |
|
|
|
|
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// See yubico/u2flib-server/src/u2flib_server/U2F.php:290 |
48
|
|
View Code Duplication |
if (strlen($decoded) < 6) { |
|
|
|
|
49
|
|
|
$this->context->addViolation($constraint->message, ['%reason%' => 'Too short'], $value); |
|
|
|
|
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.