]> source.dussan.org Git - nextcloud-server.git/commitdiff
add some more error messages, in case something went wrong
authorBjörn Schießle <schiessle@owncloud.com>
Wed, 19 Jun 2013 13:52:33 +0000 (15:52 +0200)
committerBjörn Schießle <schiessle@owncloud.com>
Wed, 19 Jun 2013 13:52:33 +0000 (15:52 +0200)
apps/files_encryption/lib/crypt.php
apps/files_encryption/lib/util.php

index 945b342a3163b36a7194b60938150e2f7aebfad4..4322bbf1af237a03c02813def4910f6806f1248f 100755 (executable)
@@ -53,19 +53,26 @@ class Crypt {
 \r
                $res = openssl_pkey_new(array('private_key_bits' => 4096));\r
 \r
-               // Get private key\r
-               openssl_pkey_export($res, $privateKey);\r
+               if ($res === false) {\r
+                       \OCP\Util::writeLog('Encryption library', 'couldn\'t generate users key-pair for ' . \OCP\User::getUser(), \OCP\Util::ERROR);\r
+                       $result = false;\r
+               } else {\r
+\r
+                       // Get private key\r
+                       openssl_pkey_export($res, $privateKey);\r
 \r
-               // Get public key\r
-               $publicKey = openssl_pkey_get_details($res);\r
+                       // Get public key\r
+                       $publicKey = openssl_pkey_get_details($res);\r
 \r
-               $publicKey = $publicKey['key'];\r
+                       $publicKey = $publicKey['key'];\r
 \r
-               return (array(\r
-                       'publicKey' => $publicKey,\r
-                       'privateKey' => $privateKey\r
-               ));\r
+                       $result = array(\r
+                               'publicKey' => $publicKey,\r
+                               'privateKey' => $privateKey\r
+                       );\r
+               }\r
 \r
+               return $result;\r
        }\r
 \r
        /**\r
@@ -287,28 +294,22 @@ class Crypt {
        public static function symmetricEncryptFileContent($plainContent, $passphrase = '') {\r
 \r
                if (!$plainContent) {\r
-\r
+                       \OCP\Util::writeLog('Encryption library', 'symmetrically encryption failed, no content given.', \OCP\Util::ERROR);\r
                        return false;\r
-\r
                }\r
 \r
                $iv = self::generateIv();\r
 \r
                if ($encryptedContent = self::encrypt($plainContent, $iv, $passphrase)) {\r
-\r
                        // Combine content to encrypt with IV identifier and actual IV\r
                        $catfile = self::concatIv($encryptedContent, $iv);\r
-\r
                        $padded = self::addPadding($catfile);\r
 \r
                        return $padded;\r
 \r
                } else {\r
-\r
                        \OCP\Util::writeLog('Encryption library', 'Encryption (symmetric) of keyfile content failed', \OCP\Util::ERROR);\r
-\r
                        return false;\r
-\r
                }\r
 \r
        }\r
index b4b3923a799ef95250a5a330bc5caaf19939f53c..e8e53859bd8b621e6dc324bbbd5b22ab785a8f02 100644 (file)
@@ -228,18 +228,21 @@ class Util {
                        // Generate keypair
                        $keypair = Crypt::createKeypair();
 
-                       \OC_FileProxy::$enabled = false;
+                       if ($keypair) {
 
-                       // Save public key
-                       $this->view->file_put_contents($this->publicKeyPath, $keypair['publicKey']);
+                               \OC_FileProxy::$enabled = false;
 
-                       // Encrypt private key with user pwd as passphrase
-                       $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $passphrase);
+                               // Encrypt private key with user pwd as passphrase
+                               $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $passphrase);
 
-                       // Save private key
-                       $this->view->file_put_contents($this->privateKeyPath, $encryptedPrivateKey);
+                               // Save key-pair
+                               if ($encryptedPrivateKey) {
+                                       $this->view->file_put_contents($this->privateKeyPath, $encryptedPrivateKey);
+                                       $this->view->file_put_contents($this->publicKeyPath, $keypair['publicKey']);
+                               }
 
-                       \OC_FileProxy::$enabled = true;
+                               \OC_FileProxy::$enabled = true;
+                       }
 
                } else {
                        // check if public-key exists but private-key is missing