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
2022-09-09 17:18:04 +00:00
import { saveAsJson } from '../../utils/saveFile';
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;