Passed
Push — develop ( e65dcd...17c2da )
by Pieter van der
05:58
created

Tiqr_OcraService_Tiqr   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 57
ccs 13
cts 14
cp 0.9286
rs 10

4 Methods

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