From 862f8a8e146e43e2e0c3ea4477cca54dbb83e464 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 12 May 2021 10:15:09 +1000 Subject: [PATCH 1/2] accept a closed group NEW encryption keypair even if group exists --- ts/receiver/closedGroups.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ts/receiver/closedGroups.ts b/ts/receiver/closedGroups.ts index 7c89425a4..403d7d3a9 100644 --- a/ts/receiver/closedGroups.ts +++ b/ts/receiver/closedGroups.ts @@ -190,10 +190,8 @@ export async function handleNewClosedGroup( const maybeConvo = ConversationController.getInstance().get(groupId); - const groupExists = !!maybeConvo; - - if (groupExists) { - if (maybeConvo && (maybeConvo.get('isKickedFromGroup') || maybeConvo.get('left'))) { + if (maybeConvo) { + if (maybeConvo.get('isKickedFromGroup') || maybeConvo.get('left')) { // TODO: indicate that we've been re-invited // to the group if that is the case @@ -202,8 +200,30 @@ export async function handleNewClosedGroup( maybeConvo.set('left', false); maybeConvo.set('lastJoinedTimestamp', _.toNumber(envelope.timestamp)); } else { - log.warn('Ignoring a closed group message of type NEW: the conversation already exists'); + const ecKeyPairAlreadyExistingConvo = new ECKeyPair( + // tslint:disable: no-non-null-assertion + encryptionKeyPair!.publicKey, + encryptionKeyPair!.privateKey + ); + const isKeyPairAlreadyHere = await isKeyPairAlreadySaved( + groupId, + ecKeyPairAlreadyExistingConvo.toHexKeyPair() + ); + + if (isKeyPairAlreadyHere) { + await getAllEncryptionKeyPairsForGroup(groupId); + window.log.info('Dropping already saved keypair for group', groupId); + await removeFromCache(envelope); + return; + } + + window.log.info(`Received the encryptionKeyPair for new group ${groupId}`); + + await addClosedGroupEncryptionKeyPair(groupId, ecKeyPairAlreadyExistingConvo.toHexKeyPair()); await removeFromCache(envelope); + log.warn( + 'Closed group message of type NEW: the conversation already exists, but we saved the new encryption keypair' + ); return; } } From 81553aed57a7d6165ebc2634fb6e88ff4ce57164 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 27 May 2021 14:41:42 +1000 Subject: [PATCH 2/2] do not overwrite attachment name on sending side Relates #1593 --- ts/models/message.ts | 15 +++------------ ts/types/Attachment.ts | 16 ---------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/ts/models/message.ts b/ts/models/message.ts index 30639d171..1760d6c19 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -19,7 +19,6 @@ import { import autoBind from 'auto-bind'; import { saveMessage } from '../../ts/data/data'; import { ConversationModel, ConversationTypeEnum } from './conversation'; -import { getSuggestedFilenameSending } from '../types/Attachment'; import { actions as conversationActions } from '../state/ducks/conversations'; import { VisibleMessage } from '../session/messages/outgoing/visibleMessage/VisibleMessage'; import { buildSyncMessage } from '../session/utils/syncUtils'; @@ -742,15 +741,7 @@ export class MessageModel extends Backbone.Model { (this.get('attachments') || []).map(window.Signal.Migrations.loadAttachmentData) ); const body = this.get('body'); - const finalAttachments = attachmentsWithData; - - const filenameOverridenAttachments = finalAttachments.map((attachment: any) => ({ - ...attachment, - fileName: getSuggestedFilenameSending({ - attachment, - timestamp: Date.now(), - }), - })); + const finalAttachments = attachmentsWithData as Array; const quoteWithData = await window.Signal.Migrations.loadQuoteData(this.get('quote')); const previewWithData = await window.Signal.Migrations.loadPreviewData(this.get('preview')); @@ -765,7 +756,7 @@ export class MessageModel extends Backbone.Model { // we want to go for the v1, if this is an OpenGroupV1 or not an open group at all if (conversation?.isOpenGroupV2()) { const openGroupV2 = conversation.toOpenGroupV2(); - attachmentPromise = uploadAttachmentsV2(filenameOverridenAttachments, openGroupV2); + attachmentPromise = uploadAttachmentsV2(finalAttachments, openGroupV2); linkPreviewPromise = uploadLinkPreviewsV2(previewWithData, openGroupV2); quotePromise = uploadQuoteThumbnailsV2(openGroupV2, quoteWithData); } else { @@ -774,7 +765,7 @@ export class MessageModel extends Backbone.Model { const openGroupV1 = conversation?.isOpenGroupV1() ? conversation?.toOpenGroupV1() : undefined; attachmentPromise = AttachmentFsV2Utils.uploadAttachmentsToFsV2( - filenameOverridenAttachments, + finalAttachments, openGroupV1 ); linkPreviewPromise = AttachmentFsV2Utils.uploadLinkPreviewsToFsV2( diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index cdb632a37..bc2984fb0 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -346,22 +346,6 @@ export const getSuggestedFilename = ({ return `${prefix}${suffix}${indexSuffix}${extension}`; }; -// Used for overriden the sent filename of an attachment, but keeping the file extension the same -export const getSuggestedFilenameSending = ({ - attachment, - timestamp, -}: { - attachment: AttachmentType; - timestamp?: number | Date; -}): string => { - const prefix = 'session-attachment'; - const suffix = timestamp ? moment(timestamp).format('-YYYY-MM-DD-HHmmss') : ''; - const fileType = getFileExtension(attachment); - const extension = fileType ? `.${fileType}` : ''; - - return `${prefix}${suffix}${extension}`; -}; - export const getFileExtension = (attachment: AttachmentType): string | undefined => { // we override textplain to the extension of the file // for contenttype starting with application, the mimetype is probably wrong so just use the extension of the file instead