You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.9 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\Encryption;
  25. use OC\Files\Filesystem;
  26. use OC\Files\Storage\Wrapper\Encryption;
  27. use OC\Files\View;
  28. use OC\Memcache\ArrayCache;
  29. use OCP\Files\Mount\IMountPoint;
  30. use OCP\Files\Storage;
  31. use OCP\ILogger;
  32. /**
  33. * Class EncryptionWrapper
  34. *
  35. * applies the encryption storage wrapper
  36. *
  37. * @package OC\Encryption
  38. */
  39. class EncryptionWrapper {
  40. /** @var ArrayCache */
  41. private $arrayCache;
  42. /** @var Manager */
  43. private $manager;
  44. /** @var ILogger */
  45. private $logger;
  46. /**
  47. * EncryptionWrapper constructor.
  48. *
  49. * @param ArrayCache $arrayCache
  50. * @param Manager $manager
  51. * @param ILogger $logger
  52. */
  53. public function __construct(ArrayCache $arrayCache,
  54. Manager $manager,
  55. ILogger $logger
  56. ) {
  57. $this->arrayCache = $arrayCache;
  58. $this->manager = $manager;
  59. $this->logger = $logger;
  60. }
  61. /**
  62. * Wraps the given storage when it is not a shared storage
  63. *
  64. * @param string $mountPoint
  65. * @param Storage $storage
  66. * @param IMountPoint $mount
  67. * @return Encryption|Storage
  68. */
  69. public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
  70. $parameters = [
  71. 'storage' => $storage,
  72. 'mountPoint' => $mountPoint,
  73. 'mount' => $mount
  74. ];
  75. if (!$storage->instanceOfStorage(Storage\IDisableEncryptionStorage::class)) {
  76. $user = \OC::$server->getUserSession()->getUser();
  77. $mountManager = Filesystem::getMountManager();
  78. $uid = $user ? $user->getUID() : null;
  79. $fileHelper = \OC::$server->getEncryptionFilesHelper();
  80. $keyStorage = \OC::$server->getEncryptionKeyStorage();
  81. $util = new Util(
  82. new View(),
  83. \OC::$server->getUserManager(),
  84. \OC::$server->getGroupManager(),
  85. \OC::$server->getConfig()
  86. );
  87. $update = new Update(
  88. new View(),
  89. $util,
  90. Filesystem::getMountManager(),
  91. $this->manager,
  92. $fileHelper,
  93. $uid
  94. );
  95. return new Encryption(
  96. $parameters,
  97. $this->manager,
  98. $util,
  99. $this->logger,
  100. $fileHelper,
  101. $uid,
  102. $keyStorage,
  103. $update,
  104. $mountManager,
  105. $this->arrayCache
  106. );
  107. } else {
  108. return $storage;
  109. }
  110. }
  111. }