Skip to content

Commit

Permalink
Backwards compatibility updates for libsignal-client
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Feb 12, 2021
1 parent 3428505 commit bc0f438
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
12 changes: 12 additions & 0 deletions preload.js
Expand Up @@ -534,6 +534,18 @@ try {
},
createKeyPair: incomingKey => {
const incomingKeyBuffer = Buffer.from(incomingKey);

if (incomingKeyBuffer.length !== 32) {
throw new Error('key must be 32 bytes long');
}

// eslint-disable-next-line no-bitwise
incomingKeyBuffer[0] &= 248;
// eslint-disable-next-line no-bitwise
incomingKeyBuffer[31] &= 127;
// eslint-disable-next-line no-bitwise
incomingKeyBuffer[31] |= 64;

const privKey = client.PrivateKey.deserialize(incomingKeyBuffer);
const pubKey = privKey.getPublicKey();

Expand Down
8 changes: 7 additions & 1 deletion ts/models/conversations.ts
Expand Up @@ -4023,6 +4023,12 @@ export class ConversationModel extends window.Backbone.Model<
async leaveGroup(): Promise<void> {
const now = Date.now();
if (this.get('type') === 'group') {
const groupId = this.get('groupId');

if (!groupId) {
throw new Error(`leaveGroup/${this.idForLogging()}: No groupId!`);
}

const groupIdentifiers = this.getRecipients();
this.set({ left: true });
window.Signal.Data.updateConversation(this.attributes);
Expand All @@ -4048,7 +4054,7 @@ export class ConversationModel extends window.Backbone.Model<
message.send(
this.wrapSend(
window.textsecure.messaging.leaveGroup(
this.id,
groupId,
groupIdentifiers,
options
)
Expand Down
4 changes: 2 additions & 2 deletions ts/models/messages.ts
Expand Up @@ -1470,11 +1470,11 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {

// General
idForLogging(): string {
const source = this.getSource();
const account = this.getSourceUuid() || this.getSource();
const device = this.getSourceDevice();
const timestamp = this.get('sent_at');

return `${source}.${device} ${timestamp}`;
return `${account}.${device} ${timestamp}`;
}

// eslint-disable-next-line class-methods-use-this
Expand Down
10 changes: 7 additions & 3 deletions ts/textsecure/MessageReceiver.ts
Expand Up @@ -622,10 +622,14 @@ class MessageReceiverInner extends EventTarget {
}

getEnvelopeId(envelope: EnvelopeClass) {
const timestamp =
envelope && envelope.timestamp && envelope.timestamp.toNumber
? envelope.timestamp.toNumber()
: null;

if (envelope.sourceUuid || envelope.source) {
return `${envelope.sourceUuid || envelope.source}.${
envelope.sourceDevice
} ${envelope.timestamp.toNumber()} (${envelope.id})`;
const sender = envelope.sourceUuid || envelope.source;
return `${sender}.${envelope.sourceDevice} ${timestamp} (${envelope.id})`;
}

return envelope.id;
Expand Down

0 comments on commit bc0f438

Please sign in to comment.