Passed
Pull Request — develop (#27)
by Michiel
06:20
created

_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
use Psr\Log\LoggerInterface;
22
23 1
require_once("Tiqr/OATH/OCRAWrapper.php");
24 1
require_once("Tiqr/OATH/OCRAWrapper_v1.php");
25
26
/**
27
 * The implementation for the tiqr ocra service class.
28
 *
29
 * @author lineke
30
 *
31
 */
32
class Tiqr_OcraService_Tiqr extends Tiqr_OcraService_Abstract
33
{
34
    protected $_ocraSuite;
35
    protected $_ocraWrapper;
36
    protected $_ocraWrapper_v1;
37
    protected $_protocolVersion;
38
39
    /**
40
     * @var LoggerInterface
41
     */
42
    private $logger;
43
44
    /**
45
     * Construct a ocra service class
46
     *
47
     * @param array $config The configuration that a specific user class may use.
48
     */
49 5
    public function __construct($config, LoggerInterface $logger)
50
    {
51 5
        $this->_ocraSuite = $config['ocra.suite'];
52 5
        $this->_protocolVersion = $config['protocolVersion'];
53 5
        $this->_ocraWrapper_v1 = new Tiqr_OCRAWrapper_v1($this->_ocraSuite);
54 5
        $this->_ocraWrapper = new Tiqr_OCRAWrapper($this->_ocraSuite);
55 5
        $this->logger = $logger;
56 5
    }
57
58
    /**
59
     * Get the correct protocol specific ocra wrapper
60
     *
61
     * @return Tiqr_OCRAWrapper|Tiqr_OCRAWrapper_v1
62
     */
63 1
    protected function _getProtocolSpecificOCRAWrapper()
64
    {
65 1
        if ($this->_protocolVersion < 2) {
66
            $this->logger->info('Using Tiqr_OCRAWrapper_v1 as protocol');
67
            return $this->_ocraWrapper_v1;
68
        } else {
69 1
            $this->logger->info('Using Tiqr_OCRAWrapper as protocol');
70 1
            return $this->_ocraWrapper;
71
        }
72
    }
73
74
    /**
75
     * Get the ocra challenge
76
     *
77
     * @return String The challenge
78
     */
79 1
    public function generateChallenge()
80
    {
81 1
        return $this->_ocraWrapper->generateChallenge();
82
    }
83
84
    /**
85
     * Verify the response
86
     *
87
     * @param string $response
88
     * @param string $userSecret
89
     * @param string $challenge
90
     * @param string $sessionKey
91
     *
92
     * @return boolean True if response matches, false otherwise
93
     */
94 1
    public function verifyResponseWithSecret($response, $userSecret, $challenge, $sessionKey)
95
    {
96 1
        $this->logger->info('Verify the response is correct');
97 1
        return $this->_getProtocolSpecificOCRAWrapper()->verifyResponse($response, $userSecret, $challenge, $sessionKey);
98
    }
99
}
100