summaryrefslogtreecommitdiffstats
path: root/apps/encryption/lib/session.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/encryption/lib/session.php')
-rw-r--r--apps/encryption/lib/session.php60
1 files changed, 59 insertions, 1 deletions
diff --git a/apps/encryption/lib/session.php b/apps/encryption/lib/session.php
index c3759c3fc56..1d0c3711487 100644
--- a/apps/encryption/lib/session.php
+++ b/apps/encryption/lib/session.php
@@ -25,6 +25,7 @@
namespace OCA\Encryption;
+use OCA\Encryption\Exceptions\PrivateKeyMissingException;
use \OCP\ISession;
class Session {
@@ -106,6 +107,61 @@ class Session {
$this->session->set('privateKey', $key);
}
+ /**
+ * store data needed for the decrypt all operation in the session
+ *
+ * @param string $user
+ * @param string $key
+ */
+ public function prepareDecryptAll($user, $key) {
+ $this->session->set('decryptAll', true);
+ $this->session->set('decryptAllKey', $key);
+ $this->session->set('decryptAllUid', $user);
+ }
+
+ /**
+ * check if we are in decrypt all mode
+ *
+ * @return bool
+ */
+ public function decryptAllModeActivated() {
+ $decryptAll = $this->session->get('decryptAll');
+ return ($decryptAll === true);
+ }
+
+ /**
+ * get uid used for decrypt all operation
+ *
+ * @return string
+ * @throws \Exception
+ */
+ public function getDecryptAllUid() {
+ $uid = $this->session->get('decryptAllUid');
+ if (is_null($uid) && $this->decryptAllModeActivated()) {
+ throw new \Exception('No uid found while in decrypt all mode');
+ } elseif (is_null($uid)) {
+ throw new \Exception('Please activate decrypt all mode first');
+ }
+
+ return $uid;
+ }
+
+ /**
+ * get private key for decrypt all operation
+ *
+ * @return string
+ * @throws PrivateKeyMissingException
+ */
+ public function getDecryptAllKey() {
+ $privateKey = $this->session->get('decryptAllKey');
+ if (is_null($privateKey) && $this->decryptAllModeActivated()) {
+ throw new PrivateKeyMissingException('No private key found while in decrypt all mode');
+ } elseif (is_null($privateKey)) {
+ throw new PrivateKeyMissingException('Please activate decrypt all mode first');
+ }
+
+ return $privateKey;
+ }
/**
* remove keys from session
@@ -114,7 +170,9 @@ class Session {
$this->session->remove('publicSharePrivateKey');
$this->session->remove('privateKey');
$this->session->remove('encryptionInitialized');
-
+ $this->session->remove('decryptAll');
+ $this->session->remove('decryptAllKey');
+ $this->session->remove('decryptAllUid');
}
}