π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix: data encoding/decoding
httpjamesm1aec54a064a7
diff --git a/apps/cast/src/pages/index.tsx b/apps/cast/src/pages/index.tsxindex 2df82064d6..c36df48519 100644--- a/apps/cast/src/pages/index.tsx+++ b/apps/cast/src/pages/index.tsx@@ -1,8 +1,9 @@import { useEffect, useState } from 'react';import _sodium from 'libsodium-wrappers';import { getKexValue, setKexValue } from 'services/kexService';-import { boxSealOpen, toB64 } from 'utils/crypto/libsodium';+import { boxSealOpen, fromB64, toB64 } from 'utils/crypto/libsodium';import { useRouter } from 'next/router';+import { SESSION_KEYS, setKey } from 'utils/storage/sessionStorage';const colourPool = ['#87CEFA', // Light Blue@@ -52,6 +53,7 @@ export default function PairingMode() {const [publicKeyB64, setPublicKeyB64] = useState('');useEffect(() => {+ init();const interval = setInterval(() => {init();}, 45 * 1000); // the kex API deletes keys every 60s, so we'll regenerate stuff prematurely@@ -97,7 +99,13 @@ export default function PairingMode() {privateKeyB64);- const decryptedPayloadObj = JSON.parse(decryptedPayload);+ const nonB64 = await fromB64(decryptedPayload);++ const decryptedPayloadObj = JSON.parse(+ new TextDecoder().decode(nonB64)+ );++ console.log(decryptedPayloadObj);return decryptedPayloadObj;};@@ -106,8 +114,8 @@ export default function PairingMode() {// 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 === 'encryptionKey') {- window.sessionStorage.setItem(key, payloadObj[key]);+ if (key === 'sessionKey') {+ setKey(SESSION_KEYS.ENCRYPTION_KEY, payloadObj[key]);} else {window.localStorage.setItem(key, payloadObj[key]);}diff --git a/apps/cast/src/services/kexService.ts b/apps/cast/src/services/kexService.tsindex 64c1971d5c..4183b3bfe0 100644--- a/apps/cast/src/services/kexService.ts+++ b/apps/cast/src/services/kexService.ts@@ -1,10 +1,13 @@import { logError } from 'utils/sentry';import HTTPService from './HTTPService';+import { getEndpoint } from 'utils/common/apiUtil';++const ENDPOINT = getEndpoint();export const getKexValue = async (key: string) => {let resp;try {- resp = await HTTPService.get(`/kex/get`, {+ resp = await HTTPService.get(`${ENDPOINT}/kex/get`, {identifier: key,});} catch (e) {@@ -17,7 +20,7 @@ export const getKexValue = async (key: string) => {export const setKexValue = async (key: string, value: string) => {try {- await HTTPService.put('/kex/add', {+ await HTTPService.put(ENDPOINT + '/kex/add', {customIdentifier: key,wrappedKey: value,});diff --git a/apps/photos/src/components/Collections/CollectionInfoWithOptions.tsx b/apps/photos/src/components/Collections/CollectionInfoWithOptions.tsxindex 05fd3a308b..9cdb5309f4 100644--- a/apps/photos/src/components/Collections/CollectionInfoWithOptions.tsx+++ b/apps/photos/src/components/Collections/CollectionInfoWithOptions.tsx@@ -75,7 +75,7 @@ export default function CollectionInfoWithOptions({</SpaceBetweenFlex></CollectionInfoBarWrapper><AlbumCastDialog- currentCollectionId={props.activeCollection.id}+ currentCollectionId={props.activeCollection?.id}show={showAlbumCastDialog}onHide={() => setShowAlbumCastDialog(false)}/>diff --git a/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx b/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsxindex 4dd9d34507..3e21de8406 100644--- a/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx+++ b/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx@@ -1,12 +1,12 @@import { Typography } from '@mui/material';-import DialogBoxV2 from 'components/DialogBoxV2';+import DialogBoxV2 from '@ente/shared/components/DialogBoxV2';import SingleInputForm, {SingleInputFormProps,-} from 'components/SingleInputForm';+} from '@ente/shared/components/SingleInputForm';import { t } from 'i18next';import { getKexValue, setKexValue } from 'services/kexService';-import { boxSeal } from 'utils/crypto/libsodium';-import { SESSION_KEYS, getKey } from 'utils/storage/sessionStorage';+import { SESSION_KEYS, getKey } from '@ente/shared/storage/sessionStorage';+import { boxSeal, toB64 } from '@ente/shared/crypto/internal/libsodium';interface Props {show: boolean;@@ -43,10 +43,20 @@ export default function AlbumCastDialog(props: Props) {targetCollectionId: props.currentCollectionId,});- const encryptedPayload = await boxSeal(payload, tvPublicKeyB64);+ console.log('payload created', payload);+ console.log('tv public key b64', tvPublicKeyB64);++ const encryptedPayload = await boxSeal(+ await toB64(new TextEncoder().encode(payload)),+ tvPublicKeyB64+ );++ console.log('payload encrypted', encryptedPayload);const encryptedPayloadForTvKexKey = `${pin}_payload`;+ console.log('setting kex');+// hey TV, we acknowlege you!await setKexValue(encryptedPayloadForTvKexKey, encryptedPayload);};diff --git a/apps/photos/src/services/kexService.ts b/apps/photos/src/services/kexService.tsindex 64c1971d5c..8a583b488b 100644--- a/apps/photos/src/services/kexService.ts+++ b/apps/photos/src/services/kexService.ts@@ -1,10 +1,13 @@-import { logError } from 'utils/sentry';-import HTTPService from './HTTPService';+import HTTPService from '@ente/shared/network/HTTPService';+import { getEndpoint } from '@ente/shared/network/api';+import { logError } from '@ente/shared/sentry';++const ENDPOINT = getEndpoint();export const getKexValue = async (key: string) => {let resp;try {- resp = await HTTPService.get(`/kex/get`, {+ resp = await HTTPService.get(`${ENDPOINT}/kex/get`, {identifier: key,});} catch (e) {@@ -17,7 +20,7 @@ export const getKexValue = async (key: string) => {export const setKexValue = async (key: string, value: string) => {try {- await HTTPService.put('/kex/add', {+ await HTTPService.put(ENDPOINT + '/kex/add', {customIdentifier: key,wrappedKey: value,});