Skip to content

Commit

Permalink
encryption based on cpu arch
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Oct 21, 2021
1 parent 1e83929 commit 577b5fd
Show file tree
Hide file tree
Showing 12 changed files with 465 additions and 151 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
build/
.settings/
vendor/

.php_cs.cache
1 change: 0 additions & 1 deletion .php_cs.cache

This file was deleted.

2 changes: 1 addition & 1 deletion lib/Command/SetupExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$setup = [
'signatory' => $this->configService->getAppValue('key_pairs'),
'remote' => $this->remoteService->getAll(true),
'encryption' => $this->encryptService->getEncryptionKey()
'encryption' => $this->encryptService->getEncryptionKeys(true)
];

$data = json_encode($setup);
Expand Down
42 changes: 42 additions & 0 deletions lib/Exceptions/PackDecryptException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);


/**
* Nextcloud - Backup now. Restore later.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/


namespace OCA\Backup\Exceptions;

use Exception;

/**
* Class PackDecryptException
*
* @package OCA\Backup\Exceptions
*/
class PackDecryptException extends Exception {
}
42 changes: 42 additions & 0 deletions lib/Exceptions/PackEncryptException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);


/**
* Nextcloud - Backup now. Restore later.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/


namespace OCA\Backup\Exceptions;

use Exception;

/**
* Class PackEncryptException
*
* @package OCA\Backup\Exceptions
*/
class PackEncryptException extends Exception {
}
27 changes: 26 additions & 1 deletion lib/Model/RestoringChunkPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class RestoringChunkPart implements JsonSerializable, IDeserializable {
/** @var bool */
private $encrypted = false;

/** @var string */
private $algorithm = '';

/** @var string */
private $encryptedChecksum = '';

Expand Down Expand Up @@ -126,8 +129,9 @@ public function getOrder(): int {
*
* @return RestoringChunkPart
*/
public function setEncrypted(bool $encrypted): self {
public function setEncrypted(bool $encrypted, string $algorithm = ''): self {
$this->encrypted = $encrypted;
$this->algorithm = $algorithm;

return $this;
}
Expand All @@ -140,6 +144,25 @@ public function isEncrypted(): bool {
}


/**
* @param string $algorithm
*
* @return RestoringChunkPart
*/
public function setAlgorithm(string $algorithm): self {
$this->algorithm = $algorithm;

return $this;
}

/**
* @return string
*/
public function getAlgorithm(): string {
return $this->algorithm;
}


/**
* @return string
*/
Expand Down Expand Up @@ -219,6 +242,7 @@ public function import(array $data): IDeserializable {
->setOrder($this->getInt('order', $data))
->setContent($this->get('content', $data))
->setEncrypted($this->getBool('encrypted', $data))
->setAlgorithm($this->get('algorithm', $data))
->setChecksum($this->get('checksum', $data))
->setEncryptedChecksum($this->get('encryptedChecksum', $data));

Expand All @@ -234,6 +258,7 @@ public function jsonSerialize(): array {
'name' => $this->getName(),
'order' => $this->getOrder(),
'encrypted' => $this->isEncrypted(),
'algorithm' => $this->getAlgorithm(),
'checksum' => $this->getChecksum(),
'encryptedChecksum' => $this->getEncryptedChecksum()
];
Expand Down
2 changes: 1 addition & 1 deletion lib/Model/RestoringPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class RestoringPoint implements IDeserializable, INC23QueryRow, ISignedModel, Js
public const STATUS_COMPRESSED = 2;
public const STATUS_ENCRYPTED = 4;

const LOCK_TIMEOUT = 3600 * 3;
public const LOCK_TIMEOUT = 3600 * 3;

public static $DEF_STATUS =
[
Expand Down
7 changes: 4 additions & 3 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class ConfigService {
public const PACK_INDEX = 'pack_index';
public const PACK_REMOTE_INDEX = 'pack_remote_index';

public const ENCRYPTION_KEY = 'encryption_key';
public const ENCRYPTION_KEYS = 'encryption_keys';
public const FORCE_CBC = 'force_cbc';
public const TIME_SLOTS = 'time_slots';
public const MOCKUP_DATE = 'mockup_date';

Expand All @@ -88,7 +89,8 @@ class ConfigService {
self::DELAY_UNIT => 'd',
self::ALLOW_WEEKDAY => 0,
self::PACK_BACKUP => '1',
self::ENCRYPTION_KEY => '',
self::ENCRYPTION_KEYS => '{}',
self::FORCE_CBC => 0,
self::TIME_SLOTS => '23-5',
self::MOCKUP_DATE => 0,
self::BACKUP_DAYS => 60,
Expand Down Expand Up @@ -365,5 +367,4 @@ public function setSettings(array $settings): array {

return $this->getSettings();
}

}

0 comments on commit 577b5fd

Please sign in to comment.