Migrate to SQLCipher for messages/cache

Quite a few other fixes, including:
  - Sending to contact with no avatar yet (not synced from mobile)
  - Left pane doesn't update quickly or at all on new message
  - Left pane doesn't show sent or error status

Also:
 - Contributing.md: Ensure set of linux dev dependencies is complete
This commit is contained in:
Scott Nonnenberg 2018-07-26 18:13:56 -07:00
parent fc461c82ce
commit 3105b77475
29 changed files with 2006 additions and 716 deletions

View file

@ -2,21 +2,7 @@
// eslint-disable-next-line func-names
(function() {
const registeredFunctions = {};
const Type = {
ENCRYPT_MESSAGE: 1,
INIT_SESSION: 2,
TRANSMIT_MESSAGE: 3,
REBUILD_MESSAGE: 4,
RETRY_SEND_MESSAGE_PROTO: 5,
};
window.textsecure = window.textsecure || {};
window.textsecure.replay = {
Type,
registerFunction(func, functionCode) {
registeredFunctions[functionCode] = func;
},
};
function inherit(Parent, Child) {
// eslint-disable-next-line no-param-reassign
@ -46,23 +32,15 @@
}
this.functionCode = options.functionCode;
this.args = options.args;
}
inherit(Error, ReplayableError);
ReplayableError.prototype.replay = function replay(...argumentsAsArray) {
const args = this.args.concat(argumentsAsArray);
return registeredFunctions[this.functionCode].apply(window, args);
};
function IncomingIdentityKeyError(number, message, key) {
// eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0];
this.identityKey = key;
ReplayableError.call(this, {
functionCode: Type.INIT_SESSION,
args: [number, message],
name: 'IncomingIdentityKeyError',
message: `The identity of ${this.number} has changed.`,
});
@ -75,8 +53,6 @@
this.identityKey = identityKey;
ReplayableError.call(this, {
functionCode: Type.ENCRYPT_MESSAGE,
args: [number, message, timestamp],
name: 'OutgoingIdentityKeyError',
message: `The identity of ${this.number} has changed.`,
});
@ -84,9 +60,10 @@
inherit(ReplayableError, OutgoingIdentityKeyError);
function OutgoingMessageError(number, message, timestamp, httpError) {
// eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0];
ReplayableError.call(this, {
functionCode: Type.ENCRYPT_MESSAGE,
args: [number, message, timestamp],
name: 'OutgoingMessageError',
message: httpError ? httpError.message : 'no http error',
});
@ -98,13 +75,11 @@
}
inherit(ReplayableError, OutgoingMessageError);
function SendMessageNetworkError(number, jsonData, httpError, timestamp) {
function SendMessageNetworkError(number, jsonData, httpError) {
this.number = number;
this.code = httpError.code;
ReplayableError.call(this, {
functionCode: Type.TRANSMIT_MESSAGE,
args: [number, jsonData, timestamp],
name: 'SendMessageNetworkError',
message: httpError.message,
});
@ -113,10 +88,8 @@
}
inherit(ReplayableError, SendMessageNetworkError);
function SignedPreKeyRotationError(numbers, message, timestamp) {
function SignedPreKeyRotationError() {
ReplayableError.call(this, {
functionCode: Type.RETRY_SEND_MESSAGE_PROTO,
args: [numbers, message, timestamp],
name: 'SignedPreKeyRotationError',
message: 'Too many signed prekey rotation failures',
});
@ -127,8 +100,6 @@
this.code = httpError.code;
ReplayableError.call(this, {
functionCode: Type.REBUILD_MESSAGE,
args: [message],
name: 'MessageError',
message: httpError.message,
});

View file

@ -292,7 +292,10 @@ MessageReceiver.prototype.extend({
},
stringToArrayBuffer(string) {
// eslint-disable-next-line new-cap
return new dcodeIO.ByteBuffer.wrap(string, 'binary').toArrayBuffer();
return dcodeIO.ByteBuffer.wrap(string, 'binary').toArrayBuffer();
},
arrayBufferToString(arrayBuffer) {
return dcodeIO.ByteBuffer.wrap(arrayBuffer).toString('binary');
},
getAllFromCache() {
window.log.info('getAllFromCache');
@ -331,7 +334,7 @@ MessageReceiver.prototype.extend({
const id = this.getEnvelopeId(envelope);
const data = {
id,
envelope: plaintext,
envelope: this.arrayBufferToString(plaintext),
timestamp: Date.now(),
attempts: 1,
};
@ -340,7 +343,7 @@ MessageReceiver.prototype.extend({
updateCache(envelope, plaintext) {
const id = this.getEnvelopeId(envelope);
const data = {
decrypted: plaintext,
decrypted: this.arrayBufferToString(plaintext),
};
return textsecure.storage.unprocessed.update(id, data);
},
@ -1153,11 +1156,6 @@ textsecure.MessageReceiver = function MessageReceiverWrapper(
this.getStatus = messageReceiver.getStatus.bind(messageReceiver);
this.close = messageReceiver.close.bind(messageReceiver);
messageReceiver.connect();
textsecure.replay.registerFunction(
messageReceiver.tryMessageAgain.bind(messageReceiver),
textsecure.replay.Type.INIT_SESSION
);
};
textsecure.MessageReceiver.prototype = {

View file

@ -705,8 +705,9 @@ MessageSender.prototype = {
profileKey
) {
return textsecure.storage.groups.getNumbers(groupId).then(targetNumbers => {
if (targetNumbers === undefined)
if (targetNumbers === undefined) {
return Promise.reject(new Error('Unknown Group'));
}
const me = textsecure.storage.user.getNumber();
const numbers = targetNumbers.filter(number => number !== me);
@ -895,22 +896,6 @@ textsecure.MessageSender = function MessageSenderWrapper(
cdnUrl
) {
const sender = new MessageSender(url, username, password, cdnUrl);
textsecure.replay.registerFunction(
sender.tryMessageAgain.bind(sender),
textsecure.replay.Type.ENCRYPT_MESSAGE
);
textsecure.replay.registerFunction(
sender.retransmitMessage.bind(sender),
textsecure.replay.Type.TRANSMIT_MESSAGE
);
textsecure.replay.registerFunction(
sender.sendMessage.bind(sender),
textsecure.replay.Type.REBUILD_MESSAGE
);
textsecure.replay.registerFunction(
sender.retrySendMessageProto.bind(sender),
textsecure.replay.Type.RETRY_SEND_MESSAGE_PROTO
);
this.sendExpirationTimerUpdateToNumber = sender.sendExpirationTimerUpdateToNumber.bind(
sender