Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: decrypt versions on IVersionedStorage #307

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 1 addition & 6 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ config = {
],
"servers": [
"daily-master-qa",
"latest",
],
"extraSetup": [
{
Expand All @@ -105,7 +104,6 @@ config = {
],
"servers": [
"daily-master-qa",
"latest",
],
"extraSetup": [
{
Expand All @@ -129,7 +127,6 @@ config = {
],
"servers": [
"daily-master-qa",
"latest",
],
"emailNeeded": True,
"extraSetup": [
Expand All @@ -155,7 +152,6 @@ config = {
],
"servers": [
"daily-master-qa",
"latest",
],
"extraSetup": [
{
Expand All @@ -179,7 +175,6 @@ config = {
],
"servers": [
"daily-master-qa",
"latest",
],
"emailNeeded": True,
"extraSetup": [
Expand Down Expand Up @@ -1920,7 +1915,7 @@ def installCore(ctx, version, db, useBundledApp):
"name": "install-core",
"image": OC_CI_CORE,
"settings": {
"version": version,
"git_reference": "feat/storage-based-encryption-key-location-2",
"core_path": dir["server"],
"db_type": dbType,
"db_name": database,
Expand Down
1 change: 0 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ function (IAppContainer $c) {
$server->getEncryptionKeyStorage(),
$c->query('Crypt'),
$server->getConfig(),
$server->getUserSession(),
new Session($server->getSession()),
$server->getLogger(),
$c->query('Util')
Expand Down
13 changes: 8 additions & 5 deletions lib/Crypto/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function getDisplayName() {
* written to the header, in case of a write operation
* or if no additional data is needed return a empty array
*/
public function begin($path, $user, $mode, array $header, array $accessList, $sourceFileOfRename = null) {
public function begin($path, $user, $mode, array $header, array $accessList, $sourceFileOfRename = null, $fileEncryptionVersion = null) {
$this->path = $this->getPathToRealFile($path);
$this->accessList = $accessList;
$this->user = $user;
Expand All @@ -198,10 +198,13 @@ public function begin($path, $user, $mode, array $header, array $accessList, $so
// 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
// final location
if ($sourceFileOfRename !== null) {
$this->version = $this->keyManager->getVersion($sourceFileOfRename, new View());
} else {
$this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View());
$this->version = $fileEncryptionVersion;
if (!$this->version) {
if ($sourceFileOfRename !== null) {
$this->version = $this->keyManager->getVersion($sourceFileOfRename, new View());
} else {
$this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View());
}
}

if (
Expand Down
1 change: 0 additions & 1 deletion lib/Factory/EncDecAllFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public function getEncryptAllObj() {
$this->encStorage,
$this->getCryptoEngine(),
$this->config,
$this->userSession,
$this->encSession,
$this->logger,
$this->encUtil
Expand Down
15 changes: 5 additions & 10 deletions lib/KeyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class KeyManager {
* @var string
*/
private $masterKeyId;
/**
* @var string UserID
*/
private $keyId;
/**
* @var string
*/
Expand Down Expand Up @@ -100,7 +96,6 @@ class KeyManager {
* @param IStorage $keyStorage
* @param Crypt $crypt
* @param IConfig $config
* @param IUserSession $userSession
* @param Session $session
* @param ILogger $log
* @param Util $util
Expand All @@ -109,7 +104,6 @@ public function __construct(
IStorage $keyStorage,
Crypt $crypt,
IConfig $config,
IUserSession $userSession,
Session $session,
ILogger $log,
Util $util
Expand All @@ -136,7 +130,6 @@ public function __construct(

$this->setPublicShareKeyIDAndMasterKeyId();

$this->keyId = $userSession !== null && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false;
$this->log = $log;
}

Expand Down Expand Up @@ -539,11 +532,13 @@ public function userHasKeys($userId) {

if ($privateKey && $publicKey) {
return true;
} elseif (!$privateKey && !$publicKey) {
}

if (!$privateKey && !$publicKey) {
return false;
} else {
throw $exception;
}

throw $exception;
}

/**
Expand Down
1 change: 0 additions & 1 deletion tests/unit/Command/FixEncryptedVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static function setUpBeforeClass(): void {
\OC::$server->getEncryptionKeyStorage(),
$crypt,
\OC::$server->getConfig(),
\OC::$server->getUserSession(),
$encryptionSession,
\OC::$server->getLogger(),
$encryptionUtil
Expand Down
9 changes: 0 additions & 9 deletions tests/unit/KeyManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class KeyManagerTest extends TestCase {
/** @var \OCA\Encryption\Crypto\Crypt|\PHPUnit\Framework\MockObject\MockObject */
private $cryptMock;

/** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject */
private $userMock;

/** @var \OCA\Encryption\Session|\PHPUnit\Framework\MockObject\MockObject */
private $sessionMock;

Expand All @@ -75,7 +72,6 @@ public function setUp(): void {
$this->configMock->expects($this->any())
->method('getAppValue')
->will($this->returnCallback([$this, 'returnAppValue']));
$this->userMock = $this->createMock('OCP\IUserSession');
$this->sessionMock = $this->getMockBuilder('OCA\Encryption\Session')
->disableOriginalConstructor()
->getMock();
Expand All @@ -88,7 +84,6 @@ public function setUp(): void {
$this->keyStorageMock,
$this->cryptMock,
$this->configMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand Down Expand Up @@ -261,7 +256,6 @@ public function testInit($useMasterKey) {
$this->keyStorageMock,
$this->cryptMock,
$this->configMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand Down Expand Up @@ -518,7 +512,6 @@ public function testGetMasterKeyId() {
$this->keyStorageMock,
$this->cryptMock,
$localConfigMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand All @@ -538,7 +531,6 @@ public function testGetPublicMasterKey() {
$this->keyStorageMock,
$this->cryptMock,
$localConfigMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand Down Expand Up @@ -593,7 +585,6 @@ public function testValidateMasterKey($masterKey) {
$this->keyStorageMock,
$this->cryptMock,
$localConfigMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand Down