set default dependencies in keymanager.php
fix calls in ocs.php
This commit is contained in:
parent
5bb3ea9740
commit
d4974b6d4a
2 changed files with 15 additions and 16 deletions
|
@ -27,10 +27,6 @@ namespace OCA_Encryption;
|
|||
*/
|
||||
class Keymanager {
|
||||
|
||||
private static $defaultProperties = array('dbClassName' => \OC_DB,
|
||||
'fileProxyClassName' => \OC_FileProxy,
|
||||
);
|
||||
|
||||
# TODO: make all dependencies (including static classes) explicit, such as ocfsview objects, by adding them as method arguments (dependency injection)
|
||||
|
||||
private static function mergeProperties($properties) {
|
||||
|
@ -167,8 +163,7 @@ class Keymanager {
|
|||
* @param string $key
|
||||
* @return bool true/false
|
||||
*/
|
||||
public static function setFileKey( $path, $key, $view, $dbClassName, $fileProxyClassName ) {
|
||||
|
||||
public static function setFileKey( $path, $key, $view = Null, $dbClassName = '\OC_DB', $fileProxyClassName = '\OC_FileProxy') {
|
||||
$fileProxyClassName::$enabled = false;
|
||||
|
||||
$targetpath = ltrim( $path, '/' );
|
||||
|
@ -194,6 +189,10 @@ class Keymanager {
|
|||
}
|
||||
|
||||
$path_parts = pathinfo( $targetpath );
|
||||
|
||||
if (!$view) {
|
||||
$view = new \OC_FilesystemView( '/' . $user . '/files_encryption/keyfiles' );
|
||||
}
|
||||
|
||||
if ( !$view->file_exists( $path_parts['dirname'] ) ) $view->mkdir( $path_parts['dirname'] );
|
||||
|
||||
|
|
20
lib/ocs.php
20
lib/ocs.php
|
@ -693,14 +693,14 @@ class OC_OCS {
|
|||
*/
|
||||
private static function publicKeySet($format, $key) {
|
||||
$login=OC_OCS::checkpassword();
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode($user) === 'client') {
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode() === 'client') {
|
||||
if (OCA_Encryption\Keymanager::setPublicKey($key)) {
|
||||
echo self::generateXml('', 'ok', 100, '');
|
||||
} else {
|
||||
echo self::generateXml('', 'fail', 404, 'could not add your public key to the key storage');
|
||||
}
|
||||
} else {
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled for user ' . $user);
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -711,7 +711,7 @@ class OC_OCS {
|
|||
*/
|
||||
private static function privateKeyGet($format) {
|
||||
$login=OC_OCS::checkpassword();
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode($user) === 'client') {
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode() === 'client') {
|
||||
if (($key = OCA_Encryption\Keymanager::getPrivateKey())) {
|
||||
$xml=array();
|
||||
$xml['key']=$key;
|
||||
|
@ -721,7 +721,7 @@ class OC_OCS {
|
|||
echo self::generateXml('', 'fail', 404, 'private key does not exist');
|
||||
}
|
||||
} else {
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled for user ' . $user);
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -733,14 +733,14 @@ class OC_OCS {
|
|||
*/
|
||||
private static function privateKeySet($format, $key) {
|
||||
$login=OC_OCS::checkpassword();
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode($user) === 'client') {
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode() === 'client') {
|
||||
if (($key = OCA_Encryption\Keymanager::setPrivateKey($key))) {
|
||||
echo self::generateXml('', 'ok', 100, '');
|
||||
} else {
|
||||
echo self::generateXml('', 'fail', 404, 'could not add your private key to the key storage');
|
||||
}
|
||||
} else {
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled for user ' . $user);
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -752,7 +752,7 @@ class OC_OCS {
|
|||
*/
|
||||
private static function fileKeyGet($format, $file) {
|
||||
$login=OC_OCS::checkpassword();
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode($user) === 'client') {
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode() === 'client') {
|
||||
if (($key = OCA_Encryption\Keymanager::getFileKey($file))) {
|
||||
$xml=array();
|
||||
$xml['key']=$key;
|
||||
|
@ -762,7 +762,7 @@ class OC_OCS {
|
|||
echo self::generateXml('', 'fail', 404, 'file key does not exist');
|
||||
}
|
||||
} else {
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled for user ' . $user);
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -775,14 +775,14 @@ class OC_OCS {
|
|||
*/
|
||||
private static function fileKeySet($format, $file, $key) {
|
||||
$login=OC_OCS::checkpassword();
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode($user) === 'client') {
|
||||
if(OC_App::isEnabled('files_encryption') && OCA_Encryption\Crypt::mode() === 'client') {
|
||||
if (($key = OCA_Encryption\Keymanager::setFileKey($file, $key))) {
|
||||
echo self::generateXml('', 'ok', 100, '');
|
||||
} 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);
|
||||
echo self::generateXml('', 'fail', 300, 'Client side encryption not enabled');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue