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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/end_to_end_encryption-files.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/end_to_end_encryption-files.mjs.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCA\EndToEndEncryption\IMetaDataStorage;
use OCA\EndToEndEncryption\IMetaDataStorageV1;
use OCA\EndToEndEncryption\KeyStorage;
use OCA\EndToEndEncryption\Listener\AllowBlobMediaInCSPListener;
use OCA\EndToEndEncryption\Listener\LoadAdditionalListener;
use OCA\EndToEndEncryption\Listener\UserDeletedListener;
use OCA\EndToEndEncryption\MetaDataStorage;
Expand All @@ -34,6 +35,7 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\SabrePluginEvent;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\User\Events\UserDeletedEvent;

class Application extends App implements IBootstrap {
Expand Down Expand Up @@ -62,6 +64,7 @@ public function register(IRegistrationContext $context): void {
$context->registerServiceAlias(IMetaDataStorage::class, MetaDataStorage::class);
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
$context->registerEventListener(AddContentSecurityPolicyEvent::class, AllowBlobMediaInCSPListener::class);
$context->registerPublicShareTemplateProvider(E2EEPublicShareTemplateProvider::class);
}

Expand Down
32 changes: 32 additions & 0 deletions lib/Listener/AllowBlobMediaInCSPListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

declare(strict_types=1);

namespace OCA\EndToEndEncryption\Listener;

use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;

/**
* @template-implements IEventListener<Event>
* We need it to be able to expose decrypted video and audio files in a blob URL.
*/
class AllowBlobMediaInCSPListener implements IEventListener {

public function handle(Event $event): void {
if (!($event instanceof AddContentSecurityPolicyEvent)) {
return;
}

$csp = new ContentSecurityPolicy();
$csp->addAllowedMediaDomain('blob:');
$event->addPolicy($csp);
}
}
4 changes: 2 additions & 2 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
}

function disableFileAction(actionId: string) {
logger.debug('Disabling file action', { actionId })
logger.debug(`Inhibiting ${actionId} actions for e2ee files`)

Check warning on line 29 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L29

Added line #L29 was not covered by tests
const actions = getFileActions()

const action = actions.find(action => action.id === actionId) as any
const action = actions.find(action => action.id === actionId) as unknown as { _action: { enabled: (nodes: Node[], view: View) => boolean } }

Check warning on line 32 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L32

Added line #L32 was not covered by tests
const originalEnabled = action._action.enabled

action._action.enabled = (nodes: Node[], view: View) => {
Expand Down
3 changes: 2 additions & 1 deletion src/services/downloadUnencryptedAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

Expand All @@ -13,6 +13,7 @@ import { FileAction, Node, FileType, DefaultType } from '@nextcloud/files'
import { isDownloadable } from './permissions.ts'

async function downloadNodes([file]: Node[]) {
// Decryption happens in the proxy.
const response = await fetch(file.encodedSource)
const decryptedFileContent = await response.arrayBuffer()
const blob = new Blob([decryptedFileContent], { type: file.mime })
Expand Down
3 changes: 2 additions & 1 deletion src/services/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { dirname } from 'path'
import type { WebDAVClient } from 'webdav'

import { getCurrentUser } from '@nextcloud/auth'
import { getClient, getDefaultPropfind } from '@nextcloud/files/dav'
Expand All @@ -17,7 +18,7 @@ import { decryptMetadataInfo, getMetadataPrivateKey } from './metadataUtils.ts'
import logger from './logger.ts'
import { validateMetadataSignature, validateUserCertificates } from './security.ts'

const davClient = getClient()
const davClient = getClient() as WebDAVClient

export const state = {
_userPrivateKey: undefined as CryptoKey | undefined,
Expand Down
7 changes: 5 additions & 2 deletions src/services/webDavProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ async function handleGet(request: Request): Promise<Response> {
throw new Error('Could not find file in metadata')
}

logger.debug('Fetching encrypted file', { request })
return await decryptFile(await responsePromise, fileInfo)
} catch (error) {
return await responsePromise
Expand Down Expand Up @@ -144,11 +143,15 @@ export function replacePlaceholdersInPropfind(xml: DAVResult, path: string, decr
}

export async function decryptFile(response: Response, fileEncryptionInfo: FileEncryptionInfo): Promise<Response> {
logger.debug('Decrypting encrypted file', { response, fileEncryptionInfo })
const decryptedFileContent = await decryptWithAES(
new Uint8Array(await response.arrayBuffer()),
await loadAESPrivateKey(base64ToBuffer(fileEncryptionInfo.key)),
{ iv: base64ToBuffer(fileEncryptionInfo.nonce) },
)

return new Response(decryptedFileContent, response)
const headers = new Headers(response.headers)
headers.set('Content-Type', fileEncryptionInfo.mimetype)

return new Response(decryptedFileContent, { ...response, headers })
}
Loading