EncryptionWrapper.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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 OC\Encryption;
  26. use OC\Files\Filesystem;
  27. use OC\Files\Storage\Wrapper\Encryption;
  28. use OC\Files\View;
  29. use OC\Memcache\ArrayCache;
  30. use OCP\Files\Mount\IMountPoint;
  31. use OCP\Files\Storage;
  32. use Psr\Log\LoggerInterface;
  33. /**
  34. * Class EncryptionWrapper
  35. *
  36. * applies the encryption storage wrapper
  37. *
  38. * @package OC\Encryption
  39. */
  40. class EncryptionWrapper {
  41. /** @var ArrayCache */
  42. private $arrayCache;
  43. /** @var Manager */
  44. private $manager;
  45. private LoggerInterface $logger;
  46. /**
  47. * EncryptionWrapper constructor.
  48. */
  49. public function __construct(ArrayCache $arrayCache,
  50. Manager $manager,
  51. LoggerInterface $logger
  52. ) {
  53. $this->arrayCache = $arrayCache;
  54. $this->manager = $manager;
  55. $this->logger = $logger;
  56. }
  57. /**
  58. * Wraps the given storage when it is not a shared storage
  59. *
  60. * @param string $mountPoint
  61. * @param Storage $storage
  62. * @param IMountPoint $mount
  63. * @return Encryption|Storage
  64. */
  65. public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
  66. $parameters = [
  67. 'storage' => $storage,
  68. 'mountPoint' => $mountPoint,
  69. 'mount' => $mount
  70. ];
  71. if (!$storage->instanceOfStorage(Storage\IDisableEncryptionStorage::class) && $mountPoint !== '/') {
  72. $user = \OC::$server->getUserSession()->getUser();
  73. $mountManager = Filesystem::getMountManager();
  74. $uid = $user ? $user->getUID() : null;
  75. $fileHelper = \OC::$server->getEncryptionFilesHelper();
  76. $keyStorage = \OC::$server->getEncryptionKeyStorage();
  77. $util = new Util(
  78. new View(),
  79. \OC::$server->getUserManager(),
  80. \OC::$server->getGroupManager(),
  81. \OC::$server->getConfig()
  82. );
  83. $update = new Update(
  84. new View(),
  85. $util,
  86. Filesystem::getMountManager(),
  87. $this->manager,
  88. $fileHelper,
  89. $this->logger,
  90. $uid
  91. );
  92. return new Encryption(
  93. $parameters,
  94. $this->manager,
  95. $util,
  96. $this->logger,
  97. $fileHelper,
  98. $uid,
  99. $keyStorage,
  100. $update,
  101. $mountManager,
  102. $this->arrayCache
  103. );
  104. } else {
  105. return $storage;
  106. }
  107. }
  108. }