2015-02-24 13:05:19 -05:00
|
|
|
<?php
|
2024-05-28 16:42:42 +02:00
|
|
|
|
2015-02-24 13:05:19 -05:00
|
|
|
/**
|
2024-05-28 16:42:42 +02: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 {
|
2015-02-24 13:05:19 -05:00
|
|
|
|
2024-09-24 23:37:18 +02:00
|
|
|
public function __construct(
|
|
|
|
private Crypt $crypt,
|
|
|
|
private KeyManager $keyManager,
|
|
|
|
) {
|
2020-04-09 09:22:29 +02:00
|
|
|
}
|
2015-02-24 13:05:19 -05:00
|
|
|
|
|
|
|
/**
|
2016-03-02 13:58:06 +01:00
|
|
|
* @param string $uid user id
|
2015-04-09 10:54:53 +02: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 13:58:06 +01:00
|
|
|
if (!$this->keyManager->userHasKeys($uid)) {
|
2020-07-22 10:05:51 +02:00
|
|
|
$keyPair = $this->crypt->createKeyPair();
|
|
|
|
return is_array($keyPair) ? $this->keyManager->storeKeyPair($uid, $password, $keyPair) : false;
|
2016-03-02 13:58:06 +01:00
|
|
|
}
|
|
|
|
return true;
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-02 13:58:06 +01:00
|
|
|
* make sure that all system keys exists
|
2015-02-24 13:05:19 -05:00
|
|
|
*/
|
2016-03-02 13:58:06 +01:00
|
|
|
public function setupSystem() {
|
2015-04-17 17:51:18 +02:00
|
|
|
$this->keyManager->validateShareKey();
|
2015-09-07 11:38:44 +02:00
|
|
|
$this->keyManager->validateMasterKey();
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
}
|