robosats/frontend/src/components/Dialogs/AuditPGP.tsx

204 lines
6.0 KiB
TypeScript
Raw Normal View History

2022-09-09 17:18:04 +00:00
import React from 'react';
import { useTranslation } from 'react-i18next';
2022-05-24 12:16:50 +00:00
import {
Dialog,
DialogTitle,
2022-09-09 17:18:04 +00:00
Tooltip,
2022-05-24 12:16:50 +00:00
IconButton,
TextField,
2022-09-09 17:18:04 +00:00
DialogActions,
2022-05-24 12:16:50 +00:00
DialogContent,
DialogContentText,
2022-09-09 17:18:04 +00:00
Button,
2022-05-24 12:16:50 +00:00
Grid,
Link,
2022-09-09 17:18:04 +00:00
} from '@mui/material';
2022-05-24 12:16:50 +00:00
Add Nav Bar, Settings Page, large refactor (#308) commit a5b63aed93e084fae19d9e444e06238a52f24f3a Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Sun Oct 30 10:46:05 2022 -0700 Small fixes commit d64adfc2bf9b9c31dca47ab113c06a1268c347c6 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Sun Oct 30 06:02:06 2022 -0700 wip work on federation settings commit ca35d6b3d2776812b07109e197d2e1d46f9f4e81 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Sun Oct 30 04:05:33 2022 -0700 Refactor confirmation Dialogs commit c660a5b0d1345d4996efb10cb8999987689bede9 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Sat Oct 29 13:36:59 2022 -0700 refactor login (clean separation robot/info. Style navbar. commit b9dc7f7c95a683e3aca024ec6d7857176b4e3a25 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Fri Oct 28 09:54:38 2022 -0700 Add size slider and settings widget commit 20b2b3dcd6838b129741705f1c65d445271e231d Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Fri Oct 28 05:41:48 2022 -0700 Add show more and Dialogs commit da8b70091b5f28139cdec1a8895f4563d64d8e88 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Thu Oct 27 16:26:07 2022 -0700 Add sliding pages commit 6dd90aa1182a7a5e0f0189d1467ba474b68c28c2 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Thu Oct 27 06:34:58 2022 -0700 Add settings forms commit d3d0f3ee1a52bbf1829714050cc798d2542af8f6 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Wed Oct 26 04:16:06 2022 -0700 Refactor utils
2022-10-30 19:13:01 +00:00
import { saveAsJson } from '../../utils';
import { systemClient } from '../../services/System';
2022-05-24 12:16:50 +00:00
// Icons
import KeyIcon from '@mui/icons-material/Key';
2022-09-09 17:18:04 +00:00
import ContentCopy from '@mui/icons-material/ContentCopy';
2022-05-24 12:16:50 +00:00
import ForumIcon from '@mui/icons-material/Forum';
import { ExportIcon, NewTabIcon } from '../Icons';
2022-05-24 12:16:50 +00:00
2022-09-09 17:18:04 +00:00
function CredentialTextfield(props) {
return (
<Grid item align='center' xs={12}>
<Tooltip placement='top' enterTouchDelay={200} enterDelay={200} title={props.tooltipTitle}>
2022-05-24 22:28:36 +00:00
<TextField
2022-09-09 17:18:04 +00:00
sx={{ width: '100%', maxWidth: '550px' }}
2022-05-24 22:28:36 +00:00
disabled
label={<b>{props.label}</b>}
value={props.value}
variant='filled'
size='small'
InputProps={{
2022-09-09 17:18:04 +00:00
endAdornment: (
2022-05-24 22:28:36 +00:00
<Tooltip disableHoverListener enterTouchDelay={0} title={props.copiedTitle}>
<IconButton onClick={() => systemClient.copyToClipboard(props.value)}>
2022-09-09 17:18:04 +00:00
<ContentCopy />
2022-05-24 22:28:36 +00:00
</IconButton>
2022-09-09 17:18:04 +00:00
</Tooltip>
),
}}
/>
2022-05-24 22:28:36 +00:00
</Tooltip>
</Grid>
2022-09-09 17:18:04 +00:00
);
2022-05-24 22:28:36 +00:00
}
interface Props {
2022-05-24 12:16:50 +00:00
open: boolean;
onClose: () => void;
orderId: number;
messages: array;
2022-09-09 17:18:04 +00:00
own_pub_key: string;
2022-05-24 12:16:50 +00:00
own_enc_priv_key: string;
peer_pub_key: string;
passphrase: string;
onClickBack: () => void;
}
2022-05-24 12:16:50 +00:00
const AuditPGPDialog = ({
2022-09-09 17:18:04 +00:00
open,
2022-05-24 12:16:50 +00:00
onClose,
orderId,
messages,
own_pub_key,
own_enc_priv_key,
peer_pub_key,
passphrase,
onClickBack,
}: Props): JSX.Element => {
const { t } = useTranslation();
return (
2022-09-09 17:18:04 +00:00
<Dialog open={open} onClose={onClose}>
<DialogTitle>{t("Don't trust, verify")}</DialogTitle>
2022-05-24 12:16:50 +00:00
<DialogContent>
<DialogContentText>
2022-09-09 17:18:04 +00:00
{t(
'Your communication is end-to-end encrypted with OpenPGP. You can verify the privacy of this chat using any tool based on the OpenPGP standard.',
)}
2022-05-24 12:16:50 +00:00
</DialogContentText>
2022-09-09 17:18:04 +00:00
<Grid container spacing={1} align='center'>
<Grid item align='center' xs={12}>
<Button
component={Link}
target='_blank'
href='https://learn.robosats.com/docs/pgp-encryption'
>
{t('Learn how to verify')} <NewTabIcon sx={{ width: 16, height: 16 }} />
</Button>
2022-05-24 12:16:50 +00:00
</Grid>
2022-09-09 17:18:04 +00:00
<CredentialTextfield
tooltipTitle={t(
'Your PGP public key. Your peer uses it to encrypt messages only you can read.',
)}
label={t('Your public key')}
2022-05-24 22:28:36 +00:00
value={own_pub_key}
2022-09-09 17:18:04 +00:00
copiedTitle={t('Copied!')}
/>
2022-05-24 12:16:50 +00:00
2022-09-09 17:18:04 +00:00
<CredentialTextfield
tooltipTitle={t(
'Your peer PGP public key. You use it to encrypt messages only he can read and to verify your peer signed the incoming messages.',
)}
label={t('Peer public key')}
2022-05-24 22:28:36 +00:00
value={peer_pub_key}
2022-09-09 17:18:04 +00:00
copiedTitle={t('Copied!')}
/>
2022-05-24 12:16:50 +00:00
2022-09-09 17:18:04 +00:00
<CredentialTextfield
tooltipTitle={t(
'Your encrypted private key. You use it to decrypt the messages that your peer encrypted for you. You also use it to sign the messages you send.',
)}
label={t('Your encrypted private key')}
2022-05-24 22:28:36 +00:00
value={own_enc_priv_key}
2022-09-09 17:18:04 +00:00
copiedTitle={t('Copied!')}
/>
2022-05-24 12:16:50 +00:00
2022-09-09 17:18:04 +00:00
<CredentialTextfield
tooltipTitle={t(
'The passphrase to decrypt your private key. Only you know it! Do not share. It is also your robot token.',
)}
label={t('Your private key passphrase (keep secure!)')}
2022-05-24 22:28:36 +00:00
value={passphrase}
2022-09-09 17:18:04 +00:00
copiedTitle={t('Copied!')}
/>
2022-05-24 12:16:50 +00:00
2022-09-09 17:18:04 +00:00
<br />
<Grid item xs={6}>
<Tooltip
placement='top'
enterTouchDelay={0}
enterDelay={1000}
enterNextDelay={2000}
title={t('Save credentials as a JSON file')}
>
<Button
size='small'
color='primary'
variant='contained'
onClick={() =>
saveAsJson('keys_' + orderId + '.json', {
own_public_key: own_pub_key,
peer_public_key: peer_pub_key,
encrypted_private_key: own_enc_priv_key,
passphrase,
2022-09-09 17:18:04 +00:00
})
}
>
<div style={{ width: 26, height: 18 }}>
<ExportIcon sx={{ width: 18, height: 18 }} />
</div>
{t('Keys')}
<div style={{ width: 26, height: 20 }}>
<KeyIcon sx={{ width: 20, height: 20 }} />
</div>
</Button>
</Tooltip>
2022-05-24 12:16:50 +00:00
</Grid>
2022-09-09 17:18:04 +00:00
<Grid item xs={6}>
<Tooltip
placement='top'
enterTouchDelay={0}
enterDelay={1000}
enterNextDelay={2000}
title={t('Save messages as a JSON file')}
>
<Button
size='small'
color='primary'
variant='contained'
onClick={() => saveAsJson('messages_' + orderId + '.json', messages)}
>
<div style={{ width: 28, height: 20 }}>
<ExportIcon sx={{ width: 18, height: 18 }} />
</div>
{t('Messages')}
<div style={{ width: 26, height: 20 }}>
<ForumIcon sx={{ width: 20, height: 20 }} />
</div>
</Button>
</Tooltip>
</Grid>
2022-05-24 12:16:50 +00:00
</Grid>
</DialogContent>
<DialogActions>
2022-09-09 17:18:04 +00:00
<Button onClick={onClickBack} autoFocus>
{t('Go back')}
</Button>
2022-05-24 12:16:50 +00:00
</DialogActions>
</Dialog>
2022-09-09 17:18:04 +00:00
);
};
2022-05-24 12:16:50 +00:00
export default AuditPGPDialog;