From 56d70da03a82fe5e7d528f08195c77f12f7d61f9 Mon Sep 17 00:00:00 2001 From: Julian Adams Date: Fri, 7 Dec 2018 16:03:33 -0500 Subject: [PATCH] Composer: Filekey for unencrypted external recipients. Closes #592 --- email_composer/src/libs/signal.js | 35 +++----------------------- email_composer/src/utils/AESUtils.js | 5 ---- email_composer/src/utils/EmailUtils.js | 29 --------------------- email_composer/src/utils/FileUtils.js | 26 ------------------- 4 files changed, 4 insertions(+), 91 deletions(-) diff --git a/email_composer/src/libs/signal.js b/email_composer/src/libs/signal.js index b518ffa3a..420cc0c5d 100644 --- a/email_composer/src/libs/signal.js +++ b/email_composer/src/libs/signal.js @@ -14,12 +14,8 @@ import { base64ToWordArray, wordArrayToByteArray, wordArrayToBase64, - byteArrayToWordArray, - textToBase64 + byteArrayToWordArray } from '../utils/AESUtils'; -import { defineTypeSource } from '../utils/FileUtils'; -import { convertToHumanSize } from '../utils/StringUtils'; -import { formExternalAttachmentTemplate } from '../utils/EmailUtils'; import { parseRateLimitBlockingTime } from './../utils/TimeUtils'; const KeyHelper = libsignal.KeyHelper; @@ -224,17 +220,14 @@ const encryptPostEmail = async ({ ]; const hasExternalRecipients = allExternalRecipients.length > 0; - const formattedBody = files - ? addAttachemtsToBody(body, files, fileKeyParams) - : body; - const guestEmail = hasExternalRecipients ? objectUtils.noNulls({ to: externalRecipients.to, cc: externalRecipients.cc, bcc: externalRecipients.bcc, - body: session ? encryptedBody : formattedBody, - session + body: session ? encryptedBody : body, + session, + fileKey: session ? null : externalFileKey }) : null; @@ -379,26 +372,6 @@ const encryptExternalEmail = async ({ }; }; -const addAttachemtsToBody = (body, files, fileKeyParams) => { - const attachmentsSection = files.map(file => { - const { token } = file; - const encodedParams = fileKeyParams - ? textToBase64(`${token}:${fileKeyParams.key}:${fileKeyParams.iv}`) + - '?e=1' - : token; - const mimeTypeSource = defineTypeSource(file.mimeType); - const filename = file.name; - const formattedSize = convertToHumanSize(file.size, true); - return formExternalAttachmentTemplate( - encodedParams, - mimeTypeSource, - filename, - formattedSize - ); - }); - return `${body}
${attachmentsSection.join('')}
`; -}; - export default { encryptPostEmail }; diff --git a/email_composer/src/utils/AESUtils.js b/email_composer/src/utils/AESUtils.js index 61eed7fea..1c1438302 100644 --- a/email_composer/src/utils/AESUtils.js +++ b/email_composer/src/utils/AESUtils.js @@ -69,8 +69,3 @@ export const wordArrayToByteArray = (wordarray, length) => { } return [].concat.apply([], result); }; - -export const textToBase64 = rawText => { - const wordArray = CryptoJS.enc.Utf8.parse(rawText); - return CryptoJS.enc.Base64.stringify(wordArray); -}; diff --git a/email_composer/src/utils/EmailUtils.js b/email_composer/src/utils/EmailUtils.js index 1f3b84953..5bf5b58c9 100644 --- a/email_composer/src/utils/EmailUtils.js +++ b/email_composer/src/utils/EmailUtils.js @@ -317,32 +317,3 @@ export const parseEmailAddress = emailAddressObject => { const parsedEmail = isEmailAddressFromAppDomain ? email.toLowerCase() : email; return { name: emailAddressObject.name, email: parsedEmail }; }; - -export const formExternalAttachmentTemplate = ( - encodedParams, - mimeTypeSource, - filename, - formattedSize -) => { - return ` -
- -
-
-
- -
-
-
- - ${filename} - - - ${formattedSize} - -
-
-
-
- `; -}; diff --git a/email_composer/src/utils/FileUtils.js b/email_composer/src/utils/FileUtils.js index e909b9339..92167a4f8 100644 --- a/email_composer/src/utils/FileUtils.js +++ b/email_composer/src/utils/FileUtils.js @@ -159,29 +159,3 @@ export const setCryptoInterfaces = (keyBase64, ivBase64) => { reader.readAsArrayBuffer(blob); }, null); }; - -export const defineTypeSource = mimetype => { - const [type, subtype] = mimetype.split('/'); - switch (type) { - case 'image': - return 'fileimage'; - case 'audio': - return 'fileaudio'; - case 'video': - return 'filevideo'; - case 'text': { - if (subtype === 'csv') return 'fileexcel'; - return 'filedefault'; - } - case 'application': { - if (subtype === 'pdf') return 'filepdf'; - if (subtype === 'zip') return 'filezip'; - if (officeDocTypes.indexOf(subtype) > -1) return 'fileword'; - if (officeSheetTypes.indexOf(subtype) > -1) return 'fileexcel'; - if (officePptTypes.indexOf(subtype) > -1) return 'fileppt'; - return 'filedefault'; - } - default: - return 'filedefault'; - } -};