diff options
Diffstat (limited to 'apps/files_encryption/lib/keymanager.php')
-rwxr-xr-x | apps/files_encryption/lib/keymanager.php | 103 |
1 files changed, 43 insertions, 60 deletions
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 0d0380db6ec..95587797154 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -28,7 +28,7 @@ namespace OCA\Encryption; * @note Where a method requires a view object, it's root must be '/' */ class Keymanager { -
+ /** * @brief retrieve the ENCRYPTED private key from a user * @@ -46,8 +46,8 @@ class Keymanager { /** * @brief retrieve public key for a specified user - * @param \OC_FilesystemView $view
- * @param $userId
+ * @param \OC_FilesystemView $view + * @param $userId * @return string public key or false */ public static function getPublicKey( \OC_FilesystemView $view, $userId ) { @@ -58,8 +58,8 @@ class Keymanager { /** * @brief retrieve both keys from a user (private and public) - * @param \OC_FilesystemView $view
- * @param $userId
+ * @param \OC_FilesystemView $view + * @param $userId * @return array keys: privateKey, publicKey */ public static function getUserKeys( \OC_FilesystemView $view, $userId ) { @@ -148,11 +148,11 @@ class Keymanager { /** * @brief retrieve keyfile for an encrypted file - * @param \OC_FilesystemView $view
- * @param $userId
- * @param $filePath
- * @internal param \OCA\Encryption\file $string name
- * @return string file key or false
+ * @param \OC_FilesystemView $view + * @param $userId + * @param $filePath + * @internal param \OCA\Encryption\file $string name + * @return string file key or false * @note The keyfile returned is asymmetrically encrypted. Decryption * of the keyfile must be performed by client code */ @@ -177,12 +177,12 @@ class Keymanager { /** * @brief Delete a keyfile * - * @param OC_FilesystemView $view
- * @param string $userId username
- * @param string $path path of the file the key belongs to
- * @return bool Outcome of unlink operation
- * @note $path must be relative to data/user/files. e.g. mydoc.txt NOT
- * /data/admin/files/mydoc.txt
+ * @param OC_FilesystemView $view + * @param string $userId username + * @param string $path path of the file the key belongs to + * @return bool Outcome of unlink operation + * @note $path must be relative to data/user/files. e.g. mydoc.txt NOT + * /data/admin/files/mydoc.txt */ public static function deleteFileKey( \OC_FilesystemView $view, $userId, $path ) { @@ -220,12 +220,11 @@ class Keymanager { \OC_FileProxy::$enabled = false; - if ( !$view->file_exists( '' ) ) $view->mkdir( '' ); + if ( !$view->file_exists( '' ) ) + $view->mkdir( '' ); return $view->file_put_contents( $user . '.private.key', $key ); - - \OC_FileProxy::$enabled = true; - + } /** @@ -253,24 +252,24 @@ class Keymanager { \OC_FileProxy::$enabled = false; - if ( !$view->file_exists( '' ) ) $view->mkdir( '' ); + if ( !$view->file_exists( '' ) ) + $view->mkdir( '' ); return $view->file_put_contents( \OCP\User::getUser() . '.public.key', $key ); - - \OC_FileProxy::$enabled = true; + } /** - * @brief store file encryption key
- *
- * @param string $path relative path of the file, including filename
- * @param string $key
- * @param null $view
- * @param string $dbClassName
- * @return bool true/false
- * @note The keyfile is not encrypted here. Client code must
- * asymmetrically encrypt the keyfile before passing it to this method
+ * @brief store file encryption key + * + * @param string $path relative path of the file, including filename + * @param string $key + * @param null $view + * @param string $dbClassName + * @return bool true/false + * @note The keyfile is not encrypted here. Client code must + * asymmetrically encrypt the keyfile before passing it to this method */ public static function setShareKey( \OC_FilesystemView $view, $path, $userId, $shareKey ) { @@ -280,54 +279,38 @@ class Keymanager { return $view->file_put_contents( $basePath . '/' . $shareKeyPath . '.shareKey', $shareKey ); - }
-
- /**
- * @brief Make preparations to vars and filesystem for saving a keyfile
- */
- public static function keySetPreparation( \OC_FilesystemView $view, $path, $basePath, $userId ) {
+ } + + /** + * @brief Make preparations to vars and filesystem for saving a keyfile + */ + public static function keySetPreparation( \OC_FilesystemView $view, $path, $basePath, $userId ) { $targetPath = ltrim( $path, '/' ); $path_parts = pathinfo( $targetPath ); // If the file resides within a subdirectory, create it - if (
- isset( $path_parts['dirname'] )
- && ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] )
+ if ( + isset( $path_parts['dirname'] ) + && ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] ) ) { $view->mkdir( $basePath . '/' . $path_parts['dirname'] ); } - return $targetPath;
-
- } + return $targetPath; - /** - * @brief change password of private encryption key - * - * @param string $oldpasswd old password - * @param string $newpasswd new password - * @return bool true/false - */ - public static function changePasswd($oldpasswd, $newpasswd) { - - if ( \OCP\User::checkPassword(\OCP\User::getUser(), $newpasswd) ) { - return Crypt::changekeypasscode($oldpasswd, $newpasswd); - } - return false; - } - + /** * @brief Fetch the legacy encryption key from user files * @param string $login used to locate the legacy key * @param string $passphrase used to decrypt the legacy key * @return true / false * - * if the key is left out, the default handeler will be used + * if the key is left out, the default handler will be used */ public function getLegacyKey() { |