Completed
Pull Request — master (#160)
by Sander
02:40
created
lib/Service/CredentialService.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
 class CredentialService {
37 37
 
38 38
 	private $credentialMapper;
39
-    private $sharingACL;
39
+	private $sharingACL;
40 40
 	private $encryptService;
41 41
 	private $server_key;
42 42
 
43 43
 	public function __construct(CredentialMapper $credentialMapper, SharingACLMapper $sharingACL, EncryptService $encryptService) {
44 44
 		$this->credentialMapper = $credentialMapper;
45
-        $this->sharingACL = $sharingACL;
46
-        $this->encryptService = $encryptService;
45
+		$this->sharingACL = $sharingACL;
46
+		$this->encryptService = $encryptService;
47 47
 		$this->server_key = \OC::$server->getConfig()->getSystemValue('passwordsalt', '');
48 48
 	}
49 49
 
@@ -136,18 +136,18 @@  discard block
 block discarded – undo
136 136
 	 * @throws DoesNotExistException
137 137
 	 */
138 138
 	public function getCredentialById($credential_id, $user_id){
139
-        $credential = $this->credentialMapper->getCredentialById($credential_id);
140
-        if ($credential->getUserId() === $user_id){
141
-            return $credential;
142
-        }
143
-        else {
144
-            $acl = $this->sharingACL->getItemACL($user_id, $credential->getGuid());
145
-            if ($acl->hasPermission(SharingACL::READ)) {
139
+		$credential = $this->credentialMapper->getCredentialById($credential_id);
140
+		if ($credential->getUserId() === $user_id){
141
+			return $credential;
142
+		}
143
+		else {
144
+			$acl = $this->sharingACL->getItemACL($user_id, $credential->getGuid());
145
+			if ($acl->hasPermission(SharingACL::READ)) {
146 146
 				return $this->encryptService->decryptCredential($credential);
147 147
 			} else {
148 148
 				throw new DoesNotExistException("Did expect one result but found none when executing");
149 149
 			}
150
-        }
150
+		}
151 151
 	}
152 152
 
153 153
 	/**
@@ -169,5 +169,5 @@  discard block
 block discarded – undo
169 169
 	public function getCredentialByGUID($credential_guid, $user_id = null){
170 170
 		$credential = $this->credentialMapper->getCredentialByGUID($credential_guid);
171 171
 		return $this->encryptService->decryptCredential($credential);
172
-    }
172
+	}
173 173
 }
174 174
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @param Credential $credential
84 84
 	 * @return \OCP\AppFramework\Db\Entity
85 85
 	 */
86
-	public function deleteCredential(Credential $credential){
86
+	public function deleteCredential(Credential $credential) {
87 87
 		return $this->credentialMapper->deleteCredential($credential);
88 88
 	}
89 89
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function getCredentialsByVaultId($vault_id, $user_id) {
97 97
 		$credentials = $this->credentialMapper->getCredentialsByVaultId($vault_id, $user_id);
98
-		foreach ($credentials as $index => $credential){
98
+		foreach ($credentials as $index => $credential) {
99 99
 			$credentials[$index] = $this->encryptService->decryptCredential($credential);
100 100
 		}
101 101
 		return $credentials;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 */
110 110
 	public function getRandomCredentialByVaultId($vault_id, $user_id) {
111 111
 		$credentials = $this->credentialMapper->getRandomCredentialByVaultId($vault_id, $user_id);
112
-		foreach ($credentials as $index => $credential){
112
+		foreach ($credentials as $index => $credential) {
113 113
 			$credentials[$index] = $this->encryptService->decryptCredential($credential);
114 114
 		}
115 115
 		return array_pop($credentials);
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function getExpiredCredentials($timestamp) {
124 124
 		$credentials = $this->credentialMapper->getExpiredCredentials($timestamp);
125
-		foreach ($credentials as $index => $credential){
125
+		foreach ($credentials as $index => $credential) {
126 126
 			$credentials[$index] = $this->encryptService->decryptCredential($credential);
127 127
 		}
128 128
 		return $credentials;
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 	 * @return Credential
136 136
 	 * @throws DoesNotExistException
137 137
 	 */
138
-	public function getCredentialById($credential_id, $user_id){
138
+	public function getCredentialById($credential_id, $user_id) {
139 139
         $credential = $this->credentialMapper->getCredentialById($credential_id);
140
-        if ($credential->getUserId() === $user_id){
140
+        if ($credential->getUserId() === $user_id) {
141 141
             return $credential;
142 142
         }
143 143
         else {
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
 	 * @param $credential_id
156 156
 	 * @return Credential
157 157
 	 */
158
-	public function getCredentialLabelById($credential_id){
159
-		$credential =  $this->credentialMapper->getCredentialLabelById($credential_id);
158
+	public function getCredentialLabelById($credential_id) {
159
+		$credential = $this->credentialMapper->getCredentialLabelById($credential_id);
160 160
 		return $this->encryptService->decryptCredential($credential);
161 161
 	}
162 162
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 * @param null $user_id
167 167
 	 * @return Credential
168 168
 	 */
169
-	public function getCredentialByGUID($credential_guid, $user_id = null){
169
+	public function getCredentialByGUID($credential_guid, $user_id = null) {
170 170
 		$credential = $this->credentialMapper->getCredentialByGUID($credential_guid);
171 171
 		return $this->encryptService->decryptCredential($credential);
172 172
     }
Please login to merge, or discard this patch.
Braces   +9 added lines, -10 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @param Credential $credential
84 84
 	 * @return \OCP\AppFramework\Db\Entity
85 85
 	 */
86
-	public function deleteCredential(Credential $credential){
86
+	public function deleteCredential(Credential $credential) {
87 87
 		return $this->credentialMapper->deleteCredential($credential);
88 88
 	}
89 89
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function getCredentialsByVaultId($vault_id, $user_id) {
97 97
 		$credentials = $this->credentialMapper->getCredentialsByVaultId($vault_id, $user_id);
98
-		foreach ($credentials as $index => $credential){
98
+		foreach ($credentials as $index => $credential) {
99 99
 			$credentials[$index] = $this->encryptService->decryptCredential($credential);
100 100
 		}
101 101
 		return $credentials;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 */
110 110
 	public function getRandomCredentialByVaultId($vault_id, $user_id) {
111 111
 		$credentials = $this->credentialMapper->getRandomCredentialByVaultId($vault_id, $user_id);
112
-		foreach ($credentials as $index => $credential){
112
+		foreach ($credentials as $index => $credential) {
113 113
 			$credentials[$index] = $this->encryptService->decryptCredential($credential);
114 114
 		}
115 115
 		return array_pop($credentials);
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function getExpiredCredentials($timestamp) {
124 124
 		$credentials = $this->credentialMapper->getExpiredCredentials($timestamp);
125
-		foreach ($credentials as $index => $credential){
125
+		foreach ($credentials as $index => $credential) {
126 126
 			$credentials[$index] = $this->encryptService->decryptCredential($credential);
127 127
 		}
128 128
 		return $credentials;
@@ -135,12 +135,11 @@  discard block
 block discarded – undo
135 135
 	 * @return Credential
136 136
 	 * @throws DoesNotExistException
137 137
 	 */
138
-	public function getCredentialById($credential_id, $user_id){
138
+	public function getCredentialById($credential_id, $user_id) {
139 139
         $credential = $this->credentialMapper->getCredentialById($credential_id);
140
-        if ($credential->getUserId() === $user_id){
140
+        if ($credential->getUserId() === $user_id) {
141 141
             return $credential;
142
-        }
143
-        else {
142
+        } else {
144 143
             $acl = $this->sharingACL->getItemACL($user_id, $credential->getGuid());
145 144
             if ($acl->hasPermission(SharingACL::READ)) {
146 145
 				return $this->encryptService->decryptCredential($credential);
@@ -155,7 +154,7 @@  discard block
 block discarded – undo
155 154
 	 * @param $credential_id
156 155
 	 * @return Credential
157 156
 	 */
158
-	public function getCredentialLabelById($credential_id){
157
+	public function getCredentialLabelById($credential_id) {
159 158
 		$credential =  $this->credentialMapper->getCredentialLabelById($credential_id);
160 159
 		return $this->encryptService->decryptCredential($credential);
161 160
 	}
@@ -166,7 +165,7 @@  discard block
 block discarded – undo
166 165
 	 * @param null $user_id
167 166
 	 * @return Credential
168 167
 	 */
169
-	public function getCredentialByGUID($credential_guid, $user_id = null){
168
+	public function getCredentialByGUID($credential_guid, $user_id = null) {
170 169
 		$credential = $this->credentialMapper->getCredentialByGUID($credential_guid);
171 170
 		return $this->encryptService->decryptCredential($credential);
172 171
     }
Please login to merge, or discard this patch.
lib/Service/EncryptService.php 3 patches
Doc Comments   +11 added lines, -6 removed lines patch added patch discarded remove patch
@@ -212,6 +212,10 @@  discard block
 block discarded – undo
212 212
 		return array($cipherKey, $macKey, $iv);
213 213
 	}
214 214
 
215
+	/**
216
+	 * @param string $a
217
+	 * @param string $b
218
+	 */
215 219
 	protected function hash_equals($a, $b) {
216 220
 		$key = openssl_random_pseudo_bytes(128);
217 221
 		return hash_hmac('sha512', $a, $key) === hash_hmac('sha512', $b, $key);
@@ -249,7 +253,7 @@  discard block
 block discarded – undo
249 253
 	/**
250 254
 	 * Pad the data with a random char chosen by the pad amount.
251 255
 	 *
252
-	 * @param $data
256
+	 * @param string $data
253 257
 	 * @return string
254 258
 	 */
255 259
 	protected function pad($data) {
@@ -265,8 +269,8 @@  discard block
 block discarded – undo
265 269
 	/**
266 270
 	 * Unpad the the data
267 271
 	 *
268
-	 * @param $data
269
-	 * @return bool|string
272
+	 * @param string $data
273
+	 * @return false|string
270 274
 	 */
271 275
 	protected function unpad($data) {
272 276
 		$length = $this->getKeySize();
@@ -283,7 +287,7 @@  discard block
 block discarded – undo
283 287
 	 * Encrypt a credential
284 288
 	 *
285 289
 	 * @param Credential|array $credential the credential to decrypt
286
-	 * @return Credential|array
290
+	 * @return string
287 291
 	 */
288 292
 	public function decryptCredential($credential) {
289 293
 		return $this->handleCredential($credential, 'decrypt');
@@ -304,6 +308,7 @@  discard block
 block discarded – undo
304 308
 	 * Handles the encryption / decryption of a credential
305 309
 	 *
306 310
 	 * @param Credential|array $credential the credential to encrypt
311
+	 * @param string $op
307 312
 	 * @return Credential|array
308 313
 	 * @throws \Exception
309 314
 	 */
@@ -347,7 +352,7 @@  discard block
 block discarded – undo
347 352
 	/**
348 353
 	 * Decrypt a file
349 354
 	 *
350
-	 * @param  File|array $file
355
+	 * @param  File $file
351 356
 	 * @return File|array
352 357
 	 */
353 358
 
@@ -358,7 +363,7 @@  discard block
 block discarded – undo
358 363
 	/**
359 364
 	 * Handles the encryption / decryption of a File
360 365
 	 *
361
-	 * @param File|array $credential the credential to encrypt
366
+	 * @param string $op
362 367
 	 * @return File|array
363 368
 	 * @throws \Exception
364 369
 	 */
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		$setting = $settings->getAppSetting('server_side_encryption');
104 104
 		$this->cipher = $setting['cipher'];
105 105
 		$this->mode = $setting['mode'];
106
-		$this->rounds = (int)100;
106
+		$this->rounds = (int) 100;
107 107
 		$this->server_key = \OC::$server->getConfig()->getSystemValue('passwordsalt', '');
108 108
 	}
109 109
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	 * @return File|array
363 363
 	 * @throws \Exception
364 364
 	 */
365
-	private function handleFile($file, $op){
365
+	private function handleFile($file, $op) {
366 366
 		$service_function = ($op === 'encrypt') ? 'encrypt' : 'decrypt';
367 367
 		if ($file instanceof File) {
368 368
 			$userSuppliedKey = $file->getSize();
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -271,7 +271,9 @@  discard block
 block discarded – undo
271 271
 	protected function unpad($data) {
272 272
 		$length = $this->getKeySize();
273 273
 		$last = ord($data[strlen($data) - 1]);
274
-		if ($last > $length) return false;
274
+		if ($last > $length) {
275
+			return false;
276
+		}
275 277
 		if (substr($data, -1 * $last) !== str_repeat(chr($last), $last)) {
276 278
 			return false;
277 279
 		}
@@ -362,7 +364,7 @@  discard block
 block discarded – undo
362 364
 	 * @return File|array
363 365
 	 * @throws \Exception
364 366
 	 */
365
-	private function handleFile($file, $op){
367
+	private function handleFile($file, $op) {
366 368
 		$service_function = ($op === 'encrypt') ? 'encrypt' : 'decrypt';
367 369
 		if ($file instanceof File) {
368 370
 			$userSuppliedKey = $file->getSize();
Please login to merge, or discard this patch.