π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat: get collection with key and get collection with master or collection key
httpjamesm72ed8b04973f
diff --git a/apps/cast/src/pages/index.tsx b/apps/cast/src/pages/index.tsxindex 31b0f87781..739929057a 100644--- a/apps/cast/src/pages/index.tsx+++ b/apps/cast/src/pages/index.tsx@@ -7,7 +7,6 @@ import {toB64,} from '@ente/shared/crypto/internal/libsodium';import { useRouter } from 'next/router';-import { SESSION_KEYS, setKey } from '@ente/shared/storage/sessionStorage';import TimerBar from 'components/TimerBar';import LargeType from 'components/LargeType';import { useCastReceiver } from '@ente/shared/hooks/useCastReceiver';@@ -137,13 +136,8 @@ export default function PairingMode() {const storePayloadLocally = (payloadObj: Object) => {// iterate through all the keys in the payload object and set them in localStorage.- // if the key is "encryptionKey", store it in session storage instead.for (const key in payloadObj) {- if (key === 'sessionKey') {- setKey(SESSION_KEYS.ENCRYPTION_KEY, payloadObj[key]);- } else {- window.localStorage.setItem(key, payloadObj[key]);- }+ window.localStorage.setItem(key, payloadObj[key]);}};diff --git a/apps/cast/src/pages/slideshow.tsx b/apps/cast/src/pages/slideshow.tsxindex a7f32e8172..2036caf1ac 100644--- a/apps/cast/src/pages/slideshow.tsx+++ b/apps/cast/src/pages/slideshow.tsx@@ -3,7 +3,7 @@ import Theatre from 'components/Theatre';import { FILE_TYPE } from 'constants/file';import { useRouter } from 'next/router';import { createContext, useEffect, useState } from 'react';-import { getCollection } from 'services/collectionService';+import { getCollectionWithKey } from 'services/collectionService';import { syncFiles } from 'services/fileService';import { EnteFile } from 'types/file';import { downloadFileAsBlob, isRawFileFromFileName } from 'utils/file';@@ -32,8 +32,13 @@ export default function Slideshow() {const requestedCollectionID =window.localStorage.getItem('targetCollectionId');- const collection = await getCollection(- Number(requestedCollectionID)+ const requestedCollectionKey = window.localStorage.getItem(+ 'targetCollectionKey'+ );++ const collection = await getCollectionWithKey(+ Number(requestedCollectionID),+ requestedCollectionKey);const files = await syncFiles('normal', [collection], () => {});diff --git a/apps/cast/src/services/collectionService.ts b/apps/cast/src/services/collectionService.tsindex da30a5f96e..87eab00b0a 100644--- a/apps/cast/src/services/collectionService.ts+++ b/apps/cast/src/services/collectionService.ts@@ -94,29 +94,34 @@ export const removeCollectionLastSyncTime = async (collection: Collection) =>const getCollectionWithSecrets = async (collection: EncryptedCollection,- masterKey: string+ key: string,+ type: 'master' | 'collection' = 'master'): Promise<Collection> => {const cryptoWorker = await ComlinkCryptoWorker.getInstance();const userID = getData(LS_KEYS.USER).id;let collectionKey: string;- if (collection.owner.id === userID) {- collectionKey = await cryptoWorker.decryptB64(- collection.encryptedKey,- collection.keyDecryptionNonce,- masterKey- );+ if (type === 'master') {+ if (collection.owner.id === userID) {+ collectionKey = await cryptoWorker.decryptB64(+ collection.encryptedKey,+ collection.keyDecryptionNonce,+ key+ );+ } else {+ const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);+ const secretKey = await cryptoWorker.decryptB64(+ keyAttributes.encryptedSecretKey,+ keyAttributes.secretKeyDecryptionNonce,+ key+ );+ collectionKey = await cryptoWorker.boxSealOpen(+ collection.encryptedKey,+ keyAttributes.publicKey,+ secretKey+ );+ }} else {- const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);- const secretKey = await cryptoWorker.decryptB64(- keyAttributes.encryptedSecretKey,- keyAttributes.secretKeyDecryptionNonce,- masterKey- );- collectionKey = await cryptoWorker.boxSealOpen(- collection.encryptedKey,- keyAttributes.publicKey,- secretKey- );+ collectionKey = key;}const collectionName =collection.name ||@@ -340,6 +345,32 @@ export const getCollection = async (}};+export const getCollectionWithKey = async (+ collectionID: number,+ key: string+): Promise<Collection> => {+ try {+ const token = getToken();+ if (!token) {+ return;+ }+ const resp = await HTTPService.get(+ `${ENDPOINT}/collections/${collectionID}`,+ null,+ { 'X-Auth-Token': token }+ );+ const collectionWithSecrets = await getCollectionWithSecrets(+ resp.data?.collection,+ key,+ 'collection'+ );+ return collectionWithSecrets;+ } catch (e) {+ logError(e, 'failed to get collection');+ throw e;+ }+};+export const getCollectionLatestFiles = (files: EnteFile[]): CollectionToFileMap => {diff --git a/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx b/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsxindex e4ec9d5525..01024d16f3 100644--- a/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx+++ b/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx@@ -5,7 +5,6 @@ import SingleInputForm, {} from '@ente/shared/components/SingleInputForm';import { t } from 'i18next';import { getKexValue, setKexValue } from '@ente/shared/network/kexService';-// import { SESSION_KEYS, getKey } from '@ente/shared/storage/sessionStorage';import { boxSeal, toB64 } from '@ente/shared/crypto/internal/libsodium';import { loadSender } from '@ente/shared/hooks/useCastSender';import { useEffect, useState } from 'react';@@ -15,7 +14,6 @@ import { VerticallyCentered } from '@ente/shared/components/Container';import { logError } from '@ente/shared/sentry';import { LS_KEYS, getData } from '@ente/shared/storage/localStorage';import { Collection } from 'types/collection';-import { SESSION_KEYS, getKey } from '@ente/shared/storage/sessionStorage';interface Props {show: boolean;@@ -75,8 +73,8 @@ export default function AlbumCastDialog(props: Props) {// ok, they exist. let's give them the good stuff.const payload = JSON.stringify({user: JSON.stringify(getData(LS_KEYS.USER)),- sessionKey: getKey(SESSION_KEYS.ENCRYPTION_KEY),targetCollectionId: props.currentCollection.id,+ targetCollectionKey: props.currentCollection.key,});const encryptedPayload = await boxSeal(