Skip to content

Commit

Permalink
Merge pull request #5629 from nextcloud/add-recovery-key-on-public-up…
Browse files Browse the repository at this point in the history
…load

Add recovery key on public upload
  • Loading branch information
schiessle authored Jul 20, 2017
2 parents 4826fd7 + 473824f commit c0e9b37
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions apps/encryption/lib/Crypto/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Encryption implements IEncryptionModule {
/** @var string */
private $user;

/** @var array */
private $owner;

/** @var string */
private $fileKey;

Expand Down Expand Up @@ -136,6 +139,7 @@ public function __construct(Crypt $crypt,
$this->decryptAll = $decryptAll;
$this->logger = $logger;
$this->l = $il10n;
$this->owner = [];
$this->useMasterPassword = $util->isMasterKeyEnabled();
}

Expand Down Expand Up @@ -280,13 +284,15 @@ public function end($path, $position = 0) {
}
}

$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);
$this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles);
}
return $result;
}



/**
* encrypt data
*
Expand Down Expand Up @@ -407,7 +413,7 @@ public function update($path, $uid, array $accessList) {
}
}

$publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $uid);
$publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->getOwner($path));

$encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys);

Expand Down Expand Up @@ -556,6 +562,19 @@ protected function stripPartFileExtension($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.
* In case a module is not ready - because e.g. key pairs have not been generated
Expand Down

0 comments on commit c0e9b37

Please sign in to comment.