diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-07-16 12:06:00 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-07-16 12:36:30 +0200 |
commit | 8105f2ac8a6451c740a5b827724c2debcfbeba41 (patch) | |
tree | 3162befc60e096bd795c62277e147c38d2ddfe77 /apps/files_encryption/lib/crypt.php | |
parent | de69c05f992dde91beab513c4f452d9b5985aa0a (diff) | |
download | nextcloud-server-8105f2ac8a6451c740a5b827724c2debcfbeba41.tar.gz nextcloud-server-8105f2ac8a6451c740a5b827724c2debcfbeba41.zip |
introduce some encryption exceptions and catch additional error cases
Diffstat (limited to 'apps/files_encryption/lib/crypt.php')
-rwxr-xr-x | apps/files_encryption/lib/crypt.php | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 5632a2bc298..18f0224391d 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -358,6 +358,7 @@ class Crypt { * @param string $plainContent content to be encrypted
* @param array $publicKeys array keys must be the userId of corresponding user
* @return array keys: keys (array, key = userId), data
+ * @throws \OCA\Encryption\Exceptions\\MultiKeyEncryptException if encryption failed
* @note symmetricDecryptFileContent() can decrypt files created using this method
*/
public static function multiKeyEncrypt($plainContent, array $publicKeys) {
@@ -365,9 +366,7 @@ class Crypt { // openssl_seal returns false without errors if $plainContent
// is empty, so trigger our own error
if (empty($plainContent)) {
-
- throw new \Exception('Cannot mutliKeyEncrypt empty plain content');
-
+ throw new Exceptions\MultiKeyEncryptException('Cannot mutliKeyEncrypt empty plain content', 10);
}
// Set empty vars to be set by openssl by reference
@@ -394,9 +393,7 @@ class Crypt { );
} else {
-
- return false;
-
+ throw new Exceptions\MultiKeyEncryptException('multi key encryption failed: ' . openssl_error_string(), 20);
}
}
@@ -406,8 +403,8 @@ class Crypt { * @param string $encryptedContent
* @param string $shareKey
* @param mixed $privateKey
- * @return false|string
- * @internal param string $plainContent content to be encrypted
+ * @throws \OCA\Encryption\Exceptions\\MultiKeyDecryptException if decryption failed
+ * @internal param string $plainContent contains decrypted content
* @return string $plainContent decrypted string
* @note symmetricDecryptFileContent() can be used to decrypt files created using this method
*
@@ -416,9 +413,7 @@ class Crypt { public static function multiKeyDecrypt($encryptedContent, $shareKey, $privateKey) {
if (!$encryptedContent) {
-
- return false;
-
+ throw new Exceptions\MultiKeyDecryptException('Cannot mutliKeyDecrypt empty plain content', 10);
}
if (openssl_open($encryptedContent, $plainContent, $shareKey, $privateKey)) {
@@ -426,11 +421,7 @@ class Crypt { return $plainContent;
} else {
-
- \OCP\Util::writeLog('Encryption library', 'Decryption (asymmetric) of sealed content with share-key "'.$shareKey.'" failed', \OCP\Util::ERROR);
-
- return false;
-
+ throw new Exceptions\MultiKeyDecryptException('multiKeyDecrypt with share-key' . $shareKey . 'failed: ' . openssl_error_string(), 20);
}
}
|