Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Move

Manav Rathic1a3cdceed0b
diff --git a/web/apps/photos/src/pages/shared-albums.tsx b/web/apps/photos/src/pages/shared-albums.tsx
index 85c1ad47b3..0b4508f593 100644
--- a/web/apps/photos/src/pages/shared-albums.tsx
+++ b/web/apps/photos/src/pages/shared-albums.tsx
@@ -14,7 +14,7 @@ import { downloadManager } from "@/gallery/services/download";
import { updateShouldDisableCFUploadProxy } from "@/gallery/services/upload";
import type { Collection } from "@/media/collection";
import { type EnteFile, mergeMetadata } from "@/media/file";
-import { verifyPublicCollectionPassword } from "@/new/albums/services/publicCollection";
+import { verifyPublicAlbumPassword } from "@/new/albums/services/publicCollection";
import {
GalleryItemsHeaderAdapter,
GalleryItemsSummary,
@@ -400,45 +400,34 @@ export default function PublicCollectionGallery() {
setFieldError,
) => {
try {
- const cryptoWorker = await sharedCryptoWorker();
- let passwordHash: string = null;
- try {
- const publicUrl = publicCollection.publicURLs[0];
- passwordHash = await cryptoWorker.deriveKey(
- password,
- publicUrl.nonce,
- publicUrl.opsLimit,
- publicUrl.memLimit,
- );
- } catch (e) {
- log.error("failed to derive key for verifyLinkPassword", e);
- setFieldError(`${t("generic_error_retry")} ${e.message}`);
- return;
- }
+ const jwtToken = await verifyPublicAlbumPassword(
+ publicCollection.publicURLs[0]!,
+ password,
+ token.current,
+ );
+ passwordJWTToken.current = jwtToken;
+ downloadManager.setPublicAlbumsCredentials(
+ token.current,
+ passwordJWTToken.current,
+ );
const collectionUID = getPublicCollectionUID(token.current);
- try {
- const jwtToken = await verifyPublicCollectionPassword(
- passwordHash,
- token.current,
- );
- passwordJWTToken.current = jwtToken;
- downloadManager.setPublicAlbumsCredentials(
- token.current,
- passwordJWTToken.current,
- );
- await savePublicCollectionPassword(collectionUID, jwtToken);
- } catch (e) {
- if (isHTTP401Error(e)) {
- setFieldError(t("INCORRECT_PASSPHRASE"));
- return;
- }
- throw e;
+ await savePublicCollectionPassword(collectionUID, jwtToken);
+ } catch (e) {
+ log.error("Failed to verifyLinkPassword", e);
+ if (isHTTP401Error(e)) {
+ setFieldError(t("INCORRECT_PASSPHRASE"));
+ } else {
+ setFieldError(t("generic_error_retry"));
}
+ return;
+ }
+
+ try {
await syncWithRemote();
hideLoadingBar();
} catch (e) {
- log.error("failed to verifyLinkPassword", e);
- setFieldError(`${t("generic_error_retry")} ${e.message}`);
+ log.error("Failed to verifyLinkPassword", e);
+ setFieldError(t("generic_error_retry"));
}
};
diff --git a/web/packages/new/albums/services/publicCollection.ts b/web/packages/new/albums/services/publicCollection.ts
index 1003815fae..c9f9c4adf4 100644
--- a/web/packages/new/albums/services/publicCollection.ts
+++ b/web/packages/new/albums/services/publicCollection.ts
@@ -1,29 +1,44 @@
+import { deriveKey } from "@/base/crypto";
import { authenticatedPublicAlbumsRequestHeaders, ensureOk } from "@/base/http";
import { apiURL } from "@/base/origins";
+import type { PublicURL } from "@/media/collection";
import { z } from "zod";
/**
- * Verify with remote that the password (hash) entered by the user is the same
- * as the password that was set by the person who shared the album.
+ * Verify with remote that the password entered by the user is the same as the
+ * password that was set by the person who shared the public album.
*
- * If they match, remote will provide us with another token that can be used to
- * make API calls for this password protected public album. See: [Note: Password
- * token for public albums requests].
+ * The verification is done on a password hash that we check with remote. If
+ * they match, remote will provide us with another token that can be used to
+ * make API calls for this password protected public album.
*
* If they don't match, or if {@link accessToken} itself has expired, then
* remote will return a HTTP 401.
*
- * @param passwordHash The hash of the password entered by the user.
+ * @param publicURL Data about the public album.
+ *
+ * @param password The password entered by the user.
*
* @param token The access token to make API requests for a particular public
* album.
*
- * @returns The password token ("accessTokenJWT").
+ * @returns A accessTokenJWT.
+ *
+ * See [Note: Password token for public albums requests]
*/
-export const verifyPublicCollectionPassword = async (
- passwordHash: string,
+export const verifyPublicAlbumPassword = async (
+ publicURL: PublicURL,
+ password: string,
accessToken: string,
) => {
+ const passwordHash = await deriveKey(
+ password,
+ // TODO: Fix the types to not require the bang.
+ publicURL.nonce!,
+ publicURL.opsLimit!,
+ publicURL.memLimit!,
+ );
+
const res = await fetch(
await apiURL("/public-collection/verify-password"),
{