summaryrefslogtreecommitdiff
path: root/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodTotpSetup.tsx
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-04-13 19:32:12 +0200
committerFlorian Dold <florian@dold.me>2022-04-13 19:32:17 +0200
commit5054ff6c6d200e8d4d7658e001b0bcb1936d6876 (patch)
tree325c7ad151554cc5927c266f0331eb4fdad57516 /packages/anastasis-webui/src/pages/home/authMethod/AuthMethodTotpSetup.tsx
parentec9aed276a5c837a9a93bae2a4c2e61d77256cc1 (diff)
downloadwallet-core-5054ff6c6d200e8d4d7658e001b0bcb1936d6876.tar.gz
wallet-core-5054ff6c6d200e8d4d7658e001b0bcb1936d6876.tar.bz2
wallet-core-5054ff6c6d200e8d4d7658e001b0bcb1936d6876.zip
anastasis-webui: make TOTP work again
Diffstat (limited to 'packages/anastasis-webui/src/pages/home/authMethod/AuthMethodTotpSetup.tsx')
-rw-r--r--packages/anastasis-webui/src/pages/home/authMethod/AuthMethodTotpSetup.tsx13
1 files changed, 9 insertions, 4 deletions
diff --git a/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodTotpSetup.tsx b/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodTotpSetup.tsx
index e0f0cc5e2..a191fb9e6 100644
--- a/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodTotpSetup.tsx
+++ b/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodTotpSetup.tsx
@@ -7,6 +7,11 @@ import { TextInput } from "../../../components/fields/TextInput";
import { QR } from "../../../components/QR";
import { base32enc, computeTOTPandCheck } from "./totp";
+/**
+ * This is hard-coded in the protocol for TOTP auth.
+ */
+const ANASTASIS_TOTP_DIGITS = 8;
+
export function AuthMethodTotpSetup({
addAuthMethod,
cancel,
@@ -14,20 +19,20 @@ export function AuthMethodTotpSetup({
}: AuthMethodSetupProps): VNode {
const [name, setName] = useState("anastasis");
const [test, setTest] = useState("");
- const digits = 8;
const secretKey = useMemo(() => {
const array = new Uint8Array(32);
return window.crypto.getRandomValues(array);
}, []);
+
const secret32 = base32enc(secretKey);
- const totpURL = `otpauth://totp/${name}?digits=${digits}&secret=${secret32}`;
+ const totpURL = `otpauth://totp/${name}?digits=${ANASTASIS_TOTP_DIGITS}&secret=${secret32}`;
const addTotpAuth = (): void =>
addAuthMethod({
authentication_method: {
type: "totp",
- instructions: `Enter ${digits} digits code for "${name}"`,
- challenge: encodeCrock(stringToBytes(totpURL)),
+ instructions: `Enter ${ANASTASIS_TOTP_DIGITS} digits code for "${name}"`,
+ challenge: encodeCrock(secretKey),
},
});