Ejemplo n.º 1
0
 /**
  * Encrypt keyfile to multiple users
  * @param Session $session
  * @param array $users list of users which should be able to access the file
  * @param string $filePath path of the file to be shared
  * @return bool
  */
 public function setSharedFileKeyfiles(Session $session, array $users, $filePath)
 {
     // Make sure users are capable of sharing
     $filteredUids = $this->filterShareReadyUsers($users);
     // If we're attempting to share to unready users
     if (!empty($filteredUids['unready'])) {
         \OCP\Util::writeLog('Encryption library', 'Sharing to these user(s) failed as they are unready for encryption:"' . print_r($filteredUids['unready'], 1), \OCP\Util::WARN);
         return false;
     }
     // Get public keys for each user, ready for generating sharekeys
     $userPubKeys = Keymanager::getPublicKeys($this->view, $filteredUids['ready']);
     // Note proxy status then disable it
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // Get the current users's private key for decrypting existing keyfile
     $privateKey = $session->getPrivateKey();
     try {
         // Decrypt keyfile
         $plainKeyfile = $this->decryptKeyfile($filePath, $privateKey);
         // Re-enc keyfile to (additional) sharekeys
         $multiEncKey = Crypt::multiKeyEncrypt($plainKeyfile, $userPubKeys);
     } catch (Exceptions\EncryptionException $e) {
         $msg = 'set shareFileKeyFailed (code: ' . $e->getCode() . '): ' . $e->getMessage();
         \OCP\Util::writeLog('files_encryption', $msg, \OCP\Util::FATAL);
         return false;
     } catch (\Exception $e) {
         $msg = 'set shareFileKeyFailed (unknown error): ' . $e->getMessage();
         \OCP\Util::writeLog('files_encryption', $msg, \OCP\Util::FATAL);
         return false;
     }
     // Save the recrypted key to it's owner's keyfiles directory
     // Save new sharekeys to all necessary user directory
     if (!Keymanager::setFileKey($this->view, $this, $filePath, $multiEncKey['data']) || !Keymanager::setShareKeys($this->view, $this, $filePath, $multiEncKey['keys'])) {
         \OCP\Util::writeLog('Encryption library', 'Keyfiles could not be saved for users sharing ' . $filePath, \OCP\Util::ERROR);
         return false;
     }
     // Return proxy to original status
     \OC_FileProxy::$enabled = $proxyStatus;
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @medium
  */
 function testSetFileKey()
 {
     $key = $this->randomKey;
     $file = 'unittest-' . $this->getUniqueID() . '.txt';
     $util = new Encryption\Util($this->view, $this->userId);
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $this->view->file_put_contents($this->userId . '/files/' . $file, $this->dataShort);
     Encryption\Keymanager::setFileKey($this->view, $util, $file, $key);
     $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keyfiles/' . $file . '.key'));
     // cleanup
     $this->view->unlink('/' . $this->userId . '/files/' . $file);
     // change encryption proxy to previous state
     \OC_FileProxy::$enabled = $proxyStatus;
 }
Ejemplo n.º 3
0
 function testSetFileKey()
 {
     # NOTE: This cannot be tested until we are able to break out
     # of the FileSystemView data directory root
     $key = Encryption\Crypt::symmetricEncryptFileContentKeyfile($this->randomKey, 'hat');
     $file = 'unittest-' . time() . '.txt';
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $this->view->file_put_contents($this->userId . '/files/' . $file, $key['encrypted']);
     // Re-enable proxy - our work is done
     \OC_FileProxy::$enabled = $proxyStatus;
     //$view = new \OC_FilesystemView( '/' . $this->userId . '/files_encryption/keyfiles' );
     Encryption\Keymanager::setFileKey($this->view, $file, $this->userId, $key['key']);
     // enable encryption proxy
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = true;
     // cleanup
     $this->view->unlink('/' . $this->userId . '/files/' . $file);
     // change encryption proxy to previous state
     \OC_FileProxy::$enabled = $proxyStatus;
 }