]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow the user to login but do not allow upload and show error message on the web
authorFlorin Peter <github@florin-peter.de>
Fri, 31 May 2013 13:57:18 +0000 (15:57 +0200)
committerFlorin Peter <github@florin-peter.de>
Fri, 31 May 2013 13:57:18 +0000 (15:57 +0200)
apps/files_encryption/appinfo/app.php
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/stream.php

index d9bb4d5e74e524b66efde8ddc974feb3148fb076..c9e3de569165f19a279b02b70aeae821c11beb7d 100644 (file)
@@ -28,9 +28,10 @@ if (OCP\User::isLoggedIn()) {
        $view = new OC_FilesystemView('/');
        $session = new \OCA\Encryption\Session($view);
 
+       $user = \OCP\USER::getUser();
        // check if user has a private key
        if (
-               !$session->getPrivateKey(\OCP\USER::getUser())
+               !$view->file_exists('/' . $user . '/files_encryption/' . $user . '.private.key')
                && OCA\Encryption\Crypt::mode() === 'server'
        ) {
 
index 639d57691540752994e1c72d9c464163aa38ac5e..c52d739eaa89bb1078607cdcf7b72436938d34e6 100644 (file)
@@ -62,13 +62,13 @@ class Hooks {
                if(is_resource($res)) {\r
                        $sslInfo = openssl_pkey_get_details($res);\r
                        if(!isset($sslInfo['key'])) {\r
-                               $privateKey = null;\r
+                               $privateKey = false;\r
                        }\r
                } else {\r
-                       $privateKey = null;\r
+                       $privateKey = false;\r
                }\r
 \r
-               if($privateKey === null) {\r
+               if($privateKey === false) {\r
                        \OCP\Util::writeLog('Encryption library', 'Private key for user "' . $params['uid'] . '" is not valid! Maybe the user password was changed from outside if so please change it back to gain access', \OCP\Util::ERROR);\r
                }\r
 \r
index 56322c100ba70af5c98edeb173a014eddbeb5f53..a5ebe8ef915d394bde6803cc550b04e4e24e8ebd 100644 (file)
@@ -236,7 +236,11 @@ class Stream {
                        // if there is no valid private key return false
                        if($privateKey === false) {
 
-                               \OCP\Util::writeLog('Encryption library', 'Private key for user "' . $this->userId . '" is not valid! Maybe the user password was changed from outside if so please change it back to gain access', \OCP\Util::ERROR);
+                               if(\OC_Util::isCallRegistered()) {
+                                       $l = \OC_L10N::get('core');
+                                       \OCP\JSON::error(array('data' => array('message' => $l->t('Private key is not valid! Maybe the user password was changed from outside if so please change it back to gain access'))));
+                                       throw new \Exception('Private key for user "' . $this->userId . '" is not valid! Maybe the user password was changed from outside if so please change it back to gain access');
+                               }
 
                                return false;
                        }
@@ -433,6 +437,22 @@ class Stream {
 
                $this->flush();
 
+               $view = new \OC_FilesystemView('/');
+               $session = new \OCA\Encryption\Session( $this->rootView );
+               $privateKey = $session->getPrivateKey($this->userId);
+
+               // if there is no valid private key return false
+               if($privateKey === false) {
+
+                       if(\OC_Util::isCallRegistered()) {
+                               $l = \OC_L10N::get('core');
+                               \OCP\JSON::error(array('data' => array('message' => $l->t('Private key is not valid! Maybe the user password was changed from outside if so please change it back to gain access'))));
+                               throw new \Exception('Private key for user "' . $this->userId . '" is not valid! Maybe the user password was changed from outside if so please change it back to gain access');
+                       }
+
+                       return false;
+               }
+
                if (
                        $this->meta['mode'] !== 'r'
                        and $this->meta['mode'] !== 'rb'
@@ -459,8 +479,6 @@ class Stream {
                        // Encrypt enc key for all sharing users
                        $this->encKeyfiles = Crypt::multiKeyEncrypt($this->plainKey, $publicKeys);
 
-                       $view = new \OC_FilesystemView('/');
-
                        // Save the new encrypted file key
                        Keymanager::setFileKey($this->rootView, $this->relPath, $this->userId, $this->encKeyfiles['data']);