Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat: 6 digit code, no TV error

httpjamesm1560cde91003
diff --git a/apps/cast/src/pages/index.tsx b/apps/cast/src/pages/index.tsx
index c36df48519..25a897fb89 100644
--- a/apps/cast/src/pages/index.tsx
+++ b/apps/cast/src/pages/index.tsx
@@ -1,9 +1,13 @@
import { useEffect, useState } from 'react';
import _sodium from 'libsodium-wrappers';
-import { getKexValue, setKexValue } from 'services/kexService';
-import { boxSealOpen, fromB64, toB64 } from 'utils/crypto/libsodium';
+import { getKexValue, setKexValue } from '@ente/shared/network/kexService';
+import {
+ boxSealOpen,
+ fromB64,
+ toB64,
+} from '@ente/shared/crypto/internal/libsodium';
import { useRouter } from 'next/router';
-import { SESSION_KEYS, setKey } from 'utils/storage/sessionStorage';
+import { SESSION_KEYS, setKey } from '@ente/shared/storage/sessionStorage';
const colourPool = [
'#87CEFA', // Light Blue
@@ -29,23 +33,23 @@ const colourPool = [
];
export default function PairingMode() {
- // Function to generate cryptographically secure data
+ // Function to generate cryptographically secure digits
const generateSecureData = (length: number): Uint8Array => {
const array = new Uint8Array(length);
window.crypto.getRandomValues(array);
- // Modulo operation to ensure each byte is a single hex digit
+ // Modulo operation to ensure each byte is a single digit
for (let i = 0; i < length; i++) {
- array[i] = array[i] % 16;
+ array[i] = array[i] % 10;
}
return array;
};
- const convertDataToHex = (data: Uint8Array): string => {
- let hex = '';
+ const convertDataToDecimalString = (data: Uint8Array): string => {
+ let decimalString = '';
for (let i = 0; i < data.length; i++) {
- hex += data[i].toString(16).padStart(2, '0');
+ decimalString += data[i].toString(); // No need to pad, as each value is a single digit
}
- return hex;
+ return decimalString;
};
const [digits, setDigits] = useState<string[]>([]);
@@ -64,8 +68,8 @@ export default function PairingMode() {
}, []);
const init = async () => {
- const data = generateSecureData(4);
- setDigits(convertDataToHex(data).split(''));
+ const data = generateSecureData(6);
+ setDigits(convertDataToDecimalString(data).split(''));
const keypair = await generateKeyPair();
setPublicKeyB64(await toB64(keypair.publicKey));
@@ -186,6 +190,8 @@ export default function PairingMode() {
fontWeight: 'bold',
fontFamily: 'monospace',
display: 'flex',
+ borderRadius: '10px',
+ overflow: 'hidden',
}}>
{digits.map((digit, i) => (
<tr
diff --git a/apps/photos/public/locales/en/translation.json b/apps/photos/public/locales/en/translation.json
index 36d6f702d8..21ef9aa19b 100644
--- a/apps/photos/public/locales/en/translation.json
+++ b/apps/photos/public/locales/en/translation.json
@@ -625,5 +625,6 @@
"INDEXED_ITEMS": "Indexed items",
"CAST_ALBUM_TO_TV": "Play album on TV",
"ENTER_CAST_PIN_CODE": "Enter the code you see on the TV below to pair this device.",
- "PAIR_DEVICE_TO_TV": "Pair devices"
+ "PAIR_DEVICE_TO_TV": "Pair devices",
+ "TV_NOT_FOUND": "TV not found. Did you enter the PIN correctly?"
}
diff --git a/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx b/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx
index 3e21de8406..43727f79b0 100644
--- a/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx
+++ b/apps/photos/src/components/Collections/CollectionOptions/AlbumCastDialog.tsx
@@ -4,7 +4,7 @@ import SingleInputForm, {
SingleInputFormProps,
} from '@ente/shared/components/SingleInputForm';
import { t } from 'i18next';
-import { getKexValue, setKexValue } from 'services/kexService';
+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';
@@ -14,6 +14,10 @@ interface Props {
currentCollectionId: number;
}
+enum AlbumCastError {
+ TV_NOT_FOUND = 'TV_NOT_FOUND',
+}
+
export default function AlbumCastDialog(props: Props) {
const onSubmit: SingleInputFormProps['callback'] = async (
value,
@@ -23,7 +27,18 @@ export default function AlbumCastDialog(props: Props) {
await doCast(value);
props.onHide();
} catch (e) {
- setFieldError(t('UNKNOWN_ERROR'));
+ const error = e as Error;
+ let fieldError: string;
+ switch (error.message) {
+ case AlbumCastError.TV_NOT_FOUND:
+ fieldError = t('TV_NOT_FOUND');
+ break;
+ default:
+ fieldError = t('UNKNOWN_ERROR');
+ break;
+ }
+
+ setFieldError(fieldError);
}
};
@@ -33,7 +48,7 @@ export default function AlbumCastDialog(props: Props) {
const tvPublicKeyB64 = await getKexValue(tvPublicKeyKexKey);
if (!tvPublicKeyB64) {
- throw new Error('Failed to get TV public key');
+ throw new Error(AlbumCastError.TV_NOT_FOUND);
}
// ok, they exist. let's give them the good stuff.
@@ -43,20 +58,13 @@ export default function AlbumCastDialog(props: Props) {
targetCollectionId: props.currentCollectionId,
});
- 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);
};