1 | <?php |
||
2 | /** |
||
3 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
||
4 | * |
||
5 | * @author Björn Schießle <[email protected]> |
||
6 | * @author Christoph Wurst <[email protected]> |
||
7 | * @author Clark Tomlinson <[email protected]> |
||
8 | * @author Julius Härtl <[email protected]> |
||
9 | * @author Lukas Reschke <[email protected]> |
||
10 | * @author Morris Jobke <[email protected]> |
||
11 | * @author Thomas Müller <[email protected]> |
||
12 | * |
||
13 | * @license AGPL-3.0 |
||
14 | * |
||
15 | * This code is free software: you can redistribute it and/or modify |
||
16 | * it under the terms of the GNU Affero General Public License, version 3, |
||
17 | * as published by the Free Software Foundation. |
||
18 | * |
||
19 | * This program is distributed in the hope that it will be useful, |
||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
22 | * GNU Affero General Public License for more details. |
||
23 | * |
||
24 | * You should have received a copy of the GNU Affero General Public License, version 3, |
||
25 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
||
26 | * |
||
27 | */ |
||
28 | namespace OCA\Encryption\Users; |
||
29 | |||
30 | use OCA\Encryption\Crypto\Crypt; |
||
31 | use OCA\Encryption\KeyManager; |
||
32 | |||
33 | class Setup { |
||
34 | /** @var Crypt */ |
||
35 | private $crypt; |
||
36 | /** @var KeyManager */ |
||
37 | private $keyManager; |
||
38 | |||
39 | public function __construct(Crypt $crypt, |
||
40 | KeyManager $keyManager) { |
||
41 | $this->crypt = $crypt; |
||
42 | $this->keyManager = $keyManager; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param string $uid user id |
||
47 | * @param string $password user password |
||
48 | * @return bool |
||
49 | */ |
||
50 | public function setupUser($uid, $password) { |
||
51 | if (!$this->keyManager->userHasKeys($uid)) { |
||
52 | $keyPair = $this->crypt->createKeyPair(); |
||
53 | return is_array($keyPair) ? $this->keyManager->storeKeyPair($uid, $password, $keyPair) : false; |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
54 | } |
||
55 | return true; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * make sure that all system keys exists |
||
60 | */ |
||
61 | public function setupSystem() { |
||
62 | $this->keyManager->validateShareKey(); |
||
63 | $this->keyManager->validateMasterKey(); |
||
64 | } |
||
65 | } |
||
66 |