1 import { c } from 'ttag';
3 import { Alert, TextLoader } from '@proton/components';
4 import { VERIFICATION_STATUS } from '@proton/crypto';
5 import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
7 import type { SignatureIssueLocation, SignatureIssues } from '../store';
8 import { hasValidAnonymousSignature } from './hasValidAnonymousSignature';
12 signatureIssues: SignatureIssues | undefined;
13 signatureNetworkError?: boolean;
14 signatureAddress: string | undefined;
17 corruptedLink?: boolean;
21 export default function SignatureAlert({
25 signatureNetworkError,
32 <Alert type="info" className={className}>
33 <TextLoader className="m-0">{c('Info').t`Checking signatures`}</TextLoader>
40 <Alert type="warning" className={className}>
42 .t`Unfortunately, it appears that the file or some of its data cannot be decrypted.`}</span>
47 if (signatureNetworkError) {
49 <Alert type="warning" className={className}>
50 <span>{c('Info').t`Signature cannot be validated due to network error, please try again later.`}</span>
55 const validAnonymousSignature =
56 !!signatureIssues && !signatureAddress && hasValidAnonymousSignature(signatureIssues);
59 <Alert type={signatureIssues && !validAnonymousSignature ? 'error' : 'success'} className={className}>
60 <SignatureAlertBody signatureIssues={signatureIssues} signatureAddress={signatureAddress} {...props} />
66 signatureIssues: SignatureIssues | undefined;
67 signatureAddress: string | undefined;
72 export function SignatureAlertBody({ signatureIssues, signatureAddress, isFile, name }: PropsBody) {
74 <strong className="text-break" key="fileName">
79 const emailAddress = (
80 <strong className="text-break" key="signatureAddress" data-testid="signature-address">
81 {signatureAddress || c('Info').t`an anonymous user`}
85 if (!signatureIssues) {
89 ? c('Info').jt`Digital signature verified. This file was securely uploaded by ${emailAddress}.`
90 : c('Info').jt`Digital signature verified. This folder was securely uploaded by ${emailAddress}.`}
95 if (!signatureAddress && hasValidAnonymousSignature(signatureIssues)) {
100 .jt`The digital signature has been partially verified. The file was uploaded from a public page that does not specify a specific user origin.`
102 .jt`The digital signature has been partially verified. The folder was uploaded from a public page that does not specify a specific user origin.`}
107 const locationTranslations: { [key in SignatureIssueLocation]: string } = {
108 passphrase: c('Item').t`keys`,
109 hash: c('Item').t`hash key`,
110 name: c('Item').t`name`,
111 xattrs: c('Item').t`file attributes`,
112 contentKeyPacket: c('Item').t`file data key`,
113 blocks: c('Item').t`file data`,
114 thumbnail: c('Item').t`thumbnail`,
115 manifest: c('Item').t`file data order`,
117 const items = Object.keys(signatureIssues)
118 .map((location) => locationTranslations[location as SignatureIssueLocation])
121 const statuses = Object.values(signatureIssues);
122 const hasNoSignatureIssue = statuses.some((status) => status === VERIFICATION_STATUS.NOT_SIGNED);
123 const hasBadSignatureIssue = statuses.some((status) => status === VERIFICATION_STATUS.SIGNED_AND_INVALID);
127 if (hasNoSignatureIssue && !hasBadSignatureIssue) {
128 if (signatureAddress) {
130 ? c('Info').jt`File is missing signature. We couldn’t verify that ${emailAddress} uploaded ${fileName}.`
132 .jt`Folder is missing signature. We couldn’t verify that ${emailAddress} uploaded ${fileName}.`;
135 ? c('Info').jt`File is missing signature. We couldn’t verify who uploaded ${fileName}.`
136 : c('Info').jt`Folder is missing signature. We couldn’t verify who uploaded ${fileName}.`;
138 textWarning = c('Info').jt`The following may have been tampered with: ${items}. Only open if you trust it.`;
140 if (signatureAddress) {
141 textReason = c('Info').jt`We couldn’t verify that ${emailAddress} uploaded ${fileName}.`;
142 textWarning = c('Info')
143 .jt`The account may have a new key, or the following may have been tampered with: ${items}. Only open if you trust it.`;
145 textReason = c('Info').jt`We couldn’t verify who uploaded ${fileName}.`;
146 textWarning = c('Info').jt`The following may have been tampered with: ${items}. Only open if you trust it.`;
156 <a href={getKnowledgeBaseUrl('/drive-signature-management')} target="_blank">
157 {c('Action').t`Learn more`}