Passed
Push — master ( 1c7137...b5ef5e )
by Pieter van der
03:26 queued 14s
created

_getProtocolSpecificOCRAWrapper()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 0
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
require_once("Tiqr/OATH/OCRAWrapper.php");
22
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
    public function __construct($config)
43
    {
44
        $this->_ocraSuite = $config['ocra.suite'];
45
        $this->_protocolVersion = $config['protocolVersion'];
46
        $this->_ocraWrapper_v1 = new Tiqr_OCRAWrapper_v1($this->_ocraSuite);
47
        $this->_ocraWrapper = new Tiqr_OCRAWrapper($this->_ocraSuite);
48
    }
49
50
    /**
51
     * Get the correct protocol specific ocra wrapper
52
     *
53
     * @return Tiqr_OCRAWrapper|Tiqr_OCRAWrapper_v1
54
     */
55
    protected function _getProtocolSpecificOCRAWrapper()
56
    {
57
        if ($this->_protocolVersion < 2) {
58
            return $this->_ocraWrapper_v1;
59
        } else {
60
            return $this->_ocraWrapper;
61
        }
62
    }
63
64
    /**
65
     * Get the ocra challenge
66
     *
67
     * @return String The challenge
68
     */
69
    public function generateChallenge()
70
    {
71
        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
    public function verifyResponseWithSecret($response, $userSecret, $challenge, $sessionKey)
85
    {
86
        return $this->_getProtocolSpecificOCRAWrapper()->verifyResponse($response, $userSecret, $challenge, $sessionKey);
87
    }
88
}
89