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