Skip to content

Commit

Permalink
feat(obi-1066): added feature flag to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Benz committed Nov 4, 2022
1 parent a9845c2 commit 5a83554
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/api/apiUploadAttachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const apiUploadAttachment = (
sendMailNotification: boolean,
uploadProgress: Function,
handleXhr: (xhr) => void,
isEncrypted: boolean,
skipEncryption: boolean,
signature: ArrayBuffer
) =>
new Promise((resolve, reject) => {
Expand All @@ -33,7 +33,7 @@ export const apiUploadAttachment = (
data.append('file', attachment);
data.append('sendNotification', sendMailNotification.toString());

if (isEncrypted) {
if (!skipEncryption) {
data.append('t', 'e2e');
data.append('fileHeader', toString(signature));
}
Expand Down
10 changes: 8 additions & 2 deletions src/components/message/MessageAttachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ import { useCallback } from 'react';
import { FETCH_METHODS, fetchData } from '../../api';
import { decryptAttachment } from '../../utils/encryptionHelpers';
import { useE2EE } from '../../hooks/useE2EE';
import { useAppConfig } from '../../hooks/useAppConfig';

interface MessageAttachmentProps {
attachment: MessageService.Schemas.AttachmentDTO;
file: MessageService.Schemas.FileDTO;
hasRenderedMessage: boolean;
rid: string;
t?: string;
}

export const MessageAttachment = (props: MessageAttachmentProps) => {
const { t: translate } = useTranslation();
const { key, keyID, encrypted } = useE2EE(props.rid);
const settings = useAppConfig();

const downloadViaJavascript = useCallback(
(url: string) => {
Expand All @@ -37,13 +40,16 @@ export const MessageAttachment = (props: MessageAttachmentProps) => {
return result.text();
})
.then((result: string) => {
const skipDecryption = !encrypted; // TODO CHECK FOR t:e2e PARAM
const hasDecryption =
encrypted &&
props.t === 'e2e' &&
settings.attachmentEncryption;
return decryptAttachment(
result,
props.attachment.title,
keyID,
key,
skipDecryption
!hasDecryption
);
})
.then((file: File) => {
Expand Down
1 change: 1 addition & 0 deletions src/components/message/MessageItemComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ export const MessageItemComponent = ({
attachment={attachment}
rid={rid}
file={file}
t={t}
hasRenderedMessage={hasRenderedMessage}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { useTimeoutOverlay } from '../../hooks/useTimeoutOverlay';
import { SubscriptionKeyLost } from '../session/SubscriptionKeyLost';
import { RoomNotFound } from '../session/RoomNotFound';
import { useDraftMessage } from './useDraftMessage';
import { useAppConfig } from '../../hooks/useAppConfig';

//Linkify Plugin
const omitKey = (key, { [key]: _, ...obj }) => obj;
Expand Down Expand Up @@ -163,6 +164,7 @@ export const MessageSubmitInterfaceComponent = (
const { t: translate } = useTranslation();
const tenant = useTenant();
const history = useHistory();
const settings = useAppConfig();

const textareaInputRef = useRef<HTMLDivElement>(null);
const inputWrapperRef = useRef<HTMLSpanElement>(null);
Expand Down Expand Up @@ -523,11 +525,14 @@ export const MessageSubmitInterfaceComponent = (
if (attachment) {
let res: any;

const skipEncryption =
!isEncrypted || !settings.attachmentEncryption;
const signature = await getSignature(attachment);
const attachmentFile = await encryptAttachment(
attachment,
keyID,
key
key,
skipEncryption
);

res = await apiUploadAttachment(
Expand All @@ -537,7 +542,7 @@ export const MessageSubmitInterfaceComponent = (
getSendMailNotificationStatus(),
setUploadProgress,
setAttachmentUpload,
isEncrypted,
skipEncryption,
signature
).catch((res: XMLHttpRequest) => {
if (res.status === 413) {
Expand Down
2 changes: 2 additions & 0 deletions src/globalState/interfaces/AppConfig/AppSettingsInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export interface AppSettingsInterface {
mainTenantSubdomainForSingleDomainMultitenancy?: string;
/** when enabled shows the overview page */
useOverviewPage?: boolean;
/** when enabled and e2ee is active (see rocket.chat) attachments will be e2e encrypted */
attachmentEncryption?: boolean;
}
1 change: 1 addition & 0 deletions src/resources/scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const config: AppConfigInterface = {
useTenantService: false,
useApiClusterSettings: false, // Feature flag to enable the cluster use the cluster settings instead of the config file
mainTenantSubdomainForSingleDomainMultitenancy: 'app',
attachmentEncryption: true, // Feature flag for attachment end to end encryption - e2e must also be enabled in rocket.chat

urls: {
consultantVideoConference:
Expand Down
5 changes: 3 additions & 2 deletions src/utils/encryptionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ export const getSignature = async (attachment: File): Promise<ArrayBuffer> => {
export const encryptAttachment = async (
attachment: File,
keyID,
key
key,
skipEncryption
): Promise<File> => {
if (!keyID) {
if (!keyID || skipEncryption) {
return attachment;
}

Expand Down

0 comments on commit 5a83554

Please sign in to comment.