EncryptionWrapper.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 OCP\ILogger;
  33. use Psr\Log\LoggerInterface;
  34. /**
  35. * Class EncryptionWrapper
  36. *
  37. * applies the encryption storage wrapper
  38. *
  39. * @package OC\Encryption
  40. */
  41. class EncryptionWrapper {
  42. /** @var ArrayCache */
  43. private $arrayCache;
  44. /** @var Manager */
  45. private $manager;
  46. /** @var ILogger */
  47. private $logger;
  48. /**
  49. * EncryptionWrapper constructor.
  50. *
  51. * @param ArrayCache $arrayCache
  52. * @param Manager $manager
  53. * @param ILogger $logger
  54. */
  55. public function __construct(ArrayCache $arrayCache,
  56. Manager $manager,
  57. ILogger $logger
  58. ) {
  59. $this->arrayCache = $arrayCache;
  60. $this->manager = $manager;
  61. $this->logger = $logger;
  62. }
  63. /**
  64. * Wraps the given storage when it is not a shared storage
  65. *
  66. * @param string $mountPoint
  67. * @param Storage $storage
  68. * @param IMountPoint $mount
  69. * @return Encryption|Storage
  70. */
  71. public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
  72. $parameters = [
  73. 'storage' => $storage,
  74. 'mountPoint' => $mountPoint,
  75. 'mount' => $mount
  76. ];
  77. if (!$storage->instanceOfStorage(Storage\IDisableEncryptionStorage::class) && $mountPoint !== '/') {
  78. $user = \OC::$server->getUserSession()->getUser();
  79. $mountManager = Filesystem::getMountManager();
  80. $uid = $user ? $user->getUID() : null;
  81. $fileHelper = \OC::$server->getEncryptionFilesHelper();
  82. $keyStorage = \OC::$server->getEncryptionKeyStorage();
  83. $util = new Util(
  84. new View(),
  85. \OC::$server->getUserManager(),
  86. \OC::$server->getGroupManager(),
  87. \OC::$server->getConfig()
  88. );
  89. $update = new Update(
  90. new View(),
  91. $util,
  92. Filesystem::getMountManager(),
  93. $this->manager,
  94. $fileHelper,
  95. \OC::$server->get(LoggerInterface::class),
  96. $uid
  97. );
  98. return new Encryption(
  99. $parameters,
  100. $this->manager,
  101. $util,
  102. $this->logger,
  103. $fileHelper,
  104. $uid,
  105. $keyStorage,
  106. $update,
  107. $mountManager,
  108. $this->arrayCache
  109. );
  110. } else {
  111. return $storage;
  112. }
  113. }
  114. }