]> source.dussan.org Git - nextcloud-server.git/commitdiff
make sharing and unsharing work
authorBjoern Schiessle <schiessle@owncloud.com>
Fri, 27 Mar 2015 10:43:02 +0000 (11:43 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:27 +0000 (13:30 +0200)
apps/encryption/lib/crypto/encryption.php
apps/encryption/lib/keymanager.php

index f036ea42cb93ecc300d0d3aacd281a3262589cc6..beb922afe7256face88e5adc8a2f32922a01af39 100644 (file)
@@ -122,11 +122,7 @@ class Encryption implements IEncryptionModule {
                        }
 
                        $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys);
-
-                       $this->keymanager->setFileKey($path, $encryptedKeyfiles['data']);
-                       foreach ($encryptedKeyfiles['keys'] as $uid => $keyFile) {
-                               $this->keymanager->setShareKey($path, $uid, $keyFile);
-                       }
+                       $this->keymanager->setAllFileKeys($path, $encryptedKeyfiles);
                }
                return $result;
        }
@@ -218,11 +214,22 @@ class Encryption implements IEncryptionModule {
         * update encrypted file, e.g. give additional users access to the file
         *
         * @param string $path path to the file which should be updated
+        * @param string $uid of the user who performs the operation
         * @param array $accessList who has access to the file contains the key 'users' and 'public'
         * @return boolean
         */
-       public function update($path, $accessList) {
-               // TODO: Implement update() method.
+       public function update($path, $uid, $accessList) {
+               $fileKey = $this->keymanager->getFileKey($path, $uid);
+               foreach ($accessList['users'] as $user) {
+                       $publicKeys[$user] = $this->keymanager->getPublicKey($user);
+               }
+               $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys);
+
+               $this->keymanager->deleteAllFileKeys($path);
+
+               $this->keymanager->setAllFileKeys($path, $encryptedFileKey);
+
+               return true;
        }
 
        /**
index e03852c1f6bbdaf30cccfc18f673a18c51f034ca..fe7fe08d277fc3a52cb6929b254908c55e325d92 100644 (file)
@@ -183,6 +183,19 @@ class KeyManager {
                return $this->keyStorage->setFileKey($path, $this->fileKeyId, $key);
        }
 
+       /**
+        * set all file keys (the file key and the corresponding share keys)
+        *
+        * @param string $path
+        * @param array $keys
+        */
+       public function setAllFileKeys($path, $keys) {
+               $this->setFileKey($path, $keys['data']);
+               foreach ($keys['keys'] as $uid => $keyFile) {
+                       $this->setShareKey($path, $uid, $keyFile);
+               }
+       }
+
        /**
         * write share key to the key storage
         *
@@ -405,6 +418,10 @@ class KeyManager {
                return $this->keyStorage->deleteUserKey($uid, $this->privateKeyId);
        }
 
+       public function deleteAllFileKeys($path) {
+               return $this->keyStorage->deleteAllFileKeys($path);
+       }
+
        /**
         * @param array $userIds
         * @return array