@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @return bool |
| 168 | 168 | */ |
| 169 | 169 | public function userHasFiles($uid) { |
| 170 | - return $this->files->file_exists($uid . '/files'); |
|
| 170 | + return $this->files->file_exists($uid.'/files'); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | if (count($parts) > 1) { |
| 184 | 184 | $owner = $parts[1]; |
| 185 | 185 | if ($this->userManager->userExists($owner) === false) { |
| 186 | - throw new \BadMethodCallException('Unknown user: ' . |
|
| 186 | + throw new \BadMethodCallException('Unknown user: '. |
|
| 187 | 187 | 'method expects path to a user folder relative to the data folder'); |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -36,164 +36,164 @@ |
||
| 36 | 36 | use OCP\PreConditionNotMetException; |
| 37 | 37 | |
| 38 | 38 | class Util { |
| 39 | - /** |
|
| 40 | - * @var View |
|
| 41 | - */ |
|
| 42 | - private $files; |
|
| 43 | - /** |
|
| 44 | - * @var Crypt |
|
| 45 | - */ |
|
| 46 | - private $crypt; |
|
| 47 | - /** |
|
| 48 | - * @var ILogger |
|
| 49 | - */ |
|
| 50 | - private $logger; |
|
| 51 | - /** |
|
| 52 | - * @var bool|IUser |
|
| 53 | - */ |
|
| 54 | - private $user; |
|
| 55 | - /** |
|
| 56 | - * @var IConfig |
|
| 57 | - */ |
|
| 58 | - private $config; |
|
| 59 | - /** |
|
| 60 | - * @var IUserManager |
|
| 61 | - */ |
|
| 62 | - private $userManager; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Util constructor. |
|
| 66 | - * |
|
| 67 | - * @param View $files |
|
| 68 | - * @param Crypt $crypt |
|
| 69 | - * @param ILogger $logger |
|
| 70 | - * @param IUserSession $userSession |
|
| 71 | - * @param IConfig $config |
|
| 72 | - * @param IUserManager $userManager |
|
| 73 | - */ |
|
| 74 | - public function __construct(View $files, |
|
| 75 | - Crypt $crypt, |
|
| 76 | - ILogger $logger, |
|
| 77 | - IUserSession $userSession, |
|
| 78 | - IConfig $config, |
|
| 79 | - IUserManager $userManager |
|
| 80 | - ) { |
|
| 81 | - $this->files = $files; |
|
| 82 | - $this->crypt = $crypt; |
|
| 83 | - $this->logger = $logger; |
|
| 84 | - $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false; |
|
| 85 | - $this->config = $config; |
|
| 86 | - $this->userManager = $userManager; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * check if recovery key is enabled for user |
|
| 91 | - * |
|
| 92 | - * @param string $uid |
|
| 93 | - * @return bool |
|
| 94 | - */ |
|
| 95 | - public function isRecoveryEnabledForUser($uid) { |
|
| 96 | - $recoveryMode = $this->config->getUserValue($uid, |
|
| 97 | - 'encryption', |
|
| 98 | - 'recoveryEnabled', |
|
| 99 | - '0'); |
|
| 100 | - |
|
| 101 | - return ($recoveryMode === '1'); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * check if the home storage should be encrypted |
|
| 106 | - * |
|
| 107 | - * @return bool |
|
| 108 | - */ |
|
| 109 | - public function shouldEncryptHomeStorage() { |
|
| 110 | - $encryptHomeStorage = $this->config->getAppValue( |
|
| 111 | - 'encryption', |
|
| 112 | - 'encryptHomeStorage', |
|
| 113 | - '1' |
|
| 114 | - ); |
|
| 115 | - |
|
| 116 | - return ($encryptHomeStorage === '1'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * set the home storage encryption on/off |
|
| 121 | - * |
|
| 122 | - * @param bool $encryptHomeStorage |
|
| 123 | - */ |
|
| 124 | - public function setEncryptHomeStorage($encryptHomeStorage) { |
|
| 125 | - $value = $encryptHomeStorage ? '1' : '0'; |
|
| 126 | - $this->config->setAppValue( |
|
| 127 | - 'encryption', |
|
| 128 | - 'encryptHomeStorage', |
|
| 129 | - $value |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * check if master key is enabled |
|
| 135 | - * |
|
| 136 | - * @return bool |
|
| 137 | - */ |
|
| 138 | - public function isMasterKeyEnabled() { |
|
| 139 | - $userMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', '1'); |
|
| 140 | - return ($userMasterKey === '1'); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param $enabled |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - public function setRecoveryForUser($enabled) { |
|
| 148 | - $value = $enabled ? '1' : '0'; |
|
| 149 | - |
|
| 150 | - try { |
|
| 151 | - $this->config->setUserValue($this->user->getUID(), |
|
| 152 | - 'encryption', |
|
| 153 | - 'recoveryEnabled', |
|
| 154 | - $value); |
|
| 155 | - return true; |
|
| 156 | - } catch (PreConditionNotMetException $e) { |
|
| 157 | - return false; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param string $uid |
|
| 163 | - * @return bool |
|
| 164 | - */ |
|
| 165 | - public function userHasFiles($uid) { |
|
| 166 | - return $this->files->file_exists($uid . '/files'); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * get owner from give path, path relative to data/ expected |
|
| 171 | - * |
|
| 172 | - * @param string $path relative to data/ |
|
| 173 | - * @return string |
|
| 174 | - * @throws \BadMethodCallException |
|
| 175 | - */ |
|
| 176 | - public function getOwner($path) { |
|
| 177 | - $owner = ''; |
|
| 178 | - $parts = explode('/', $path, 3); |
|
| 179 | - if (count($parts) > 1) { |
|
| 180 | - $owner = $parts[1]; |
|
| 181 | - if ($this->userManager->userExists($owner) === false) { |
|
| 182 | - throw new \BadMethodCallException('Unknown user: ' . |
|
| 183 | - 'method expects path to a user folder relative to the data folder'); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $owner; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * get storage of path |
|
| 192 | - * |
|
| 193 | - * @param string $path |
|
| 194 | - * @return \OC\Files\Storage\Storage |
|
| 195 | - */ |
|
| 196 | - public function getStorage($path) { |
|
| 197 | - return $this->files->getMount($path)->getStorage(); |
|
| 198 | - } |
|
| 39 | + /** |
|
| 40 | + * @var View |
|
| 41 | + */ |
|
| 42 | + private $files; |
|
| 43 | + /** |
|
| 44 | + * @var Crypt |
|
| 45 | + */ |
|
| 46 | + private $crypt; |
|
| 47 | + /** |
|
| 48 | + * @var ILogger |
|
| 49 | + */ |
|
| 50 | + private $logger; |
|
| 51 | + /** |
|
| 52 | + * @var bool|IUser |
|
| 53 | + */ |
|
| 54 | + private $user; |
|
| 55 | + /** |
|
| 56 | + * @var IConfig |
|
| 57 | + */ |
|
| 58 | + private $config; |
|
| 59 | + /** |
|
| 60 | + * @var IUserManager |
|
| 61 | + */ |
|
| 62 | + private $userManager; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Util constructor. |
|
| 66 | + * |
|
| 67 | + * @param View $files |
|
| 68 | + * @param Crypt $crypt |
|
| 69 | + * @param ILogger $logger |
|
| 70 | + * @param IUserSession $userSession |
|
| 71 | + * @param IConfig $config |
|
| 72 | + * @param IUserManager $userManager |
|
| 73 | + */ |
|
| 74 | + public function __construct(View $files, |
|
| 75 | + Crypt $crypt, |
|
| 76 | + ILogger $logger, |
|
| 77 | + IUserSession $userSession, |
|
| 78 | + IConfig $config, |
|
| 79 | + IUserManager $userManager |
|
| 80 | + ) { |
|
| 81 | + $this->files = $files; |
|
| 82 | + $this->crypt = $crypt; |
|
| 83 | + $this->logger = $logger; |
|
| 84 | + $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false; |
|
| 85 | + $this->config = $config; |
|
| 86 | + $this->userManager = $userManager; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * check if recovery key is enabled for user |
|
| 91 | + * |
|
| 92 | + * @param string $uid |
|
| 93 | + * @return bool |
|
| 94 | + */ |
|
| 95 | + public function isRecoveryEnabledForUser($uid) { |
|
| 96 | + $recoveryMode = $this->config->getUserValue($uid, |
|
| 97 | + 'encryption', |
|
| 98 | + 'recoveryEnabled', |
|
| 99 | + '0'); |
|
| 100 | + |
|
| 101 | + return ($recoveryMode === '1'); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * check if the home storage should be encrypted |
|
| 106 | + * |
|
| 107 | + * @return bool |
|
| 108 | + */ |
|
| 109 | + public function shouldEncryptHomeStorage() { |
|
| 110 | + $encryptHomeStorage = $this->config->getAppValue( |
|
| 111 | + 'encryption', |
|
| 112 | + 'encryptHomeStorage', |
|
| 113 | + '1' |
|
| 114 | + ); |
|
| 115 | + |
|
| 116 | + return ($encryptHomeStorage === '1'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * set the home storage encryption on/off |
|
| 121 | + * |
|
| 122 | + * @param bool $encryptHomeStorage |
|
| 123 | + */ |
|
| 124 | + public function setEncryptHomeStorage($encryptHomeStorage) { |
|
| 125 | + $value = $encryptHomeStorage ? '1' : '0'; |
|
| 126 | + $this->config->setAppValue( |
|
| 127 | + 'encryption', |
|
| 128 | + 'encryptHomeStorage', |
|
| 129 | + $value |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * check if master key is enabled |
|
| 135 | + * |
|
| 136 | + * @return bool |
|
| 137 | + */ |
|
| 138 | + public function isMasterKeyEnabled() { |
|
| 139 | + $userMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', '1'); |
|
| 140 | + return ($userMasterKey === '1'); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param $enabled |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + public function setRecoveryForUser($enabled) { |
|
| 148 | + $value = $enabled ? '1' : '0'; |
|
| 149 | + |
|
| 150 | + try { |
|
| 151 | + $this->config->setUserValue($this->user->getUID(), |
|
| 152 | + 'encryption', |
|
| 153 | + 'recoveryEnabled', |
|
| 154 | + $value); |
|
| 155 | + return true; |
|
| 156 | + } catch (PreConditionNotMetException $e) { |
|
| 157 | + return false; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param string $uid |
|
| 163 | + * @return bool |
|
| 164 | + */ |
|
| 165 | + public function userHasFiles($uid) { |
|
| 166 | + return $this->files->file_exists($uid . '/files'); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * get owner from give path, path relative to data/ expected |
|
| 171 | + * |
|
| 172 | + * @param string $path relative to data/ |
|
| 173 | + * @return string |
|
| 174 | + * @throws \BadMethodCallException |
|
| 175 | + */ |
|
| 176 | + public function getOwner($path) { |
|
| 177 | + $owner = ''; |
|
| 178 | + $parts = explode('/', $path, 3); |
|
| 179 | + if (count($parts) > 1) { |
|
| 180 | + $owner = $parts[1]; |
|
| 181 | + if ($this->userManager->userExists($owner) === false) { |
|
| 182 | + throw new \BadMethodCallException('Unknown user: ' . |
|
| 183 | + 'method expects path to a user folder relative to the data folder'); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $owner; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * get storage of path |
|
| 192 | + * |
|
| 193 | + * @param string $path |
|
| 194 | + * @return \OC\Files\Storage\Storage |
|
| 195 | + */ |
|
| 196 | + public function getStorage($path) { |
|
| 197 | + return $this->files->getMount($path)->getStorage(); |
|
| 198 | + } |
|
| 199 | 199 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | // always use the version from the original file, also part files |
| 205 | 205 | // need to have a correct version number if they get moved over to the |
| 206 | 206 | // final location |
| 207 | - $this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View()); |
|
| 207 | + $this->version = (int) $this->keyManager->getVersion($this->stripPartFileExtension($path), new View()); |
|
| 208 | 208 | |
| 209 | 209 | if ( |
| 210 | 210 | $mode === 'w' |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | if ($this->writeCache) { |
| 309 | 309 | |
| 310 | 310 | // Concat writeCache to start of $data |
| 311 | - $data = $this->writeCache . $data; |
|
| 311 | + $data = $this->writeCache.$data; |
|
| 312 | 312 | |
| 313 | 313 | // Clear the write cache, ready for reuse - it has been |
| 314 | 314 | // flushed and its old contents processed |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | try { |
| 405 | 405 | $publicKeys[$user] = $this->keyManager->getPublicKey($user); |
| 406 | 406 | } catch (PublicKeyMissingException $e) { |
| 407 | - $this->logger->warning('Could not encrypt file for ' . $user . ': ' . $e->getMessage()); |
|
| 407 | + $this->logger->warning('Could not encrypt file for '.$user.': '.$e->getMessage()); |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
@@ -492,8 +492,8 @@ discard block |
||
| 492 | 492 | // error message because in this case it means that the file was |
| 493 | 493 | // shared with the user at a point where the user didn't had a |
| 494 | 494 | // valid private/public key |
| 495 | - $msg = 'Encryption module "' . $this->getDisplayName() . |
|
| 496 | - '" is not able to read ' . $path; |
|
| 495 | + $msg = 'Encryption module "'.$this->getDisplayName(). |
|
| 496 | + '" is not able to read '.$path; |
|
| 497 | 497 | $hint = $this->l->t('Can not read this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'); |
| 498 | 498 | $this->logger->warning($msg); |
| 499 | 499 | throw new DecryptionFailedException($msg, $hint); |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | $realPath = $path; |
| 536 | 536 | $parts = explode('/', $path); |
| 537 | 537 | if ($parts[2] === 'files_versions') { |
| 538 | - $realPath = '/' . $parts[1] . '/files/' . implode('/', array_slice($parts, 3)); |
|
| 538 | + $realPath = '/'.$parts[1].'/files/'.implode('/', array_slice($parts, 3)); |
|
| 539 | 539 | $length = strrpos($realPath, '.'); |
| 540 | 540 | $realPath = substr($realPath, 0, $length); |
| 541 | 541 | } |
@@ -45,553 +45,553 @@ |
||
| 45 | 45 | use Symfony\Component\Console\Output\OutputInterface; |
| 46 | 46 | |
| 47 | 47 | class Encryption implements IEncryptionModule { |
| 48 | - public const ID = 'OC_DEFAULT_MODULE'; |
|
| 49 | - public const DISPLAY_NAME = 'Default encryption module'; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var Crypt |
|
| 53 | - */ |
|
| 54 | - private $crypt; |
|
| 55 | - |
|
| 56 | - /** @var string */ |
|
| 57 | - private $cipher; |
|
| 58 | - |
|
| 59 | - /** @var string */ |
|
| 60 | - private $path; |
|
| 61 | - |
|
| 62 | - /** @var string */ |
|
| 63 | - private $user; |
|
| 64 | - |
|
| 65 | - /** @var array */ |
|
| 66 | - private $owner; |
|
| 67 | - |
|
| 68 | - /** @var string */ |
|
| 69 | - private $fileKey; |
|
| 70 | - |
|
| 71 | - /** @var string */ |
|
| 72 | - private $writeCache; |
|
| 73 | - |
|
| 74 | - /** @var KeyManager */ |
|
| 75 | - private $keyManager; |
|
| 76 | - |
|
| 77 | - /** @var array */ |
|
| 78 | - private $accessList; |
|
| 79 | - |
|
| 80 | - /** @var boolean */ |
|
| 81 | - private $isWriteOperation; |
|
| 82 | - |
|
| 83 | - /** @var Util */ |
|
| 84 | - private $util; |
|
| 85 | - |
|
| 86 | - /** @var Session */ |
|
| 87 | - private $session; |
|
| 88 | - |
|
| 89 | - /** @var ILogger */ |
|
| 90 | - private $logger; |
|
| 91 | - |
|
| 92 | - /** @var IL10N */ |
|
| 93 | - private $l; |
|
| 94 | - |
|
| 95 | - /** @var EncryptAll */ |
|
| 96 | - private $encryptAll; |
|
| 97 | - |
|
| 98 | - /** @var bool */ |
|
| 99 | - private $useMasterPassword; |
|
| 100 | - |
|
| 101 | - /** @var DecryptAll */ |
|
| 102 | - private $decryptAll; |
|
| 103 | - |
|
| 104 | - /** @var int unencrypted block size if block contains signature */ |
|
| 105 | - private $unencryptedBlockSizeSigned = 6072; |
|
| 106 | - |
|
| 107 | - /** @var int unencrypted block size */ |
|
| 108 | - private $unencryptedBlockSize = 6126; |
|
| 109 | - |
|
| 110 | - /** @var int Current version of the file */ |
|
| 111 | - private $version = 0; |
|
| 112 | - |
|
| 113 | - /** @var array remember encryption signature version */ |
|
| 114 | - private static $rememberVersion = []; |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * |
|
| 119 | - * @param Crypt $crypt |
|
| 120 | - * @param KeyManager $keyManager |
|
| 121 | - * @param Util $util |
|
| 122 | - * @param Session $session |
|
| 123 | - * @param EncryptAll $encryptAll |
|
| 124 | - * @param DecryptAll $decryptAll |
|
| 125 | - * @param ILogger $logger |
|
| 126 | - * @param IL10N $il10n |
|
| 127 | - */ |
|
| 128 | - public function __construct(Crypt $crypt, |
|
| 129 | - KeyManager $keyManager, |
|
| 130 | - Util $util, |
|
| 131 | - Session $session, |
|
| 132 | - EncryptAll $encryptAll, |
|
| 133 | - DecryptAll $decryptAll, |
|
| 134 | - ILogger $logger, |
|
| 135 | - IL10N $il10n) { |
|
| 136 | - $this->crypt = $crypt; |
|
| 137 | - $this->keyManager = $keyManager; |
|
| 138 | - $this->util = $util; |
|
| 139 | - $this->session = $session; |
|
| 140 | - $this->encryptAll = $encryptAll; |
|
| 141 | - $this->decryptAll = $decryptAll; |
|
| 142 | - $this->logger = $logger; |
|
| 143 | - $this->l = $il10n; |
|
| 144 | - $this->owner = []; |
|
| 145 | - $this->useMasterPassword = $util->isMasterKeyEnabled(); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return string defining the technical unique id |
|
| 150 | - */ |
|
| 151 | - public function getId() { |
|
| 152 | - return self::ID; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 157 | - * |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public function getDisplayName() { |
|
| 161 | - return self::DISPLAY_NAME; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * start receiving chunks from a file. This is the place where you can |
|
| 166 | - * perform some initial step before starting encrypting/decrypting the |
|
| 167 | - * chunks |
|
| 168 | - * |
|
| 169 | - * @param string $path to the file |
|
| 170 | - * @param string $user who read/write the file |
|
| 171 | - * @param string $mode php stream open mode |
|
| 172 | - * @param array $header contains the header data read from the file |
|
| 173 | - * @param array $accessList who has access to the file contains the key 'users' and 'public' |
|
| 174 | - * |
|
| 175 | - * @return array $header contain data as key-value pairs which should be |
|
| 176 | - * written to the header, in case of a write operation |
|
| 177 | - * or if no additional data is needed return a empty array |
|
| 178 | - */ |
|
| 179 | - public function begin($path, $user, $mode, array $header, array $accessList) { |
|
| 180 | - $this->path = $this->getPathToRealFile($path); |
|
| 181 | - $this->accessList = $accessList; |
|
| 182 | - $this->user = $user; |
|
| 183 | - $this->isWriteOperation = false; |
|
| 184 | - $this->writeCache = ''; |
|
| 185 | - |
|
| 186 | - if ($this->session->isReady() === false) { |
|
| 187 | - // if the master key is enabled we can initialize encryption |
|
| 188 | - // with a empty password and user name |
|
| 189 | - if ($this->util->isMasterKeyEnabled()) { |
|
| 190 | - $this->keyManager->init('', ''); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($this->session->decryptAllModeActivated()) { |
|
| 195 | - $encryptedFileKey = $this->keyManager->getEncryptedFileKey($this->path); |
|
| 196 | - $shareKey = $this->keyManager->getShareKey($this->path, $this->session->getDecryptAllUid()); |
|
| 197 | - $this->fileKey = $this->crypt->multiKeyDecrypt($encryptedFileKey, |
|
| 198 | - $shareKey, |
|
| 199 | - $this->session->getDecryptAllKey()); |
|
| 200 | - } else { |
|
| 201 | - $this->fileKey = $this->keyManager->getFileKey($this->path, $this->user); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // always use the version from the original file, also part files |
|
| 205 | - // need to have a correct version number if they get moved over to the |
|
| 206 | - // final location |
|
| 207 | - $this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View()); |
|
| 208 | - |
|
| 209 | - if ( |
|
| 210 | - $mode === 'w' |
|
| 211 | - || $mode === 'w+' |
|
| 212 | - || $mode === 'wb' |
|
| 213 | - || $mode === 'wb+' |
|
| 214 | - ) { |
|
| 215 | - $this->isWriteOperation = true; |
|
| 216 | - if (empty($this->fileKey)) { |
|
| 217 | - $this->fileKey = $this->crypt->generateFileKey(); |
|
| 218 | - } |
|
| 219 | - } else { |
|
| 220 | - // if we read a part file we need to increase the version by 1 |
|
| 221 | - // because the version number was also increased by writing |
|
| 222 | - // the part file |
|
| 223 | - if (Scanner::isPartialFile($path)) { |
|
| 224 | - $this->version = $this->version + 1; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - if ($this->isWriteOperation) { |
|
| 229 | - $this->cipher = $this->crypt->getCipher(); |
|
| 230 | - } elseif (isset($header['cipher'])) { |
|
| 231 | - $this->cipher = $header['cipher']; |
|
| 232 | - } else { |
|
| 233 | - // if we read a file without a header we fall-back to the legacy cipher |
|
| 234 | - // which was used in <=oC6 |
|
| 235 | - $this->cipher = $this->crypt->getLegacyCipher(); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return ['cipher' => $this->cipher, 'signed' => 'true']; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * last chunk received. This is the place where you can perform some final |
|
| 243 | - * operation and return some remaining data if something is left in your |
|
| 244 | - * buffer. |
|
| 245 | - * |
|
| 246 | - * @param string $path to the file |
|
| 247 | - * @param int $position |
|
| 248 | - * @return string remained data which should be written to the file in case |
|
| 249 | - * of a write operation |
|
| 250 | - * @throws PublicKeyMissingException |
|
| 251 | - * @throws \Exception |
|
| 252 | - * @throws \OCA\Encryption\Exceptions\MultiKeyEncryptException |
|
| 253 | - */ |
|
| 254 | - public function end($path, $position = 0) { |
|
| 255 | - $result = ''; |
|
| 256 | - if ($this->isWriteOperation) { |
|
| 257 | - // in case of a part file we remember the new signature versions |
|
| 258 | - // the version will be set later on update. |
|
| 259 | - // This way we make sure that other apps listening to the pre-hooks |
|
| 260 | - // still get the old version which should be the correct value for them |
|
| 261 | - if (Scanner::isPartialFile($path)) { |
|
| 262 | - self::$rememberVersion[$this->stripPartFileExtension($path)] = $this->version + 1; |
|
| 263 | - } |
|
| 264 | - if (!empty($this->writeCache)) { |
|
| 265 | - $result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version + 1, $position); |
|
| 266 | - $this->writeCache = ''; |
|
| 267 | - } |
|
| 268 | - $publicKeys = []; |
|
| 269 | - if ($this->useMasterPassword === true) { |
|
| 270 | - $publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey(); |
|
| 271 | - } else { |
|
| 272 | - foreach ($this->accessList['users'] as $uid) { |
|
| 273 | - try { |
|
| 274 | - $publicKeys[$uid] = $this->keyManager->getPublicKey($uid); |
|
| 275 | - } catch (PublicKeyMissingException $e) { |
|
| 276 | - $this->logger->warning( |
|
| 277 | - 'no public key found for user "{uid}", user will not be able to read the file', |
|
| 278 | - ['app' => 'encryption', 'uid' => $uid] |
|
| 279 | - ); |
|
| 280 | - // if the public key of the owner is missing we should fail |
|
| 281 | - if ($uid === $this->user) { |
|
| 282 | - throw $e; |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->getOwner($path)); |
|
| 289 | - $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys); |
|
| 290 | - $this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles); |
|
| 291 | - } |
|
| 292 | - return $result; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * encrypt data |
|
| 299 | - * |
|
| 300 | - * @param string $data you want to encrypt |
|
| 301 | - * @param int $position |
|
| 302 | - * @return string encrypted data |
|
| 303 | - */ |
|
| 304 | - public function encrypt($data, $position = 0) { |
|
| 305 | - // If extra data is left over from the last round, make sure it |
|
| 306 | - // is integrated into the next block |
|
| 307 | - if ($this->writeCache) { |
|
| 308 | - |
|
| 309 | - // Concat writeCache to start of $data |
|
| 310 | - $data = $this->writeCache . $data; |
|
| 311 | - |
|
| 312 | - // Clear the write cache, ready for reuse - it has been |
|
| 313 | - // flushed and its old contents processed |
|
| 314 | - $this->writeCache = ''; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - $encrypted = ''; |
|
| 318 | - // While there still remains some data to be processed & written |
|
| 319 | - while (strlen($data) > 0) { |
|
| 320 | - |
|
| 321 | - // Remaining length for this iteration, not of the |
|
| 322 | - // entire file (may be greater than 8192 bytes) |
|
| 323 | - $remainingLength = strlen($data); |
|
| 324 | - |
|
| 325 | - // If data remaining to be written is less than the |
|
| 326 | - // size of 1 6126 byte block |
|
| 327 | - if ($remainingLength < $this->unencryptedBlockSizeSigned) { |
|
| 328 | - |
|
| 329 | - // Set writeCache to contents of $data |
|
| 330 | - // The writeCache will be carried over to the |
|
| 331 | - // next write round, and added to the start of |
|
| 332 | - // $data to ensure that written blocks are |
|
| 333 | - // always the correct length. If there is still |
|
| 334 | - // data in writeCache after the writing round |
|
| 335 | - // has finished, then the data will be written |
|
| 336 | - // to disk by $this->flush(). |
|
| 337 | - $this->writeCache = $data; |
|
| 338 | - |
|
| 339 | - // Clear $data ready for next round |
|
| 340 | - $data = ''; |
|
| 341 | - } else { |
|
| 342 | - |
|
| 343 | - // Read the chunk from the start of $data |
|
| 344 | - $chunk = substr($data, 0, $this->unencryptedBlockSizeSigned); |
|
| 345 | - |
|
| 346 | - $encrypted .= $this->crypt->symmetricEncryptFileContent($chunk, $this->fileKey, $this->version + 1, $position); |
|
| 347 | - |
|
| 348 | - // Remove the chunk we just processed from |
|
| 349 | - // $data, leaving only unprocessed data in $data |
|
| 350 | - // var, for handling on the next round |
|
| 351 | - $data = substr($data, $this->unencryptedBlockSizeSigned); |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - return $encrypted; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * decrypt data |
|
| 360 | - * |
|
| 361 | - * @param string $data you want to decrypt |
|
| 362 | - * @param int $position |
|
| 363 | - * @return string decrypted data |
|
| 364 | - * @throws DecryptionFailedException |
|
| 365 | - */ |
|
| 366 | - public function decrypt($data, $position = 0) { |
|
| 367 | - if (empty($this->fileKey)) { |
|
| 368 | - $msg = 'Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'; |
|
| 369 | - $hint = $this->l->t('Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'); |
|
| 370 | - $this->logger->error($msg); |
|
| 371 | - |
|
| 372 | - throw new DecryptionFailedException($msg, $hint); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return $this->crypt->symmetricDecryptFileContent($data, $this->fileKey, $this->cipher, $this->version, $position); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * update encrypted file, e.g. give additional users access to the file |
|
| 380 | - * |
|
| 381 | - * @param string $path path to the file which should be updated |
|
| 382 | - * @param string $uid of the user who performs the operation |
|
| 383 | - * @param array $accessList who has access to the file contains the key 'users' and 'public' |
|
| 384 | - * @return boolean |
|
| 385 | - */ |
|
| 386 | - public function update($path, $uid, array $accessList) { |
|
| 387 | - if (empty($accessList)) { |
|
| 388 | - if (isset(self::$rememberVersion[$path])) { |
|
| 389 | - $this->keyManager->setVersion($path, self::$rememberVersion[$path], new View()); |
|
| 390 | - unset(self::$rememberVersion[$path]); |
|
| 391 | - } |
|
| 392 | - return; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - $fileKey = $this->keyManager->getFileKey($path, $uid); |
|
| 396 | - |
|
| 397 | - if (!empty($fileKey)) { |
|
| 398 | - $publicKeys = []; |
|
| 399 | - if ($this->useMasterPassword === true) { |
|
| 400 | - $publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey(); |
|
| 401 | - } else { |
|
| 402 | - foreach ($accessList['users'] as $user) { |
|
| 403 | - try { |
|
| 404 | - $publicKeys[$user] = $this->keyManager->getPublicKey($user); |
|
| 405 | - } catch (PublicKeyMissingException $e) { |
|
| 406 | - $this->logger->warning('Could not encrypt file for ' . $user . ': ' . $e->getMessage()); |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->getOwner($path)); |
|
| 412 | - |
|
| 413 | - $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys); |
|
| 414 | - |
|
| 415 | - $this->keyManager->deleteAllFileKeys($path); |
|
| 416 | - |
|
| 417 | - $this->keyManager->setAllFileKeys($path, $encryptedFileKey); |
|
| 418 | - } else { |
|
| 419 | - $this->logger->debug('no file key found, we assume that the file "{file}" is not encrypted', |
|
| 420 | - ['file' => $path, 'app' => 'encryption']); |
|
| 421 | - |
|
| 422 | - return false; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return true; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * should the file be encrypted or not |
|
| 430 | - * |
|
| 431 | - * @param string $path |
|
| 432 | - * @return boolean |
|
| 433 | - */ |
|
| 434 | - public function shouldEncrypt($path) { |
|
| 435 | - if ($this->util->shouldEncryptHomeStorage() === false) { |
|
| 436 | - $storage = $this->util->getStorage($path); |
|
| 437 | - if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
| 438 | - return false; |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - $parts = explode('/', $path); |
|
| 442 | - if (count($parts) < 4) { |
|
| 443 | - return false; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - if ($parts[2] === 'files') { |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - if ($parts[2] === 'files_versions') { |
|
| 450 | - return true; |
|
| 451 | - } |
|
| 452 | - if ($parts[2] === 'files_trashbin') { |
|
| 453 | - return true; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - return false; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * get size of the unencrypted payload per block. |
|
| 461 | - * Nextcloud read/write files with a block size of 8192 byte |
|
| 462 | - * |
|
| 463 | - * @param bool $signed |
|
| 464 | - * @return int |
|
| 465 | - */ |
|
| 466 | - public function getUnencryptedBlockSize($signed = false) { |
|
| 467 | - if ($signed === false) { |
|
| 468 | - return $this->unencryptedBlockSize; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - return $this->unencryptedBlockSizeSigned; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * check if the encryption module is able to read the file, |
|
| 476 | - * e.g. if all encryption keys exists |
|
| 477 | - * |
|
| 478 | - * @param string $path |
|
| 479 | - * @param string $uid user for whom we want to check if he can read the file |
|
| 480 | - * @return bool |
|
| 481 | - * @throws DecryptionFailedException |
|
| 482 | - */ |
|
| 483 | - public function isReadable($path, $uid) { |
|
| 484 | - $fileKey = $this->keyManager->getFileKey($path, $uid); |
|
| 485 | - if (empty($fileKey)) { |
|
| 486 | - $owner = $this->util->getOwner($path); |
|
| 487 | - if ($owner !== $uid) { |
|
| 488 | - // if it is a shared file we throw a exception with a useful |
|
| 489 | - // error message because in this case it means that the file was |
|
| 490 | - // shared with the user at a point where the user didn't had a |
|
| 491 | - // valid private/public key |
|
| 492 | - $msg = 'Encryption module "' . $this->getDisplayName() . |
|
| 493 | - '" is not able to read ' . $path; |
|
| 494 | - $hint = $this->l->t('Can not read this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'); |
|
| 495 | - $this->logger->warning($msg); |
|
| 496 | - throw new DecryptionFailedException($msg, $hint); |
|
| 497 | - } |
|
| 498 | - return false; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - return true; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Initial encryption of all files |
|
| 506 | - * |
|
| 507 | - * @param InputInterface $input |
|
| 508 | - * @param OutputInterface $output write some status information to the terminal during encryption |
|
| 509 | - */ |
|
| 510 | - public function encryptAll(InputInterface $input, OutputInterface $output) { |
|
| 511 | - $this->encryptAll->encryptAll($input, $output); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * prepare module to perform decrypt all operation |
|
| 516 | - * |
|
| 517 | - * @param InputInterface $input |
|
| 518 | - * @param OutputInterface $output |
|
| 519 | - * @param string $user |
|
| 520 | - * @return bool |
|
| 521 | - */ |
|
| 522 | - public function prepareDecryptAll(InputInterface $input, OutputInterface $output, $user = '') { |
|
| 523 | - return $this->decryptAll->prepare($input, $output, $user); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * @param string $path |
|
| 529 | - * @return string |
|
| 530 | - */ |
|
| 531 | - protected function getPathToRealFile($path) { |
|
| 532 | - $realPath = $path; |
|
| 533 | - $parts = explode('/', $path); |
|
| 534 | - if ($parts[2] === 'files_versions') { |
|
| 535 | - $realPath = '/' . $parts[1] . '/files/' . implode('/', array_slice($parts, 3)); |
|
| 536 | - $length = strrpos($realPath, '.'); |
|
| 537 | - $realPath = substr($realPath, 0, $length); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return $realPath; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * remove .part file extension and the ocTransferId from the file to get the |
|
| 545 | - * original file name |
|
| 546 | - * |
|
| 547 | - * @param string $path |
|
| 548 | - * @return string |
|
| 549 | - */ |
|
| 550 | - protected function stripPartFileExtension($path) { |
|
| 551 | - if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
|
| 552 | - $pos = strrpos($path, '.', -6); |
|
| 553 | - $path = substr($path, 0, $pos); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - return $path; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * get owner of a file |
|
| 561 | - * |
|
| 562 | - * @param string $path |
|
| 563 | - * @return string |
|
| 564 | - */ |
|
| 565 | - protected function getOwner($path) { |
|
| 566 | - if (!isset($this->owner[$path])) { |
|
| 567 | - $this->owner[$path] = $this->util->getOwner($path); |
|
| 568 | - } |
|
| 569 | - return $this->owner[$path]; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Check if the module is ready to be used by that specific user. |
|
| 574 | - * In case a module is not ready - because e.g. key pairs have not been generated |
|
| 575 | - * upon login this method can return false before any operation starts and might |
|
| 576 | - * cause issues during operations. |
|
| 577 | - * |
|
| 578 | - * @param string $user |
|
| 579 | - * @return boolean |
|
| 580 | - * @since 9.1.0 |
|
| 581 | - */ |
|
| 582 | - public function isReadyForUser($user) { |
|
| 583 | - if ($this->util->isMasterKeyEnabled()) { |
|
| 584 | - return true; |
|
| 585 | - } |
|
| 586 | - return $this->keyManager->userHasKeys($user); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * We only need a detailed access list if the master key is not enabled |
|
| 591 | - * |
|
| 592 | - * @return bool |
|
| 593 | - */ |
|
| 594 | - public function needDetailedAccessList() { |
|
| 595 | - return !$this->util->isMasterKeyEnabled(); |
|
| 596 | - } |
|
| 48 | + public const ID = 'OC_DEFAULT_MODULE'; |
|
| 49 | + public const DISPLAY_NAME = 'Default encryption module'; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var Crypt |
|
| 53 | + */ |
|
| 54 | + private $crypt; |
|
| 55 | + |
|
| 56 | + /** @var string */ |
|
| 57 | + private $cipher; |
|
| 58 | + |
|
| 59 | + /** @var string */ |
|
| 60 | + private $path; |
|
| 61 | + |
|
| 62 | + /** @var string */ |
|
| 63 | + private $user; |
|
| 64 | + |
|
| 65 | + /** @var array */ |
|
| 66 | + private $owner; |
|
| 67 | + |
|
| 68 | + /** @var string */ |
|
| 69 | + private $fileKey; |
|
| 70 | + |
|
| 71 | + /** @var string */ |
|
| 72 | + private $writeCache; |
|
| 73 | + |
|
| 74 | + /** @var KeyManager */ |
|
| 75 | + private $keyManager; |
|
| 76 | + |
|
| 77 | + /** @var array */ |
|
| 78 | + private $accessList; |
|
| 79 | + |
|
| 80 | + /** @var boolean */ |
|
| 81 | + private $isWriteOperation; |
|
| 82 | + |
|
| 83 | + /** @var Util */ |
|
| 84 | + private $util; |
|
| 85 | + |
|
| 86 | + /** @var Session */ |
|
| 87 | + private $session; |
|
| 88 | + |
|
| 89 | + /** @var ILogger */ |
|
| 90 | + private $logger; |
|
| 91 | + |
|
| 92 | + /** @var IL10N */ |
|
| 93 | + private $l; |
|
| 94 | + |
|
| 95 | + /** @var EncryptAll */ |
|
| 96 | + private $encryptAll; |
|
| 97 | + |
|
| 98 | + /** @var bool */ |
|
| 99 | + private $useMasterPassword; |
|
| 100 | + |
|
| 101 | + /** @var DecryptAll */ |
|
| 102 | + private $decryptAll; |
|
| 103 | + |
|
| 104 | + /** @var int unencrypted block size if block contains signature */ |
|
| 105 | + private $unencryptedBlockSizeSigned = 6072; |
|
| 106 | + |
|
| 107 | + /** @var int unencrypted block size */ |
|
| 108 | + private $unencryptedBlockSize = 6126; |
|
| 109 | + |
|
| 110 | + /** @var int Current version of the file */ |
|
| 111 | + private $version = 0; |
|
| 112 | + |
|
| 113 | + /** @var array remember encryption signature version */ |
|
| 114 | + private static $rememberVersion = []; |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * |
|
| 119 | + * @param Crypt $crypt |
|
| 120 | + * @param KeyManager $keyManager |
|
| 121 | + * @param Util $util |
|
| 122 | + * @param Session $session |
|
| 123 | + * @param EncryptAll $encryptAll |
|
| 124 | + * @param DecryptAll $decryptAll |
|
| 125 | + * @param ILogger $logger |
|
| 126 | + * @param IL10N $il10n |
|
| 127 | + */ |
|
| 128 | + public function __construct(Crypt $crypt, |
|
| 129 | + KeyManager $keyManager, |
|
| 130 | + Util $util, |
|
| 131 | + Session $session, |
|
| 132 | + EncryptAll $encryptAll, |
|
| 133 | + DecryptAll $decryptAll, |
|
| 134 | + ILogger $logger, |
|
| 135 | + IL10N $il10n) { |
|
| 136 | + $this->crypt = $crypt; |
|
| 137 | + $this->keyManager = $keyManager; |
|
| 138 | + $this->util = $util; |
|
| 139 | + $this->session = $session; |
|
| 140 | + $this->encryptAll = $encryptAll; |
|
| 141 | + $this->decryptAll = $decryptAll; |
|
| 142 | + $this->logger = $logger; |
|
| 143 | + $this->l = $il10n; |
|
| 144 | + $this->owner = []; |
|
| 145 | + $this->useMasterPassword = $util->isMasterKeyEnabled(); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return string defining the technical unique id |
|
| 150 | + */ |
|
| 151 | + public function getId() { |
|
| 152 | + return self::ID; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 157 | + * |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public function getDisplayName() { |
|
| 161 | + return self::DISPLAY_NAME; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * start receiving chunks from a file. This is the place where you can |
|
| 166 | + * perform some initial step before starting encrypting/decrypting the |
|
| 167 | + * chunks |
|
| 168 | + * |
|
| 169 | + * @param string $path to the file |
|
| 170 | + * @param string $user who read/write the file |
|
| 171 | + * @param string $mode php stream open mode |
|
| 172 | + * @param array $header contains the header data read from the file |
|
| 173 | + * @param array $accessList who has access to the file contains the key 'users' and 'public' |
|
| 174 | + * |
|
| 175 | + * @return array $header contain data as key-value pairs which should be |
|
| 176 | + * written to the header, in case of a write operation |
|
| 177 | + * or if no additional data is needed return a empty array |
|
| 178 | + */ |
|
| 179 | + public function begin($path, $user, $mode, array $header, array $accessList) { |
|
| 180 | + $this->path = $this->getPathToRealFile($path); |
|
| 181 | + $this->accessList = $accessList; |
|
| 182 | + $this->user = $user; |
|
| 183 | + $this->isWriteOperation = false; |
|
| 184 | + $this->writeCache = ''; |
|
| 185 | + |
|
| 186 | + if ($this->session->isReady() === false) { |
|
| 187 | + // if the master key is enabled we can initialize encryption |
|
| 188 | + // with a empty password and user name |
|
| 189 | + if ($this->util->isMasterKeyEnabled()) { |
|
| 190 | + $this->keyManager->init('', ''); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($this->session->decryptAllModeActivated()) { |
|
| 195 | + $encryptedFileKey = $this->keyManager->getEncryptedFileKey($this->path); |
|
| 196 | + $shareKey = $this->keyManager->getShareKey($this->path, $this->session->getDecryptAllUid()); |
|
| 197 | + $this->fileKey = $this->crypt->multiKeyDecrypt($encryptedFileKey, |
|
| 198 | + $shareKey, |
|
| 199 | + $this->session->getDecryptAllKey()); |
|
| 200 | + } else { |
|
| 201 | + $this->fileKey = $this->keyManager->getFileKey($this->path, $this->user); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // always use the version from the original file, also part files |
|
| 205 | + // need to have a correct version number if they get moved over to the |
|
| 206 | + // final location |
|
| 207 | + $this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View()); |
|
| 208 | + |
|
| 209 | + if ( |
|
| 210 | + $mode === 'w' |
|
| 211 | + || $mode === 'w+' |
|
| 212 | + || $mode === 'wb' |
|
| 213 | + || $mode === 'wb+' |
|
| 214 | + ) { |
|
| 215 | + $this->isWriteOperation = true; |
|
| 216 | + if (empty($this->fileKey)) { |
|
| 217 | + $this->fileKey = $this->crypt->generateFileKey(); |
|
| 218 | + } |
|
| 219 | + } else { |
|
| 220 | + // if we read a part file we need to increase the version by 1 |
|
| 221 | + // because the version number was also increased by writing |
|
| 222 | + // the part file |
|
| 223 | + if (Scanner::isPartialFile($path)) { |
|
| 224 | + $this->version = $this->version + 1; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + if ($this->isWriteOperation) { |
|
| 229 | + $this->cipher = $this->crypt->getCipher(); |
|
| 230 | + } elseif (isset($header['cipher'])) { |
|
| 231 | + $this->cipher = $header['cipher']; |
|
| 232 | + } else { |
|
| 233 | + // if we read a file without a header we fall-back to the legacy cipher |
|
| 234 | + // which was used in <=oC6 |
|
| 235 | + $this->cipher = $this->crypt->getLegacyCipher(); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return ['cipher' => $this->cipher, 'signed' => 'true']; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * last chunk received. This is the place where you can perform some final |
|
| 243 | + * operation and return some remaining data if something is left in your |
|
| 244 | + * buffer. |
|
| 245 | + * |
|
| 246 | + * @param string $path to the file |
|
| 247 | + * @param int $position |
|
| 248 | + * @return string remained data which should be written to the file in case |
|
| 249 | + * of a write operation |
|
| 250 | + * @throws PublicKeyMissingException |
|
| 251 | + * @throws \Exception |
|
| 252 | + * @throws \OCA\Encryption\Exceptions\MultiKeyEncryptException |
|
| 253 | + */ |
|
| 254 | + public function end($path, $position = 0) { |
|
| 255 | + $result = ''; |
|
| 256 | + if ($this->isWriteOperation) { |
|
| 257 | + // in case of a part file we remember the new signature versions |
|
| 258 | + // the version will be set later on update. |
|
| 259 | + // This way we make sure that other apps listening to the pre-hooks |
|
| 260 | + // still get the old version which should be the correct value for them |
|
| 261 | + if (Scanner::isPartialFile($path)) { |
|
| 262 | + self::$rememberVersion[$this->stripPartFileExtension($path)] = $this->version + 1; |
|
| 263 | + } |
|
| 264 | + if (!empty($this->writeCache)) { |
|
| 265 | + $result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version + 1, $position); |
|
| 266 | + $this->writeCache = ''; |
|
| 267 | + } |
|
| 268 | + $publicKeys = []; |
|
| 269 | + if ($this->useMasterPassword === true) { |
|
| 270 | + $publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey(); |
|
| 271 | + } else { |
|
| 272 | + foreach ($this->accessList['users'] as $uid) { |
|
| 273 | + try { |
|
| 274 | + $publicKeys[$uid] = $this->keyManager->getPublicKey($uid); |
|
| 275 | + } catch (PublicKeyMissingException $e) { |
|
| 276 | + $this->logger->warning( |
|
| 277 | + 'no public key found for user "{uid}", user will not be able to read the file', |
|
| 278 | + ['app' => 'encryption', 'uid' => $uid] |
|
| 279 | + ); |
|
| 280 | + // if the public key of the owner is missing we should fail |
|
| 281 | + if ($uid === $this->user) { |
|
| 282 | + throw $e; |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->getOwner($path)); |
|
| 289 | + $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys); |
|
| 290 | + $this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles); |
|
| 291 | + } |
|
| 292 | + return $result; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * encrypt data |
|
| 299 | + * |
|
| 300 | + * @param string $data you want to encrypt |
|
| 301 | + * @param int $position |
|
| 302 | + * @return string encrypted data |
|
| 303 | + */ |
|
| 304 | + public function encrypt($data, $position = 0) { |
|
| 305 | + // If extra data is left over from the last round, make sure it |
|
| 306 | + // is integrated into the next block |
|
| 307 | + if ($this->writeCache) { |
|
| 308 | + |
|
| 309 | + // Concat writeCache to start of $data |
|
| 310 | + $data = $this->writeCache . $data; |
|
| 311 | + |
|
| 312 | + // Clear the write cache, ready for reuse - it has been |
|
| 313 | + // flushed and its old contents processed |
|
| 314 | + $this->writeCache = ''; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + $encrypted = ''; |
|
| 318 | + // While there still remains some data to be processed & written |
|
| 319 | + while (strlen($data) > 0) { |
|
| 320 | + |
|
| 321 | + // Remaining length for this iteration, not of the |
|
| 322 | + // entire file (may be greater than 8192 bytes) |
|
| 323 | + $remainingLength = strlen($data); |
|
| 324 | + |
|
| 325 | + // If data remaining to be written is less than the |
|
| 326 | + // size of 1 6126 byte block |
|
| 327 | + if ($remainingLength < $this->unencryptedBlockSizeSigned) { |
|
| 328 | + |
|
| 329 | + // Set writeCache to contents of $data |
|
| 330 | + // The writeCache will be carried over to the |
|
| 331 | + // next write round, and added to the start of |
|
| 332 | + // $data to ensure that written blocks are |
|
| 333 | + // always the correct length. If there is still |
|
| 334 | + // data in writeCache after the writing round |
|
| 335 | + // has finished, then the data will be written |
|
| 336 | + // to disk by $this->flush(). |
|
| 337 | + $this->writeCache = $data; |
|
| 338 | + |
|
| 339 | + // Clear $data ready for next round |
|
| 340 | + $data = ''; |
|
| 341 | + } else { |
|
| 342 | + |
|
| 343 | + // Read the chunk from the start of $data |
|
| 344 | + $chunk = substr($data, 0, $this->unencryptedBlockSizeSigned); |
|
| 345 | + |
|
| 346 | + $encrypted .= $this->crypt->symmetricEncryptFileContent($chunk, $this->fileKey, $this->version + 1, $position); |
|
| 347 | + |
|
| 348 | + // Remove the chunk we just processed from |
|
| 349 | + // $data, leaving only unprocessed data in $data |
|
| 350 | + // var, for handling on the next round |
|
| 351 | + $data = substr($data, $this->unencryptedBlockSizeSigned); |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + return $encrypted; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * decrypt data |
|
| 360 | + * |
|
| 361 | + * @param string $data you want to decrypt |
|
| 362 | + * @param int $position |
|
| 363 | + * @return string decrypted data |
|
| 364 | + * @throws DecryptionFailedException |
|
| 365 | + */ |
|
| 366 | + public function decrypt($data, $position = 0) { |
|
| 367 | + if (empty($this->fileKey)) { |
|
| 368 | + $msg = 'Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'; |
|
| 369 | + $hint = $this->l->t('Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'); |
|
| 370 | + $this->logger->error($msg); |
|
| 371 | + |
|
| 372 | + throw new DecryptionFailedException($msg, $hint); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return $this->crypt->symmetricDecryptFileContent($data, $this->fileKey, $this->cipher, $this->version, $position); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * update encrypted file, e.g. give additional users access to the file |
|
| 380 | + * |
|
| 381 | + * @param string $path path to the file which should be updated |
|
| 382 | + * @param string $uid of the user who performs the operation |
|
| 383 | + * @param array $accessList who has access to the file contains the key 'users' and 'public' |
|
| 384 | + * @return boolean |
|
| 385 | + */ |
|
| 386 | + public function update($path, $uid, array $accessList) { |
|
| 387 | + if (empty($accessList)) { |
|
| 388 | + if (isset(self::$rememberVersion[$path])) { |
|
| 389 | + $this->keyManager->setVersion($path, self::$rememberVersion[$path], new View()); |
|
| 390 | + unset(self::$rememberVersion[$path]); |
|
| 391 | + } |
|
| 392 | + return; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + $fileKey = $this->keyManager->getFileKey($path, $uid); |
|
| 396 | + |
|
| 397 | + if (!empty($fileKey)) { |
|
| 398 | + $publicKeys = []; |
|
| 399 | + if ($this->useMasterPassword === true) { |
|
| 400 | + $publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey(); |
|
| 401 | + } else { |
|
| 402 | + foreach ($accessList['users'] as $user) { |
|
| 403 | + try { |
|
| 404 | + $publicKeys[$user] = $this->keyManager->getPublicKey($user); |
|
| 405 | + } catch (PublicKeyMissingException $e) { |
|
| 406 | + $this->logger->warning('Could not encrypt file for ' . $user . ': ' . $e->getMessage()); |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->getOwner($path)); |
|
| 412 | + |
|
| 413 | + $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys); |
|
| 414 | + |
|
| 415 | + $this->keyManager->deleteAllFileKeys($path); |
|
| 416 | + |
|
| 417 | + $this->keyManager->setAllFileKeys($path, $encryptedFileKey); |
|
| 418 | + } else { |
|
| 419 | + $this->logger->debug('no file key found, we assume that the file "{file}" is not encrypted', |
|
| 420 | + ['file' => $path, 'app' => 'encryption']); |
|
| 421 | + |
|
| 422 | + return false; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return true; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * should the file be encrypted or not |
|
| 430 | + * |
|
| 431 | + * @param string $path |
|
| 432 | + * @return boolean |
|
| 433 | + */ |
|
| 434 | + public function shouldEncrypt($path) { |
|
| 435 | + if ($this->util->shouldEncryptHomeStorage() === false) { |
|
| 436 | + $storage = $this->util->getStorage($path); |
|
| 437 | + if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
| 438 | + return false; |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + $parts = explode('/', $path); |
|
| 442 | + if (count($parts) < 4) { |
|
| 443 | + return false; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + if ($parts[2] === 'files') { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + if ($parts[2] === 'files_versions') { |
|
| 450 | + return true; |
|
| 451 | + } |
|
| 452 | + if ($parts[2] === 'files_trashbin') { |
|
| 453 | + return true; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + return false; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * get size of the unencrypted payload per block. |
|
| 461 | + * Nextcloud read/write files with a block size of 8192 byte |
|
| 462 | + * |
|
| 463 | + * @param bool $signed |
|
| 464 | + * @return int |
|
| 465 | + */ |
|
| 466 | + public function getUnencryptedBlockSize($signed = false) { |
|
| 467 | + if ($signed === false) { |
|
| 468 | + return $this->unencryptedBlockSize; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + return $this->unencryptedBlockSizeSigned; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * check if the encryption module is able to read the file, |
|
| 476 | + * e.g. if all encryption keys exists |
|
| 477 | + * |
|
| 478 | + * @param string $path |
|
| 479 | + * @param string $uid user for whom we want to check if he can read the file |
|
| 480 | + * @return bool |
|
| 481 | + * @throws DecryptionFailedException |
|
| 482 | + */ |
|
| 483 | + public function isReadable($path, $uid) { |
|
| 484 | + $fileKey = $this->keyManager->getFileKey($path, $uid); |
|
| 485 | + if (empty($fileKey)) { |
|
| 486 | + $owner = $this->util->getOwner($path); |
|
| 487 | + if ($owner !== $uid) { |
|
| 488 | + // if it is a shared file we throw a exception with a useful |
|
| 489 | + // error message because in this case it means that the file was |
|
| 490 | + // shared with the user at a point where the user didn't had a |
|
| 491 | + // valid private/public key |
|
| 492 | + $msg = 'Encryption module "' . $this->getDisplayName() . |
|
| 493 | + '" is not able to read ' . $path; |
|
| 494 | + $hint = $this->l->t('Can not read this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'); |
|
| 495 | + $this->logger->warning($msg); |
|
| 496 | + throw new DecryptionFailedException($msg, $hint); |
|
| 497 | + } |
|
| 498 | + return false; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + return true; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Initial encryption of all files |
|
| 506 | + * |
|
| 507 | + * @param InputInterface $input |
|
| 508 | + * @param OutputInterface $output write some status information to the terminal during encryption |
|
| 509 | + */ |
|
| 510 | + public function encryptAll(InputInterface $input, OutputInterface $output) { |
|
| 511 | + $this->encryptAll->encryptAll($input, $output); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * prepare module to perform decrypt all operation |
|
| 516 | + * |
|
| 517 | + * @param InputInterface $input |
|
| 518 | + * @param OutputInterface $output |
|
| 519 | + * @param string $user |
|
| 520 | + * @return bool |
|
| 521 | + */ |
|
| 522 | + public function prepareDecryptAll(InputInterface $input, OutputInterface $output, $user = '') { |
|
| 523 | + return $this->decryptAll->prepare($input, $output, $user); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * @param string $path |
|
| 529 | + * @return string |
|
| 530 | + */ |
|
| 531 | + protected function getPathToRealFile($path) { |
|
| 532 | + $realPath = $path; |
|
| 533 | + $parts = explode('/', $path); |
|
| 534 | + if ($parts[2] === 'files_versions') { |
|
| 535 | + $realPath = '/' . $parts[1] . '/files/' . implode('/', array_slice($parts, 3)); |
|
| 536 | + $length = strrpos($realPath, '.'); |
|
| 537 | + $realPath = substr($realPath, 0, $length); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $realPath; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * remove .part file extension and the ocTransferId from the file to get the |
|
| 545 | + * original file name |
|
| 546 | + * |
|
| 547 | + * @param string $path |
|
| 548 | + * @return string |
|
| 549 | + */ |
|
| 550 | + protected function stripPartFileExtension($path) { |
|
| 551 | + if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
|
| 552 | + $pos = strrpos($path, '.', -6); |
|
| 553 | + $path = substr($path, 0, $pos); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + return $path; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * get owner of a file |
|
| 561 | + * |
|
| 562 | + * @param string $path |
|
| 563 | + * @return string |
|
| 564 | + */ |
|
| 565 | + protected function getOwner($path) { |
|
| 566 | + if (!isset($this->owner[$path])) { |
|
| 567 | + $this->owner[$path] = $this->util->getOwner($path); |
|
| 568 | + } |
|
| 569 | + return $this->owner[$path]; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Check if the module is ready to be used by that specific user. |
|
| 574 | + * In case a module is not ready - because e.g. key pairs have not been generated |
|
| 575 | + * upon login this method can return false before any operation starts and might |
|
| 576 | + * cause issues during operations. |
|
| 577 | + * |
|
| 578 | + * @param string $user |
|
| 579 | + * @return boolean |
|
| 580 | + * @since 9.1.0 |
|
| 581 | + */ |
|
| 582 | + public function isReadyForUser($user) { |
|
| 583 | + if ($this->util->isMasterKeyEnabled()) { |
|
| 584 | + return true; |
|
| 585 | + } |
|
| 586 | + return $this->keyManager->userHasKeys($user); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * We only need a detailed access list if the master key is not enabled |
|
| 591 | + * |
|
| 592 | + * @return bool |
|
| 593 | + */ |
|
| 594 | + public function needDetailedAccessList() { |
|
| 595 | + return !$this->util->isMasterKeyEnabled(); |
|
| 596 | + } |
|
| 597 | 597 | } |
@@ -28,13 +28,13 @@ |
||
| 28 | 28 | |
| 29 | 29 | class PrivateKeyMissingException extends GenericEncryptionException { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param string $userId |
|
| 33 | - */ |
|
| 34 | - public function __construct($userId) { |
|
| 35 | - if (empty($userId)) { |
|
| 36 | - $userId = "<no-user-id-given>"; |
|
| 37 | - } |
|
| 38 | - parent::__construct("Private Key missing for user: $userId"); |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * @param string $userId |
|
| 33 | + */ |
|
| 34 | + public function __construct($userId) { |
|
| 35 | + if (empty($userId)) { |
|
| 36 | + $userId = "<no-user-id-given>"; |
|
| 37 | + } |
|
| 38 | + parent::__construct("Private Key missing for user: $userId"); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -25,13 +25,13 @@ |
||
| 25 | 25 | |
| 26 | 26 | class PublicKeyMissingException extends GenericEncryptionException { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $userId |
|
| 30 | - */ |
|
| 31 | - public function __construct($userId) { |
|
| 32 | - if (empty($userId)) { |
|
| 33 | - $userId = "<no-user-id-given>"; |
|
| 34 | - } |
|
| 35 | - parent::__construct("Public Key missing for user: $userId"); |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * @param string $userId |
|
| 30 | + */ |
|
| 31 | + public function __construct($userId) { |
|
| 32 | + if (empty($userId)) { |
|
| 33 | + $userId = "<no-user-id-given>"; |
|
| 34 | + } |
|
| 35 | + parent::__construct("Public Key missing for user: $userId"); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -32,63 +32,63 @@ |
||
| 32 | 32 | |
| 33 | 33 | class Personal implements ISettings { |
| 34 | 34 | |
| 35 | - /** @var IConfig */ |
|
| 36 | - private $config; |
|
| 37 | - /** @var Session */ |
|
| 38 | - private $session; |
|
| 39 | - /** @var Util */ |
|
| 40 | - private $util; |
|
| 41 | - /** @var IUserSession */ |
|
| 42 | - private $userSession; |
|
| 35 | + /** @var IConfig */ |
|
| 36 | + private $config; |
|
| 37 | + /** @var Session */ |
|
| 38 | + private $session; |
|
| 39 | + /** @var Util */ |
|
| 40 | + private $util; |
|
| 41 | + /** @var IUserSession */ |
|
| 42 | + private $userSession; |
|
| 43 | 43 | |
| 44 | - public function __construct(IConfig $config, Session $session, Util $util, IUserSession $userSession) { |
|
| 45 | - $this->config = $config; |
|
| 46 | - $this->session = $session; |
|
| 47 | - $this->util = $util; |
|
| 48 | - $this->userSession = $userSession; |
|
| 49 | - } |
|
| 44 | + public function __construct(IConfig $config, Session $session, Util $util, IUserSession $userSession) { |
|
| 45 | + $this->config = $config; |
|
| 46 | + $this->session = $session; |
|
| 47 | + $this->util = $util; |
|
| 48 | + $this->userSession = $userSession; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 53 | - * @since 9.1 |
|
| 54 | - */ |
|
| 55 | - public function getForm() { |
|
| 56 | - $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled'); |
|
| 57 | - $privateKeySet = $this->session->isPrivateKeySet(); |
|
| 51 | + /** |
|
| 52 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 53 | + * @since 9.1 |
|
| 54 | + */ |
|
| 55 | + public function getForm() { |
|
| 56 | + $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled'); |
|
| 57 | + $privateKeySet = $this->session->isPrivateKeySet(); |
|
| 58 | 58 | |
| 59 | - if (!$recoveryAdminEnabled && $privateKeySet) { |
|
| 60 | - return new TemplateResponse('settings', 'settings/empty', [], ''); |
|
| 61 | - } |
|
| 59 | + if (!$recoveryAdminEnabled && $privateKeySet) { |
|
| 60 | + return new TemplateResponse('settings', 'settings/empty', [], ''); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $userId = $this->userSession->getUser()->getUID(); |
|
| 64 | - $recoveryEnabledForUser = $this->util->isRecoveryEnabledForUser($userId); |
|
| 63 | + $userId = $this->userSession->getUser()->getUID(); |
|
| 64 | + $recoveryEnabledForUser = $this->util->isRecoveryEnabledForUser($userId); |
|
| 65 | 65 | |
| 66 | - $parameters = [ |
|
| 67 | - 'recoveryEnabled' => $recoveryAdminEnabled, |
|
| 68 | - 'recoveryEnabledForUser' => $recoveryEnabledForUser, |
|
| 69 | - 'privateKeySet' => $privateKeySet, |
|
| 70 | - 'initialized' => $this->session->getStatus(), |
|
| 71 | - ]; |
|
| 72 | - return new TemplateResponse('encryption', 'settings-personal', $parameters, ''); |
|
| 73 | - } |
|
| 66 | + $parameters = [ |
|
| 67 | + 'recoveryEnabled' => $recoveryAdminEnabled, |
|
| 68 | + 'recoveryEnabledForUser' => $recoveryEnabledForUser, |
|
| 69 | + 'privateKeySet' => $privateKeySet, |
|
| 70 | + 'initialized' => $this->session->getStatus(), |
|
| 71 | + ]; |
|
| 72 | + return new TemplateResponse('encryption', 'settings-personal', $parameters, ''); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return string the section ID, e.g. 'sharing' |
|
| 77 | - * @since 9.1 |
|
| 78 | - */ |
|
| 79 | - public function getSection() { |
|
| 80 | - return 'security'; |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * @return string the section ID, e.g. 'sharing' |
|
| 77 | + * @since 9.1 |
|
| 78 | + */ |
|
| 79 | + public function getSection() { |
|
| 80 | + return 'security'; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @return int whether the form should be rather on the top or bottom of |
|
| 85 | - * the admin section. The forms are arranged in ascending order of the |
|
| 86 | - * priority values. It is required to return a value between 0 and 100. |
|
| 87 | - * |
|
| 88 | - * E.g.: 70 |
|
| 89 | - * @since 9.1 |
|
| 90 | - */ |
|
| 91 | - public function getPriority() { |
|
| 92 | - return 80; |
|
| 93 | - } |
|
| 83 | + /** |
|
| 84 | + * @return int whether the form should be rather on the top or bottom of |
|
| 85 | + * the admin section. The forms are arranged in ascending order of the |
|
| 86 | + * priority values. It is required to return a value between 0 and 100. |
|
| 87 | + * |
|
| 88 | + * E.g.: 70 |
|
| 89 | + * @since 9.1 |
|
| 90 | + */ |
|
| 91 | + public function getPriority() { |
|
| 92 | + return 80; |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -23,10 +23,10 @@ |
||
| 23 | 23 | namespace OCA\Encryption\Hooks\Contracts; |
| 24 | 24 | |
| 25 | 25 | interface IHook { |
| 26 | - /** |
|
| 27 | - * Connects Hooks |
|
| 28 | - * |
|
| 29 | - * @return null |
|
| 30 | - */ |
|
| 31 | - public function addHooks(); |
|
| 26 | + /** |
|
| 27 | + * Connects Hooks |
|
| 28 | + * |
|
| 29 | + * @return null |
|
| 30 | + */ |
|
| 31 | + public function addHooks(); |
|
| 32 | 32 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | print_unescaped($l->t("Hey there,\n\nthe admin enabled server-side-encryption. Your files were encrypted using the password '%s'.\n\nPlease login to the web interface, go to the section 'basic encryption module' of your personal settings and update your encryption password by entering this password into the 'old log-in password' field and your current login-password.\n\n", [$_['password']])); |
| 6 | 6 | if (isset($_['expiration'])) { |
| 7 | - print_unescaped($l->t("The share will expire on %s.", [$_['expiration']])); |
|
| 8 | - print_unescaped("\n\n"); |
|
| 7 | + print_unescaped($l->t("The share will expire on %s.", [$_['expiration']])); |
|
| 8 | + print_unescaped("\n\n"); |
|
| 9 | 9 | } |
| 10 | 10 | // TRANSLATORS term at the end of a mail |
| 11 | 11 | p($l->t("Cheers!")); |
@@ -6,5 +6,5 @@ |
||
| 6 | 6 | ?> |
| 7 | 7 | |
| 8 | 8 | -- |
| 9 | -<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?> |
|
| 9 | +<?php p($theme->getName().' - '.$theme->getSlogan()); ?> |
|
| 10 | 10 | <?php print_unescaped("\n".$theme->getBaseUrl()); |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | <p id="encryptHomeStorageSetting"> |
| 14 | 14 | <input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage" |
| 15 | 15 | value="1" <?php if ($_['encryptHomeStorage']) { |
| 16 | - print_unescaped('checked="checked"'); |
|
| 16 | + print_unescaped('checked="checked"'); |
|
| 17 | 17 | } ?> /> |
| 18 | 18 | <label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br> |
| 19 | 19 | <em><?php p($l->t("Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted")); ?></em> |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | <br/><br/> |
| 46 | 46 | |
| 47 | 47 | <p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if ($_['recoveryEnabled'] === '0') { |
| 48 | - print_unescaped('class="hidden"'); |
|
| 48 | + print_unescaped('class="hidden"'); |
|
| 49 | 49 | }?>> |
| 50 | 50 | <?php p($l->t("Change recovery key password:")); ?> |
| 51 | 51 | <span class="msg"></span> |
@@ -9,11 +9,13 @@ |
||
| 9 | 9 | <h3><?php p($l->t("Default encryption module")); ?></h3> |
| 10 | 10 | <?php if (!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?> |
| 11 | 11 | <?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?> |
| 12 | - <?php else: ?> |
|
| 12 | + <?php else { |
|
| 13 | + : ?> |
|
| 13 | 14 | <p id="encryptHomeStorageSetting"> |
| 14 | 15 | <input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage" |
| 15 | 16 | value="1" <?php if ($_['encryptHomeStorage']) { |
| 16 | 17 | print_unescaped('checked="checked"'); |
| 18 | +} |
|
| 17 | 19 | } ?> /> |
| 18 | 20 | <label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br> |
| 19 | 21 | <em><?php p($l->t("Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted")); ?></em> |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | value="1" <?php if ($_['encryptHomeStorage']) { |
| 15 | 15 | print_unescaped('checked="checked"'); |
| 16 | 16 | } ?> /> |
| 17 | - <label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br> |
|
| 17 | + <label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage')); ?></label></br> |
|
| 18 | 18 | <em><?php p($l->t("Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted")); ?></em> |
| 19 | 19 | </p> |
| 20 | 20 | <br /> |
@@ -26,66 +26,66 @@ |
||
| 26 | 26 | |
| 27 | 27 | class RequestURL extends AbstractStringCheck { |
| 28 | 28 | |
| 29 | - /** @var string */ |
|
| 30 | - protected $url; |
|
| 29 | + /** @var string */ |
|
| 30 | + protected $url; |
|
| 31 | 31 | |
| 32 | - /** @var IRequest */ |
|
| 33 | - protected $request; |
|
| 32 | + /** @var IRequest */ |
|
| 33 | + protected $request; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param IL10N $l |
|
| 37 | - * @param IRequest $request |
|
| 38 | - */ |
|
| 39 | - public function __construct(IL10N $l, IRequest $request) { |
|
| 40 | - parent::__construct($l); |
|
| 41 | - $this->request = $request; |
|
| 42 | - } |
|
| 35 | + /** |
|
| 36 | + * @param IL10N $l |
|
| 37 | + * @param IRequest $request |
|
| 38 | + */ |
|
| 39 | + public function __construct(IL10N $l, IRequest $request) { |
|
| 40 | + parent::__construct($l); |
|
| 41 | + $this->request = $request; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param string $operator |
|
| 46 | - * @param string $value |
|
| 47 | - * @return bool |
|
| 48 | - */ |
|
| 49 | - public function executeCheck($operator, $value) { |
|
| 50 | - $actualValue = $this->getActualValue(); |
|
| 51 | - if (in_array($operator, ['is', '!is'])) { |
|
| 52 | - switch ($value) { |
|
| 53 | - case 'webdav': |
|
| 54 | - if ($operator === 'is') { |
|
| 55 | - return $this->isWebDAVRequest(); |
|
| 56 | - } else { |
|
| 57 | - return !$this->isWebDAVRequest(); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - return $this->executeStringCheck($operator, $value, $actualValue); |
|
| 62 | - } |
|
| 44 | + /** |
|
| 45 | + * @param string $operator |
|
| 46 | + * @param string $value |
|
| 47 | + * @return bool |
|
| 48 | + */ |
|
| 49 | + public function executeCheck($operator, $value) { |
|
| 50 | + $actualValue = $this->getActualValue(); |
|
| 51 | + if (in_array($operator, ['is', '!is'])) { |
|
| 52 | + switch ($value) { |
|
| 53 | + case 'webdav': |
|
| 54 | + if ($operator === 'is') { |
|
| 55 | + return $this->isWebDAVRequest(); |
|
| 56 | + } else { |
|
| 57 | + return !$this->isWebDAVRequest(); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + return $this->executeStringCheck($operator, $value, $actualValue); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - protected function getActualValue() { |
|
| 68 | - if ($this->url !== null) { |
|
| 69 | - return $this->url; |
|
| 70 | - } |
|
| 64 | + /** |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + protected function getActualValue() { |
|
| 68 | + if ($this->url !== null) { |
|
| 69 | + return $this->url; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $this->url = $this->request->getServerProtocol() . '://';// E.g. http(s) + :// |
|
| 73 | - $this->url .= $this->request->getServerHost();// E.g. localhost |
|
| 74 | - $this->url .= $this->request->getScriptName();// E.g. /nextcloud/index.php |
|
| 75 | - $this->url .= $this->request->getPathInfo();// E.g. /apps/files_texteditor/ajax/loadfile |
|
| 72 | + $this->url = $this->request->getServerProtocol() . '://';// E.g. http(s) + :// |
|
| 73 | + $this->url .= $this->request->getServerHost();// E.g. localhost |
|
| 74 | + $this->url .= $this->request->getScriptName();// E.g. /nextcloud/index.php |
|
| 75 | + $this->url .= $this->request->getPathInfo();// E.g. /apps/files_texteditor/ajax/loadfile |
|
| 76 | 76 | |
| 77 | - return $this->url; // E.g. https://localhost/nextcloud/index.php/apps/files_texteditor/ajax/loadfile |
|
| 78 | - } |
|
| 77 | + return $this->url; // E.g. https://localhost/nextcloud/index.php/apps/files_texteditor/ajax/loadfile |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return bool |
|
| 82 | - */ |
|
| 83 | - protected function isWebDAVRequest() { |
|
| 84 | - return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( |
|
| 85 | - $this->request->getPathInfo() === '/webdav' || |
|
| 86 | - strpos($this->request->getPathInfo(), '/webdav/') === 0 || |
|
| 87 | - $this->request->getPathInfo() === '/dav/files' || |
|
| 88 | - strpos($this->request->getPathInfo(), '/dav/files/') === 0 |
|
| 89 | - ); |
|
| 90 | - } |
|
| 80 | + /** |
|
| 81 | + * @return bool |
|
| 82 | + */ |
|
| 83 | + protected function isWebDAVRequest() { |
|
| 84 | + return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( |
|
| 85 | + $this->request->getPathInfo() === '/webdav' || |
|
| 86 | + strpos($this->request->getPathInfo(), '/webdav/') === 0 || |
|
| 87 | + $this->request->getPathInfo() === '/dav/files' || |
|
| 88 | + strpos($this->request->getPathInfo(), '/dav/files/') === 0 |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -69,10 +69,10 @@ |
||
| 69 | 69 | return $this->url; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $this->url = $this->request->getServerProtocol() . '://';// E.g. http(s) + :// |
|
| 73 | - $this->url .= $this->request->getServerHost();// E.g. localhost |
|
| 74 | - $this->url .= $this->request->getScriptName();// E.g. /nextcloud/index.php |
|
| 75 | - $this->url .= $this->request->getPathInfo();// E.g. /apps/files_texteditor/ajax/loadfile |
|
| 72 | + $this->url = $this->request->getServerProtocol().'://'; // E.g. http(s) + :// |
|
| 73 | + $this->url .= $this->request->getServerHost(); // E.g. localhost |
|
| 74 | + $this->url .= $this->request->getScriptName(); // E.g. /nextcloud/index.php |
|
| 75 | + $this->url .= $this->request->getPathInfo(); // E.g. /apps/files_texteditor/ajax/loadfile |
|
| 76 | 76 | |
| 77 | 77 | return $this->url; // E.g. https://localhost/nextcloud/index.php/apps/files_texteditor/ajax/loadfile |
| 78 | 78 | } |