Merge branch 'encryption_work_with_public_gallery' into encryption_enable_public_upload

This commit is contained in:
Bjoern Schiessle 2013-11-21 10:34:25 +01:00
commit 009bbef17e
12 changed files with 36 additions and 60 deletions

View File

@ -180,6 +180,7 @@ class Keymanager {
*/
public static function getFileKey(\OC_FilesystemView $view, $util, $filePath) {
list($owner, $filename) = $util->getUidAndFilename($filePath);
$filename = Helper::stripPartialFileExtension($filename);
$filePath_f = ltrim($filename, '/');

View File

@ -349,7 +349,10 @@ class Proxy extends \OC_FileProxy {
$fileInfo = false;
// get file info from database/cache if not .part file
if (!Helper::isPartialFilePath($path)) {
$proxyState = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$fileInfo = $view->getFileInfo($path);
\OC_FileProxy::$enabled = $proxyState;
}
// if file is encrypted return real file size

View File

@ -498,7 +498,8 @@ class Stream {
if (
$this->meta['mode'] !== 'r' &&
$this->meta['mode'] !== 'rb' &&
$this->size > 0
$this->size > 0 &&
$this->unencryptedSize > 0
) {
// only write keyfiles if it was a new file

View File

@ -455,22 +455,19 @@ class Util {
*/
public function isEncryptedPath($path) {
// Disable encryption proxy so data retrieved is in its
// original form
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$relPath = Helper::getPathToRealFile($path);
// we only need 24 byte from the last chunk
$data = '';
$handle = $this->view->fopen($path, 'r');
if (is_resource($handle) && !fseek($handle, -24, SEEK_END)) {
$data = fgets($handle);
if ($relPath === false) {
$relPath = Helper::stripUserFilesPath($path);
}
// re-enable proxy
\OC_FileProxy::$enabled = $proxyStatus;
$fileKey = Keymanager::getFileKey($this->view, $relPath);
return Crypt::isCatfileContent($data);
if ($fileKey === false) {
return false;
}
return true;
}

View File

@ -94,15 +94,17 @@ class SFTP extends \OC\Files\Storage\Common {
private function writeHostKeys($keys) {
try {
$keyPath = $this->hostKeysPath();
$fp = fopen($keyPath, 'w');
foreach ($keys as $host => $key) {
fwrite($fp, $host . '::' . $key . "\n");
if ($keyPath && file_exists($keyPath)) {
$fp = fopen($keyPath, 'w');
foreach ($keys as $host => $key) {
fwrite($fp, $host . '::' . $key . "\n");
}
fclose($fp);
return true;
}
fclose($fp);
return true;
} catch (\Exception $e) {
return false;
}
return false;
}
private function readHostKeys() {

View File

@ -268,7 +268,7 @@ class DAV extends \OC\Files\Storage\Common{
public function rename($path1, $path2) {
$this->init();
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
$path2=$this->createBaseUri().$this->cleanPath($path2);
try {
$this->client->request('MOVE', $path1, null, array('Destination'=>$path2));
return true;
@ -280,7 +280,7 @@ class DAV extends \OC\Files\Storage\Common{
public function copy($path1, $path2) {
$this->init();
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
$path2=$this->createBaseUri().$this->cleanPath($path2);
try {
$this->client->request('COPY', $path1, null, array('Destination'=>$path2));
return true;

View File

@ -78,6 +78,8 @@ class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin
* @throws Sabre_DAV_Exception_BadRequest
*/
public function sendFileIdHeader($filePath, Sabre_DAV_INode $node = null) {
// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
$node = $this->server->tree->getNodeForPath($filePath);
if ($node instanceof OC_Connector_Sabre_Node) {
$fileId = $node->getFileId();
if (!is_null($fileId)) {

View File

@ -142,7 +142,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
return false;
} else {
$directoryHandle = $this->opendir($directory);
if(is_resource($directoryHandle)) {
if (is_resource($directoryHandle)) {
while (($contents = readdir($directoryHandle)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
$path = $directory . '/' . $contents;
@ -165,27 +165,13 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
public function getMimeType($path) {
if (!$this->file_exists($path)) {
return false;
}
if ($this->is_dir($path)) {
return 'httpd/unix-directory';
}
$source = $this->fopen($path, 'r');
if (!$source) {
} elseif ($this->file_exists($path)) {
return \OC_Helper::getFileNameMimeType($path);
} else {
return false;
}
$head = fread($source, 8192); //8kb should suffice to determine a mimetype
if ($pos = strrpos($path, '.')) {
$extension = substr($path, $pos);
} else {
$extension = '';
}
$tmpFile = \OC_Helper::tmpFile($extension);
file_put_contents($tmpFile, $head);
$mime = \OC_Helper::getMimeType($tmpFile);
unlink($tmpFile);
return $mime;
}
public function hash($type, $path, $raw = false) {
@ -227,7 +213,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
private function addLocalFolder($path, $target) {
$dh = $this->opendir($path);
if(is_resource($dh)) {
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file !== '.' and $file !== '..') {
if ($this->is_dir($path . '/' . $file)) {
@ -298,7 +284,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
return $this->watcher;
}
public function getStorageCache(){
public function getStorageCache() {
if (!isset($this->storageCache)) {
$this->storageCache = new \OC\Files\Cache\Storage($this);
}

View File

@ -54,7 +54,7 @@ class CommonTest extends \OC\Files\Storage\Common{
return $this->storage->stat($path);
}
public function filetype($path) {
return $this->storage->filetype($path);
return @$this->storage->filetype($path);
}
public function isReadable($path) {
return $this->storage->isReadable($path);

View File

@ -203,14 +203,6 @@ if (\OC_Util::runningOnWindows()) {
return $return;
}
public function getMimeType($path) {
if ($this->isReadable($path)) {
return \OC_Helper::getMimeType($this->datadir . $path);
} else {
return false;
}
}
private function delTree($dir) {
$dirRelative = $dir;
$dir = $this->datadir . $dir;

View File

@ -210,14 +210,6 @@ class MappedLocal extends \OC\Files\Storage\Common{
return $return;
}
public function getMimeType($path) {
if($this->isReadable($path)) {
return \OC_Helper::getMimeType($this->buildPath($path));
}else{
return false;
}
}
private function delTree($dir, $isLogicPath=true) {
$dirRelative=$dir;
if ($isLogicPath) {

View File

@ -1,10 +1,10 @@
<?php
// We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel when updating major/minor version number.
$OC_Version=array(6, 00, 0, 7);
$OC_Version=array(6, 00, 0, 8);
// The human readable string
$OC_VersionString='6.0 beta 4';
$OC_VersionString='6.0 beta 5';
// The ownCloud edition
$OC_Edition='';