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

Enable user-keys if no encryption mode is enabled during login #36

Merged
merged 1 commit into from
Jun 1, 2018
Merged
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
2 changes: 1 addition & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function registerHooks() {
$container->query('Util'),
$container->query('Session'),
$container->query('Crypt'),
$container->query('Recovery'))
$container->query('Recovery'), $server->getConfig())
]);

$hookManager->fireHooks();
Expand Down
14 changes: 13 additions & 1 deletion lib/Hooks/UserHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


use OC\Files\Filesystem;
use OCP\IConfig;
use OCP\IUserManager;
use OCP\Util as OCUtil;
use OCA\Encryption\Hooks\Contracts\IHook;
Expand Down Expand Up @@ -76,6 +77,10 @@ class UserHooks implements IHook {
* @var Crypt
*/
private $crypt;
/**
* @var IConfig
*/
private $config;

/**
* UserHooks constructor.
Expand All @@ -89,6 +94,7 @@ class UserHooks implements IHook {
* @param Session $session
* @param Crypt $crypt
* @param Recovery $recovery
* @param IConfig $config
*/
public function __construct(KeyManager $keyManager,
IUserManager $userManager,
Expand All @@ -98,7 +104,7 @@ public function __construct(KeyManager $keyManager,
Util $util,
Session $session,
Crypt $crypt,
Recovery $recovery) {
Recovery $recovery, IConfig $config) {

$this->keyManager = $keyManager;
$this->userManager = $userManager;
Expand All @@ -109,6 +115,7 @@ public function __construct(KeyManager $keyManager,
$this->session = $session;
$this->recovery = $recovery;
$this->crypt = $crypt;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -166,6 +173,11 @@ public function login($params) {
$this->userSetup->setupUser($params['uid'], $params['password']);
}

if (($this->util->isMasterKeyEnabled() === false) &&
($this->config->getAppValue('encryption', 'userSpecificKey', '') === '')) {
$this->config->setAppValue('encryption', 'userSpecificKey', '1');
}

$this->keyManager->init($params['uid'], $params['password']);
}

Expand Down
28 changes: 21 additions & 7 deletions tests/Hooks/UserHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

use OCA\Encryption\Crypto\Crypt;
use OCA\Encryption\Hooks\UserHooks;
use OCA\Encryption\Util;
use OCP\IConfig;
use Test\TestCase;

/**
Expand Down Expand Up @@ -76,6 +78,7 @@ class UserHooksTest extends TestCase {
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $loggerMock;
private $config;
/**
* @var UserHooks
*/
Expand All @@ -92,6 +95,12 @@ public function testLogin() {
->method('init')
->with('testUser', 'password');

$this->config->expects($this->once())
->method('getAppValue')
->willReturnMap([
['encryption', 'userSpecificKey', '', ''],
]);

$this->assertNull($this->instance->login($this->params));
}

Expand Down Expand Up @@ -136,7 +145,8 @@ public function testPreSetPassphrase($canChange) {
$this->utilMock,
$this->sessionMock,
$this->cryptMock,
$this->recoveryMock
$this->recoveryMock,
$this->config
]
)
->setMethods(['setPassphrase'])
Expand Down Expand Up @@ -215,7 +225,8 @@ public function testSetPassphrase() {
$this->utilMock,
$this->sessionMock,
$this->cryptMock,
$this->recoveryMock
$this->recoveryMock,
$this->config
]
)->setMethods(['initMountPoints'])->getMock();

Expand Down Expand Up @@ -278,7 +289,8 @@ public function testSetPasswordNoUser() {
$this->utilMock,
$this->sessionMock,
$this->cryptMock,
$this->recoveryMock
$this->recoveryMock,
$this->config
]
)->setMethods(['initMountPoints'])->getMock();

Expand Down Expand Up @@ -331,9 +343,9 @@ protected function setUp() {
->method($this->anything())
->will($this->returnSelf());

$utilMock = $this->getMockBuilder('OCA\Encryption\Util')
/*$utilMock = $this->getMockBuilder('OCA\Encryption\Util')
->disableOriginalConstructor()
->getMock();
->getMock();*/

$sessionMock = $this->getMockBuilder('OCA\Encryption\Session')
->disableOriginalConstructor()
Expand All @@ -345,10 +357,11 @@ protected function setUp() {
$recoveryMock = $this->getMockBuilder('OCA\Encryption\Recovery')
->disableOriginalConstructor()
->getMock();
$this->config = $this->createMock(IConfig::class);

$this->sessionMock = $sessionMock;
$this->recoveryMock = $recoveryMock;
$this->utilMock = $utilMock;
$this->utilMock = $this->createMock(Util::class);
$this->utilMock->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false);

$this->instance = $this->getMockBuilder('OCA\Encryption\Hooks\UserHooks')
Expand All @@ -362,7 +375,8 @@ protected function setUp() {
$this->utilMock,
$this->sessionMock,
$this->cryptMock,
$this->recoveryMock
$this->recoveryMock,
$this->config
]
)->setMethods(['setupFS'])->getMock();

Expand Down