Exemple #1
0
 /**
  * Check if a file requires encryption
  * @param string $path
  * @param string $mode type of access
  * @return bool
  *
  * Tests if server side encryption is enabled, and if we should call the
  * crypt stream wrapper for the given file
  */
 private function shouldEncrypt($path, $mode = 'w')
 {
     $userId = Helper::getUser($path);
     $session = new Session(new \OC\Files\View());
     // don't call the crypt stream wrapper, if...
     if ($session->getInitialized() !== Session::INIT_SUCCESSFUL || Crypt::mode() !== 'server' || $this->isExcludedPath($path, $userId) || substr($path, 0, 8) === 'crypt://') {
         return false;
     }
     $view = new \OC\Files\View('');
     $util = new Util($view, $userId);
     // for write operation we always encrypt the files, for read operations
     // we check if the existing file is encrypted or not decide if it needs to
     // decrypt it.
     if ($mode !== 'r' && $mode !== 'rb' || $util->isEncryptedPath($path)) {
         return true;
     }
     return false;
 }
Exemple #2
0
 /**
  * redirect to a error page
  * @param Session $session
  * @param int|null $errorCode
  * @throws \Exception
  */
 public static function redirectToErrorPage(Session $session, $errorCode = null)
 {
     if ($errorCode === null) {
         $init = $session->getInitialized();
         switch ($init) {
             case \OCA\Encryption\Session::INIT_EXECUTED:
                 $errorCode = \OCA\Encryption\Crypt::ENCRYPTION_PRIVATE_KEY_NOT_VALID_ERROR;
                 break;
             case \OCA\Encryption\Session::NOT_INITIALIZED:
                 $errorCode = \OCA\Encryption\Crypt::ENCRYPTION_NOT_INITIALIZED_ERROR;
                 break;
             default:
                 $errorCode = \OCA\Encryption\Crypt::ENCRYPTION_UNKNOWN_ERROR;
         }
     }
     $location = \OC_Helper::linkToAbsolute('apps/files_encryption/files', 'error.php');
     $post = 0;
     if (count($_POST) > 0) {
         $post = 1;
     }
     if (defined('PHPUNIT_RUN') and PHPUNIT_RUN) {
         throw new \Exception("Encryption error: {$errorCode}");
     }
     header('Location: ' . $location . '?p=' . $post . '&errorCode=' . $errorCode);
     exit;
 }