$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'
) {
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
// 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;
}
$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'
// 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']);