Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a24702e3 authored by Akhil's avatar Akhil 🙂
Browse files

feat: add config flag to enable e2ee setup

parent a18d80fa
Loading
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ use OCA\EcloudAccounts\Service\CaptchaService;
use OCA\EcloudAccounts\Service\HCaptchaService;
use OCA\EcloudAccounts\Service\NewsLetterService;
use OCA\EcloudAccounts\Service\UserService;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@@ -52,6 +53,7 @@ class AccountController extends Controller {
	private const HCAPTCHA_PROVIDER = 'hcaptcha';
	private const HCAPTCHA_DOMAINS = ['https://hcaptcha.com', 'https://*.hcaptcha.com'];
	private const BLACKLISTED_USERNAMES_FILE_NAME = 'blacklisted_usernames';
	private const PASSWORDS_APP_ID = 'passwords';

	private LoggerInterface $logger;
	public function __construct(
@@ -66,6 +68,7 @@ class AccountController extends Controller {
		IURLGenerator $urlGenerator,
		ISession $session,
		IConfig $config,
		private IAppManager $appManager,
		LoggerInterface $logger,
		IInitialState $initialState,
		IAppData $appData,
@@ -114,7 +117,13 @@ class AccountController extends Controller {
		$this->initialState->provideInitialState('captchaProvider', $captchaProvider);
		
		$csp = $response->getContentSecurityPolicy();
		$setupPasswordsE2ee = false;

		if ($this->appManager->isEnabledForUser(self::PASSWORDS_APP_ID) && $this->config->getAppValue(self::PASSWORDS_APP_ID, 'mandatoryEndToEndEncryption', false)) {
			$setupPasswordsE2ee = true;
			$csp->allowEvalWasm();
		}
		$this->initialState->provideInitialState('setupPasswordsE2ee', $setupPasswordsE2ee);

		if ($captchaProvider === self::HCAPTCHA_PROVIDER) {
			foreach (self::HCAPTCHA_DOMAINS as $domain) {
@@ -221,8 +230,11 @@ class AccountController extends Controller {
			$this->session->remove(self::SESSION_VERIFIED_DISPLAYNAME);
			$this->session->remove(self::CAPTCHA_VERIFIED_CHECK);

			// Session needed for client to setup E2EE at passwords app via API calls
			if ($this->appManager->isEnabledForUser(self::PASSWORDS_APP_ID) && $this->config->getAppValue(self::PASSWORDS_APP_ID, 'mandatoryEndToEndEncryption', false)) {
				$user = $this->userService->getUser($username);
				$this->userSession->setUser($user);
			}
			$response->setStatus(200);
			$response->setData(['success' => true]);

+5 −2
Original line number Diff line number Diff line
@@ -109,7 +109,10 @@ export default {
				const url = generateUrl(`/apps/${this.appName}/accounts/create`)
				this.processingCreation = true
				await Axios.post(url, data)
				await this.setupEncryption()
			    const setupPasswordsE2ee = loadState(APPLICATION_NAME, 'setupPasswordsE2ee')
				if (setupPasswordsE2ee) {
					await this.setupPasswordsE2ee()
				}

				// If the execution reaches here, the response status is in the 2xx range
				this.showRegistrationForm = false
@@ -128,7 +131,7 @@ export default {
				this.showMessage(errorMessage, 'error')
			}
		},
		async setupEncryption() {
		async setupPasswordsE2ee() {
			const token = this.formData.password
			const user = this.formData.username
			let baseUrl = new URL(generateUrl('/', [], {}), location.origin).href