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-2011 SURFnet BV |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @internal includes |
24
|
|
|
*/ |
25
|
|
|
require_once("OATH/OCRAParser.php"); |
26
|
|
|
require_once("Tiqr/Random.php"); |
27
|
|
|
require_once("Tiqr/OATH/OCRA.php"); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* A wrapper for the OCRA algorithm implementing just the features we support. |
31
|
|
|
* @author ivo |
32
|
|
|
*/ |
33
|
|
|
class Tiqr_OCRAWrapper |
34
|
|
|
{ |
35
|
|
|
private $_ocraParser; |
36
|
|
|
private $_ocraSuite; |
37
|
|
|
|
38
|
7 |
|
public function __construct($ocraSuite) { |
39
|
7 |
|
$this->_ocraSuite = $ocraSuite; |
40
|
7 |
|
$this->_ocraParser = new OATH_OCRAParser($ocraSuite); |
41
|
7 |
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Generate a challenge string based on an ocraSuite |
46
|
|
|
* @return String An OCRA challenge that matches the specification of |
47
|
|
|
* the ocraSuite. |
48
|
|
|
*/ |
49
|
1 |
|
public function generateChallenge() |
50
|
|
|
{ |
51
|
1 |
|
return $this->_ocraParser->generateChallenge(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Generate a session key based on an ocraSuite |
56
|
|
|
* @return String Hexadecimal session key |
57
|
|
|
*/ |
58
|
3 |
|
public function generateSessionKey() |
59
|
|
|
{ |
60
|
3 |
|
return $this->_ocraParser->generateSessionInformation(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Calculate an OCRA repsonse to a given OCRA challenge, according to |
65
|
|
|
* the algorithm specified by an OCRA Suite. |
66
|
|
|
* @param String $secret a hex representation of the user's secret |
67
|
|
|
* @param String $challenge a hex or (alfa)numeric challenge question |
68
|
|
|
* @param String $sessionKey a hex sessionKey identifying the current session |
69
|
|
|
* @return String An OCRA response, the length of which is determined by the |
70
|
|
|
* OCRA suite. |
71
|
|
|
*/ |
72
|
3 |
|
public function calculateResponse($secret, $challenge, $sessionKey) |
73
|
|
|
{ |
74
|
3 |
|
return OCRA::generateOCRA($this->_ocraSuite, $secret, "", $challenge, "", $sessionKey, ""); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Calculate and verify an OCRA response. |
79
|
|
|
* @param String $response Expected OCRA response |
80
|
|
|
* @param String $secret a hex representation of the user's secret |
81
|
|
|
* @param String $challenge a hex or (alfa)numeric challenge question |
82
|
|
|
* @param String $sessionKey the sessionKey identifying the current session |
83
|
|
|
* @return Boolean True if response matches, false otherwise |
84
|
|
|
*/ |
85
|
2 |
|
public function verifyResponse($response, $secret, $challenge, $sessionKey) |
86
|
|
|
{ |
87
|
2 |
|
$expected = OCRA::generateOCRA($this->_ocraSuite, $secret, "", $challenge, "", $sessionKey, ""); |
|
|
|
|
88
|
2 |
|
return $this->_ocraParser->constEqual($expected, $response); |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|