"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ts/textsecure/MessageReceiver.ts" between
Signal-Desktop-1.35.2.tar.gz and Signal-Desktop-1.36.1.tar.gz

About: Signal-Desktop is a cross-platform encrypted messaging service (also available for mobile devices).

MessageReceiver.ts  (Signal-Desktop-1.35.2):MessageReceiver.ts  (Signal-Desktop-1.36.1)
skipping to change at line 33 skipping to change at line 33
DataMessageClass, DataMessageClass,
DownloadAttachmentType, DownloadAttachmentType,
EnvelopeClass, EnvelopeClass,
ReceiptMessageClass, ReceiptMessageClass,
SyncMessageClass, SyncMessageClass,
TypingMessageClass, TypingMessageClass,
UnprocessedType, UnprocessedType,
VerifiedClass, VerifiedClass,
} from '../textsecure.d'; } from '../textsecure.d';
import { deriveGroupFields, MASTER_KEY_LENGTH } from '../groups';
const RETRY_TIMEOUT = 2 * 60 * 1000; const RETRY_TIMEOUT = 2 * 60 * 1000;
declare global { declare global {
interface Event { interface Event {
code?: string | number; code?: string | number;
configuration?: any; configuration?: any;
confirm?: () => void; confirm?: () => void;
contactDetails?: any; contactDetails?: any;
count?: number; count?: number;
data?: any; data?: any;
skipping to change at line 438 skipping to change at line 440
const { count } = this; const { count } = this;
const update = () => { const update = () => {
this.updateProgress(count); this.updateProgress(count);
}; };
promise.then(update, update); promise.then(update, update);
return promise; return promise;
} }
hasEmptied(): boolean {
return Boolean(this.isEmptied);
}
onEmpty() { onEmpty() {
const emitEmpty = () => { const emitEmpty = () => {
window.log.info("MessageReceiver: emitting 'empty' event"); window.log.info("MessageReceiver: emitting 'empty' event");
const ev = new Event('empty'); const ev = new Event('empty');
this.dispatchEvent(ev); this.dispatchEvent(ev);
this.isEmptied = true; this.isEmptied = true;
this.maybeScheduleRetryTimeout(); this.maybeScheduleRetryTimeout();
}; };
skipping to change at line 1073 skipping to change at line 1078
message: msg, message: msg,
expirationStartTimestamp, expirationStartTimestamp,
unidentifiedStatus, unidentifiedStatus,
isRecipientUpdate, isRecipientUpdate,
} = sentContainer; } = sentContainer;
if (!msg) { if (!msg) {
throw new Error('MessageReceiver.handleSentMessage: message was falsey!'); throw new Error('MessageReceiver.handleSentMessage: message was falsey!');
} }
if (msg.groupV2) {
window.log.warn(
'MessageReceiver.handleSentMessage: Dropping GroupsV2 message'
);
this.removeFromCache(envelope);
return;
}
let p: Promise<any> = Promise.resolve(); let p: Promise<any> = Promise.resolve();
// eslint-disable-next-line no-bitwise // eslint-disable-next-line no-bitwise
if ( if (
msg.flags && msg.flags &&
msg.flags & window.textsecure.protobuf.DataMessage.Flags.END_SESSION msg.flags & window.textsecure.protobuf.DataMessage.Flags.END_SESSION
) { ) {
const identifier = destination || destinationUuid; const identifier = destination || destinationUuid;
if (!identifier) { if (!identifier) {
throw new Error( throw new Error(
'MessageReceiver.handleSentMessage: Cannot end session with falsey des tination' 'MessageReceiver.handleSentMessage: Cannot end session with falsey des tination'
); );
} }
p = this.handleEndSession(identifier); p = this.handleEndSession(identifier);
} }
return p.then(async () => return p.then(async () =>
this.processDecrypted(envelope, msg).then(message => { this.processDecrypted(envelope, msg).then(message => {
const groupId = message.group && message.group.id; // prettier-ignore
const groupId = this.getGroupId(message);
const isBlocked = this.isGroupBlocked(groupId); const isBlocked = this.isGroupBlocked(groupId);
const { source, sourceUuid } = envelope; const { source, sourceUuid } = envelope;
const ourE164 = window.textsecure.storage.user.getNumber(); const ourE164 = window.textsecure.storage.user.getNumber();
const ourUuid = window.textsecure.storage.user.getUuid(); const ourUuid = window.textsecure.storage.user.getUuid();
const isMe = const isMe =
(source && ourE164 && source === ourE164) || (source && ourE164 && source === ourE164) ||
(sourceUuid && ourUuid && sourceUuid === ourUuid); (sourceUuid && ourUuid && sourceUuid === ourUuid);
const isLeavingGroup = Boolean( const isLeavingGroup = Boolean(
message.group && !message.groupV2 &&
message.group &&
message.group.type === message.group.type ===
window.textsecure.protobuf.GroupContext.Type.QUIT window.textsecure.protobuf.GroupContext.Type.QUIT
); );
if (groupId && isBlocked && !(isMe && isLeavingGroup)) { if (groupId && isBlocked && !(isMe && isLeavingGroup)) {
window.log.warn( window.log.warn(
`Message ${this.getEnvelopeId( `Message ${this.getEnvelopeId(
envelope envelope
)} ignored; destined for blocked group` )} ignored; destined for blocked group`
); );
skipping to change at line 1151 skipping to change at line 1150
window.log.info('data message from', this.getEnvelopeId(envelope)); window.log.info('data message from', this.getEnvelopeId(envelope));
let p: Promise<any> = Promise.resolve(); let p: Promise<any> = Promise.resolve();
// eslint-disable-next-line no-bitwise // eslint-disable-next-line no-bitwise
const destination = envelope.source || envelope.sourceUuid; const destination = envelope.source || envelope.sourceUuid;
if (!destination) { if (!destination) {
throw new Error( throw new Error(
'MessageReceiver.handleDataMessage: source and sourceUuid were falsey' 'MessageReceiver.handleDataMessage: source and sourceUuid were falsey'
); );
} }
if (msg.groupV2) { if (!window.GV2 && msg.groupV2) {
window.log.warn(
'MessageReceiver.handleDataMessage: Dropping GroupsV2 message'
);
this.removeFromCache(envelope); this.removeFromCache(envelope);
window.log.info(
'MessageReceiver.handleDataMessage: dropping GroupV2 message'
);
return; return;
} }
this.deriveGroupsV2Data(msg);
if ( if (
msg.flags && msg.flags &&
msg.flags & window.textsecure.protobuf.DataMessage.Flags.END_SESSION msg.flags & window.textsecure.protobuf.DataMessage.Flags.END_SESSION
) { ) {
p = this.handleEndSession(destination); p = this.handleEndSession(destination);
} }
if ( if (
msg.flags && msg.flags &&
msg.flags & msg.flags &
skipping to change at line 1183 skipping to change at line 1184
ev.data = { ev.data = {
source: envelope.source, source: envelope.source,
sourceUuid: envelope.sourceUuid, sourceUuid: envelope.sourceUuid,
profileKey: msg.profileKey.toString('base64'), profileKey: msg.profileKey.toString('base64'),
}; };
return this.dispatchAndWait(ev); return this.dispatchAndWait(ev);
} }
return p.then(async () => return p.then(async () =>
this.processDecrypted(envelope, msg).then(message => { this.processDecrypted(envelope, msg).then(message => {
const groupId = message.group && message.group.id; // prettier-ignore
const groupId = this.getGroupId(message);
const isBlocked = this.isGroupBlocked(groupId); const isBlocked = this.isGroupBlocked(groupId);
const { source, sourceUuid } = envelope; const { source, sourceUuid } = envelope;
const ourE164 = window.textsecure.storage.user.getNumber(); const ourE164 = window.textsecure.storage.user.getNumber();
const ourUuid = window.textsecure.storage.user.getUuid(); const ourUuid = window.textsecure.storage.user.getUuid();
const isMe = const isMe =
(source && ourE164 && source === ourE164) || (source && ourE164 && source === ourE164) ||
(sourceUuid && ourUuid && sourceUuid === ourUuid); (sourceUuid && ourUuid && sourceUuid === ourUuid);
const isLeavingGroup = Boolean( const isLeavingGroup = Boolean(
message.group && !message.groupV2 &&
message.group &&
message.group.type === message.group.type ===
window.textsecure.protobuf.GroupContext.Type.QUIT window.textsecure.protobuf.GroupContext.Type.QUIT
); );
if (groupId && isBlocked && !(isMe && isLeavingGroup)) { if (groupId && isBlocked && !(isMe && isLeavingGroup)) {
window.log.warn( window.log.warn(
`Message ${this.getEnvelopeId( `Message ${this.getEnvelopeId(
envelope envelope
)} ignored; destined for blocked group` )} ignored; destined for blocked group`
); );
skipping to change at line 1339 skipping to change at line 1342
const typingTimestamp = typingMessage.timestamp.toNumber(); const typingTimestamp = typingMessage.timestamp.toNumber();
if (typingTimestamp !== envelopeTimestamp) { if (typingTimestamp !== envelopeTimestamp) {
window.log.warn( window.log.warn(
`Typing message envelope timestamp (${envelopeTimestamp}) did not matc h typing timestamp (${typingTimestamp})` `Typing message envelope timestamp (${envelopeTimestamp}) did not matc h typing timestamp (${typingTimestamp})`
); );
return null; return null;
} }
} }
const { groupId, timestamp, action } = typingMessage;
ev.sender = envelope.source; ev.sender = envelope.source;
ev.senderUuid = envelope.sourceUuid; ev.senderUuid = envelope.sourceUuid;
ev.senderDevice = envelope.sourceDevice; ev.senderDevice = envelope.sourceDevice;
const groupIdBuffer = groupId ? groupId.toArrayBuffer() : null;
ev.typing = { ev.typing = {
typingMessage, typingMessage,
timestamp: typingMessage.timestamp timestamp: timestamp ? timestamp.toNumber() : Date.now(),
? typingMessage.timestamp.toNumber() groupId:
: Date.now(), groupIdBuffer && groupIdBuffer.byteLength <= 16
groupId: typingMessage.groupId ? groupId.toString('binary')
? typingMessage.groupId.toString('binary') : null,
: null, groupV2Id:
groupIdBuffer && groupIdBuffer.byteLength > 16
? groupId.toString('base64')
: null,
started: started:
typingMessage.action === action === window.textsecure.protobuf.TypingMessage.Action.STARTED,
window.textsecure.protobuf.TypingMessage.Action.STARTED,
stopped: stopped:
typingMessage.action === action === window.textsecure.protobuf.TypingMessage.Action.STOPPED,
window.textsecure.protobuf.TypingMessage.Action.STOPPED,
}; };
return this.dispatchEvent(ev); return this.dispatchEvent(ev);
} }
handleNullMessage(envelope: EnvelopeClass) { handleNullMessage(envelope: EnvelopeClass) {
window.log.info('null message from', this.getEnvelopeId(envelope)); window.log.info('null message from', this.getEnvelopeId(envelope));
this.removeFromCache(envelope); this.removeFromCache(envelope);
} }
deriveGroupsV2Data(message: DataMessageClass) {
const { groupV2 } = message;
if (!groupV2) {
return;
}
if (!isNumber(groupV2.revision)) {
throw new Error('deriveGroupsV2Data: revision was not a number');
}
if (!groupV2.masterKey) {
throw new Error('deriveGroupsV2Data: had falsey masterKey');
}
const toBase64 = MessageReceiverInner.arrayBufferToStringBase64;
const masterKey: ArrayBuffer = groupV2.masterKey.toArrayBuffer();
const length = masterKey.byteLength;
if (length !== MASTER_KEY_LENGTH) {
throw new Error(
`deriveGroupsV2Data: masterKey had length ${length}, expected ${MASTER_K
EY_LENGTH}`
);
}
const fields = deriveGroupFields(masterKey);
groupV2.masterKey = toBase64(masterKey);
groupV2.secretParams = toBase64(fields.secretParams);
groupV2.publicParams = toBase64(fields.publicParams);
groupV2.id = toBase64(fields.id);
if (groupV2.groupChange) {
groupV2.groupChange = groupV2.groupChange.toString('base64');
}
}
getGroupId(message: DataMessageClass) {
if (message.groupV2) {
return message.groupV2.id;
}
if (message.group) {
return message.group.id.toString('binary');
}
return null;
}
getDestination(sentMessage: SyncMessageClass.Sent) {
if (sentMessage.message && sentMessage.message.groupV2) {
return `groupv2(${sentMessage.message.groupV2.id})`;
} else if (sentMessage.message && sentMessage.message.group) {
return `group(${sentMessage.message.group.id.toBinary()})`;
} else {
return sentMessage.destination || sentMessage.destinationUuid;
}
}
// tslint:disable-next-line cyclomatic-complexity // tslint:disable-next-line cyclomatic-complexity
async handleSyncMessage( async handleSyncMessage(
envelope: EnvelopeClass, envelope: EnvelopeClass,
syncMessage: SyncMessageClass syncMessage: SyncMessageClass
) { ) {
const unidentified = syncMessage.sent const unidentified = syncMessage.sent
? syncMessage.sent.unidentifiedStatus || [] ? syncMessage.sent.unidentifiedStatus || []
: []; : [];
window.normalizeUuids( window.normalizeUuids(
syncMessage, syncMessage,
skipping to change at line 1402 skipping to change at line 1465
throw new Error('Received sync message from our own device'); throw new Error('Received sync message from our own device');
} }
if (syncMessage.sent) { if (syncMessage.sent) {
const sentMessage = syncMessage.sent; const sentMessage = syncMessage.sent;
if (!sentMessage || !sentMessage.message) { if (!sentMessage || !sentMessage.message) {
throw new Error( throw new Error(
'MessageReceiver.handleSyncMessage: sync sent message was missing mess age' 'MessageReceiver.handleSyncMessage: sync sent message was missing mess age'
); );
} }
const to = sentMessage.message.group
? `group(${sentMessage.message.group.id.toBinary()})` if (!window.GV2 && sentMessage.message.groupV2) {
: sentMessage.destination || sentMessage.destinationUuid; this.removeFromCache(envelope);
window.log.info(
'MessageReceiver.handleSyncMessage: dropping GroupV2 message'
);
return;
}
this.deriveGroupsV2Data(sentMessage.message);
window.log.info( window.log.info(
'sent message to', 'sent message to',
to, this.getDestination(sentMessage),
sentMessage.timestamp.toNumber(), sentMessage.timestamp.toNumber(),
'from', 'from',
this.getEnvelopeId(envelope) this.getEnvelopeId(envelope)
); );
return this.handleSentMessage(envelope, sentMessage); return this.handleSentMessage(envelope, sentMessage);
} else if (syncMessage.contacts) { } else if (syncMessage.contacts) {
this.handleContacts(envelope, syncMessage.contacts); this.handleContacts(envelope, syncMessage.contacts);
return; return;
} else if (syncMessage.groups) { } else if (syncMessage.groups) {
this.handleGroups(envelope, syncMessage.groups); this.handleGroups(envelope, syncMessage.groups);
skipping to change at line 1885 skipping to change at line 1955
decrypted.group.avatar = this.cleanAttachment(decrypted.group.avatar); decrypted.group.avatar = this.cleanAttachment(decrypted.group.avatar);
} }
} }
decrypted.attachments = (decrypted.attachments || []).map( decrypted.attachments = (decrypted.attachments || []).map(
this.cleanAttachment.bind(this) this.cleanAttachment.bind(this)
); );
decrypted.preview = (decrypted.preview || []).map(item => ({ decrypted.preview = (decrypted.preview || []).map(item => ({
...item, ...item,
date: this.cleanLinkPreviewDate(item.date), date: this.cleanLinkPreviewDate(item.date),
...(item.image ? this.cleanAttachment(item.image) : {}), ...(item.image ? { image: this.cleanAttachment(item.image) } : {}),
})); }));
decrypted.contact = (decrypted.contact || []).map(item => { decrypted.contact = (decrypted.contact || []).map(item => {
const { avatar } = item; const { avatar } = item;
if (!avatar || !avatar.avatar) { if (!avatar || !avatar.avatar) {
return item; return item;
} }
return { return {
...item, ...item,
skipping to change at line 1942 skipping to change at line 2012
} }
} }
const { delete: del } = decrypted; const { delete: del } = decrypted;
if (del) { if (del) {
if (del.targetSentTimestamp) { if (del.targetSentTimestamp) {
del.targetSentTimestamp = del.targetSentTimestamp.toNumber(); del.targetSentTimestamp = del.targetSentTimestamp.toNumber();
} }
} }
const { reaction } = decrypted;
if (reaction) {
if (reaction.targetTimestamp) {
reaction.targetTimestamp = reaction.targetTimestamp.toNumber();
}
}
return Promise.resolve(decrypted); return Promise.resolve(decrypted);
/* eslint-enable no-bitwise, no-param-reassign */ /* eslint-enable no-bitwise, no-param-reassign */
} }
} }
export default class MessageReceiver { export default class MessageReceiver {
constructor( constructor(
oldUsername: string, oldUsername: string,
username: string, username: string,
password: string, password: string,
skipping to change at line 1967 skipping to change at line 2044
) { ) {
const inner = new MessageReceiverInner( const inner = new MessageReceiverInner(
oldUsername, oldUsername,
username, username,
password, password,
signalingKey, signalingKey,
options options
); );
this.addEventListener = inner.addEventListener.bind(inner); this.addEventListener = inner.addEventListener.bind(inner);
this.removeEventListener = inner.removeEventListener.bind(inner);
this.getStatus = inner.getStatus.bind(inner);
this.close = inner.close.bind(inner); this.close = inner.close.bind(inner);
this.downloadAttachment = inner.downloadAttachment.bind(inner); this.downloadAttachment = inner.downloadAttachment.bind(inner);
this.getStatus = inner.getStatus.bind(inner);
this.hasEmptied = inner.hasEmptied.bind(inner);
this.removeEventListener = inner.removeEventListener.bind(inner);
this.stopProcessing = inner.stopProcessing.bind(inner); this.stopProcessing = inner.stopProcessing.bind(inner);
this.unregisterBatchers = inner.unregisterBatchers.bind(inner); this.unregisterBatchers = inner.unregisterBatchers.bind(inner);
inner.connect(); inner.connect();
} }
addEventListener: (name: string, handler: Function) => void; addEventListener: (name: string, handler: Function) => void;
removeEventListener: (name: string, handler: Function) => void;
getStatus: () => number;
close: () => Promise<void>; close: () => Promise<void>;
downloadAttachment: ( downloadAttachment: (
attachment: AttachmentPointerClass attachment: AttachmentPointerClass
) => Promise<DownloadAttachmentType>; ) => Promise<DownloadAttachmentType>;
getStatus: () => number;
hasEmptied: () => boolean;
removeEventListener: (name: string, handler: Function) => void;
stopProcessing: () => Promise<void>; stopProcessing: () => Promise<void>;
unregisterBatchers: () => void; unregisterBatchers: () => void;
static stringToArrayBuffer = MessageReceiverInner.stringToArrayBuffer; static stringToArrayBuffer = MessageReceiverInner.stringToArrayBuffer;
static arrayBufferToString = MessageReceiverInner.arrayBufferToString; static arrayBufferToString = MessageReceiverInner.arrayBufferToString;
static stringToArrayBufferBase64 = static stringToArrayBufferBase64 =
MessageReceiverInner.stringToArrayBufferBase64; MessageReceiverInner.stringToArrayBufferBase64;
static arrayBufferToStringBase64 = static arrayBufferToStringBase64 =
MessageReceiverInner.arrayBufferToStringBase64; MessageReceiverInner.arrayBufferToStringBase64;
} }
 End of changes. 25 change blocks. 
36 lines changed or deleted 115 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)