Setup.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Clark Tomlinson <fallen013@gmail.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Encryption\Users;
  26. use OCA\Encryption\Crypto\Crypt;
  27. use OCA\Encryption\KeyManager;
  28. use OCP\ILogger;
  29. use OCP\IUserSession;
  30. class Setup {
  31. /**
  32. * @var Crypt
  33. */
  34. private $crypt;
  35. /**
  36. * @var KeyManager
  37. */
  38. private $keyManager;
  39. /**
  40. * @var ILogger
  41. */
  42. private $logger;
  43. /**
  44. * @var bool|string
  45. */
  46. private $user;
  47. /**
  48. * @param ILogger $logger
  49. * @param IUserSession $userSession
  50. * @param Crypt $crypt
  51. * @param KeyManager $keyManager
  52. */
  53. public function __construct(ILogger $logger,
  54. IUserSession $userSession,
  55. Crypt $crypt,
  56. KeyManager $keyManager) {
  57. $this->logger = $logger;
  58. $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false;
  59. $this->crypt = $crypt;
  60. $this->keyManager = $keyManager;
  61. }
  62. /**
  63. * @param string $uid user id
  64. * @param string $password user password
  65. * @return bool
  66. */
  67. public function setupUser($uid, $password) {
  68. if (!$this->keyManager->userHasKeys($uid)) {
  69. return $this->keyManager->storeKeyPair($uid, $password,
  70. $this->crypt->createKeyPair());
  71. }
  72. return true;
  73. }
  74. /**
  75. * make sure that all system keys exists
  76. */
  77. public function setupSystem() {
  78. $this->keyManager->validateShareKey();
  79. $this->keyManager->validateMasterKey();
  80. }
  81. }