From 3f8351442709763e535ae1b288061f12833d5686 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Sun, 1 May 2022 20:56:30 +0530 Subject: [PATCH] Fix #514 --- .../emoji-verification/EmojiVerification.jsx | 51 +++++++++++++++---- src/app/organisms/settings/KeyBackup.jsx | 2 +- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/app/organisms/emoji-verification/EmojiVerification.jsx b/src/app/organisms/emoji-verification/EmojiVerification.jsx index f56a467..d1d3325 100644 --- a/src/app/organisms/emoji-verification/EmojiVerification.jsx +++ b/src/app/organisms/emoji-verification/EmojiVerification.jsx @@ -7,6 +7,8 @@ import { twemojify } from '../../../util/twemojify'; import initMatrix from '../../../client/initMatrix'; import cons from '../../../client/state/cons'; import navigation from '../../../client/state/navigation'; +import { hasPrivateKey } from '../../../client/state/secretStorageKeys'; +import { getDefaultSSKey, isCrossVerified } from '../../../util/matrixUtil'; import Text from '../../atoms/text/Text'; import IconButton from '../../atoms/button/IconButton'; @@ -16,35 +18,61 @@ import Dialog from '../../molecules/dialog/Dialog'; import CrossIC from '../../../../public/res/ic/outlined/cross.svg'; import { useStore } from '../../hooks/useStore'; +import { accessSecretStorage } from '../settings/SecretStorageAccess'; function EmojiVerificationContent({ request, requestClose }) { const [sas, setSas] = useState(null); const [process, setProcess] = useState(false); + const mx = initMatrix.matrixClient; const mountStore = useStore(); - mountStore.setItem(true); - - const handleChange = () => { - if (request.done || request.cancelled) requestClose(); - }; useEffect(() => { mountStore.setItem(true); + const handleChange = () => { + if (request.done || request.cancelled) requestClose(); + }; + if (request === null) return null; const req = request; req.on('change', handleChange); - return () => req.off('change', handleChange); + return () => { + req.off('change', handleChange); + if (!req.cancelled && !req.done) { + req.cancel(); + } + }; }, [request]); const acceptRequest = async () => { + if (isCrossVerified(mx.deviceId) && !hasPrivateKey(getDefaultSSKey())) { + const keyData = await accessSecretStorage('Session verification'); + if (!keyData) { + request.cancel(); + return; + } + } setProcess(true); await request.accept(); - const verifier = request.beginKeyVerification('m.sas.v1'); - verifier.on('show_sas', (data) => { + let targetDevice; + try { + targetDevice = request.targetDevice; + } catch { + targetDevice = { + userId: mx.getUserId(), + deviceId: request.channel.devices[0], + }; + } + + const verifier = request.beginKeyVerification('m.sas.v1', targetDevice); + + const handleVerifier = (data) => { + verifier.off('show_sas', handleVerifier); if (!mountStore.getItem()) return; setSas(data); setProcess(false); - }); + }; + verifier.on('show_sas', handleVerifier); await verifier.verify(); }; @@ -70,8 +98,9 @@ function EmojiVerificationContent({ request, requestClose }) {
Confirm the emoji below are displayed on both devices, in the same order:
- {sas.sas.emoji.map((emoji) => ( -
+ {sas.sas.emoji.map((emoji, i) => ( + // eslint-disable-next-line react/no-array-index-key +
{twemojify(emoji[0])} {emoji[1]}
diff --git a/src/app/organisms/settings/KeyBackup.jsx b/src/app/organisms/settings/KeyBackup.jsx index 5d2f4ed..75f032b 100644 --- a/src/app/organisms/settings/KeyBackup.jsx +++ b/src/app/organisms/settings/KeyBackup.jsx @@ -159,9 +159,9 @@ function DeleteKeyBackupDialog({ requestClose }) { const [isDeleting, setIsDeleting] = useState(false); const mx = initMatrix.matrixClient; const mountStore = useStore(); - mountStore.setItem(true); const deleteBackup = async () => { + mountStore.setItem(true); setIsDeleting(true); try { const backupInfo = await mx.getKeyBackupVersion();