1
0

Setup.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Encryption\Users;
  8. use OCA\Encryption\Crypto\Crypt;
  9. use OCA\Encryption\KeyManager;
  10. class Setup {
  11. /** @var Crypt */
  12. private $crypt;
  13. /** @var KeyManager */
  14. private $keyManager;
  15. public function __construct(Crypt $crypt,
  16. KeyManager $keyManager) {
  17. $this->crypt = $crypt;
  18. $this->keyManager = $keyManager;
  19. }
  20. /**
  21. * @param string $uid user id
  22. * @param string $password user password
  23. * @return bool
  24. */
  25. public function setupUser($uid, $password) {
  26. if (!$this->keyManager->userHasKeys($uid)) {
  27. $keyPair = $this->crypt->createKeyPair();
  28. return is_array($keyPair) ? $this->keyManager->storeKeyPair($uid, $password, $keyPair) : false;
  29. }
  30. return true;
  31. }
  32. /**
  33. * make sure that all system keys exists
  34. */
  35. public function setupSystem() {
  36. $this->keyManager->validateShareKey();
  37. $this->keyManager->validateMasterKey();
  38. }
  39. }