]> source.dussan.org Git - nextcloud-server.git/commitdiff
cleanup - more to come after
authorThomas Müller <thomas.mueller@tmit.eu>
Sat, 9 Feb 2013 17:01:38 +0000 (18:01 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Sat, 9 Feb 2013 17:01:38 +0000 (18:01 +0100)
apps/files_encryption/ajax/mode.php [deleted file]
apps/files_encryption/appinfo/app.php
apps/files_encryption/hooks/hooks.php
apps/files_encryption/js/settings-personal.js [deleted file]
apps/files_encryption/js/settings.js
apps/files_encryption/lib/crypt.php
apps/files_encryption/lib/keymanager.php
apps/files_encryption/lib/stream.php
apps/files_encryption/settings-personal.php
apps/files_encryption/templates/settings-personal.php

diff --git a/apps/files_encryption/ajax/mode.php b/apps/files_encryption/ajax/mode.php
deleted file mode 100644 (file)
index 64c5be9..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/**\r
- * Copyright (c) 2012, Bjoern Schiessle <schiessle@owncloud.com>\r
- * This file is licensed under the Affero General Public License version 3 or later.\r
- * See the COPYING-README file.\r
- */
-\r
-use OCA\Encryption\Keymanager;
-
-OCP\JSON::checkAppEnabled('files_encryption');\r
-OCP\JSON::checkLoggedIn();\r
-OCP\JSON::callCheck();\r
-
-$mode = $_POST['mode'];
-$changePasswd = false;
-$passwdChanged = false;
-
-if ( isset($_POST['newpasswd']) && isset($_POST['oldpasswd']) ) {
-       $oldpasswd = $_POST['oldpasswd'];
-       $newpasswd = $_POST['newpasswd'];
-       $changePasswd = true;
-       $passwdChanged = Keymanager::changePasswd($oldpasswd, $newpasswd);
-}
-
-$query = \OC_DB::prepare( "SELECT mode FROM *PREFIX*encryption WHERE uid = ?" );\r
-$result = $query->execute(array(\OCP\User::getUser()));\r
-
-if ($result->fetchRow()){
-       $query = OC_DB::prepare( 'UPDATE *PREFIX*encryption SET mode = ? WHERE uid = ?' );
-} else {
-       $query = OC_DB::prepare( 'INSERT INTO *PREFIX*encryption ( mode, uid ) VALUES( ?, ? )' );
-}
-
-if ( (!$changePasswd || $passwdChanged) && $query->execute(array($mode, \OCP\User::getUser())) ) {
-       OCP\JSON::success();
-} else {
-       OCP\JSON::error();
-}
\ No newline at end of file
index f83109a18eaa7c0b49b2a1bab6650fca846781ae..08728622525e963ec6fb195b4ce05152c20a8008 100644 (file)
@@ -43,6 +43,6 @@ if (
 
 }
 
-// Reguster settings scripts
+// Register settings scripts
 OCP\App::registerAdmin( 'files_encryption', 'settings' );
-OCP\App::registerPersonal( 'files_encryption', 'settings-personal' );
\ No newline at end of file
+OCP\App::registerPersonal( 'files_encryption', 'settings-personal' );
index 8bdeee0937b811b56ef599dae766f002da2887f6..7e4f677ce9d230a9b7c80b029fd02fdce49b9e9e 100644 (file)
@@ -165,16 +165,6 @@ class Hooks {
         * @brief \r
         */\r
        public static function postShared( $params ) {\r
-               \r
-               // Delete existing catfile\r
-               Keymanager::deleteFileKey(  );\r
-               \r
-               // Generate new catfile and env keys\r
-               Crypt::multiKeyEncrypt( $plainContent, $publicKeys );\r
-               \r
-               // Save env keys to user folders\r
-               \r
-               \r
        }\r
        \r
        /**\r
diff --git a/apps/files_encryption/js/settings-personal.js b/apps/files_encryption/js/settings-personal.js
deleted file mode 100644 (file)
index 1a53e99..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Copyright (c) 2012, Bjoern Schiessle <schiessle@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or later.
- * See the COPYING-README file.
- */
-
-$(document).ready(function(){
-       $('input[name=encryption_mode]').change(function(){
-               var prevmode = document.getElementById('prev_encryption_mode').value
-               var  client=$('input[value="client"]:checked').val()
-                        ,server=$('input[value="server"]:checked').val()
-                        ,user=$('input[value="user"]:checked').val()
-                        ,none=$('input[value="none"]:checked').val()
-               if (client) {
-                       $.post(OC.filePath('files_encryption', 'ajax', 'mode.php'), { mode: 'client' });
-                       if (prevmode == 'server') {
-                               OC.dialogs.info(t('encryption', 'Please switch to your ownCloud client and change your encryption password to complete the conversion.'), t('encryption', 'switched to client side encryption'));
-                       }
-               } else if (server) {
-                       if (prevmode == 'client') {
-                               OC.dialogs.form([{text:'Login password', name:'newpasswd', type:'password'},{text:'Encryption password used on the client', name:'oldpasswd', type:'password'}],t('encryption', 'Change encryption password to login password'), function(data) {
-                                       $.post(OC.filePath('files_encryption', 'ajax', 'mode.php'), { mode: 'server', newpasswd: data[0].value, oldpasswd: data[1].value }, function(result) {
-                                               if (result.status != 'success') {
-                                                       document.getElementById(prevmode+'_encryption').checked = true;
-                                                       OC.dialogs.alert(t('encryption', 'Please check your passwords and try again.'), t('encryption', 'Could not change your file encryption password to your login password'))
-                                               } else {
-                                                       console.log("alles super");
-                                               }
-                                       }, true);
-                               });
-                       } else {
-                               $.post(OC.filePath('files_encryption', 'ajax', 'mode.php'), { mode: 'server' });
-                       }
-               } else {
-                       $.post(OC.filePath('files_encryption', 'ajax', 'mode.php'), { mode: 'none' });
-               }
-       })
-})
\ No newline at end of file
index 60563bde859cd59683bbb7706fb4c0992b3523f9..0be857bb73e9dd6d35a7ad30e702d3a5c25a08a6 100644 (file)
@@ -9,38 +9,11 @@ $(document).ready(function(){
        $('#encryption_blacklist').multiSelect({
                oncheck:blackListChange,
                onuncheck:blackListChange,
-               createText:'...',
+               createText:'...'
        });
        
        function blackListChange(){
                var blackList=$('#encryption_blacklist').val().join(',');
                OC.AppConfig.setValue('files_encryption','type_blacklist',blackList);
        }
-
-       //TODO: Handle switch between client and server side encryption
-       $('input[name=encryption_mode]').change(function(){
-               var  client=$('input[value="client"]:checked').val()
-                        ,server=$('input[value="server"]:checked').val()
-                        ,user=$('input[value="user"]:checked').val()
-                        ,none=$('input[value="none"]:checked').val()
-                        ,disable=false
-               if (client) {
-                       OC.AppConfig.setValue('files_encryption','mode','client');
-                       disable = true;
-               } else if (server) {
-                       OC.AppConfig.setValue('files_encryption','mode','server');
-                       disable = true;
-               } else if (user) {
-                       OC.AppConfig.setValue('files_encryption','mode','user');
-                       disable = true;
-               } else {
-                       OC.AppConfig.setValue('files_encryption','mode','none');
-               }
-               if (disable) {
-                       document.getElementById('server_encryption').disabled = true;
-                       document.getElementById('client_encryption').disabled = true;
-                       document.getElementById('user_encryption').disabled = true;
-                       document.getElementById('none_encryption').disabled = true;
-               }
-       })
 })
\ No newline at end of file
index e3d23023db3f53b482c1c6f3a0b9a3d4bd4e4812..c7a414c5080926a9b17ca9a18870c1efcf94f74f 100755 (executable)
@@ -4,8 +4,8 @@
  * ownCloud\r
  *\r
  * @author Sam Tuke, Frank Karlitschek, Robin Appelman\r
- * @copyright 2012 Sam Tuke samtuke@owncloud.com, \r
- * Robin Appelman icewind@owncloud.com, Frank Karlitschek \r
+ * @copyright 2012 Sam Tuke samtuke@owncloud.com,\r
+ * Robin Appelman icewind@owncloud.com, Frank Karlitschek\r
  * frank@owncloud.org\r
  *\r
  * This library is free software; you can redistribute it and/or\r
@@ -47,15 +47,15 @@ class Crypt {
        public static function mode( $user = null ) {\r
 \r
                return 'server';\r
-               \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Create a new encryption keypair\r
-         * @return array publicKey, privatekey\r
-         */\r
+\r
+       /**\r
+        * @brief Create a new encryption keypair\r
+        * @return array publicKey, privatekey\r
+        */\r
        public static function createKeypair() {\r
-               \r
+\r
                $res = openssl_pkey_new();\r
 \r
                // Get private key\r
@@ -63,576 +63,543 @@ class Crypt {
 \r
                // Get public key\r
                $publicKey = openssl_pkey_get_details( $res );\r
-               \r
+\r
                $publicKey = $publicKey['key'];\r
-               \r
+\r
                return( array( 'publicKey' => $publicKey, 'privateKey' => $privateKey ) );\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Add arbitrary padding to encrypted data\r
-         * @param string $data data to be padded\r
-         * @return padded data\r
-         * @note In order to end up with data exactly 8192 bytes long we must \r
-         * add two letters. It is impossible to achieve exactly 8192 length \r
-         * blocks with encryption alone, hence padding is added to achieve the \r
-         * required length. \r
-         */\r
+\r
+       /**\r
+        * @brief Add arbitrary padding to encrypted data\r
+        * @param string $data data to be padded\r
+        * @return padded data\r
+        * @note In order to end up with data exactly 8192 bytes long we must\r
+        * add two letters. It is impossible to achieve exactly 8192 length\r
+        * blocks with encryption alone, hence padding is added to achieve the\r
+        * required length.\r
+        */\r
        public static function addPadding( $data ) {\r
-       \r
+\r
                $padded = $data . 'xx';\r
-               \r
+\r
                return $padded;\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Remove arbitrary padding to encrypted data\r
-         * @param string $padded padded data to remove padding from\r
-         * @return unpadded data on success, false on error\r
-         */\r
+\r
+       /**\r
+        * @brief Remove arbitrary padding to encrypted data\r
+        * @param string $padded padded data to remove padding from\r
+        * @return unpadded data on success, false on error\r
+        */\r
        public static function removePadding( $padded ) {\r
-       \r
+\r
                if ( substr( $padded, -2 ) == 'xx' ) {\r
-       \r
+\r
                        $data = substr( $padded, 0, -2 );\r
-                       \r
+\r
                        return $data;\r
-               \r
+\r
                } else {\r
-               \r
+\r
                        // TODO: log the fact that unpadded data was submitted for removal of padding\r
                        return false;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Check if a file's contents contains an IV and is symmetrically encrypted\r
-         * @return true / false\r
-         * @note see also OCA\Encryption\Util->isEncryptedPath()\r
-         */\r
+\r
+       /**\r
+        * @brief Check if a file's contents contains an IV and is symmetrically encrypted\r
+        * @return true / false\r
+        * @note see also OCA\Encryption\Util->isEncryptedPath()\r
+        */\r
        public static function isCatfile( $content ) {\r
-       \r
+\r
                if ( !$content ) {\r
-               \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-               \r
+\r
                $noPadding = self::removePadding( $content );\r
-               \r
+\r
                // Fetch encryption metadata from end of file\r
                $meta = substr( $noPadding, -22 );\r
-               \r
+\r
                // Fetch IV from end of file\r
                $iv = substr( $meta, -16 );\r
-               \r
+\r
                // Fetch identifier from start of metadata\r
                $identifier = substr( $meta, 0, 6 );\r
-               \r
+\r
                if ( $identifier == '00iv00') {\r
-               \r
+\r
                        return true;\r
-                       \r
+\r
                } else {\r
-               \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
+\r
        /**\r
         * Check if a file is encrypted according to database file cache\r
         * @param string $path\r
         * @return bool\r
         */\r
        public static function isEncryptedMeta( $path ) {\r
-       \r
+\r
                // TODO: Use DI to get \OC\Files\Filesystem out of here\r
-       \r
+\r
                // Fetch all file metadata from DB\r
                $metadata = \OC\Files\Filesystem::getFileInfo( $path, '' );\r
-               \r
+\r
                // Return encryption status\r
                return isset( $metadata['encrypted'] ) and ( bool )$metadata['encrypted'];\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Check if a file is encrypted via legacy system\r
-         * @param string $relPath The path of the file, relative to user/data;\r
-         *        e.g. filename or /Docs/filename, NOT admin/files/filename\r
-         * @return true / false\r
-         */\r
+\r
+       /**\r
+        * @brief Check if a file is encrypted via legacy system\r
+        * @param string $relPath The path of the file, relative to user/data;\r
+        *        e.g. filename or /Docs/filename, NOT admin/files/filename\r
+        * @return true / false\r
+        */\r
        public static function isLegacyEncryptedContent( $data, $relPath ) {\r
-       \r
+\r
                // Fetch all file metadata from DB\r
                $metadata = \OC\Files\Filesystem::getFileInfo( $relPath, '' );\r
-               \r
+\r
                // If a file is flagged with encryption in DB, but isn't a \r
                // valid content + IV combination, it's probably using the \r
                // legacy encryption system\r
-               if ( \r
-                       isset( $metadata['encrypted'] ) \r
-                       and $metadata['encrypted'] === true \r
-                       and ! self::isCatfile( $data ) \r
+               if (\r
+                       isset( $metadata['encrypted'] )\r
+                       and $metadata['encrypted'] === true\r
+                       and ! self::isCatfile( $data )\r
                ) {\r
-               \r
+\r
                        return true;\r
-               \r
+\r
                } else {\r
-               \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Symmetrically encrypt a string\r
-         * @returns encrypted file\r
-         */\r
+\r
+       /**\r
+        * @brief Symmetrically encrypt a string\r
+        * @returns encrypted file\r
+        */\r
        public static function encrypt( $plainContent, $iv, $passphrase = '' ) {\r
-               \r
+\r
                if ( $encryptedContent = openssl_encrypt( $plainContent, 'AES-128-CFB', $passphrase, false, $iv ) ) {\r
 \r
                        return $encryptedContent;\r
-                       \r
+\r
                } else {\r
-               \r
+\r
                        \OC_Log::write( 'Encryption library', 'Encryption (symmetric) of content failed', \OC_Log::ERROR );\r
-                       \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Symmetrically decrypt a string\r
-         * @returns decrypted file\r
-         */\r
+\r
+       /**\r
+        * @brief Symmetrically decrypt a string\r
+        * @returns decrypted file\r
+        */\r
        public static function decrypt( $encryptedContent, $iv, $passphrase ) {\r
-       \r
+\r
                if ( $plainContent = openssl_decrypt( $encryptedContent, 'AES-128-CFB', $passphrase, false, $iv ) ) {\r
 \r
                        return $plainContent;\r
-               \r
-                       \r
+\r
+\r
                } else {\r
-               \r
+\r
                        throw new \Exception( 'Encryption library: Decryption (symmetric) of content failed' );\r
-                       \r
-                       return false;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Concatenate encrypted data with its IV and padding\r
-         * @param string $content content to be concatenated\r
-         * @param string $iv IV to be concatenated\r
-         * @returns string concatenated content\r
-         */\r
+\r
+       /**\r
+        * @brief Concatenate encrypted data with its IV and padding\r
+        * @param string $content content to be concatenated\r
+        * @param string $iv IV to be concatenated\r
+        * @returns string concatenated content\r
+        */\r
        public static function concatIv ( $content, $iv ) {\r
-       \r
+\r
                $combined = $content . '00iv00' . $iv;\r
-               \r
+\r
                return $combined;\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Split concatenated data and IV into respective parts\r
-         * @param string $catFile concatenated data to be split\r
-         * @returns array keys: encrypted, iv\r
-         */\r
+\r
+       /**\r
+        * @brief Split concatenated data and IV into respective parts\r
+        * @param string $catFile concatenated data to be split\r
+        * @returns array keys: encrypted, iv\r
+        */\r
        public static function splitIv ( $catFile ) {\r
-       \r
+\r
                // Fetch encryption metadata from end of file\r
                $meta = substr( $catFile, -22 );\r
-               \r
+\r
                // Fetch IV from end of file\r
                $iv = substr( $meta, -16 );\r
-               \r
+\r
                // Remove IV and IV identifier text to expose encrypted content\r
                $encrypted = substr( $catFile, 0, -22 );\r
-       \r
+\r
                $split = array(\r
                        'encrypted' => $encrypted\r
-                       , 'iv' => $iv\r
+               , 'iv' => $iv\r
                );\r
-               \r
+\r
                return $split;\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Symmetrically encrypts a string and returns keyfile content\r
-         * @param $plainContent content to be encrypted in keyfile\r
-         * @returns encrypted content combined with IV\r
-         * @note IV need not be specified, as it will be stored in the returned keyfile\r
-         * and remain accessible therein.\r
-         */\r
+\r
+       /**\r
+        * @brief Symmetrically encrypts a string and returns keyfile content\r
+        * @param $plainContent content to be encrypted in keyfile\r
+        * @returns encrypted content combined with IV\r
+        * @note IV need not be specified, as it will be stored in the returned keyfile\r
+        * and remain accessible therein.\r
+        */\r
        public static function symmetricEncryptFileContent( $plainContent, $passphrase = '' ) {\r
-               \r
+\r
                if ( !$plainContent ) {\r
-               \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-               \r
+\r
                $iv = self::generateIv();\r
-               \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
+\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
+\r
                        \OC_Log::write( 'Encryption library', 'Encryption (symmetric) of keyfile content failed', \OC_Log::ERROR );\r
-                       \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-               \r
+\r
        }\r
 \r
 \r
        /**\r
-       * @brief Symmetrically decrypts keyfile content\r
-       * @param string $source\r
-       * @param string $target\r
-       * @param string $key the decryption key\r
-       * @returns decrypted content\r
-       *\r
-       * This function decrypts a file\r
-       */\r
+        * @brief Symmetrically decrypts keyfile content\r
+        * @param string $source\r
+        * @param string $target\r
+        * @param string $key the decryption key\r
+        * @returns decrypted content\r
+        *\r
+        * This function decrypts a file\r
+        */\r
        public static function symmetricDecryptFileContent( $keyfileContent, $passphrase = '' ) {\r
-       \r
+\r
                if ( !$keyfileContent ) {\r
-               \r
+\r
                        throw new \Exception( 'Encryption library: no data provided for decryption' );\r
-                       \r
+\r
                }\r
-               \r
+\r
                // Remove padding\r
                $noPadding = self::removePadding( $keyfileContent );\r
-               \r
+\r
                // Split into enc data and catfile\r
                $catfile = self::splitIv( $noPadding );\r
-               \r
+\r
                if ( $plainContent = self::decrypt( $catfile['encrypted'], $catfile['iv'], $passphrase ) ) {\r
-               \r
+\r
                        return $plainContent;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
+\r
        /**\r
-       * @brief Creates symmetric keyfile content using a generated key\r
-       * @param string $plainContent content to be encrypted\r
-       * @returns array keys: key, encrypted\r
-       * @note symmetricDecryptFileContent() can be used to decrypt files created using this method\r
-       *\r
-       * This function decrypts a file\r
-       */\r
+        * @brief Creates symmetric keyfile content using a generated key\r
+        * @param string $plainContent content to be encrypted\r
+        * @returns array keys: key, encrypted\r
+        * @note symmetricDecryptFileContent() can be used to decrypt files created using this method\r
+        *\r
+        * This function decrypts a file\r
+        */\r
        public static function symmetricEncryptFileContentKeyfile( $plainContent ) {\r
-       \r
+\r
                $key = self::generateKey();\r
-       \r
+\r
                if( $encryptedContent = self::symmetricEncryptFileContent( $plainContent, $key ) ) {\r
-               \r
+\r
                        return array(\r
                                'key' => $key\r
-                               , 'encrypted' => $encryptedContent\r
+                       , 'encrypted' => $encryptedContent\r
                        );\r
-               \r
+\r
                } else {\r
-               \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
+\r
        /**\r
-       * @brief Create asymmetrically encrypted keyfile content using a generated key\r
-       * @param string $plainContent content to be encrypted\r
-       * @returns array keys: key, encrypted\r
-       * @note symmetricDecryptFileContent() can be used to decrypt files created using this method\r
-       *\r
-       * This function decrypts a file\r
-       */\r
+        * @brief Create asymmetrically encrypted keyfile content using a generated key\r
+        * @param string $plainContent content to be encrypted\r
+        * @returns array keys: key, encrypted\r
+        * @note symmetricDecryptFileContent() can be used to decrypt files created using this method\r
+        *\r
+        * This function decrypts a file\r
+        */\r
        public static function multiKeyEncrypt( $plainContent, array $publicKeys ) {\r
-       \r
+\r
                // Set empty vars to be set by openssl by reference\r
                $sealed = '';\r
                $envKeys = array();\r
-       \r
+\r
                if( openssl_seal( $plainContent, $sealed, $envKeys, $publicKeys ) ) {\r
-               \r
+\r
                        return array(\r
                                'keys' => $envKeys\r
-                               , 'encrypted' => $sealed\r
+                       , 'encrypted' => $sealed\r
                        );\r
-               \r
+\r
                } else {\r
-               \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
+\r
        /**\r
-       * @brief Asymmetrically encrypt a file using multiple public keys\r
-       * @param string $plainContent content to be encrypted\r
-       * @returns string $plainContent decrypted string\r
-       * @note symmetricDecryptFileContent() can be used to decrypt files created using this method\r
-       *\r
-       * This function decrypts a file\r
-       */\r
+        * @brief Asymmetrically encrypt a file using multiple public keys\r
+        * @param string $plainContent content to be encrypted\r
+        * @returns string $plainContent decrypted string\r
+        * @note symmetricDecryptFileContent() can be used to decrypt files created using this method\r
+        *\r
+        * This function decrypts a file\r
+        */\r
        public static function multiKeyDecrypt( $encryptedContent, $envKey, $privateKey ) {\r
-       \r
+\r
                if ( !$encryptedContent ) {\r
-               \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-               \r
+\r
                if ( openssl_open( $encryptedContent, $plainContent, $envKey, $privateKey ) ) {\r
-               \r
+\r
                        return $plainContent;\r
-                       \r
+\r
                } else {\r
-               \r
+\r
                        \OC_Log::write( 'Encryption library', 'Decryption (asymmetric) of sealed content failed', \OC_Log::ERROR );\r
-                       \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Asymetrically encrypt a string using a public key\r
-         * @returns encrypted file\r
-         */\r
+\r
+       /**\r
+        * @brief Asymmetrically encrypt a string using a public key\r
+        * @returns encrypted file\r
+        */\r
        public static function keyEncrypt( $plainContent, $publicKey ) {\r
-       \r
+\r
                openssl_public_encrypt( $plainContent, $encryptedContent, $publicKey );\r
-               \r
+\r
                return $encryptedContent;\r
-       \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Asymetrically decrypt a file using a private key\r
-         * @returns decrypted file\r
-         */\r
+\r
+       /**\r
+        * @brief Asymetrically decrypt a file using a private key\r
+        * @returns decrypted file\r
+        */\r
        public static function keyDecrypt( $encryptedContent, $privatekey ) {\r
-       \r
+\r
                openssl_private_decrypt( $encryptedContent, $plainContent, $privatekey );\r
-               \r
+\r
                return $plainContent;\r
-       \r
+\r
        }\r
 \r
-        /**\r
-         * @brief Encrypts content symmetrically and generates keyfile asymmetrically\r
-         * @returns array containing catfile and new keyfile. \r
-         * keys: data, key\r
-         * @note this method is a wrapper for combining other crypt class methods\r
-         */\r
+       /**\r
+        * @brief Encrypts content symmetrically and generates keyfile asymmetrically\r
+        * @returns array containing catfile and new keyfile.\r
+        * keys: data, key\r
+        * @note this method is a wrapper for combining other crypt class methods\r
+        */\r
        public static function keyEncryptKeyfile( $plainContent, $publicKey ) {\r
-               \r
+\r
                // Encrypt plain data, generate keyfile & encrypted file\r
                $cryptedData = self::symmetricEncryptFileContentKeyfile( $plainContent );\r
-               \r
+\r
                // Encrypt keyfile\r
                $cryptedKey = self::keyEncrypt( $cryptedData['key'], $publicKey );\r
-               \r
+\r
                return array( 'data' => $cryptedData['encrypted'], 'key' => $cryptedKey );\r
-               \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Takes catfile, keyfile, and private key, and\r
-         * performs decryption\r
-         * @returns decrypted content\r
-         * @note this method is a wrapper for combining other crypt class methods\r
-         */\r
+\r
+       /**\r
+        * @brief Takes catfile, keyfile, and private key, and\r
+        * performs decryption\r
+        * @returns decrypted content\r
+        * @note this method is a wrapper for combining other crypt class methods\r
+        */\r
        public static function keyDecryptKeyfile( $catfile, $keyfile, $privateKey ) {\r
-               \r
+\r
                // Decrypt the keyfile with the user's private key\r
                $decryptedKeyfile = self::keyDecrypt( $keyfile, $privateKey );\r
-               \r
+\r
                // Decrypt the catfile symmetrically using the decrypted keyfile\r
                $decryptedData = self::symmetricDecryptFileContent( $catfile, $decryptedKeyfile );\r
-               \r
+\r
                return $decryptedData;\r
-               \r
+\r
        }\r
-       \r
+\r
        /**\r
-       * @brief Symmetrically encrypt a file by combining encrypted component data blocks\r
-       */\r
+        * @brief Symmetrically encrypt a file by combining encrypted component data blocks\r
+        */\r
        public static function symmetricBlockEncryptFileContent( $plainContent, $key ) {\r
-       \r
+\r
                $crypted = '';\r
-               \r
+\r
                $remaining = $plainContent;\r
-               \r
+\r
                $testarray = array();\r
-               \r
+\r
                while( strlen( $remaining ) ) {\r
-               \r
+\r
                        //echo "\n\n\$block = ".substr( $remaining, 0, 6126 );\r
-               \r
+\r
                        // Encrypt a chunk of unencrypted data and add it to the rest\r
                        $block = self::symmetricEncryptFileContent( substr( $remaining, 0, 6126 ), $key );\r
-                       \r
+\r
                        $padded = self::addPadding( $block );\r
-                       \r
+\r
                        $crypted .= $block;\r
-                       \r
+\r
                        $testarray[] = $block;\r
-                       \r
+\r
                        // Remove the data already encrypted from remaining unencrypted data\r
                        $remaining = substr( $remaining, 6126 );\r
-               \r
+\r
                }\r
-               \r
-               //echo "hags   ";\r
-               \r
-               //echo "\n\n\n\$crypted = $crypted\n\n\n";\r
-               \r
-               //print_r($testarray);\r
-               \r
+\r
                return $crypted;\r
 \r
        }\r
 \r
 \r
        /**\r
-       * @brief Symmetrically decrypt a file by combining encrypted component data blocks\r
-       */\r
+        * @brief Symmetrically decrypt a file by combining encrypted component data blocks\r
+        */\r
        public static function symmetricBlockDecryptFileContent( $crypted, $key ) {\r
-               \r
+\r
                $decrypted = '';\r
-               \r
+\r
                $remaining = $crypted;\r
-               \r
+\r
                $testarray = array();\r
-               \r
+\r
                while( strlen( $remaining ) ) {\r
-                       \r
+\r
                        $testarray[] = substr( $remaining, 0, 8192 );\r
-               \r
+\r
                        // Decrypt a chunk of unencrypted data and add it to the rest\r
                        $decrypted .= self::symmetricDecryptFileContent( $remaining, $key );\r
-                       \r
+\r
                        // Remove the data already encrypted from remaining unencrypted data\r
                        $remaining = substr( $remaining, 8192 );\r
-                       \r
+\r
                }\r
-               \r
-               //echo "\n\n\$testarray = "; print_r($testarray);\r
-               \r
+\r
                return $decrypted;\r
-               \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Generates a pseudo random initialisation vector\r
-         * @return String $iv generated IV\r
-         */\r
+\r
+       /**\r
+        * @brief Generates a pseudo random initialisation vector\r
+        * @return String $iv generated IV\r
+        */\r
        public static function generateIv() {\r
-               \r
+\r
                if ( $random = openssl_random_pseudo_bytes( 12, $strong ) ) {\r
-               \r
+\r
                        if ( !$strong ) {\r
-                       \r
+\r
                                // If OpenSSL indicates randomness is insecure, log error\r
                                \OC_Log::write( 'Encryption library', 'Insecure symmetric key was generated using openssl_random_pseudo_bytes()', \OC_Log::WARN );\r
-                       \r
+\r
                        }\r
-                       \r
+\r
                        // We encode the iv purely for string manipulation \r
                        // purposes - it gets decoded before use\r
                        $iv = base64_encode( $random );\r
-                       \r
+\r
                        return $iv;\r
-                       \r
+\r
                } else {\r
-               \r
-                       throw new Exception( 'Generating IV failed' );\r
-                       \r
+\r
+                       throw new \Exception( 'Generating IV failed' );\r
+\r
                }\r
-               \r
+\r
        }\r
-       \r
-        /**\r
-         * @brief Generate a pseudo random 1024kb ASCII key\r
-         * @returns $key Generated key\r
-         */\r
+\r
+       /**\r
+        * @brief Generate a pseudo random 1024kb ASCII key\r
+        * @returns $key Generated key\r
+        */\r
        public static function generateKey() {\r
-               \r
+\r
                // Generate key\r
                if ( $key = base64_encode( openssl_random_pseudo_bytes( 183, $strong ) ) ) {\r
-               \r
+\r
                        if ( !$strong ) {\r
-                       \r
+\r
                                // If OpenSSL indicates randomness is insecure, log error\r
-                               throw new Exception ( 'Encryption library, Insecure symmetric key was generated using openssl_random_pseudo_bytes()' );\r
-                       \r
+                               throw new \Exception ( 'Encryption library, Insecure symmetric key was generated using openssl_random_pseudo_bytes()' );\r
+\r
                        }\r
-               \r
+\r
                        return $key;\r
-                       \r
+\r
                } else {\r
-               \r
+\r
                        return false;\r
-                       \r
-               }\r
-               \r
-       }\r
 \r
-       public static function changekeypasscode( $oldPassword, $newPassword ) {\r
-\r
-               if ( \OCP\User::isLoggedIn() ) {\r
-               \r
-                       $key = Keymanager::getPrivateKey( $user, $view );\r
-                       \r
-                       if ( ( $key = Crypt::symmetricDecryptFileContent($key,$oldpasswd) ) ) {\r
-                       \r
-                               if ( ( $key = Crypt::symmetricEncryptFileContent( $key, $newpasswd ) ) ) {\r
-                               \r
-                                       Keymanager::setPrivateKey( $key );\r
-                                       \r
-                                       return true;\r
-                               }\r
-                               \r
-                       }\r
-                       \r
                }\r
-               \r
-               return false;\r
-               \r
+\r
        }\r
-       \r
+\r
        /**\r
         * @brief Get the blowfish encryption handeler for a key\r
         * @param $key string (optional)\r
@@ -641,21 +608,21 @@ class Crypt {
         * if the key is left out, the default handeler will be used\r
         */\r
        public static function getBlowfish( $key = '' ) {\r
-       \r
+\r
                if ( $key ) {\r
-               \r
+\r
                        return new \Crypt_Blowfish( $key );\r
-               \r
+\r
                } else {\r
-               \r
+\r
                        return false;\r
-                       \r
+\r
                }\r
-               \r
+\r
        }\r
-       \r
+\r
        public static function legacyCreateKey( $passphrase ) {\r
-       \r
+\r
                // Generate a random integer\r
                $key = mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 );\r
 \r
@@ -663,9 +630,9 @@ class Crypt {
                $legacyEncKey = self::legacyEncrypt( $key, $passphrase );\r
 \r
                return $legacyEncKey;\r
-       \r
+\r
        }\r
-       \r
+\r
        /**\r
         * @brief encrypts content using legacy blowfish system\r
         * @param $content the cleartext message you want to encrypt\r
@@ -675,54 +642,54 @@ class Crypt {
         * This function encrypts an content\r
         */\r
        public static function legacyEncrypt( $content, $passphrase = '' ) {\r
-       \r
+\r
                $bf = self::getBlowfish( $passphrase );\r
-               \r
+\r
                return $bf->encrypt( $content );\r
-               \r
+\r
        }\r
-       \r
+\r
        /**\r
-       * @brief decrypts content using legacy blowfish system\r
-       * @param $content the cleartext message you want to decrypt\r
-       * @param $key the encryption key (optional)\r
-       * @returns cleartext content\r
-       *\r
-       * This function decrypts an content\r
-       */\r
+        * @brief decrypts content using legacy blowfish system\r
+        * @param $content the cleartext message you want to decrypt\r
+        * @param $key the encryption key (optional)\r
+        * @returns cleartext content\r
+        *\r
+        * This function decrypts an content\r
+        */\r
        public static function legacyDecrypt( $content, $passphrase = '' ) {\r
-               \r
+\r
                $bf = self::getBlowfish( $passphrase );\r
-               \r
+\r
                $decrypted = $bf->decrypt( $content );\r
-               \r
+\r
                $trimmed = rtrim( $decrypted, "\0" );\r
-               \r
+\r
                return $trimmed;\r
-               \r
+\r
        }\r
-       \r
+\r
        public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKey, $newPassphrase ) {\r
-       \r
+\r
                $decrypted = self::legacyDecrypt( $legacyEncryptedContent, $legacyPassphrase );\r
-       \r
+\r
                $recrypted = self::keyEncryptKeyfile( $decrypted, $publicKey );\r
-               \r
+\r
                return $recrypted;\r
-       \r
+\r
        }\r
-       \r
+\r
        /**\r
-       * @brief Re-encryptes a legacy blowfish encrypted file using AES with integrated IV\r
-       * @param $legacyContent the legacy encrypted content to re-encrypt\r
-       * @returns cleartext content\r
-       *\r
-       * This function decrypts an content\r
-       */\r
+        * @brief Re-encryptes a legacy blowfish encrypted file using AES with integrated IV\r
+        * @param $legacyContent the legacy encrypted content to re-encrypt\r
+        * @returns cleartext content\r
+        *\r
+        * This function decrypts an content\r
+        */\r
        public static function legacyRecrypt( $legacyContent, $legacyPassphrase, $newPassphrase ) {\r
-               \r
+\r
                // TODO: write me\r
-       \r
+\r
        }\r
-       \r
+\r
 }
\ No newline at end of file
index 0d0380db6ec401ff5571600025adbb054fdf3a3f..955877971540bf86144ec6048ec47742cefff752 100755 (executable)
@@ -28,7 +28,7 @@ namespace OCA\Encryption;
  * @note Where a method requires a view object, it's root must be '/'
  */
 class Keymanager {
-               \r
+               
        /**
         * @brief retrieve the ENCRYPTED private key from a user
         * 
@@ -46,8 +46,8 @@ class Keymanager {
 
        /**
         * @brief retrieve public key for a specified user
-        * @param \OC_FilesystemView $view\r
-        * @param $userId\r
+        * @param \OC_FilesystemView $view
+        * @param $userId
         * @return string public key or false
         */
        public static function getPublicKey( \OC_FilesystemView $view, $userId ) {
@@ -58,8 +58,8 @@ class Keymanager {
        
        /**
         * @brief retrieve both keys from a user (private and public)
-        * @param \OC_FilesystemView $view\r
-        * @param $userId\r
+        * @param \OC_FilesystemView $view
+        * @param $userId
         * @return array keys: privateKey, publicKey
         */
        public static function getUserKeys( \OC_FilesystemView $view, $userId ) {
@@ -148,11 +148,11 @@ class Keymanager {
        
        /**
         * @brief retrieve keyfile for an encrypted file
-        * @param \OC_FilesystemView $view\r
-        * @param $userId\r
-        * @param $filePath\r
-        * @internal param \OCA\Encryption\file $string name\r
-        * @return string file key or false\r
+        * @param \OC_FilesystemView $view
+        * @param $userId
+        * @param $filePath
+        * @internal param \OCA\Encryption\file $string name
+        * @return string file key or false
         * @note The keyfile returned is asymmetrically encrypted. Decryption
         * of the keyfile must be performed by client code
         */
@@ -177,12 +177,12 @@ class Keymanager {
        /**
         * @brief Delete a keyfile
         *
-        * @param OC_FilesystemView $view\r
-        * @param string $userId username\r
-        * @param string $path path of the file the key belongs to\r
-        * @return bool Outcome of unlink operation\r
-        * @note $path must be relative to data/user/files. e.g. mydoc.txt NOT\r
-        *       /data/admin/files/mydoc.txt\r
+        * @param OC_FilesystemView $view
+        * @param string $userId username
+        * @param string $path path of the file the key belongs to
+        * @return bool Outcome of unlink operation
+        * @note $path must be relative to data/user/files. e.g. mydoc.txt NOT
+        *       /data/admin/files/mydoc.txt
         */
        public static function deleteFileKey( \OC_FilesystemView $view, $userId, $path ) {
                
@@ -220,12 +220,11 @@ class Keymanager {
                
                \OC_FileProxy::$enabled = false;
                
-               if ( !$view->file_exists( '' ) ) $view->mkdir( '' );
+               if ( !$view->file_exists( '' ) )
+                       $view->mkdir( '' );
                
                return $view->file_put_contents( $user . '.private.key', $key );
-               
-               \OC_FileProxy::$enabled = true;
-               
+
        }
        
        /**
@@ -253,24 +252,24 @@ class Keymanager {
                
                \OC_FileProxy::$enabled = false;
                
-               if ( !$view->file_exists( '' ) ) $view->mkdir( '' );
+               if ( !$view->file_exists( '' ) )
+                       $view->mkdir( '' );
                
                return $view->file_put_contents( \OCP\User::getUser() . '.public.key', $key );
-               
-               \OC_FileProxy::$enabled = true;
+
                
        }
        
        /**
-        * @brief store file encryption key\r
-        *\r
-        * @param string $path relative path of the file, including filename\r
-        * @param string $key\r
-        * @param null $view\r
-        * @param string $dbClassName\r
-        * @return bool true/false\r
-        * @note The keyfile is not encrypted here. Client code must\r
-        * asymmetrically encrypt the keyfile before passing it to this method\r
+        * @brief store file encryption key
+        *
+        * @param string $path relative path of the file, including filename
+        * @param string $key
+        * @param null $view
+        * @param string $dbClassName
+        * @return bool true/false
+        * @note The keyfile is not encrypted here. Client code must
+        * asymmetrically encrypt the keyfile before passing it to this method
         */
        public static function setShareKey( \OC_FilesystemView $view, $path, $userId, $shareKey ) {
                
@@ -280,54 +279,38 @@ class Keymanager {
                
                return $view->file_put_contents( $basePath . '/' . $shareKeyPath . '.shareKey', $shareKey );
                
-       }\r
-       \r
-       /**\r
-        * @brief Make preparations to vars and filesystem for saving a keyfile\r
-        */\r
-       public static function keySetPreparation( \OC_FilesystemView $view, $path, $basePath, $userId ) {\r
+       }
+       
+       /**
+        * @brief Make preparations to vars and filesystem for saving a keyfile
+        */
+       public static function keySetPreparation( \OC_FilesystemView $view, $path, $basePath, $userId ) {
                
                $targetPath = ltrim( $path, '/' );
                
                $path_parts = pathinfo( $targetPath );
                
                // If the file resides within a subdirectory, create it
-               if ( \r
-               isset( $path_parts['dirname'] )\r
-               && ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] ) \r
+               if ( 
+               isset( $path_parts['dirname'] )
+               && ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] ) 
                ) {
                
                        $view->mkdir( $basePath . '/' . $path_parts['dirname'] );
                        
                }
                
-               return $targetPath;\r
-       \r
-       }
+               return $targetPath;
        
-       /**
-        * @brief change password of private encryption key
-        *
-        * @param string $oldpasswd old password
-        * @param string $newpasswd new password
-        * @return bool true/false
-        */
-       public static function changePasswd($oldpasswd, $newpasswd) {
-               
-               if ( \OCP\User::checkPassword(\OCP\User::getUser(), $newpasswd) ) {
-                       return Crypt::changekeypasscode($oldpasswd, $newpasswd);
-               }
-               return false;
-               
        }
-       
+
        /**
         * @brief Fetch the legacy encryption key from user files
         * @param string $login used to locate the legacy key
         * @param string $passphrase used to decrypt the legacy key
         * @return true / false
         *
-        * if the key is left out, the default handeler will be used
+        * if the key is left out, the default handler will be used
         */
        public function getLegacyKey() {
                
index d4b993b4c0638a7a6596c56cfc5edd8fd7955814..65d7d57a05a740bd164e7476b1c3910afcd7f49f 100644 (file)
@@ -173,7 +173,7 @@ class Stream {
                        
                        // $count will always be 8192 https://bugs.php.net/bug.php?id=21641
                        // This makes this function a lot simpler, but will break this class if the above 'bug' gets 'fixed'
-                       \OCP\Util::writeLog( 'files_encryption', 'PHP "bug" 21641 no longer holds, decryption system requires refactoring', OCP\Util::FATAL );
+                       \OCP\Util::writeLog( 'files_encryption', 'PHP "bug" 21641 no longer holds, decryption system requires refactoring', \OCP\Util::FATAL );
 
                        die();
 
@@ -209,7 +209,7 @@ class Stream {
        }
        
        /**
-        * @brief Encrypt and pad data ready for writting to disk
+        * @brief Encrypt and pad data ready for writing to disk
         * @param string $plainData data to be encrypted
         * @param string $key key to use for encryption
         * @return encrypted data on success, false on failure
@@ -403,7 +403,7 @@ class Stream {
                                $encrypted = $this->preWriteEncrypt( $chunk, $this->keyfile );
                                
                                // Write the data chunk to disk. This will be 
-                               // addended to the last data chunk if the file 
+                               // attended to the last data chunk if the file
                                // being handled totals more than 6126 bytes
                                fwrite( $this->handle, $encrypted );
                                
index 6fe4ea6d564c1b84ed64901941155aaf77c32ccf..af0273cfdc4dc4cf1a5c31f6155ff158c8b04d5b 100644 (file)
@@ -12,8 +12,6 @@ $blackList = explode( ',', \OCP\Config::getAppValue( 'files_encryption', 'type_b
 \r
 $tmpl->assign( 'blacklist', $blackList );\r
 \r
-OCP\Util::addscript('files_encryption','settings-personal');\r
-\r
 return $tmpl->fetchPage();\r
 \r
 return null;\r
index 1f71efb1735772e8c864c7886ae3d36c903f6471..47467c52c08a3879064624754a3e271815e63146 100644 (file)
@@ -16,7 +16,7 @@
                                <?php echo $type; ?>\r
                        </li>\r
                        <?php endforeach; ?>\r
-               </p>\r
+               </ul>\r
                <?php endif; ?>\r
        </fieldset>\r
 </form>\r