Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 0 additions & 32 deletions apps/encryption/js/encryption.js

This file was deleted.

80 changes: 0 additions & 80 deletions apps/encryption/js/settings-admin.js

This file was deleted.

64 changes: 0 additions & 64 deletions apps/encryption/js/settings-personal.js

This file was deleted.

87 changes: 41 additions & 46 deletions apps/encryption/lib/Controller/RecoveryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,23 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\Encryption\Exceptions\GenericEncryptionException;
use OCP\IL10N;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

class RecoveryController extends Controller {
/**
* @param string $AppName
* @param IRequest $request
* @param IConfig $config
* @param IL10N $l
* @param Recovery $recovery
*/
public function __construct(
$appName,
string $appName,
IRequest $request,
private IConfig $config,
private IL10N $l,
private Recovery $recovery,
private LoggerInterface $logger,
) {
parent::__construct($appName, $request);
}

/**
* @param string $recoveryPassword
* @param string $confirmPassword
* @param string $adminEnableRecovery
* @return DataResponse
*/
public function adminRecovery($recoveryPassword, $confirmPassword, $adminEnableRecovery) {
public function adminRecovery(string $recoveryPassword, string $confirmPassword, bool $adminEnableRecovery): DataResponse {
// Check if both passwords are the same
if (empty($recoveryPassword)) {
$errorMessage = $this->l->t('Missing recovery key password');
Expand All @@ -60,28 +48,28 @@ public function adminRecovery($recoveryPassword, $confirmPassword, $adminEnableR
Http::STATUS_BAD_REQUEST);
}

if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') {
if ($this->recovery->enableAdminRecovery($recoveryPassword)) {
return new DataResponse(['data' => ['message' => $this->l->t('Recovery key successfully enabled')]]);
try {
if ($adminEnableRecovery) {
if ($this->recovery->enableAdminRecovery($recoveryPassword)) {
return new DataResponse(['data' => ['message' => $this->l->t('Recovery key successfully enabled')]]);
}
return new DataResponse(['data' => ['message' => $this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST);
} else {
if ($this->recovery->disableAdminRecovery($recoveryPassword)) {
return new DataResponse(['data' => ['message' => $this->l->t('Recovery key successfully disabled')]]);
}
return new DataResponse(['data' => ['message' => $this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST);
}
return new DataResponse(['data' => ['message' => $this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST);
} elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') {
if ($this->recovery->disableAdminRecovery($recoveryPassword)) {
return new DataResponse(['data' => ['message' => $this->l->t('Recovery key successfully disabled')]]);
} catch (\Exception $e) {
$this->logger->error('Error enabling or disabling recovery key', ['exception' => $e]);
if ($e instanceof GenericEncryptionException) {
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new DataResponse(['data' => ['message' => $this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST);
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
// this response should never be sent but just in case.
return new DataResponse(['data' => ['message' => $this->l->t('Missing parameters')]], Http::STATUS_BAD_REQUEST);
}

/**
* @param string $newPassword
* @param string $oldPassword
* @param string $confirmPassword
* @return DataResponse
*/
public function changeRecoveryPassword($newPassword, $oldPassword, $confirmPassword) {
public function changeRecoveryPassword(string $newPassword, string $oldPassword, string $confirmPassword): DataResponse {
//check if both passwords are the same
if (empty($oldPassword)) {
$errorMessage = $this->l->t('Please provide the old recovery password');
Expand All @@ -103,23 +91,30 @@ public function changeRecoveryPassword($newPassword, $oldPassword, $confirmPassw
return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST);
}

$result = $this->recovery->changeRecoveryKeyPassword($newPassword,
$oldPassword);
try {
$result = $this->recovery->changeRecoveryKeyPassword($newPassword,
$oldPassword);

if ($result) {
return new DataResponse(
[
'data' => [
'message' => $this->l->t('Password successfully changed.')]
]
);
}
return new DataResponse(
[
if ($result) {
return new DataResponse(
[
'data' => [
'message' => $this->l->t('Password successfully changed.')]
]
);
}
return new DataResponse([
'data' => [
'message' => $this->l->t('Could not change the password. Maybe the old password was not correct.')
]
], Http::STATUS_BAD_REQUEST);
} catch (\Exception $e) {
$this->logger->error('Error changing recovery password', ['exception' => $e]);
if ($e instanceof GenericEncryptionException) {
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion apps/encryption/lib/Controller/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public function getStatus() {
return new DataResponse(
[
'status' => $status,
'initStatus' => $this->session->getStatus(),
'data' => [
'message' => $message]
'message' => $message,
],
]
);
}
Expand Down
15 changes: 11 additions & 4 deletions apps/encryption/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
namespace OCA\Encryption\Settings;

use OC\Files\View;
use OCA\Encryption\AppInfo\Application;
use OCA\Encryption\Crypto\Crypt;
use OCA\Encryption\Session;
use OCA\Encryption\Util;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ISession;
Expand All @@ -27,6 +30,8 @@ public function __construct(
private IConfig $config,
private IUserManager $userManager,
private ISession $session,
private IInitialState $initialState,
private IAppConfig $appConfig,
) {
}

Expand All @@ -48,19 +53,21 @@ public function getForm() {
$this->userManager);

// Check if an adminRecovery account is enabled for recovering files after lost pwd
$recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0');
$recoveryAdminEnabled = $this->appConfig->getValueBool('encryption', 'recoveryAdminEnabled');
$session = new Session($this->session);

$encryptHomeStorage = $util->shouldEncryptHomeStorage();

$parameters = [
$this->initialState->provideInitialState('adminSettings', [
'recoveryEnabled' => $recoveryAdminEnabled,
'initStatus' => $session->getStatus(),
'encryptHomeStorage' => $encryptHomeStorage,
'masterKeyEnabled' => $util->isMasterKeyEnabled(),
];
]);

return new TemplateResponse('encryption', 'settings-admin', $parameters, '');
\OCP\Util::addStyle(Application::APP_ID, 'settings_admin');
\OCP\Util::addScript(Application::APP_ID, 'settings_admin');
return new TemplateResponse(Application::APP_ID, 'settings', renderAs: '');
}

/**
Expand Down
Loading
Loading