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
|
|
|
/** |
22
|
|
|
* The implementation for the tiqr ocra service class. |
23
|
|
|
* |
24
|
|
|
* @author lineke |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
class Tiqr_OcraService_Tiqr extends Tiqr_OcraService_Abstract |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @see Tiqr_OcraService_Interface::verifyResponse() |
32
|
|
|
*/ |
33
|
4 |
|
public function verifyResponse(String $response, String $userId, String $userSecret, String $challenge, String $sessionInformation): bool |
34
|
|
|
{ |
35
|
|
|
// Calculate the response. Because we have the same information as the client this should result in the same |
36
|
|
|
// response as the client calculated. |
37
|
|
|
try { |
38
|
4 |
|
$expected = OCRA::generateOCRA($this->_ocraSuite, $userSecret, "", $challenge, "", $sessionInformation, ""); |
39
|
|
|
} |
40
|
|
|
catch (Exception $e) { |
41
|
|
|
$this->logger->warning(sprintf('Error calculating OCRA response for user "%s"', $userId), array('exception'=>$e)); |
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
|
45
|
4 |
|
if (strlen($expected) != strlen($response)) { |
46
|
2 |
|
$this->logger->warning('verifyResponse: calculated and expected response have different lengths'); |
47
|
|
|
} |
48
|
|
|
// Use constant time compare |
49
|
4 |
|
return $this->_ocraParser->constEqual($expected, $response); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|