// - Add a setting "Don´t encrypt files larger than xx because of performance reasons"
// - Transparent decrypt/encrypt in filesystem.php. Autodetect if a file is encrypted (.encrypted extension)
// - Don't use a password directly as encryption key. but a key which is stored on the server and encrypted with the user password. -> password change faster
// - IMPORTANT! Check if the block lenght of the encrypted data stays the same
// - Add a setting "Don´t encrypt files larger than xx because of performance"
// - Don't use a password directly as encryption key. but a key which is
// stored on the server and encrypted with the user password. -> change pass
// faster
/**
* Class for common cryptography functionality
@ -93,7 +92,10 @@ class Crypt {
* @brief Add arbitrary padding to encrypted data
* @param string $data data to be padded
* @return padded data
* @note In order to end up with data exactly 8192 bytes long we must add two letters. It is impossible to achieve exactly 8192 length blocks with encryption alone, hence padding is added to achieve the required length.
* @note In order to end up with data exactly 8192 bytes long we must
* add two letters. It is impossible to achieve exactly 8192 length
* blocks with encryption alone, hence padding is added to achieve the
* required length.
*/
public static function addPadding( $data ) {
@ -118,7 +120,7 @@ class Crypt {
} else {
# TODO: log the fact that unpadded data was submitted for removal of padding
// TODO: log the fact that unpadded data was submitted for removal of padding
return false;
}
@ -168,7 +170,7 @@ class Crypt {
*/
public static function isEncryptedMeta( $path ) {
# TODO: Use DI to get OC_FileCache_Cached out of here
// TODO: Use DI to get OC_FileCache_Cached out of here
// Only get the user again if it isn't already set
if ( empty( $this->userId ) ) {
# TODO: Move this user call out of here - it belongs elsewhere
// TODO: Move this user call out of here - it belongs
// elsewhere
$this->userId = \OCP\User::getUser();
}
# TODO: Add a method for getting the user in case OCP\User::
# getUser() doesn't work (can that scenario ever occur?)
// TODO: Add a method for getting the user in case OCP\User::
// getUser() doesn't work (can that scenario ever occur?)
}
@ -287,7 +291,10 @@ class Stream {
*/
public function stream_write( $data ) {
// Disable the file proxies so that encryption is not automatically attempted when the file is written to disk - we are handling that separately here and we don't want to get into an infinite loop
// Disable the file proxies so that encryption is not
// automatically attempted when the file is written to disk -
// we are handling that separately here and we don't want to
// get into an infinite loop
\OC_FileProxy::$enabled = false;
// Get the length of the unencrypted data that we are handling
@ -296,14 +303,15 @@ class Stream {
// So far this round, no data has been written
$written = 0;
// Find out where we are up to in the writing of data to the file
// Find out where we are up to in the writing of data to the
// file
$pointer = ftell( $this->handle );
// Make sure the userId is set
$this->getuser();
# TODO: Check if file is shared, if so, use multiKeyEncrypt and
# save shareKeys in necessary user directories
// TODO: Check if file is shared, if so, use multiKeyEncrypt and
// save shareKeys in necessary user directories
// Get / generate the keyfile for the file we're handling
// If we're writing a new file (not overwriting an existing
@ -324,19 +332,24 @@ class Stream {
}
// If extra data is left over from the last round, make sure it is integrated into the next 6126 / 8192 block
// If extra data is left over from the last round, make sure it
// is integrated into the next 6126 / 8192 block
if ( $this->writeCache ) {
// Concat writeCache to start of $data
$data = $this->writeCache . $data;
// Clear the write cache, ready for resuse - it has been flushed and its old contents processed
// Clear the write cache, ready for resuse - it has been
// flushed and its old contents processed
$this->writeCache = '';
}
//
// // Make sure we always start on a block start
if ( 0 != ( $pointer % 8192 ) ) { // if the current positoin of file indicator is not aligned to a 8192 byte block, fix it so that it is
if ( 0 != ( $pointer % 8192 ) ) {
// if the current positoin of
// file indicator is not aligned to a 8192 byte block, fix it
// // While there still remains somed data to be processed & written
while( strlen( $data ) > 0 ) {
//
// // Remaining length for this iteration, not of the entire file (may be greater than 8192 bytes)
// // Remaining length for this iteration, not of the
// // entire file (may be greater than 8192 bytes)
// $remainingLength = strlen( $data );
//
// // If data remaining to be written is less than the size of 1 6126 byte block
// // If data remaining to be written is less than the
// // size of 1 6126 byte block
if ( strlen( $data ) <6126){
// Set writeCache to contents of $data
// The writeCache will be carried over to the next write round, and added to the start of $data to ensure that written blocks are always the correct length. If there is still data in writeCache after the writing round has finished, then the data will be written to disk by $this->flush().
// - Add a setting "Don´t encrypt files larger than xx because of performance reasons"
// - Transparent decrypt/encrypt in filesystem.php. Autodetect if a file is encrypted (.encrypted extension)
// - Don't use a password directly as encryption key. but a key which is stored on the server and encrypted with the user password. -> password change faster
// - Add a setting "Don´t encrypt files larger than xx because of performance
// reasons"
// - Transparent decrypt/encrypt in filesystem.php. Autodetect if a file is
// encrypted (.encrypted extension)
// - Don't use a password directly as encryption key. but a key which is
// stored on the server and encrypted with the user password. -> password
// change faster
// - IMPORTANT! Check if the block lenght of the encrypted data stays the same
namespace OCA\Encryption;
@ -41,56 +45,57 @@ namespace OCA\Encryption;
class Util {
# Web UI:
// Web UI:
## DONE: files created via web ui are encrypted
## DONE: file created & encrypted via web ui are readable in web ui
## DONE: file created & encrypted via web ui are readable via webdav
//// DONE: files created via web ui are encrypted
//// DONE: file created & encrypted via web ui are readable in web ui
//// DONE: file created & encrypted via web ui are readable via webdav
# WebDAV:
// WebDAV:
## DONE: new data filled files added via webdav get encrypted
## DONE: new data filled files added via webdav are readable via webdav
## DONE: reading unencrypted files when encryption is enabled works via webdav
## DONE: files created & encrypted via web ui are readable via webdav
//// DONE: new data filled files added via webdav get encrypted
//// DONE: new data filled files added via webdav are readable via webdav
//// DONE: reading unencrypted files when encryption is enabled works via
//// webdav
//// DONE: files created & encrypted via web ui are readable via webdav
# Legacy support:
// Legacy support:
## DONE: add method to check if file is encrypted using new system
## DONE: add method to check if file is encrypted using old system
## DONE: add method to fetch legacy key
## DONE: add method to decrypt legacy encrypted data
//// DONE: add method to check if file is encrypted using new system
//// DONE: add method to check if file is encrypted using old system
//// DONE: add method to fetch legacy key
//// DONE: add method to decrypt legacy encrypted data
## TODO: add method to encrypt all user files using new system
## TODO: add method to decrypt all user files using new system
## TODO: add method to encrypt all user files using old system
## TODO: add method to decrypt all user files using old system
//// TODO: add method to encrypt all user files using new system
//// TODO: add method to decrypt all user files using new system
//// TODO: add method to encrypt all user files using old system
//// TODO: add method to decrypt all user files using old system
# Admin UI:
// Admin UI:
## DONE: changing user password also changes encryption passphrase
//// DONE: changing user password also changes encryption passphrase
## TODO: add support for optional recovery in case of lost passphrase / keys
## TODO: add admin optional required long passphrase for users
## TODO: add UI buttons for encrypt / decrypt everything
## TODO: implement flag system to allow user to specify encryption by folder, subfolder, etc.
//// TODO: add support for optional recovery in case of lost passphrase / keys
//// TODO: add admin optional required long passphrase for users
//// TODO: add UI buttons for encrypt / decrypt everything
//// TODO: implement flag system to allow user to specify encryption by folder, subfolder, etc.
# Sharing:
// Sharing:
## TODO: add support for encrypting to multiple public keys
## TODO: add support for decrypting to multiple private keys
//// TODO: add support for encrypting to multiple public keys
//// TODO: add support for decrypting to multiple private keys
# Integration testing:
// Integration testing:
## TODO: test new encryption with webdav
## TODO: test new encryption with versioning
## TODO: test new encryption with sharing
## TODO: test new encryption with proxies
//// TODO: test new encryption with webdav
//// TODO: test new encryption with versioning
//// TODO: test new encryption with sharing
//// TODO: test new encryption with proxies
private $view; // OC_FilesystemView object for filesystem operations