π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathia39948ccc39d
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 7488dc5f53..624e33706e 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -60,6 +60,7 @@ import {import {constructUserIDToEmailMap,createShareeSuggestionEmails,+ validateKey,} from "ente-new/photos/components/gallery/helpers";import {useGalleryReducer,@@ -97,7 +98,6 @@ import {} from "ente-new/photos/services/user-details";import { usePhotosAppContext } from "ente-new/photos/types/context";import { FlexWrapper } from "ente-shared/components/Container";-import { getRecoveryKey } from "ente-shared/crypto/helpers";import { CustomError } from "ente-shared/error";import { getData } from "ente-shared/storage/localStorage";import {@@ -290,19 +290,6 @@ const Page: React.FC = () => {const router = useRouter();- // Ensure that the keys in local storage are not malformed by verifying that- // the recoveryKey can be decrypted with the masterKey.- // Note: This is not bullet-proof.- const validateKey = async () => {- try {- await getRecoveryKey();- return true;- } catch {- logout();- return false;- }- };-useEffect(() => {const key = getKey("encryptionKey");const token = getToken();@@ -314,8 +301,8 @@ const Page: React.FC = () => {preloadImage("/images/subscription-card-background");const electron = globalThis.electron;const main = async () => {- const valid = await validateKey();- if (!valid) {+ if (!(await validateKey())) {+ logout();return;}initSettings();diff --git a/web/packages/new/photos/components/gallery/helpers.ts b/web/packages/new/photos/components/gallery/helpers.tsindex 39785fd64a..fde1b89526 100644--- a/web/packages/new/photos/components/gallery/helpers.ts+++ b/web/packages/new/photos/components/gallery/helpers.ts@@ -10,10 +10,32 @@* is a needed for fast refresh to work.*/+import log from "ente-base/log";import type { Collection } from "ente-media/collection";import type { FamilyData } from "ente-new/photos/services/user-details";+import { getRecoveryKey } from "ente-shared/crypto/helpers";import type { User } from "ente-shared/user/types";+/**+ * Ensure that the keys in local storage are not malformed by verifying that the+ * recoveryKey can be decrypted with the masterKey.+ *+ * This is not meant to be bullet proof, but more like an extra sanity check.+ *+ * @returns `true` if the sanity check passed, otherwise `false`. Since failure+ * is not expected, the caller should {@link logout} on `false` to avoid+ * continuing with an unexpected local state.+ */+export const validateKey = async () => {+ try {+ await getRecoveryKey();+ return true;+ } catch (e) {+ log.warn("Failed to validate key" /*, caller will logout */, e);+ return false;+ }+};+export const constructUserIDToEmailMap = (user: User,collections: Collection[],