use fallbacks for message even if we have a session with the device

pull/1381/head
Audric Ackermann 5 years ago
parent 09bd207b1d
commit f28dfe5a94

@ -57,18 +57,15 @@ export async function encrypt(
const address = new window.libsignal.SignalProtocolAddress(device.key, 1);
let innerCipherText: CipherTextObject;
if (encryptionType === EncryptionType.Fallback) {
const cipher = new window.libloki.crypto.FallBackSessionCipher(address);
innerCipherText = await cipher.encrypt(plainText.buffer);
} else {
const cipher = new window.libsignal.SessionCipher(
window.textsecure.storage.protocol,
address
if (encryptionType === EncryptionType.Signal) {
console.warn(
'EncryptionType.Signal is deprecated. Only Fallback is supported'
);
innerCipherText = await cipher.encrypt(plainText.buffer);
}
const cipher = new window.libloki.crypto.FallBackSessionCipher(address);
const innerCipherText = await cipher.encrypt(plainText.buffer);
return encryptUsingSealedSender(device, innerCipherText);
}

@ -22,14 +22,9 @@ export async function toRawMessage(
message instanceof MediumGroupUpdateMessage
) {
encryption = EncryptionType.MediumGroup;
} else if (message instanceof SessionRequestMessage) {
encryption = EncryptionType.Fallback;
} else {
// If we don't have a session yet then send using fallback encryption until we have a session
const hasSession = await SessionProtocol.hasSession(device);
encryption = hasSession ? EncryptionType.Signal : EncryptionType.Fallback;
encryption = EncryptionType.Fallback;
}
// tslint:disable-next-line: no-unnecessary-local-variable
const rawMessage: RawMessage = {
identifier: message.identifier,

@ -114,48 +114,6 @@ describe('MessageEncrypter', () => {
);
});
});
describe('Signal', () => {
it('should call SessionCipher encrypt', async () => {
const data = crypto.randomBytes(10);
const spy = sandbox.spy(Stubs.SessionCipherStub.prototype, 'encrypt');
await MessageEncrypter.encrypt(
TestUtils.generateFakePubKey(),
data,
EncryptionType.Signal
);
expect(spy.called).to.equal(
true,
'SessionCipher.encrypt should be called.'
);
});
it('should pass the padded message body to encrypt', async () => {
const data = crypto.randomBytes(10);
const spy = sandbox.spy(Stubs.SessionCipherStub.prototype, 'encrypt');
await MessageEncrypter.encrypt(
TestUtils.generateFakePubKey(),
data,
EncryptionType.Signal
);
const paddedData = MessageEncrypter.padPlainTextBuffer(data);
const firstArgument = new Uint8Array(spy.args[0][0]);
expect(firstArgument).to.deep.equal(paddedData);
});
it('should return an UNIDENTIFIED SENDER envelope type', async () => {
const data = crypto.randomBytes(10);
const result = await MessageEncrypter.encrypt(
TestUtils.generateFakePubKey(),
data,
EncryptionType.Signal
);
expect(result.envelopeType).to.deep.equal(
SignalService.Envelope.Type.UNIDENTIFIED_SENDER
);
});
});
});
describe('Sealed Sender', () => {

@ -137,14 +137,14 @@ describe('Message Utils', () => {
expect(rawMessage.encryption).to.equal(EncryptionType.Fallback);
});
it('should set encryption to Signal on other messages if we have a session', async () => {
it('should set encryption to Fallback on other messages even if we have a session', async () => {
hasSessionStub.resolves(true);
const device = TestUtils.generateFakePubKey();
const message = TestUtils.generateChatMessage();
const rawMessage = await MessageUtils.toRawMessage(device, message);
expect(rawMessage.encryption).to.equal(EncryptionType.Signal);
expect(rawMessage.encryption).to.equal(EncryptionType.Fallback);
});
});
});

Loading…
Cancel
Save