From 8105f2ac8a6451c740a5b827724c2debcfbeba41 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 16 Jul 2014 12:06:00 +0200 Subject: introduce some encryption exceptions and catch additional error cases --- apps/files_encryption/lib/crypt.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'apps/files_encryption/lib/crypt.php') 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); } } -- cgit v1.2.3