GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( cbd473...ead32d )
by François
03:13
created

Otp::verify()   B

Complexity

Conditions 4
Paths 12

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 17
nc 12
nop 1
dl 0
loc 31
rs 8.5806
c 0
b 0
f 0
1
<?php
2
/**
3
 *  Copyright (C) 2016 SURFnet.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
namespace SURFnet\VPN\Server;
19
20
use Psr\Log\LoggerInterface;
21
use SURFnet\VPN\Common\HttpClient\ServerClient;
22
use SURFnet\VPN\Server\Exception\InputValidationException;
23
24
class Otp
25
{
26
    /** @var \Psr\Log\LoggerInterface */
27
    private $logger;
28
29
    /** @var \SURFnet\VPN\Common\HttpClient\HttpClientInterface */
30
    private $serverClient;
31
32
    public function __construct(LoggerInterface $logger, ServerClient $serverClient)
33
    {
34
        $this->logger = $logger;
35
        $this->serverClient = $serverClient;
0 ignored issues
show
Documentation Bug introduced by
It seems like $serverClient of type object<SURFnet\VPN\Commo...ttpClient\ServerClient> is incompatible with the declared type object<SURFnet\VPN\Commo...nt\HttpClientInterface> of property $serverClient.

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..

Loading history...
36
    }
37
38
    public function verify(array $envData)
39
    {
40
        try {
41
            InputValidation::userName($envData['username']);
42
            $commonName = InputValidation::commonName($envData['common_name']);
43
            $otpKey = InputValidation::otpKey($envData['password']);
44
            $userId = self::getUserId($commonName);
45
46
            // user has OTP secret registered?
47
            if (false === $this->serverClient->hasOtpSecret($userId)) {
0 ignored issues
show
Bug introduced by
The method hasOtpSecret() does not seem to exist on object<SURFnet\VPN\Commo...nt\HttpClientInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
                $this->logger->error('no OTP secret registered', $envData);
49
50
                return false;
51
            }
52
53
            // verify the OTP key
54
            if (false === $this->serverClient->verifyOtpKey($userId, $otpKey)) {
0 ignored issues
show
Bug introduced by
The method verifyOtpKey() does not seem to exist on object<SURFnet\VPN\Commo...nt\HttpClientInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
                $this->logger->error('invalid OTP key', $envData);
56
57
                return false;
58
            }
59
60
            $this->logger->info('OTP verified', $envData);
61
62
            return true;
63
        } catch (InputValidationException $e) {
64
            $this->logger->error($e->getMessage(), $envData);
65
66
            return false;
67
        }
68
    }
69
70
    private static function getUserId($commonName)
71
    {
72
        // XXX share this with "Connection" class and possibly others
73
74
        // return the part before the first underscore, it is already validated
75
        // so we can be sure this is fine
76
        return substr($commonName, 0, strpos($commonName, '_'));
77
    }
78
}
79