@@ -71,7 +71,9 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function createACLEntry(SharingACL $acl) { |
| 74 | - if ($acl->getCreated() === null) $acl->setCreated((new \DateTime())->getTimestamp()); |
|
| 74 | + if ($acl->getCreated() === null) { |
|
| 75 | + $acl->setCreated((new \DateTime())->getTimestamp()); |
|
| 76 | + } |
|
| 75 | 77 | return $this->sharingACL->createACLEntry($acl); |
| 76 | 78 | } |
| 77 | 79 | |
@@ -124,12 +126,16 @@ discard block |
||
| 124 | 126 | $return = []; |
| 125 | 127 | foreach ($entries as $entry) { |
| 126 | 128 | // Check if the user can read the credential, probably unnecesary, but just to be sure |
| 127 | - if (!$entry->hasPermission(SharingACL::READ)) continue; |
|
| 129 | + if (!$entry->hasPermission(SharingACL::READ)) { |
|
| 130 | + continue; |
|
| 131 | + } |
|
| 128 | 132 | |
| 129 | 133 | $tmp = $entry->jsonSerialize(); |
| 130 | 134 | $tmp['credential_data'] = $this->credential->getCredentialById($entry->getItemId())->jsonSerialize(); |
| 131 | 135 | |
| 132 | - if (!$entry->hasPermission(SharingACL::FILES)) unset($tmp['credential_data']['files']); |
|
| 136 | + if (!$entry->hasPermission(SharingACL::FILES)) { |
|
| 137 | + unset($tmp['credential_data']['files']); |
|
| 138 | + } |
|
| 133 | 139 | unset($tmp['credential_data']['shared_key']); |
| 134 | 140 | $return[] = $tmp; |
| 135 | 141 | } |
@@ -150,12 +156,16 @@ discard block |
||
| 150 | 156 | $acl = $this->sharingACL->getItemACL($user_id, $item_guid); |
| 151 | 157 | |
| 152 | 158 | // Check if the user can read the credential, probably unnecesary, but just to be sure |
| 153 | - if (!$acl->hasPermission(SharingACL::READ)) throw new DoesNotExistException("Item not found or wrong access level"); |
|
| 159 | + if (!$acl->hasPermission(SharingACL::READ)) { |
|
| 160 | + throw new DoesNotExistException("Item not found or wrong access level"); |
|
| 161 | + } |
|
| 154 | 162 | |
| 155 | 163 | $tmp = $acl->jsonSerialize(); |
| 156 | 164 | $tmp['credential_data'] = $this->credential->getCredentialById($acl->getItemId())->jsonSerialize(); |
| 157 | 165 | |
| 158 | - if (!$acl->hasPermission(SharingACL::FILES)) unset($tmp['credential_data']['files']); |
|
| 166 | + if (!$acl->hasPermission(SharingACL::FILES)) { |
|
| 167 | + unset($tmp['credential_data']['files']); |
|
| 168 | + } |
|
| 159 | 169 | unset($tmp['credential_data']['shared_key']); |
| 160 | 170 | |
| 161 | 171 | return $tmp; |
@@ -170,7 +180,9 @@ discard block |
||
| 170 | 180 | */ |
| 171 | 181 | public function getItemHistory($user_id, $item_guid) { |
| 172 | 182 | $acl = $this->sharingACL->getItemACL($user_id, $item_guid); |
| 173 | - if (!$acl->hasPermission(SharingACL::READ | SharingACL::HISTORY)) return []; |
|
| 183 | + if (!$acl->hasPermission(SharingACL::READ | SharingACL::HISTORY)) { |
|
| 184 | + return []; |
|
| 185 | + } |
|
| 174 | 186 | |
| 175 | 187 | return $this->revisions->getRevisions($acl->getItemId()); |
| 176 | 188 | } |
@@ -205,6 +205,10 @@ discard block |
||
| 205 | 205 | return array($cipherKey, $macKey, $iv); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | + /** |
|
| 209 | + * @param string $a |
|
| 210 | + * @param string $b |
|
| 211 | + */ |
|
| 208 | 212 | protected function hash_equals($a, $b) { |
| 209 | 213 | $key = openssl_random_pseudo_bytes(128); |
| 210 | 214 | return hash_hmac('sha512', $a, $key) === hash_hmac('sha512', $b, $key); |
@@ -242,7 +246,7 @@ discard block |
||
| 242 | 246 | /** |
| 243 | 247 | * Pad the data with a random char chosen by the pad amount. |
| 244 | 248 | * |
| 245 | - * @param $data |
|
| 249 | + * @param string $data |
|
| 246 | 250 | * @return string |
| 247 | 251 | */ |
| 248 | 252 | protected function pad($data) { |
@@ -258,8 +262,8 @@ discard block |
||
| 258 | 262 | /** |
| 259 | 263 | * Unpad the the data |
| 260 | 264 | * |
| 261 | - * @param $data |
|
| 262 | - * @return bool|string |
|
| 265 | + * @param string $data |
|
| 266 | + * @return false|string |
|
| 263 | 267 | */ |
| 264 | 268 | protected function unpad($data) { |
| 265 | 269 | $length = $this->getKeySize(); |
@@ -276,7 +280,7 @@ discard block |
||
| 276 | 280 | * Encrypt a credential |
| 277 | 281 | * |
| 278 | 282 | * @param Credential|array $credential the credential to decrypt |
| 279 | - * @return Credential|array |
|
| 283 | + * @return string |
|
| 280 | 284 | */ |
| 281 | 285 | public function decryptCredential($credential) { |
| 282 | 286 | return $this->handleCredential($credential, 'decrypt'); |
@@ -297,6 +301,7 @@ discard block |
||
| 297 | 301 | * Handles the encryption / decryption of a credential |
| 298 | 302 | * |
| 299 | 303 | * @param Credential|array $credential the credential to encrypt |
| 304 | + * @param string $op |
|
| 300 | 305 | * @return Credential|array |
| 301 | 306 | * @throws \Exception |
| 302 | 307 | */ |
@@ -342,7 +347,7 @@ discard block |
||
| 342 | 347 | /** |
| 343 | 348 | * Decrypt a file |
| 344 | 349 | * |
| 345 | - * @param File|array $file |
|
| 350 | + * @param File $file |
|
| 346 | 351 | * @return File|array |
| 347 | 352 | */ |
| 348 | 353 | |
@@ -354,6 +359,7 @@ discard block |
||
| 354 | 359 | * Handles the encryption / decryption of a File |
| 355 | 360 | * |
| 356 | 361 | * @param File|array $file the credential to encrypt |
| 362 | + * @param string $op |
|
| 357 | 363 | * @return File|array |
| 358 | 364 | * @throws \Exception |
| 359 | 365 | */ |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function __construct(SettingsService $settings) { |
| 98 | 98 | $this->cipher = $settings->getAppSetting('server_side_encryption'); |
| 99 | - $this->rounds = (int)100; |
|
| 99 | + $this->rounds = (int) 100; |
|
| 100 | 100 | $this->server_key = \OC::$server->getConfig()->getSystemValue('passwordsalt', ''); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $userKey = (isset($sk)) ? $sk : $credential->getUserId(); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if(is_array($credential)){ |
|
| 311 | + if (is_array($credential)) { |
|
| 312 | 312 | $userSuppliedKey = $credential['label']; |
| 313 | 313 | $userKey = (isset($credential['shared_key'])) ? $credential['shared_key'] : $credential['user_id']; |
| 314 | 314 | } |
@@ -264,7 +264,9 @@ discard block |
||
| 264 | 264 | protected function unpad($data) { |
| 265 | 265 | $length = $this->getKeySize(); |
| 266 | 266 | $last = ord($data[strlen($data) - 1]); |
| 267 | - if ($last > $length) return false; |
|
| 267 | + if ($last > $length) { |
|
| 268 | + return false; |
|
| 269 | + } |
|
| 268 | 270 | if (substr($data, -1 * $last) !== str_repeat(chr($last), $last)) { |
| 269 | 271 | return false; |
| 270 | 272 | } |
@@ -308,7 +310,7 @@ discard block |
||
| 308 | 310 | $userKey = (isset($sk)) ? $sk : $credential->getUserId(); |
| 309 | 311 | } |
| 310 | 312 | |
| 311 | - if(is_array($credential)){ |
|
| 313 | + if(is_array($credential)) { |
|
| 312 | 314 | $userSuppliedKey = $credential['label']; |
| 313 | 315 | $userKey = (isset($credential['shared_key'])) ? $credential['shared_key'] : $credential['user_id']; |
| 314 | 316 | } |