Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Autodetect legacy filekey instead of trusting the header for leg…
…acy header

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc authored and backportbot[bot] committed Jun 11, 2024
commit 92e053aab323d238b6f2e9ebdbb8e29d36838e1e
20 changes: 4 additions & 16 deletions apps/encryption/lib/Crypto/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class Encryption implements IEncryptionModule {
/** @var int Current version of the file */
private int $version = 0;

private bool $useLegacyFileKey = true;

/** @var array remember encryption signature version */
private static $rememberVersion = [];

Expand Down Expand Up @@ -138,7 +136,6 @@ public function begin($path, $user, $mode, array $header, array $accessList) {
$this->writeCache = '';
$this->useLegacyBase64Encoding = true;

$this->useLegacyFileKey = ($header['useLegacyFileKey'] ?? 'true') !== 'false';

if (isset($header['encoding'])) {
$this->useLegacyBase64Encoding = $header['encoding'] !== Crypt::BINARY_ENCODING_FORMAT;
Expand All @@ -152,19 +149,10 @@ public function begin($path, $user, $mode, array $header, array $accessList) {
}
}

if ($this->session->decryptAllModeActivated()) {
$shareKey = $this->keyManager->getShareKey($this->path, $this->session->getDecryptAllUid());
if ($this->useLegacyFileKey) {
$encryptedFileKey = $this->keyManager->getEncryptedFileKey($this->path);
$this->fileKey = $this->crypt->multiKeyDecryptLegacy($encryptedFileKey,
$shareKey,
$this->session->getDecryptAllKey());
} else {
$this->fileKey = $this->crypt->multiKeyDecrypt($shareKey, $this->session->getDecryptAllKey());
}
} else {
$this->fileKey = $this->keyManager->getFileKey($this->path, $this->user, $this->useLegacyFileKey);
}
/* If useLegacyFileKey is not specified in header, auto-detect, to be safe */
$useLegacyFileKey = (($header['useLegacyFileKey'] ?? '') == 'false' ? false : null);

$this->fileKey = $this->keyManager->getFileKey($this->path, $this->user, $useLegacyFileKey, $this->session->decryptAllModeActivated());

// always use the version from the original file, also part files
// need to have a correct version number if they get moved over to the
Expand Down
11 changes: 5 additions & 6 deletions apps/encryption/lib/KeyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,9 @@ public function getPrivateKey($userId) {
}

/**
* @param string $path
* @param $uid
* @param ?bool $useLegacyFileKey null means try both
* @return string
*/
public function getFileKey(string $path, ?string $uid, ?bool $useLegacyFileKey): string {
public function getFileKey(string $path, ?string $uid, ?bool $useLegacyFileKey, bool $useDecryptAll): string {
if ($uid === '') {
$uid = null;
}
Expand All @@ -385,8 +382,10 @@ public function getFileKey(string $path, ?string $uid, ?bool $useLegacyFileKey):
return '';
}
}

if ($this->util->isMasterKeyEnabled()) {
if ($useDecryptAll) {
$shareKey = $this->getShareKey($path, $this->session->getDecryptAllUid());
$privateKey = $this->session->getDecryptAllKey();
} elseif ($this->util->isMasterKeyEnabled()) {
$uid = $this->getMasterKeyId();
$shareKey = $this->getShareKey($path, $uid);
if ($publicAccess) {
Expand Down