Passive UUID fixes

This commit is contained in:
Ken Powers 2020-03-20 15:01:15 -04:00 committed by Scott Nonnenberg
parent e7a01f8270
commit 37ad95af27
9 changed files with 80 additions and 40 deletions

View File

@ -1229,7 +1229,7 @@
).map(contact => {
const error = new Error('Network is not available');
error.name = 'SendMessageNetworkError';
error.number = contact.get('uuid') || contact.get('e164');
error.identifier = contact.get('uuid') || contact.get('e164');
return error;
});
await message.saveErrors(errors);

View File

@ -264,7 +264,9 @@
// If an error has a specific number it's associated with, we'll show it next to
// that contact. Otherwise, it will be a standalone entry.
const errors = _.reject(allErrors, error => Boolean(error.number));
const errors = _.reject(allErrors, error =>
Boolean(error.identifer || error.number)
);
const errorsGroupedById = _.groupBy(allErrors, 'number');
const finalContacts = (conversationIds || []).map(id => {
const errorsForContact = errorsGroupedById[id];
@ -1264,16 +1266,27 @@
this.set({ errors: null });
const conversation = this.getConversation();
const intendedRecipients = this.get('recipients') || [];
const successfulRecipients = this.get('sent_to') || [];
const currentRecipients = conversation.getRecipients();
const intendedRecipients = (this.get('recipients') || [])
.map(identifier => ConversationController.getConversationId(identifier))
.filter(Boolean);
const successfulRecipients = (this.get('sent_to') || [])
.map(identifier => ConversationController.getConversationId(identifier))
.filter(Boolean);
const currentRecipients = conversation
.getRecipients()
.map(identifier => ConversationController.getConversationId(identifier))
.filter(Boolean);
const profileKey = conversation.get('profileSharing')
? storage.get('profileKey')
: null;
// Determine retry recipients and get their most up-to-date addressing information
let recipients = _.intersection(intendedRecipients, currentRecipients);
recipients = _.without(recipients, successfulRecipients);
recipients = _.without(recipients, successfulRecipients).map(id => {
const c = ConversationController.get(id);
return c.get('uuid') || c.get('e164');
});
if (!recipients.length) {
window.log.warn('retrySend: Nobody to send to!');
@ -1297,7 +1310,10 @@
const stickerWithData = await loadStickerData(this.get('sticker'));
// Special-case the self-send case - we send only a sync message
if (recipients.length === 1 && recipients[0] === this.OUR_NUMBER) {
if (
recipients.length === 1 &&
(recipients[0] === this.OUR_NUMBER || recipients[0] === this.OUR_UUID)
) {
const [identifier] = recipients;
const dataMessage = await textsecure.messaging.getMessageProto(
identifier,
@ -1348,7 +1364,7 @@
expireTimer: this.get('expireTimer'),
profileKey,
group: {
id: this.get('conversationId'),
id: this.getConversation().get('groupId'),
type: textsecure.protobuf.GroupContext.Type.DELIVER,
},
},
@ -1429,13 +1445,14 @@
const { wrap, sendOptions } = ConversationController.prepareForSend(
identifier
);
const promise = textsecure.messaging.sendMessageToNumber(
const promise = textsecure.messaging.sendMessageToIdentifier(
identifier,
body,
attachments,
quoteWithData,
previewWithData,
stickerWithData,
null,
this.get('sent_at'),
this.get('expireTimer'),
profileKey,
@ -1444,11 +1461,15 @@
return this.send(wrap(promise));
},
removeOutgoingErrors(number) {
removeOutgoingErrors(incomingIdentifier) {
const incomingConversationId = ConversationController.getConversationId(
incomingIdentifier
);
const errors = _.partition(
this.get('errors'),
e =>
e.number === number &&
ConversationController.getConversationId(e.identifer || e.number) ===
incomingConversationId &&
(e.name === 'MessageError' ||
e.name === 'OutgoingMessageError' ||
e.name === 'SendMessageNetworkError' ||
@ -1535,7 +1556,9 @@
promises = promises.concat(
_.map(result.errors, error => {
if (error.name === 'OutgoingIdentityKeyError') {
const c = ConversationController.get(error.number);
const c = ConversationController.get(
error.identifer || error.number
);
promises.push(c.getProfiles());
}
})

View File

@ -8,7 +8,7 @@ const { escapeRegExp } = require('lodash');
const APP_ROOT_PATH = path.join(__dirname, '..', '..', '..');
const PHONE_NUMBER_PATTERN = /\+\d{7,12}(\d{3})/g;
const UUID_PATTERN = /[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{10}([0-9A-F]{2})/gi;
const UUID_PATTERN = /[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{9}([0-9A-F]{3})/gi;
const GROUP_ID_PATTERN = /(group\()([^)]+)(\))/g;
const REDACTION_PLACEHOLDER = '[REDACTED]';

View File

@ -2004,7 +2004,7 @@
await contact.setApproved();
}
message.resend(contact.get('e164'), contact.get('uuid'));
message.resend(contact.get('uuid') || contact.get('e164'));
},
});

View File

@ -35,33 +35,38 @@
}
inherit(Error, ReplayableError);
function IncomingIdentityKeyError(number, message, key) {
function IncomingIdentityKeyError(identifier, message, key) {
// eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0];
this.identifier = identifier.split('.')[0];
this.identityKey = key;
ReplayableError.call(this, {
name: 'IncomingIdentityKeyError',
message: `The identity of ${this.number} has changed.`,
message: `The identity of ${this.identifier} has changed.`,
});
}
inherit(ReplayableError, IncomingIdentityKeyError);
function OutgoingIdentityKeyError(number, message, timestamp, identityKey) {
function OutgoingIdentityKeyError(
identifier,
message,
timestamp,
identityKey
) {
// eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0];
this.identifier = identifier.split('.')[0];
this.identityKey = identityKey;
ReplayableError.call(this, {
name: 'OutgoingIdentityKeyError',
message: `The identity of ${this.number} has changed.`,
message: `The identity of ${this.identifier} has changed.`,
});
}
inherit(ReplayableError, OutgoingIdentityKeyError);
function OutgoingMessageError(number, message, timestamp, httpError) {
function OutgoingMessageError(identifier, message, timestamp, httpError) {
// eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0];
this.identifier = identifier.split('.')[0];
ReplayableError.call(this, {
name: 'OutgoingMessageError',
@ -75,8 +80,9 @@
}
inherit(ReplayableError, OutgoingMessageError);
function SendMessageNetworkError(number, jsonData, httpError) {
this.number = number;
function SendMessageNetworkError(identifier, jsonData, httpError) {
// eslint-disable-next-line prefer-destructuring
this.identifier = identifier.split('.')[0];
this.code = httpError.code;
ReplayableError.call(this, {
@ -108,7 +114,7 @@
}
inherit(ReplayableError, MessageError);
function UnregisteredUserError(number, httpError) {
function UnregisteredUserError(identifier, httpError) {
this.message = httpError.message;
this.name = 'UnregisteredUserError';
@ -120,7 +126,7 @@
Error.captureStackTrace(this);
}
this.number = number;
this.identifier = identifier;
this.code = httpError.code;
appendStack(this, httpError);

View File

@ -242,7 +242,12 @@ MessageReceiver.prototype.extend({
return;
}
envelope.id = envelope.serverGuid || window.getGuid();
// Make non-private envelope IDs dashless so they don't get redacted
// from logs
envelope.id = (envelope.serverGuid || window.getGuid()).replace(
/-/g,
''
);
envelope.serverTimestamp = envelope.serverTimestamp
? envelope.serverTimestamp.toNumber()
: null;
@ -550,12 +555,17 @@ MessageReceiver.prototype.extend({
const promise = this.addToQueue(taskWithTimeout);
return promise.catch(error => {
window.log.error(
const args = [
'queueEnvelope error handling envelope',
this.getEnvelopeId(envelope),
':',
error && error.stack ? error.stack : error
);
error && error.stack ? error.stack : error,
];
if (error.warn) {
window.log.warn(...args);
} else {
window.log.error(...args);
}
});
},
// Same as handleEnvelope, just without the decryption step. Necessary for handling
@ -1418,9 +1428,12 @@ MessageReceiver.prototype.extend({
decrypted.group.members = [];
decrypted.group.avatar = null;
break;
default:
default: {
this.removeFromCache(envelope);
throw new Error('Unknown group message type');
const err = new Error('Unknown group message type');
err.warn = true;
throw err;
}
}
}

View File

@ -62,8 +62,6 @@ OutgoingMessage.prototype = {
);
}
// eslint-disable-next-line no-param-reassign
error.number = identifier;
// eslint-disable-next-line no-param-reassign
error.reason = reason;
this.errors[this.errors.length] = error;

View File

@ -29,8 +29,8 @@ describe('Privacy', () => {
const actual = Privacy.redactUuids(text);
const expected =
'This is a log line with a uuid [REDACTED]b4\n' +
'and another one IN ALL UPPERCASE [REDACTED]A3';
'This is a log line with a uuid [REDACTED]6b4\n' +
'and another one IN ALL UPPERCASE [REDACTED]CA3';
assert.equal(actual, expected);
});
});

View File

@ -1235,17 +1235,17 @@
"rule": "jQuery-wrap(",
"path": "libtextsecure/message_receiver.js",
"line": " const buffer = dcodeIO.ByteBuffer.wrap(ciphertext);",
"lineNumber": 812,
"lineNumber": 822,
"reasonCategory": "falseMatch",
"updated": "2020-03-04T21:24:23.269Z"
"updated": "2020-03-20T17:24:11.472Z"
},
{
"rule": "jQuery-wrap(",
"path": "libtextsecure/message_receiver.js",
"line": " const buffer = dcodeIO.ByteBuffer.wrap(ciphertext);",
"lineNumber": 837,
"lineNumber": 847,
"reasonCategory": "falseMatch",
"updated": "2020-03-04T21:24:23.269Z"
"updated": "2020-03-20T17:24:11.472Z"
},
{
"rule": "jQuery-wrap(",