1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the tiqr project. |
4
|
|
|
* |
5
|
|
|
* The tiqr project aims to provide an open implementation for |
6
|
|
|
* authentication using mobile devices. It was initiated by |
7
|
|
|
* SURFnet and developed by Egeniq. |
8
|
|
|
* |
9
|
|
|
* More information: http://www.tiqr.org |
10
|
|
|
* |
11
|
|
|
* @author Ivo Jansch <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @package tiqr |
14
|
|
|
* |
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
16
|
|
|
* |
17
|
|
|
* @copyright (C) 2010-2012 SURFnet BV |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
use Psr\Log\LoggerInterface; |
21
|
|
|
|
22
|
1 |
|
require_once 'Tiqr/UserStorage/FileTrait.php'; |
23
|
1 |
|
require_once 'Tiqr/UserSecretStorage/UserSecretStorageTrait.php'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* This user storage implementation implements a simple user's secret storage using json files. |
27
|
|
|
* This is mostly for demonstration and development purposes. In a production environment |
28
|
|
|
* please supply your own implementation that hosts the data in your user database OR |
29
|
|
|
* in a secure (e.g. hardware encrypted) storage. |
30
|
|
|
* @author ivo |
31
|
|
|
*/ |
32
|
|
|
class Tiqr_UserSecretStorage_File implements Tiqr_UserSecretStorage_Interface |
33
|
|
|
{ |
34
|
|
|
use UserSecretStorageTrait; |
35
|
|
|
use FileTrait; |
36
|
|
|
|
37
|
|
|
private $userSecretStorage; |
|
|
|
|
38
|
|
|
|
39
|
|
|
private $logger; |
40
|
|
|
|
41
|
|
|
private $path; |
42
|
|
|
|
43
|
5 |
|
public function __construct( |
44
|
|
|
Tiqr_UserSecretStorage_Encryption_Interface $encryption, |
45
|
|
|
string $path, |
46
|
|
|
LoggerInterface $logger |
47
|
|
|
) { |
48
|
|
|
// See UserSecretStorageTrait |
49
|
5 |
|
$this->encryption = $encryption; |
50
|
5 |
|
$this->logger = $logger; |
51
|
5 |
|
$this->path = $path; |
52
|
5 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the user's secret |
56
|
|
|
* |
57
|
|
|
* @param String $userId |
58
|
|
|
* |
59
|
|
|
* @return String The user's secret |
60
|
|
|
*/ |
61
|
1 |
|
private function getUserSecret($userId) |
|
|
|
|
62
|
|
|
{ |
63
|
1 |
|
if ($data = $this->_loadUser($userId)) { |
64
|
1 |
|
if (isset($data["secret"])) { |
65
|
1 |
|
return $data["secret"]; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
$this->logger->error('Unable to retrieve the secret (user not found). In user secret storage (file)'); |
69
|
|
|
return NULL; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Store a secret for a user |
74
|
|
|
* |
75
|
|
|
* @param String $userId |
76
|
|
|
* @param String $secret |
77
|
|
|
*/ |
78
|
1 |
|
private function setUserSecret($userId, $secret) |
|
|
|
|
79
|
|
|
{ |
80
|
1 |
|
$data = $this->_loadUser($userId, false); |
81
|
1 |
|
$data["secret"] = $secret; |
82
|
1 |
|
$this->_saveUser($userId, $data); |
|
|
|
|
83
|
1 |
|
} |
84
|
|
|
} |
85
|
|
|
|