IEncryptionModule.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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 OCP\Encryption;
  26. use Symfony\Component\Console\Input\InputInterface;
  27. use Symfony\Component\Console\Output\OutputInterface;
  28. /**
  29. * Interface IEncryptionModule
  30. *
  31. * @package OCP\Encryption
  32. * @since 8.1.0
  33. */
  34. interface IEncryptionModule {
  35. /**
  36. * @return string defining the technical unique id
  37. * @since 8.1.0
  38. */
  39. public function getId();
  40. /**
  41. * In comparison to getKey() this function returns a human readable (maybe translated) name
  42. *
  43. * @return string
  44. * @since 8.1.0
  45. */
  46. public function getDisplayName();
  47. /**
  48. * start receiving chunks from a file. This is the place where you can
  49. * perform some initial step before starting encrypting/decrypting the
  50. * chunks
  51. *
  52. * @param string $path to the file
  53. * @param string $user who read/write the file (null for public access)
  54. * @param string $mode php stream open mode
  55. * @param array $header contains the header data read from the file
  56. * @param array $accessList who has access to the file contains the key 'users' and 'public'
  57. *
  58. * $return array $header contain data as key-value pairs which should be
  59. * written to the header, in case of a write operation
  60. * or if no additional data is needed return a empty array
  61. * @since 8.1.0
  62. */
  63. public function begin($path, $user, $mode, array $header, array $accessList);
  64. /**
  65. * last chunk received. This is the place where you can perform some final
  66. * operation and return some remaining data if something is left in your
  67. * buffer.
  68. *
  69. * @param string $path to the file
  70. * @param string $position id of the last block (looks like "<Number>end")
  71. *
  72. * @return string remained data which should be written to the file in case
  73. * of a write operation
  74. *
  75. * @since 8.1.0
  76. * @since 9.0.0 parameter $position added
  77. */
  78. public function end($path, $position);
  79. /**
  80. * encrypt data
  81. *
  82. * @param string $data you want to encrypt
  83. * @param string $position position of the block we want to encrypt (starts with '0')
  84. *
  85. * @return mixed encrypted data
  86. *
  87. * @since 8.1.0
  88. * @since 9.0.0 parameter $position added
  89. */
  90. public function encrypt($data, $position);
  91. /**
  92. * decrypt data
  93. *
  94. * @param string $data you want to decrypt
  95. * @param string $position position of the block we want to decrypt
  96. *
  97. * @return mixed decrypted data
  98. *
  99. * @since 8.1.0
  100. * @since 9.0.0 parameter $position added
  101. */
  102. public function decrypt($data, $position);
  103. /**
  104. * update encrypted file, e.g. give additional users access to the file
  105. *
  106. * @param string $path path to the file which should be updated
  107. * @param string $uid of the user who performs the operation
  108. * @param array $accessList who has access to the file contains the key 'users' and 'public'
  109. * @return boolean
  110. * @since 8.1.0
  111. */
  112. public function update($path, $uid, array $accessList);
  113. /**
  114. * should the file be encrypted or not
  115. *
  116. * @param string $path
  117. * @return boolean
  118. * @since 8.1.0
  119. */
  120. public function shouldEncrypt($path);
  121. /**
  122. * get size of the unencrypted payload per block.
  123. * ownCloud read/write files with a block size of 8192 byte
  124. *
  125. * @param bool $signed
  126. * @return int
  127. * @since 8.1.0 optional parameter $signed was added in 9.0.0
  128. */
  129. public function getUnencryptedBlockSize($signed = false);
  130. /**
  131. * check if the encryption module is able to read the file,
  132. * e.g. if all encryption keys exists
  133. *
  134. * @param string $path
  135. * @param string $uid user for whom we want to check if he can read the file
  136. * @return boolean
  137. * @since 8.1.0
  138. */
  139. public function isReadable($path, $uid);
  140. /**
  141. * Initial encryption of all files
  142. *
  143. * @param InputInterface $input
  144. * @param OutputInterface $output write some status information to the terminal during encryption
  145. * @since 8.2.0
  146. */
  147. public function encryptAll(InputInterface $input, OutputInterface $output);
  148. /**
  149. * prepare encryption module to decrypt all files
  150. *
  151. * @param InputInterface $input
  152. * @param OutputInterface $output write some status information to the terminal during encryption
  153. * @param $user (optional) for which the files should be decrypted, default = all users
  154. * @return bool return false on failure or if it isn't supported by the module
  155. * @since 8.2.0
  156. */
  157. public function prepareDecryptAll(InputInterface $input, OutputInterface $output, $user = '');
  158. /**
  159. * Check if the module is ready to be used by that specific user.
  160. * In case a module is not ready - because e.g. key pairs have not been generated
  161. * upon login this method can return false before any operation starts and might
  162. * cause issues during operations.
  163. *
  164. * @param string $user
  165. * @return boolean
  166. * @since 9.1.0
  167. */
  168. public function isReadyForUser($user);
  169. }