Skip to content

Commit

Permalink
Merge pull request #593 from JulianAdams4/update-external
Browse files Browse the repository at this point in the history
Filekey for unencrypted external recipients
  • Loading branch information
erikaperugachi authored Dec 7, 2018
2 parents a1772c8 + 56d70da commit 52fc651
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 91 deletions.
35 changes: 4 additions & 31 deletions email_composer/src/libs/signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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}<br/><div>${attachmentsSection.join('')}</div>`;
};

export default {
encryptPostEmail
};
5 changes: 0 additions & 5 deletions email_composer/src/utils/AESUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
29 changes: 0 additions & 29 deletions email_composer/src/utils/EmailUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
<div style="margin-top: 6px; float: left;">
<a style="cursor: pointer; text-decoration: none;" href="https://services.criptext.com/downloader/${encodedParams}">
<div style="align-items: center; border: 1px solid #e7e5e5; border-radius: 6px; display: flex; height: 20px; margin-right: 20px; padding: 10px; position: relative; width: 236px;">
<div style="position: relative;">
<div style="align-items: center; border-radius: 4px; display: flex; height: 22px; width: 22px;">
<img src="https://cdn.criptext.com/External-Email/imgs/${mimeTypeSource}.png" style="height: 100%; width: 100%;"/>
</div>
</div>
<div style="padding-top: 1px; display: flex; flex-grow: 1; height: 100%; margin-left: 10px; width: calc(100% - 32px);">
<span style="color: black; padding-top: 1px; width: 160px; flex-grow: 1; font-size: 14px; font-weight: 700; overflow: hidden; padding-right: 5px; text-overflow: ellipsis; white-space: nowrap;">
${filename}
</span>
<span style="color: #9b9b9b; flex-grow: 0; font-size: 13px; white-space: nowrap; line-height: 21px;">
${formattedSize}
</span>
</div>
</div>
</a>
</div>
`;
};
26 changes: 0 additions & 26 deletions email_composer/src/utils/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
};

0 comments on commit 52fc651

Please sign in to comment.