]> source.dussan.org Git - nextcloud-server.git/commitdiff
add public link share key to file if it was shared as public link
authorBjoern Schiessle <schiessle@owncloud.com>
Fri, 27 Mar 2015 17:10:32 +0000 (18:10 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:28 +0000 (13:30 +0200)
apps/encryption/lib/crypto/encryption.php
apps/encryption/lib/keymanager.php
apps/encryption/lib/users/setup.php
apps/encryption/settings/settings-personal.php

index beb922afe7256face88e5adc8a2f32922a01af39..da805892eafd383a83e91d9e38c0bc18a02bb12b 100644 (file)
@@ -220,9 +220,15 @@ class Encryption implements IEncryptionModule {
         */
        public function update($path, $uid, $accessList) {
                $fileKey = $this->keymanager->getFileKey($path, $uid);
+               $publicKeys = array();
                foreach ($accessList['users'] as $user) {
                        $publicKeys[$user] = $this->keymanager->getPublicKey($user);
                }
+
+               if (!empty($accessList['public'])) {
+                       $publicKeys[$this->keymanager->getPublicShareKeyId()] = $this->keymanager->getPublicShareKey();
+               }
+
                $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys);
 
                $this->keymanager->deleteAllFileKeys($path);
index fe7fe08d277fc3a52cb6929b254908c55e325d92..44a46458692cf004bf1c837e796c8b60d9350809 100644 (file)
@@ -95,7 +95,13 @@ class KeyManager {
         * @param \OCP\ISession $session
         * @param ILogger $log
         */
-       public function __construct(IStorage $keyStorage, Crypt $crypt, IConfig $config, IUserSession $userSession, ISession $session, ILogger $log) {
+       public function __construct(
+               IStorage $keyStorage,
+               Crypt $crypt,
+               IConfig $config,
+               IUserSession $userSession,
+               ISession $session,
+               ILogger $log) {
 
                self::$session = $session;
                $this->keyStorage = $keyStorage;
@@ -105,6 +111,28 @@ class KeyManager {
                        'recoveryKeyId');
                $this->publicShareKeyId = $this->config->getAppValue('encryption',
                        'publicShareKeyId');
+
+               if (empty($this->publicShareKeyId)) {
+                       $this->publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8);
+                       $this->config->setAppValue('encryption', 'publicShareKeyId', $this->publicShareKeyId);
+
+                       $keypair = $this->crypt->createKeyPair();
+
+                       // Save public key
+                       $this->keyStorage->setSystemUserKey(
+                               $this->publicShareKeyId . '.publicKey',
+                               $keypair['publicKey']);
+
+                       // Encrypt private key empty passphrase
+                       $encryptedKey = $this->crypt->symmetricEncryptFileContent($keypair['privateKey'], '');
+                       if ($encryptedKey) {
+                               $this->keyStorage->setSystemUserKey($this->publicShareKeyId . '.privateKey', $encryptedKey);
+                       } else {
+                               $this->log->error('Could not create public share keys');
+                       }
+
+               }
+
                $this->keyId = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false;
                $this->log = $log;
        }
@@ -259,7 +287,7 @@ class KeyManager {
                $encryptedFileKey = $this->keyStorage->getFileKey($path,
                        $this->fileKeyId);
                $shareKey = $this->getShareKey($path, $uid);
-               $privateKey = $this->session->get('privateKey');
+               $privateKey = self::$session->get('privateKey');
 
                if ($encryptedFileKey && $shareKey && $privateKey) {
                        $key = $this->crypt->multiKeyDecrypt($encryptedFileKey,
@@ -384,6 +412,19 @@ class KeyManager {
                throw new PublicKeyMissingException();
        }
 
+       public function getPublicShareKeyId() {
+               return $this->publicShareKeyId;
+       }
+
+       /**
+        * get public key  for public link shares
+        *
+        * @return string
+        */
+       public function getPublicShareKey() {
+               return $this->keyStorage->getSystemUserKey($this->publicShareKeyId . '.publicKey');
+       }
+
        /**
         * @param $purpose
         * @param bool $timestamp
index 662a4b4b6afe78e103cadaaf9b32564432550711..bf415c81888c2d5dde3b74b02df4bec07b59f73b 100644 (file)
@@ -36,7 +36,7 @@ class Setup extends \OCA\Encryption\Setup {
                parent::__construct($logger, $userSession);
                $this->crypt = $crypt;
                $this->keyManager = $keyManager;
-       }
+       }
 
        /**
         * @param $uid userid
index dc1ef167b113245b10fb451b76528359b2e6aa78..d1da649e374756e8b0b37730f93db174079ed430 100644 (file)
 \OC_Util::addStyle('encryption', 'settings-personal');
 
 $tmpl = new OCP\Template('encryption', 'settings-personal');
+$crypt = new \OCA\Encryption\Crypto\Crypt(
+       \OC::$server->getLogger(),
+       \OC::$server->getUserSession(),
+       \OC::$server->getConfig());
+$keymanager = new \OCA\Encryption\KeyManager(
+       \OC::$server->getEncryptionKeyStorage(\OCA\Encryption\Crypto\Encryption::ID),
+       $crypt,
+       \OC::$server->getConfig(),
+       \OC::$server->getUserSession(),
+       \OC::$server->getSession(),
+       \OC::$server->getLogger());
 
 $user = \OCP\User::getUser();
+
 $view = new \OC\Files\View('/');
-$util = new \OCA\Files_Encryption\Util($view, $user);
+
+$util = new \OCA\Encryption\Util(
+       new \OC\Files\View(),
+       new \OC\Files\Filesystem(),
+       $crypt,
+       $keymanager,
+       \OC::$server->getLogger(),
+       \OC::$server->getUserSession(),
+       \OC::$server->getConfig());
+
 $session = new \OCA\Files_Encryption\Session($view);
+$session = \OC::$server->getSession();
 
-$privateKeySet = $session->getPrivateKey() !== false;
+$privateKeySet = $session->get('privateKey') !== false;
 // did we tried to initialize the keys for this session?
 $initialized = $session->getInitialized();