2015-02-24 13:05:19 -05:00
|
|
|
<?php
|
2024-05-28 10:42:42 -04:00
|
|
|
|
2015-02-24 13:05:19 -05:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-02-24 13:05:19 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Encryption\Users;
|
|
|
|
|
|
|
|
|
|
use OCA\Encryption\Crypto\Crypt;
|
|
|
|
|
use OCA\Encryption\KeyManager;
|
|
|
|
|
|
2015-03-31 14:50:58 -04:00
|
|
|
class Setup {
|
2020-11-22 15:56:00 -05:00
|
|
|
/** @var Crypt */
|
2015-02-24 13:05:19 -05:00
|
|
|
private $crypt;
|
2020-11-22 15:56:00 -05:00
|
|
|
/** @var KeyManager */
|
2015-02-24 13:05:19 -05:00
|
|
|
private $keyManager;
|
|
|
|
|
|
2020-11-22 15:56:00 -05:00
|
|
|
public function __construct(Crypt $crypt,
|
2023-11-23 04:22:34 -05:00
|
|
|
KeyManager $keyManager) {
|
2015-02-24 13:05:19 -05:00
|
|
|
$this->crypt = $crypt;
|
|
|
|
|
$this->keyManager = $keyManager;
|
2020-04-09 03:22:29 -04:00
|
|
|
}
|
2015-02-24 13:05:19 -05:00
|
|
|
|
|
|
|
|
/**
|
2016-03-02 07:58:06 -05:00
|
|
|
* @param string $uid user id
|
2015-04-09 04:54:53 -04:00
|
|
|
* @param string $password user password
|
2015-02-24 13:05:19 -05:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2015-03-24 17:29:10 -04:00
|
|
|
public function setupUser($uid, $password) {
|
2016-03-02 07:58:06 -05:00
|
|
|
if (!$this->keyManager->userHasKeys($uid)) {
|
2020-07-22 04:05:51 -04:00
|
|
|
$keyPair = $this->crypt->createKeyPair();
|
|
|
|
|
return is_array($keyPair) ? $this->keyManager->storeKeyPair($uid, $password, $keyPair) : false;
|
2016-03-02 07:58:06 -05:00
|
|
|
}
|
|
|
|
|
return true;
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-02 07:58:06 -05:00
|
|
|
* make sure that all system keys exists
|
2015-02-24 13:05:19 -05:00
|
|
|
*/
|
2016-03-02 07:58:06 -05:00
|
|
|
public function setupSystem() {
|
2015-04-17 11:51:18 -04:00
|
|
|
$this->keyManager->validateShareKey();
|
2015-09-07 05:38:44 -04:00
|
|
|
$this->keyManager->validateMasterKey();
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
}
|