Setup.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Clark Tomlinson <fallen013@gmail.com>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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. use OCA\Encryption\Crypto\Crypt;
  30. use OCA\Encryption\KeyManager;
  31. class Setup {
  32. /** @var Crypt */
  33. private $crypt;
  34. /** @var KeyManager */
  35. private $keyManager;
  36. public function __construct(Crypt $crypt,
  37. KeyManager $keyManager) {
  38. $this->crypt = $crypt;
  39. $this->keyManager = $keyManager;
  40. }
  41. /**
  42. * @param string $uid user id
  43. * @param string $password user password
  44. * @return bool
  45. */
  46. public function setupUser($uid, $password) {
  47. if (!$this->keyManager->userHasKeys($uid)) {
  48. $keyPair = $this->crypt->createKeyPair();
  49. return is_array($keyPair) ? $this->keyManager->storeKeyPair($uid, $password, $keyPair) : false;
  50. }
  51. return true;
  52. }
  53. /**
  54. * make sure that all system keys exists
  55. */
  56. public function setupSystem() {
  57. $this->keyManager->validateShareKey();
  58. $this->keyManager->validateMasterKey();
  59. }
  60. }