1
0

Setup.php 926 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. public function __construct(
  12. private Crypt $crypt,
  13. private KeyManager $keyManager,
  14. ) {
  15. }
  16. /**
  17. * @param string $uid user id
  18. * @param string $password user password
  19. * @return bool
  20. */
  21. public function setupUser($uid, $password) {
  22. if (!$this->keyManager->userHasKeys($uid)) {
  23. $keyPair = $this->crypt->createKeyPair();
  24. return is_array($keyPair) ? $this->keyManager->storeKeyPair($uid, $password, $keyPair) : false;
  25. }
  26. return true;
  27. }
  28. /**
  29. * make sure that all system keys exists
  30. */
  31. public function setupSystem() {
  32. $this->keyManager->validateShareKey();
  33. $this->keyManager->validateMasterKey();
  34. }
  35. }