setup.php 2.1 KB

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