diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 0bef3b749282cb263e06720a519b8d8ee9581240..ab50fba69774430016d7313b565d6aa3aea6bd52 100644 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -118,7 +118,7 @@ class Keymanager { \OC_FileProxy::$enabled = false; - $view = new \OC_FilesystemView( '/' . $userId . '/' . 'files_encryption' ); + $view = new \OC_FilesystemView( '/' . $userId . '/' . 'files_encryption/keyfiles' ); $path_parts = pathinfo($path); if (!$view->file_exists($path_parts['dirname'])) $view->mkdir($path_parts['dirname']); $result = $view->file_put_contents( '/' . $path . '.key', $key ); diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index b2eba051515828ad60966bbaf651cc1667f977b2..f04cf7c1076839af4b4d2b4f9017ebd7a1a457a2 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -12,7 +12,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ } } public function mkdir($path){ - return @mkdir($this->datadir.$path); + return @mkdir($this->datadir.$path, 0755, true); } public function rmdir($path){ return @rmdir($this->datadir.$path); diff --git a/lib/ocs.php b/lib/ocs.php index 5349053ad28592fd21aa6ead07eb214f289493e4..e0c240d3306f398d392ac17f547f96e06c089519 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -183,11 +183,24 @@ class OC_OCS { }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'privatekey')){ $user=$ex[$paracount-3]; OC_OCS::privateKeyGet($format,$user); + + //keysetprivate }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'privatekey')){ $user=$ex[$paracount-3]; $key = self::readData('post', 'key', 'string'); OC_OCS::privateKeySet($format,$user, $key); - + + // keygetfiles + }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'filekey')){ + $user=$ex[$paracount-3]; + OC_OCS::fileKeyGet($format,$user); + + //keysetfiles + }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'filekey')){ + $user=$ex[$paracount-3]; + $key = self::readData('post', 'key', 'string'); + $file = self::readData('post', 'file', 'string'); + OC_OCS::fileKeySet($format,$user, $file, $key); // add more calls here // please document all the call in the draft spec @@ -766,7 +779,7 @@ class OC_OCS { $login=OC_OCS::checkpassword(); if(OC_Group::inGroup($login, 'admin') or ($login==$user)) { if(OC_User::userExists($user)){ - //TODO: GET file key + //TODO: GET file key, check needed if it is a shared file or not $xml=array(); $xml['key']="this is the key for $file"; $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', '', 1, 0, 0); @@ -787,18 +800,25 @@ class OC_OCS { * @param string $key * @return string xml/json */ - private static function fileKeySet($format, $user, $file, $key) { + private static function fileKeySet($format, $user, $file, $key) { $login=OC_OCS::checkpassword(); - if($login == $user) { - if(OC_User::userExists($user)){ - //TODO: SET file key - echo self::generateXml('', 'ok', 100, 'File key uploaded'); - }else{ - echo self::generateXml('', 'fail', 300, 'User does not exist'); + if(($login==$user)) { + if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode($user) === 'client') { + if (($key = OCA_Encryption\Keymanager::setFileKey($user, $file, $key))) { + // TODO: emit hook to move file from tmp location to the right place + echo self::generateXml('', 'ok', 100, ''); + return true; + } else { + echo self::generateXml('', 'fail', 404, 'could not write key file'); + } + } else { + echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled for user ' . $user); } }else{ echo self::generateXml('', 'fail', 300, 'You don“t have permission to access this ressource.'); - } - } + } + //TODO: emit signal to remove file from tmp location + return false; + } }