chore: Revert encrypted file description (#5668)
This commit is contained in:
parent
77d32f4747
commit
7cacd11e61
|
@ -95,21 +95,16 @@ export const RecordAudio = (): ReactElement | null => {
|
||||||
try {
|
try {
|
||||||
if (!rid) return;
|
if (!rid) return;
|
||||||
setRecordingAudio(false);
|
setRecordingAudio(false);
|
||||||
const fileURI = recordingRef.current?.getURI() as string;
|
const fileURI = recordingRef.current?.getURI();
|
||||||
const fileData = await getInfoAsync(fileURI);
|
const fileData = await getInfoAsync(fileURI as string);
|
||||||
|
const fileInfo = {
|
||||||
if (!fileData.exists) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileInfo: IUpload = {
|
|
||||||
rid,
|
|
||||||
name: `${Date.now()}${RECORDING_EXTENSION}`,
|
name: `${Date.now()}${RECORDING_EXTENSION}`,
|
||||||
|
mime: 'audio/aac',
|
||||||
type: 'audio/aac',
|
type: 'audio/aac',
|
||||||
store: 'Uploads',
|
store: 'Uploads',
|
||||||
path: fileURI,
|
path: fileURI,
|
||||||
size: fileData.size
|
size: fileData.exists ? fileData.size : null
|
||||||
};
|
} as IUpload;
|
||||||
|
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
if (permissionToUpload) {
|
if (permissionToUpload) {
|
||||||
|
|
|
@ -55,14 +55,14 @@ const AttachedActions = ({ attachment, getCustomEmoji }: { attachment: IAttachme
|
||||||
|
|
||||||
const Attachments: React.FC<IMessageAttachments> = React.memo(
|
const Attachments: React.FC<IMessageAttachments> = React.memo(
|
||||||
({ attachments, timeFormat, showAttachment, style, getCustomEmoji, isReply, author }: IMessageAttachments) => {
|
({ attachments, timeFormat, showAttachment, style, getCustomEmoji, isReply, author }: IMessageAttachments) => {
|
||||||
const { translateLanguage, isEncrypted } = useContext(MessageContext);
|
const { translateLanguage } = useContext(MessageContext);
|
||||||
|
|
||||||
if (!attachments || attachments.length === 0) {
|
if (!attachments || attachments.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const attachmentsElements = attachments.map((file: IAttachment, index: number) => {
|
const attachmentsElements = attachments.map((file: IAttachment, index: number) => {
|
||||||
const msg = isEncrypted ? '' : getMessageFromAttachment(file, translateLanguage);
|
const msg = getMessageFromAttachment(file, translateLanguage);
|
||||||
if (file && file.image_url) {
|
if (file && file.image_url) {
|
||||||
return (
|
return (
|
||||||
<Image
|
<Image
|
||||||
|
|
|
@ -428,8 +428,7 @@ class MessageContainer extends React.Component<IMessageContainerProps, IMessageC
|
||||||
threadBadgeColor,
|
threadBadgeColor,
|
||||||
toggleFollowThread,
|
toggleFollowThread,
|
||||||
replies,
|
replies,
|
||||||
translateLanguage: canTranslateMessage ? autoTranslateLanguage : undefined,
|
translateLanguage: canTranslateMessage ? autoTranslateLanguage : undefined
|
||||||
isEncrypted: this.isEncrypted
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* @ts-ignore*/}
|
{/* @ts-ignore*/}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import Model from '@nozbe/watermelondb/Model';
|
import Model from '@nozbe/watermelondb/Model';
|
||||||
|
|
||||||
import { E2EType, MessageType } from './IMessage';
|
|
||||||
|
|
||||||
export interface IUpload {
|
export interface IUpload {
|
||||||
id?: string;
|
id?: string;
|
||||||
rid: string;
|
rid?: string;
|
||||||
path: string;
|
path: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
tmid?: string;
|
tmid?: string;
|
||||||
|
@ -16,8 +14,6 @@ export interface IUpload {
|
||||||
error?: boolean;
|
error?: boolean;
|
||||||
subscription?: { id: string };
|
subscription?: { id: string };
|
||||||
msg?: string;
|
msg?: string;
|
||||||
t?: MessageType;
|
|
||||||
e2e?: E2EType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TUploadModel = IUpload & Model;
|
export type TUploadModel = IUpload & Model;
|
||||||
|
|
|
@ -11,15 +11,7 @@ import log from '../methods/helpers/log';
|
||||||
import { store } from '../store/auxStore';
|
import { store } from '../store/auxStore';
|
||||||
import { joinVectorData, randomPassword, splitVectorData, toString, utf8ToBuffer } from './utils';
|
import { joinVectorData, randomPassword, splitVectorData, toString, utf8ToBuffer } from './utils';
|
||||||
import { EncryptionRoom } from './index';
|
import { EncryptionRoom } from './index';
|
||||||
import {
|
import { IMessage, ISubscription, TMessageModel, TSubscriptionModel, TThreadMessageModel, TThreadModel } from '../../definitions';
|
||||||
IMessage,
|
|
||||||
ISubscription,
|
|
||||||
IUpload,
|
|
||||||
TMessageModel,
|
|
||||||
TSubscriptionModel,
|
|
||||||
TThreadMessageModel,
|
|
||||||
TThreadModel
|
|
||||||
} from '../../definitions';
|
|
||||||
import {
|
import {
|
||||||
E2E_BANNER_TYPE,
|
E2E_BANNER_TYPE,
|
||||||
E2E_MESSAGE_TYPE,
|
E2E_MESSAGE_TYPE,
|
||||||
|
@ -29,7 +21,6 @@ import {
|
||||||
E2E_STATUS
|
E2E_STATUS
|
||||||
} from '../constants';
|
} from '../constants';
|
||||||
import { Services } from '../services';
|
import { Services } from '../services';
|
||||||
import { compareServerVersion } from '../methods/helpers';
|
|
||||||
|
|
||||||
class Encryption {
|
class Encryption {
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
|
@ -43,7 +34,6 @@ class Encryption {
|
||||||
handshake: Function;
|
handshake: Function;
|
||||||
decrypt: Function;
|
decrypt: Function;
|
||||||
encrypt: Function;
|
encrypt: Function;
|
||||||
encryptUpload: Function;
|
|
||||||
importRoomKey: Function;
|
importRoomKey: Function;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -285,7 +275,7 @@ class Encryption {
|
||||||
];
|
];
|
||||||
toDecrypt = (await Promise.all(
|
toDecrypt = (await Promise.all(
|
||||||
toDecrypt.map(async message => {
|
toDecrypt.map(async message => {
|
||||||
const { t, msg, tmsg, attachments } = message;
|
const { t, msg, tmsg } = message;
|
||||||
let newMessage: TMessageModel = {} as TMessageModel;
|
let newMessage: TMessageModel = {} as TMessageModel;
|
||||||
if (message.subscription) {
|
if (message.subscription) {
|
||||||
const { id: rid } = message.subscription;
|
const { id: rid } = message.subscription;
|
||||||
|
@ -294,8 +284,7 @@ class Encryption {
|
||||||
t,
|
t,
|
||||||
rid,
|
rid,
|
||||||
msg: msg as string,
|
msg: msg as string,
|
||||||
tmsg,
|
tmsg
|
||||||
attachments
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,7 +434,7 @@ class Encryption {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Encrypt a message
|
// Encrypt a message
|
||||||
encryptMessage = async (message: IMessage | IUpload) => {
|
encryptMessage = async (message: IMessage) => {
|
||||||
const { rid } = message;
|
const { rid } = message;
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const subCollection = db.get('subscriptions');
|
const subCollection = db.get('subscriptions');
|
||||||
|
@ -467,11 +456,6 @@ class Encryption {
|
||||||
}
|
}
|
||||||
|
|
||||||
const roomE2E = await this.getRoomInstance(rid);
|
const roomE2E = await this.getRoomInstance(rid);
|
||||||
|
|
||||||
const { version: serverVersion } = store.getState().server;
|
|
||||||
if ('path' in message && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.8.0')) {
|
|
||||||
return roomE2E.encryptUpload(message);
|
|
||||||
}
|
|
||||||
return roomE2E.encrypt(message);
|
return roomE2E.encrypt(message);
|
||||||
} catch {
|
} catch {
|
||||||
// Subscription not found
|
// Subscription not found
|
||||||
|
@ -483,7 +467,7 @@ class Encryption {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Decrypt a message
|
// Decrypt a message
|
||||||
decryptMessage = async (message: Pick<IMessage, 't' | 'e2e' | 'rid' | 'msg' | 'tmsg' | 'attachments'>) => {
|
decryptMessage = async (message: Pick<IMessage, 't' | 'e2e' | 'rid' | 'msg' | 'tmsg'>) => {
|
||||||
const { t, e2e } = message;
|
const { t, e2e } = message;
|
||||||
|
|
||||||
// Prevent create a new instance if this room was encrypted sometime ago
|
// Prevent create a new instance if this room was encrypted sometime ago
|
||||||
|
|
|
@ -5,7 +5,7 @@ import ByteBuffer from 'bytebuffer';
|
||||||
import parse from 'url-parse';
|
import parse from 'url-parse';
|
||||||
|
|
||||||
import getSingleMessage from '../methods/getSingleMessage';
|
import getSingleMessage from '../methods/getSingleMessage';
|
||||||
import { IMessage, IUpload, IUser } from '../../definitions';
|
import { IMessage, IUser } from '../../definitions';
|
||||||
import Deferred from './helpers/deferred';
|
import Deferred from './helpers/deferred';
|
||||||
import { debounce } from '../methods/helpers';
|
import { debounce } from '../methods/helpers';
|
||||||
import database from '../database';
|
import database from '../database';
|
||||||
|
@ -243,38 +243,8 @@ export default class EncryptionRoom {
|
||||||
return message;
|
return message;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Encrypt upload
|
|
||||||
encryptUpload = async (message: IUpload) => {
|
|
||||||
if (!this.ready) {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
let description = '';
|
|
||||||
|
|
||||||
if (message.description) {
|
|
||||||
description = await this.encryptText(EJSON.stringify({ text: message.description }));
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...message,
|
|
||||||
t: E2E_MESSAGE_TYPE,
|
|
||||||
e2e: E2E_STATUS.PENDING,
|
|
||||||
description
|
|
||||||
};
|
|
||||||
} catch {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
return message;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Decrypt text
|
// Decrypt text
|
||||||
decryptText = async (msg: string | ArrayBuffer) => {
|
decryptText = async (msg: string | ArrayBuffer) => {
|
||||||
if (!msg) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = b64ToBuffer(msg.slice(12) as string);
|
msg = b64ToBuffer(msg.slice(12) as string);
|
||||||
const [vector, cipherText] = splitVectorData(msg);
|
const [vector, cipherText] = splitVectorData(msg);
|
||||||
|
|
||||||
|
@ -305,10 +275,6 @@ export default class EncryptionRoom {
|
||||||
tmsg = await this.decryptText(tmsg);
|
tmsg = await this.decryptText(tmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.attachments?.length) {
|
|
||||||
message.attachments[0].description = await this.decryptText(message.attachments[0].description as string);
|
|
||||||
}
|
|
||||||
|
|
||||||
const decryptedMessage: IMessage = {
|
const decryptedMessage: IMessage = {
|
||||||
...message,
|
...message,
|
||||||
tmsg,
|
tmsg,
|
||||||
|
|
|
@ -4,16 +4,12 @@ import isEmpty from 'lodash/isEmpty';
|
||||||
import { FetchBlobResponse, StatefulPromise } from 'rn-fetch-blob';
|
import { FetchBlobResponse, StatefulPromise } from 'rn-fetch-blob';
|
||||||
import { Alert } from 'react-native';
|
import { Alert } from 'react-native';
|
||||||
|
|
||||||
import { Encryption } from '../encryption';
|
|
||||||
import { IUpload, IUser, TUploadModel } from '../../definitions';
|
import { IUpload, IUser, TUploadModel } from '../../definitions';
|
||||||
import i18n from '../../i18n';
|
import i18n from '../../i18n';
|
||||||
import database from '../database';
|
import database from '../database';
|
||||||
import FileUpload from './helpers/fileUpload';
|
import FileUpload from './helpers/fileUpload';
|
||||||
import { IFileUpload } from './helpers/fileUpload/interfaces';
|
import { IFileUpload } from './helpers/fileUpload/interfaces';
|
||||||
import log from './helpers/log';
|
import log from './helpers/log';
|
||||||
import { E2E_MESSAGE_TYPE } from '../constants';
|
|
||||||
import { store } from '../store/auxStore';
|
|
||||||
import { compareServerVersion } from './helpers';
|
|
||||||
|
|
||||||
const uploadQueue: { [index: string]: StatefulPromise<FetchBlobResponse> } = {};
|
const uploadQueue: { [index: string]: StatefulPromise<FetchBlobResponse> } = {};
|
||||||
|
|
||||||
|
@ -89,8 +85,6 @@ export function sendFileMessage(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const encryptedFileInfo = await Encryption.encryptMessage(fileInfo);
|
|
||||||
|
|
||||||
const formData: IFileUpload[] = [];
|
const formData: IFileUpload[] = [];
|
||||||
formData.push({
|
formData.push({
|
||||||
name: 'file',
|
name: 'file',
|
||||||
|
@ -102,7 +96,7 @@ export function sendFileMessage(
|
||||||
if (fileInfo.description) {
|
if (fileInfo.description) {
|
||||||
formData.push({
|
formData.push({
|
||||||
name: 'description',
|
name: 'description',
|
||||||
data: encryptedFileInfo.description
|
data: fileInfo.description
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,18 +114,6 @@ export function sendFileMessage(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { version: serverVersion } = store.getState().server;
|
|
||||||
if (encryptedFileInfo.t === E2E_MESSAGE_TYPE && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.8.0')) {
|
|
||||||
formData.push({
|
|
||||||
name: 't',
|
|
||||||
data: encryptedFileInfo.t
|
|
||||||
});
|
|
||||||
formData.push({
|
|
||||||
name: 'e2e',
|
|
||||||
data: encryptedFileInfo.e2e
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
...RocketChatSettings.customHeaders,
|
...RocketChatSettings.customHeaders,
|
||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
|
|
|
@ -257,7 +257,6 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
return sendFileMessage(
|
return sendFileMessage(
|
||||||
room.rid,
|
room.rid,
|
||||||
{
|
{
|
||||||
rid: room.rid,
|
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
size,
|
size,
|
||||||
|
@ -351,8 +350,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
||||||
selectedMessages,
|
selectedMessages,
|
||||||
onSendMessage: this.send,
|
onSendMessage: this.send,
|
||||||
onRemoveQuoteMessage: this.onRemoveQuoteMessage
|
onRemoveQuoteMessage: this.onRemoveQuoteMessage
|
||||||
}}
|
}}>
|
||||||
>
|
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Preview
|
<Preview
|
||||||
// using key just to reset zoom/move after change selected
|
// using key just to reset zoom/move after change selected
|
||||||
|
|
Loading…
Reference in New Issue