Skip to content

Commit 61e0a9c

Browse files
committed
Make legacy cipher opt in
* Systems that upgrade have this enabled by default * New systems disable it * We'll have to add some wargning in the setup checks if this is enabled Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 4ff492a commit 61e0a9c

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed

apps/encryption/lib/Crypto/Crypt.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
use OC\Encryption\Exceptions\DecryptionFailedException;
3434
use OC\Encryption\Exceptions\EncryptionFailedException;
35+
use OC\ServerNotAvailableException;
3536
use OCA\Encryption\Exceptions\MultiKeyDecryptException;
3637
use OCA\Encryption\Exceptions\MultiKeyEncryptException;
3738
use OCP\Encryption\Exceptions\GenericEncryptionException;
@@ -89,6 +90,9 @@ class Crypt {
8990
'AES-128-CFB' => 16,
9091
];
9192

93+
/** @var bool */
94+
private $supportLegacy;
95+
9296
/**
9397
* @param ILogger $logger
9498
* @param IUserSession $userSession
@@ -101,6 +105,8 @@ public function __construct(ILogger $logger, IUserSession $userSession, IConfig
101105
$this->config = $config;
102106
$this->l = $l;
103107
$this->supportedKeyFormats = ['hash', 'password'];
108+
109+
$this->supportLegacy = $this->config->getSystemValueBool('encryption.legacy_format_support', false);
104110
}
105111

106112
/**
@@ -299,6 +305,10 @@ protected function getKeySize($cipher) {
299305
* @return string
300306
*/
301307
public function getLegacyCipher() {
308+
if (!$this->supportLegacy) {
309+
throw new ServerNotAvailableException('Legacy cipher is no longer supported!');
310+
}
311+
302312
return self::LEGACY_CIPHER;
303313
}
304314

@@ -391,7 +401,7 @@ public function decryptPrivateKey($privateKey, $password = '', $uid = '') {
391401
if (isset($header['cipher'])) {
392402
$cipher = $header['cipher'];
393403
} else {
394-
$cipher = self::LEGACY_CIPHER;
404+
$cipher = $this->getLegacyCipher();
395405
}
396406

397407
if (isset($header['keyFormat'])) {
@@ -570,6 +580,11 @@ private function hasSignature($catFile, $cipher) {
570580
$meta = substr($catFile, -93);
571581
$signaturePosition = strpos($meta, '00sig00');
572582

583+
// If we no longer support the legacy format then everything needs a signature
584+
if (!$skipSignatureCheck && !$this->supportLegacy && $signaturePosition === false) {
585+
throw new GenericEncryptionException('Missing Signature', $this->l->t('Missing Signature'));
586+
}
587+
573588
// enforce signature for the new 'CTR' ciphers
574589
if (!$skipSignatureCheck && $signaturePosition === false && stripos($cipher, 'ctr') !== false) {
575590
throw new GenericEncryptionException('Missing Signature', $this->l->t('Missing Signature'));

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@
12451245
'OC\\Repair\\NC16\\CleanupCardDAVPhotoCache' => $baseDir . '/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php',
12461246
'OC\\Repair\\NC16\\ClearCollectionsAccessCache' => $baseDir . '/lib/private/Repair/NC16/ClearCollectionsAccessCache.php',
12471247
'OC\\Repair\\NC18\\ResetGeneratedAvatarFlag' => $baseDir . '/lib/private/Repair/NC18/ResetGeneratedAvatarFlag.php',
1248+
'OC\\Repair\\NC20\\EncryptionLegacyCipher' => $baseDir . '/lib/private/Repair/NC20/EncryptionLegacyCipher.php',
12481249
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
12491250
'OC\\Repair\\Owncloud\\DropAccountTermsTable' => $baseDir . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php',
12501251
'OC\\Repair\\Owncloud\\SaveAccountsTableData' => $baseDir . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
12741274
'OC\\Repair\\NC16\\CleanupCardDAVPhotoCache' => __DIR__ . '/../../..' . '/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php',
12751275
'OC\\Repair\\NC16\\ClearCollectionsAccessCache' => __DIR__ . '/../../..' . '/lib/private/Repair/NC16/ClearCollectionsAccessCache.php',
12761276
'OC\\Repair\\NC18\\ResetGeneratedAvatarFlag' => __DIR__ . '/../../..' . '/lib/private/Repair/NC18/ResetGeneratedAvatarFlag.php',
1277+
'OC\\Repair\\NC20\\EncryptionLegacyCipher' => __DIR__ . '/../../..' . '/lib/private/Repair/NC20/EncryptionLegacyCipher.php',
12771278
'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php',
12781279
'OC\\Repair\\Owncloud\\DropAccountTermsTable' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php',
12791280
'OC\\Repair\\Owncloud\\SaveAccountsTableData' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php',

lib/private/Repair.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
use OC\Repair\NC16\CleanupCardDAVPhotoCache;
4949
use OC\Repair\NC16\ClearCollectionsAccessCache;
5050
use OC\Repair\NC18\ResetGeneratedAvatarFlag;
51+
use OC\Repair\NC20\EncryptionLegacyCipher;
5152
use OC\Repair\OldGroupMembershipShares;
5253
use OC\Repair\Owncloud\DropAccountTermsTable;
5354
use OC\Repair\Owncloud\SaveAccountsTableData;
@@ -156,6 +157,7 @@ public static function getRepairSteps() {
156157
new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)),
157158
new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)),
158159
\OC::$server->query(ResetGeneratedAvatarFlag::class),
160+
\OC::$server->query(EncryptionLegacyCipher::class),
159161
];
160162
}
161163

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
6+
*
7+
* @author Roeland Jago Douma <roeland@famdouma.nl>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OC\Repair\NC20;
27+
28+
use OCP\Encryption\IManager;
29+
use OCP\IConfig;
30+
use OCP\Migration\IOutput;
31+
use OCP\Migration\IRepairStep;
32+
33+
class EncryptionLegacyCipher implements IRepairStep {
34+
35+
/** @var IConfig */
36+
private $config;
37+
/** @var IManager */
38+
private $manager;
39+
40+
public function __construct(IConfig $config,
41+
IManager $manager) {
42+
$this->config = $config;
43+
$this->manager = $manager;
44+
}
45+
46+
public function getName(): string {
47+
return 'Keep legacy encryption enabled';
48+
}
49+
50+
private function shouldRun(): bool {
51+
$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');
52+
return version_compare($versionFromBeforeUpdate, '20.0.0.0', '<=');
53+
}
54+
55+
public function run(IOutput $output): void {
56+
if ($this->manager->isEnabled()) {
57+
if ($this->config->getSystemValue('encryption.legacy_format_support', '') === '') {
58+
$this->config->setSystemValue('encryption.legacy_format_support', true);
59+
}
60+
}
61+
}
62+
}

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
3030
// when updating major/minor version number.
3131

32-
$OC_Version = [20, 0, 0, 0];
32+
$OC_Version = [20, 0, 0, 1];
3333

3434
// The human readable string
3535
$OC_VersionString = '20.0.0 alpha';

0 commit comments

Comments
 (0)