1
0

EncryptionWrapper.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. *
  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 OC\Encryption;
  23. use OC\Memcache\ArrayCache;
  24. use OC\Files\Filesystem;
  25. use OC\Files\Storage\Wrapper\Encryption;
  26. use OCP\Files\Mount\IMountPoint;
  27. use OC\Files\View;
  28. use OCP\Files\Storage;
  29. use OCP\ILogger;
  30. /**
  31. * Class EncryptionWrapper
  32. *
  33. * applies the encryption storage wrapper
  34. *
  35. * @package OC\Encryption
  36. */
  37. class EncryptionWrapper {
  38. /** @var ArrayCache */
  39. private $arrayCache;
  40. /** @var Manager */
  41. private $manager;
  42. /** @var ILogger */
  43. private $logger;
  44. /**
  45. * EncryptionWrapper constructor.
  46. *
  47. * @param ArrayCache $arrayCache
  48. * @param Manager $manager
  49. * @param ILogger $logger
  50. */
  51. public function __construct(ArrayCache $arrayCache,
  52. Manager $manager,
  53. ILogger $logger
  54. ) {
  55. $this->arrayCache = $arrayCache;
  56. $this->manager = $manager;
  57. $this->logger = $logger;
  58. }
  59. /**
  60. * Wraps the given storage when it is not a shared storage
  61. *
  62. * @param string $mountPoint
  63. * @param Storage $storage
  64. * @param IMountPoint $mount
  65. * @return Encryption|Storage
  66. */
  67. public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
  68. $parameters = [
  69. 'storage' => $storage,
  70. 'mountPoint' => $mountPoint,
  71. 'mount' => $mount
  72. ];
  73. if (!$storage->instanceOfStorage('OCA\Files_Sharing\SharedStorage')
  74. && !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')
  75. && !$storage->instanceOfStorage('OC\Files\Storage\OwnCloud')) {
  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. }