reformat code

This commit is contained in:
Florin Peter 2013-06-03 18:42:13 +02:00
parent 1e601cd6f1
commit dc8bcf0688
10 changed files with 83 additions and 74 deletions

View File

@ -29,7 +29,7 @@ $user = \OCP\User::getUser();
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
$keyPath = '/' . $user . '/files_encryption/'.$user.'.private.key'; $keyPath = '/' . $user . '/files_encryption/' . $user . '.private.key';
$encryptedKey = $view->file_get_contents($keyPath); $encryptedKey = $view->file_get_contents($keyPath);
$decryptedKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, $oldPassword); $decryptedKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, $oldPassword);

View File

@ -57,8 +57,9 @@ class Hooks {
$privateKey = Crypt::decryptPrivateKey($encryptedKey, $params['password']); $privateKey = Crypt::decryptPrivateKey($encryptedKey, $params['password']);
if($privateKey === false) { if ($privateKey === false) {
\OCP\Util::writeLog('Encryption library', 'Private key for user "' . $params['uid'] . '" is not valid! Maybe the user password was changed from outside if so please change it back to gain access', \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', 'Private key for user "' . $params['uid']
. '" is not valid! Maybe the user password was changed from outside if so please change it back to gain access', \OCP\Util::ERROR);
} }
$session = new \OCA\Encryption\Session($view); $session = new \OCA\Encryption\Session($view);
@ -332,7 +333,7 @@ class Hooks {
$sharingEnabled = \OCP\Share::isEnabled(); $sharingEnabled = \OCP\Share::isEnabled();
// get the path including mount point only if not a shared folder // get the path including mount point only if not a shared folder
if(strncmp($path, '/Shared' , strlen('/Shared') !== 0)) { if (strncmp($path, '/Shared', strlen('/Shared') !== 0)) {
// get path including the the storage mount point // get path including the the storage mount point
$path = $util->getPathWithMountPoint($params['itemSource']); $path = $util->getPathWithMountPoint($params['itemSource']);
} }
@ -409,14 +410,14 @@ class Hooks {
} }
// get the path including mount point only if not a shared folder // get the path including mount point only if not a shared folder
if(strncmp($path, '/Shared' , strlen('/Shared') !== 0)) { if (strncmp($path, '/Shared', strlen('/Shared') !== 0)) {
// get path including the the storage mount point // get path including the the storage mount point
$path = $util->getPathWithMountPoint($params['itemSource']); $path = $util->getPathWithMountPoint($params['itemSource']);
} }
// if we unshare a folder we need a list of all (sub-)files // if we unshare a folder we need a list of all (sub-)files
if ($params['itemType'] === 'folder') { if ($params['itemType'] === 'folder') {
$allFiles = $util->getAllFiles( $path ); $allFiles = $util->getAllFiles($path);
} else { } else {
$allFiles = array($path); $allFiles = array($path);
} }

View File

@ -365,9 +365,9 @@ class Crypt {
// check if this a valid private key // check if this a valid private key
$res = openssl_pkey_get_private($plainKey); $res = openssl_pkey_get_private($plainKey);
if(is_resource($res)) { if (is_resource($res)) {
$sslInfo = openssl_pkey_get_details($res); $sslInfo = openssl_pkey_get_details($res);
if(!isset($sslInfo['key'])) { if (!isset($sslInfo['key'])) {
$plainKey = false; $plainKey = false;
} }
} else { } else {

View File

@ -73,7 +73,7 @@ class Helper {
if (!$util->ready()) { if (!$util->ready()) {
\OCP\Util::writeLog('Encryption library', 'User account "' . $util->getUserId() \OCP\Util::writeLog('Encryption library', 'User account "' . $util->getUserId()
. '" is not ready for encryption; configuration started', \OCP\Util::DEBUG); . '" is not ready for encryption; configuration started', \OCP\Util::DEBUG);
if (!$util->setupServerSide($password)) { if (!$util->setupServerSide($password)) {
return false; return false;

View File

@ -88,9 +88,10 @@ class Session {
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
$encryptedKey = $this->view->file_get_contents( '/owncloud_private_key/' . $publicShareKeyId . '.private.key' ); $encryptedKey = $this->view->file_get_contents(
'/owncloud_private_key/' . $publicShareKeyId . '.private.key');
$privateKey = Crypt::decryptPrivateKey($encryptedKey, ''); $privateKey = Crypt::decryptPrivateKey($encryptedKey, '');
$this->setPublicSharePrivateKey( $privateKey ); $this->setPublicSharePrivateKey($privateKey);
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
} }
@ -121,7 +122,7 @@ class Session {
if (\OCA\Encryption\Helper::isPublicAccess()) { if (\OCA\Encryption\Helper::isPublicAccess()) {
return $this->getPublicSharePrivateKey(); return $this->getPublicSharePrivateKey();
} else { } else {
if (!is_null( \OC::$session->get('privateKey') )) { if (!is_null(\OC::$session->get('privateKey'))) {
return \OC::$session->get('privateKey'); return \OC::$session->get('privateKey');
} else { } else {
return false; return false;
@ -136,7 +137,7 @@ class Session {
*/ */
public function setPublicSharePrivateKey($privateKey) { public function setPublicSharePrivateKey($privateKey) {
\OC::$session->set('publicSharePrivateKey', $privateKey); \OC::$session->set('publicSharePrivateKey', $privateKey);
return true; return true;
@ -149,7 +150,7 @@ class Session {
*/ */
public function getPublicSharePrivateKey() { public function getPublicSharePrivateKey() {
if (!is_null( \OC::$session->get('publicSharePrivateKey') )) { if (!is_null(\OC::$session->get('publicSharePrivateKey'))) {
return \OC::$session->get('publicSharePrivateKey'); return \OC::$session->get('publicSharePrivateKey');
} else { } else {
return false; return false;
@ -176,7 +177,7 @@ class Session {
*/ */
public function getLegacyKey() { public function getLegacyKey() {
if ( !is_null( \OC::$session->get('legacyKey') ) ) { if (!is_null(\OC::$session->get('legacyKey'))) {
return \OC::$session->get('legacyKey'); return \OC::$session->get('legacyKey');

View File

@ -302,7 +302,7 @@ class Util {
if (\OCP\DB::isError($result)) { if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else { } else {
if($result->numRows() > 0) { if ($result->numRows() > 0) {
$row = $result->fetchRow(); $row = $result->fetchRow();
if (isset($row['recovery_enabled'])) { if (isset($row['recovery_enabled'])) {
$recoveryEnabled[] = $row['recovery_enabled']; $recoveryEnabled[] = $row['recovery_enabled'];
@ -442,7 +442,7 @@ class Util {
// If the file uses old // If the file uses old
// encryption system // encryption system
} elseif ( Crypt::isLegacyEncryptedContent( $data, $relPath ) ) { } elseif (Crypt::isLegacyEncryptedContent($data, $relPath)) {
$found['legacy'][] = array( $found['legacy'][] = array(
'name' => $file, 'name' => $file,
@ -573,7 +573,9 @@ class Util {
// get relative path // get relative path
$relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path); $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);
if (isset($pathParts[2]) && $pathParts[2] === 'files' && $this->view->file_exists($path) && $this->isEncryptedPath($path)) { if (isset($pathParts[2]) && $pathParts[2] === 'files' && $this->view->file_exists($path)
&& $this->isEncryptedPath($path)
) {
// get the size from filesystem // get the size from filesystem
$fullPath = $this->view->getLocalFile($path); $fullPath = $this->view->getLocalFile($path);
@ -643,7 +645,7 @@ class Util {
return $result; return $result;
} }
/** /**
* @param $path * @param $path
* @return bool * @return bool
@ -687,28 +689,32 @@ class Util {
$relPath = $plainFile['path']; $relPath = $plainFile['path'];
//relative to /data //relative to /data
$rawPath = '/'.$this->userId . '/files/' . $plainFile['path']; $rawPath = '/' . $this->userId . '/files/' . $plainFile['path'];
// Open plain file handle for binary reading // Open plain file handle for binary reading
$plainHandle = $this->view->fopen( $rawPath, 'rb' ); $plainHandle = $this->view->fopen($rawPath, 'rb');
// Open enc file handle for binary writing, with same filename as original plain file // Open enc file handle for binary writing, with same filename as original plain file
$encHandle = fopen( 'crypt://' . $relPath.'.tmp', 'wb' ); $encHandle = fopen('crypt://' . $relPath . '.tmp', 'wb');
// Move plain file to a temporary location // Move plain file to a temporary location
$size = stream_copy_to_stream( $plainHandle, $encHandle ); $size = stream_copy_to_stream($plainHandle, $encHandle);
fclose($encHandle); fclose($encHandle);
$fakeRoot = $this->view->getRoot(); $fakeRoot = $this->view->getRoot();
$this->view->chroot('/'.$this->userId.'/files'); $this->view->chroot('/' . $this->userId . '/files');
$this->view->rename($relPath . '.tmp', $relPath); $this->view->rename($relPath . '.tmp', $relPath);
$this->view->chroot($fakeRoot); $this->view->chroot($fakeRoot);
// Add the file to the cache // Add the file to the cache
\OC\Files\Filesystem::putFileInfo( $relPath, array( 'encrypted' => true, 'size' => $size, 'unencrypted_size' => $size ) ); \OC\Files\Filesystem::putFileInfo($relPath, array(
'encrypted' => true,
'size' => $size,
'unencrypted_size' => $size
));
} }
// Encrypt legacy encrypted files // Encrypt legacy encrypted files
@ -735,7 +741,7 @@ class Util {
$publicKeys = Keymanager::getPublicKeys($this->view, $uniqueUserIds); $publicKeys = Keymanager::getPublicKeys($this->view, $uniqueUserIds);
// Recrypt data, generate catfile // Recrypt data, generate catfile
$recrypted = Crypt::legacyKeyRecryptKeyfile( $legacyData, $legacyPassphrase, $publicKeys ); $recrypted = Crypt::legacyKeyRecryptKeyfile($legacyData, $legacyPassphrase, $publicKeys);
$rawPath = $legacyFile['path']; $rawPath = $legacyFile['path'];
$relPath = \OCA\Encryption\Helper::stripUserFilesPath($rawPath); $relPath = \OCA\Encryption\Helper::stripUserFilesPath($rawPath);
@ -831,7 +837,7 @@ class Util {
if (\OCP\DB::isError($result)) { if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else { } else {
if($result->numRows() > 0) { if ($result->numRows() > 0) {
$row = $result->fetchRow(); $row = $result->fetchRow();
$path = substr($row['path'], strlen('files')); $path = substr($row['path'], strlen('files'));
} }
@ -1102,7 +1108,7 @@ class Util {
if (\OCP\DB::isError($result)) { if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else { } else {
if($result->numRows() > 0) { if ($result->numRows() > 0) {
$row = $result->fetchRow(); $row = $result->fetchRow();
if (isset($row['migration_status'])) { if (isset($row['migration_status'])) {
$migrationStatus[] = $row['migration_status']; $migrationStatus[] = $row['migration_status'];
@ -1191,7 +1197,8 @@ class Util {
$result = array(); $result = array();
$content = $this->view->getDirectoryContent(\OC\Files\Filesystem::normalizePath($this->userFilesDir . '/' . $dir)); $content = $this->view->getDirectoryContent(\OC\Files\Filesystem::normalizePath(
$this->userFilesDir . '/' . $dir));
// handling for re shared folders // handling for re shared folders
$pathSplit = explode('/', $dir); $pathSplit = explode('/', $dir);
@ -1252,7 +1259,7 @@ class Util {
if (\OCP\DB::isError($result)) { if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else { } else {
if($result->numRows() > 0) { if ($result->numRows() > 0) {
$row = $result->fetchRow(); $row = $result->fetchRow();
} }
} }
@ -1278,7 +1285,7 @@ class Util {
if (\OCP\DB::isError($result)) { if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else { } else {
if($result->numRows() > 0) { if ($result->numRows() > 0) {
$row = $result->fetchRow(); $row = $result->fetchRow();
} }
} }
@ -1303,7 +1310,7 @@ class Util {
if (\OCP\DB::isError($result)) { if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else { } else {
if($result->numRows() > 0) { if ($result->numRows() > 0) {
$source = $result->fetchRow(); $source = $result->fetchRow();
} }
} }
@ -1324,7 +1331,7 @@ class Util {
if (\OCP\DB::isError($result)) { if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
} else { } else {
if($result->numRows() > 0) { if ($result->numRows() > 0) {
$item = $result->fetchRow(); $item = $result->fetchRow();
} }
} }
@ -1534,7 +1541,7 @@ class Util {
list($storage, $internalPath) = \OC\Files\Cache\Cache::getById($id); list($storage, $internalPath) = \OC\Files\Cache\Cache::getById($id);
$mount = \OC\Files\Filesystem::getMountByStorageId($storage); $mount = \OC\Files\Filesystem::getMountByStorageId($storage);
$mountPoint = $mount[0]->getMountPoint(); $mountPoint = $mount[0]->getMountPoint();
$path = \OC\Files\Filesystem::normalizePath($mountPoint.'/'.$internalPath); $path = \OC\Files\Filesystem::normalizePath($mountPoint . '/' . $internalPath);
// reformat the path to be relative e.g. /user/files/folder becomes /folder/ // reformat the path to be relative e.g. /user/files/folder becomes /folder/
$relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path); $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);

View File

@ -26,7 +26,7 @@ $recoveryEnabledForUser = $util->recoveryEnabledForUser();
$tmpl->assign('recoveryEnabled', $recoveryAdminEnabled); $tmpl->assign('recoveryEnabled', $recoveryAdminEnabled);
$tmpl->assign('recoveryEnabledForUser', $recoveryEnabledForUser); $tmpl->assign('recoveryEnabledForUser', $recoveryEnabledForUser);
$tmpl->assign("privateKeySet" , $privateKeySet); $tmpl->assign('privateKeySet', $privateKeySet);
return $tmpl->fetchPage(); return $tmpl->fetchPage();

View File

@ -1,54 +1,56 @@
<form id="encryption"> <form id="encryption">
<fieldset class="personalblock"> <fieldset class="personalblock">
<p> <p>
<strong><?php p($l->t( 'Encryption' )); ?></strong> <strong><?php p($l->t('Encryption')); ?></strong>
<br /> <br/>
</p> </p>
<p> <p>
<?php p($l->t( "Enable encryption passwords recovery key (allow sharing to recovery key):" )); ?> <?php p($l->t("Enable encryption passwords recovery key (allow sharing to recovery key):")); ?>
<br /> <br/>
<br /> <br/>
<input type="password" name="recoveryPassword" id="recoveryPassword" /> <input type="password" name="recoveryPassword" id="recoveryPassword"/>
<label for="recoveryPassword"><?php p($l->t( "Recovery account password" )); ?></label> <label for="recoveryPassword"><?php p($l->t("Recovery account password")); ?></label>
<br /> <br/>
<input <input
type='radio' type='radio'
name='adminEnableRecovery' name='adminEnableRecovery'
value='1' value='1'
<?php echo ( $_["recoveryEnabled"] == 1 ? 'checked="checked"' : 'disabled' ); ?> /> <?php echo($_["recoveryEnabled"] == 1 ? 'checked="checked"' : 'disabled'); ?> />
<?php p($l->t( "Enabled" )); ?> <?php p($l->t("Enabled")); ?>
<br /> <br/>
<input <input
type='radio' type='radio'
name='adminEnableRecovery' name='adminEnableRecovery'
value='0' value='0'
<?php echo ( $_["recoveryEnabled"] == 0 ? 'checked="checked"' : 'disabled' ); ?> /> <?php echo($_["recoveryEnabled"] == 0 ? 'checked="checked"' : 'disabled'); ?> />
<?php p($l->t( "Disabled" )); ?> <?php p($l->t("Disabled")); ?>
</p> </p>
<br /><br /> <br/><br/>
<p> <p>
<strong><?php p($l->t( "Change encryption passwords recovery key:" )); ?></strong> <strong><?php p($l->t("Change encryption passwords recovery key:")); ?></strong>
<br /><br /> <br/><br/>
<input <input
type="password" type="password"
name="changeRecoveryPassword" name="changeRecoveryPassword"
id="oldRecoveryPassword" id="oldRecoveryPassword"
<?php echo ( $_["recoveryEnabled"] == 0 ? 'disabled' : '' ); ?> /> <?php echo($_["recoveryEnabled"] == 0 ? 'disabled' : ''); ?> />
<label for="oldRecoveryPassword"><?php p($l->t( "Old Recovery account password" )); ?></label> <label for="oldRecoveryPassword"><?php p($l->t("Old Recovery account password")); ?></label>
<br /> <br/>
<input <input
type="password" type="password"
name="changeRecoveryPassword" name="changeRecoveryPassword"
id="newRecoveryPassword" id="newRecoveryPassword"
<?php echo ( $_["recoveryEnabled"] == 0 ? 'disabled' : '' ); ?> /> <?php echo($_["recoveryEnabled"] == 0 ? 'disabled' : ''); ?> />
<label for="newRecoveryPassword"><?php p($l->t( "New Recovery account password" )); ?></label> <label for="newRecoveryPassword"><?php p($l->t("New Recovery account password")); ?></label>
<br /> <br/>
<button <button
type="button" type="button"
name="submitChangeRecoveryKey" name="submitChangeRecoveryKey"
disabled><?php p($l->t( "Change Password" )); ?> disabled><?php p($l->t("Change Password")); ?>
</button> </button>
<span class="msg"></span> <span class="msg"></span>
</p> </p>

View File

@ -92,8 +92,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
// reset app files_trashbin // reset app files_trashbin
if ($this->stateFilesTrashbin) { if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin'); OC_App::enable('files_trashbin');
} } else {
else {
OC_App::disable('files_trashbin'); OC_App::disable('files_trashbin');
} }
} }

View File

@ -111,8 +111,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
// reset app files_trashbin // reset app files_trashbin
if ($this->stateFilesTrashbin) { if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin'); OC_App::enable('files_trashbin');
} } else {
else {
OC_App::disable('files_trashbin'); OC_App::disable('files_trashbin');
} }
} }