Passed
Push — develop ( 1e050e...a909ab )
by Pieter van der
01:06 queued 12s
created

Tiqr_OcraService_Tiqr::_getProtocolSpecificOCRAWrapper()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 8
ccs 4
cts 6
cp 0.6667
rs 10
cc 2
nc 2
nop 0
crap 2.1481
1
<?php
2
3
/**
4
 * This file is part of the tiqr project.
5
 *
6
 * The tiqr project aims to provide an open implementation for
7
 * authentication using mobile devices. It was initiated by
8
 * SURFnet and developed by Egeniq.
9
 *
10
 * More information: http://www.tiqr.org
11
 *
12
 * @author Ivo Jansch <[email protected]>
13
 *
14
 * @package tiqr
15
 *
16
 * @license New BSD License - See LICENSE file for details.
17
 *
18
 * @copyright (C) 2010-2012 SURFnet BV
19
 */
20
21
/**
22
 * The implementation for the tiqr ocra service class.
23
 *
24
 * @author lineke
25
 *
26
 */
27
class Tiqr_OcraService_Tiqr extends Tiqr_OcraService_Abstract
28
{
29
30
    /**
31
     *  @see Tiqr_OcraService_Interface::verifyResponse()
32
     */
33 3
    public function verifyResponse(String $response, String $userId, String $userSecret, String $challenge, String $sessionInformation): bool
34
    {
35
        // Calculate the response. Because we have the same information as the client this should result in the same
36
        // response as the client calculated.
37
        try {
38 3
            $expected = OCRA::generateOCRA($this->_ocraSuite, $userSecret, "", $challenge, "", $sessionInformation, "");
39
        }
40
        catch (Exception $e) {
41
            $this->logger->warning(sprintf('Error calculating OCRA response for user "%s"', $userId), array('exception'=>$e));
42
            return false;
43
        }
44
45 3
        if (strlen($expected) != strlen($response)) {
46 1
            $this->logger->warning('verifyResponse: calculated and expected response have different lengths');
47
        }
48
        // Use constant time compare
49 3
        return $this->_ocraParser->constEqual($expected, $response);
50
    }
51
}
52