Merge pull request #5629 from nextcloud/add-recovery-key-on-public-upload

Add recovery key on public upload
This commit is contained in:
Björn Schießle 2017-07-20 14:07:57 +02:00 committed by GitHub
commit c0e9b374f1
1 changed files with 21 additions and 2 deletions

View File

@ -60,6 +60,9 @@ class Encryption implements IEncryptionModule {
/** @var string */ /** @var string */
private $user; private $user;
/** @var array */
private $owner;
/** @var string */ /** @var string */
private $fileKey; private $fileKey;
@ -136,6 +139,7 @@ class Encryption implements IEncryptionModule {
$this->decryptAll = $decryptAll; $this->decryptAll = $decryptAll;
$this->logger = $logger; $this->logger = $logger;
$this->l = $il10n; $this->l = $il10n;
$this->owner = [];
$this->useMasterPassword = $util->isMasterKeyEnabled(); $this->useMasterPassword = $util->isMasterKeyEnabled();
} }
@ -280,13 +284,15 @@ class Encryption implements IEncryptionModule {
} }
} }
$publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->user); $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->getOwner($path));
$encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys); $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys);
$this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles); $this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles);
} }
return $result; return $result;
} }
/** /**
* encrypt data * encrypt data
* *
@ -407,7 +413,7 @@ class Encryption implements IEncryptionModule {
} }
} }
$publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $uid); $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->getOwner($path));
$encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys); $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys);
@ -556,6 +562,19 @@ class Encryption implements IEncryptionModule {
return $path; return $path;
} }
/**
* get owner of a file
*
* @param string $path
* @return string
*/
protected function getOwner($path) {
if (!isset($this->owner[$path])) {
$this->owner[$path] = $this->util->getOwner($path);
}
return $this->owner[$path];
}
/** /**
* Check if the module is ready to be used by that specific user. * Check if the module is ready to be used by that specific user.
* In case a module is not ready - because e.g. key pairs have not been generated * In case a module is not ready - because e.g. key pairs have not been generated