π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Finalize twoof3 recovery and help polish
Manav Rathiad06d08fbfa4
diff --git a/web/apps/twoof3/src/features/twoof3/utils/export.ts b/web/apps/twoof3/src/features/twoof3/utils/export.tsindex a68dc5644d..8a2ac64aff 100644--- a/web/apps/twoof3/src/features/twoof3/utils/export.ts+++ b/web/apps/twoof3/src/features/twoof3/utils/export.ts@@ -712,7 +712,7 @@ export const createOfflineRecoveryHtml = async () => {return Uint8Array.from(binary, (char) => char.charCodeAt(0));};const parseShare = (input) => {- const encoded = input.trim();+ const encoded = input.replace(/\\s+/gu, "");if (!encoded.startsWith("2of3-")) throw new Error("That code does not look like a 2of3 share.");const payload = base64UrlDecode(encoded.slice(5));if (payload.length <= HEADER_LENGTH) throw new Error("That share looks incomplete.");@@ -869,7 +869,25 @@ export const createOfflineRecoveryHtml = async () => {}};const fileToText = async (file) => {- if (file.type.startsWith("text/")) return (await file.text()).trim();+ const canBeText =+ file.type.startsWith("text/") ||+ !file.type ||+ /\\.txt$/iu.test(file.name);+ if (canBeText) {+ const text = (await file.text()).trim();+ if (text) {+ try {+ parseShare(text);+ return text;+ } catch {+ if (file.type.startsWith("text/") || /\\.txt$/iu.test(file.name)) {+ throw new Error("That text file does not look like a 2of3 share.");+ }+ }+ } else if (file.type.startsWith("text/") || /\\.txt$/iu.test(file.name)) {+ throw new Error("That text file does not look like a 2of3 share.");+ }+ }const value = decodeQrImage(await imageDataFromFile(file));parseShare(value);return value;@@ -897,7 +915,11 @@ export const createOfflineRecoveryHtml = async () => {};fileInput.addEventListener("change", async (event) => {const file = event.target.files && event.target.files[0];- await applyFile(file);+ try {+ await applyFile(file);+ } finally {+ event.target.value = "";+ }});textarea.addEventListener("input", (event) => {meta.textContent = describeSlotValue(event.target.value.trim());diff --git a/web/apps/twoof3/src/features/twoof3/utils/shamir.ts b/web/apps/twoof3/src/features/twoof3/utils/shamir.tsindex 49ec440443..e3136d0b5d 100644--- a/web/apps/twoof3/src/features/twoof3/utils/shamir.ts+++ b/web/apps/twoof3/src/features/twoof3/utils/shamir.ts@@ -179,7 +179,7 @@ export const splitSecret = (secret: string): SplitShare[] => {};export const parseShare = (input: string): ParsedShare => {- const encoded = input.trim();+ const encoded = input.replace(/\s+/gu, "");if (!encoded.startsWith(SHARE_PREFIX)) {throw new Error("That code does not look like a 2of3 share.");}diff --git a/web/apps/twoof3/src/pages/index.tsx b/web/apps/twoof3/src/pages/index.tsxindex 1a5550b6e1..cb5fb1ea0c 100644--- a/web/apps/twoof3/src/pages/index.tsx+++ b/web/apps/twoof3/src/pages/index.tsx@@ -144,6 +144,32 @@ const HELP_FAQS = [question: "Does this send my secret to Ente?",answer: "No. Your secret is split and recovered in your browser. The downloaded recovery page also works fully offline.",},+ {+ question: "What if 2of3.ente.io is unavailable?",+ answer: (+ <>+ A fully offline HTML recovery page is included when you use+ {" "}"Download all cards". Open that file locally,+ add any two matching cards, and recover without needing the+ site. 2of3 is also{" "}+ <Box+ component="a"+ href="https://github.com/ente-io/ente"+ target="_blank"+ rel="noreferrer"+ sx={{+ color: "inherit",+ textDecorationColor: "currentColor",+ textUnderlineOffset: "0.14em",+ }}+ >+ open source+ </Box>+ , so the format is inspectable and recovery is not locked to+ one hosted service.+ </>+ ),+ },{question: "What if I need to change the secret?",answer: "Treat it as a new set. Make three fresh cards and replace the old ones together. Do not mix cards from different IDs.",@@ -156,6 +182,10 @@ const HELP_FAQS = [question: "All this sounds magical, how does it work?",answer: "It uses Shamir secret sharing. Your secret is split into three shares in a way where mathematically any two parts reconstruct it while one alone reveals nothing. Think of it like a lock which needs 2 of 3 keys to open.",},+ {+ question: "Should I test recovery before storing the cards?",+ answer: "Yes. Before you put the cards away, try recovering the secret once with any two of them. It is the quickest way to catch a bad print, a saving mistake, or a card from the wrong set.",+ },{question: "Is the source code open?",answer: (@@ -210,10 +240,12 @@ const HELP_CARD_LAYOUTS = [{ offset: "0rem", span: 7, tone: "soft" },{ offset: "0rem", span: 6, tone: "plain" },{ offset: "1.2rem", span: 6, tone: "accent" },- { offset: "0rem", span: 4, tone: "soft" },{ offset: "1rem", span: 8, tone: "plain" },+ { offset: "0rem", span: 4, tone: "soft" },{ offset: "0.45rem", span: 5, tone: "plain" },{ offset: "1.35rem", span: 7, tone: "soft" },+ { offset: "0.25rem", span: 6, tone: "plain" },+ { offset: "0.95rem", span: 6, tone: "accent" },] as const;const recoverSlotLabel = (index: number) =>@@ -615,8 +647,32 @@ const describeRecoverSlot = (value: string): RecoverSlotDetails | null => {};const readShareFile = async (file: File) => {- if (file.type.startsWith("text/")) {- return (await file.text()).trim();+ const canBeText =+ file.type.startsWith("text/") ||+ !file.type ||+ /\.txt$/iu.test(file.name);++ if (canBeText) {+ const text = (await file.text()).trim();+ if (!text) {+ if (file.type.startsWith("text/") || /\.txt$/iu.test(file.name)) {+ throw new Error("That text file does not look like a 2of3 share.");+ }+ } else {+ try {+ parseShare(text);+ return text;+ } catch {+ if (+ file.type.startsWith("text/") ||+ /\.txt$/iu.test(file.name)+ ) {+ throw new Error(+ "That text file does not look like a 2of3 share.",+ );+ }+ }+ }}return decodeQrFromFile(file);@@ -1146,6 +1202,16 @@ const Page = () => {different places.</Typography>+ <Typography+ sx={{+ color: "var(--muted)",+ maxWidth: 360,+ fontSize: "0.98rem",+ }}+ >+ Your secret never leaves your browser.+ </Typography>+<TextFieldlabel="Secret"multiline@@ -1401,7 +1467,7 @@ const Page = () => {fontSize: "0.82rem",}}>- Recover later+ Recover</Typography></Box>