match envelope type with ios protos

pull/1692/head
Audric Ackermann 4 years ago
parent 60a6d5c55e
commit 01fd927070
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -7,8 +7,8 @@ option java_outer_classname = "SignalServiceProtos";
message Envelope { message Envelope {
enum Type { enum Type {
UNIDENTIFIED_SENDER = 6; SESSION_MESSAGE = 6;
CLOSED_GROUP_CIPHERTEXT = 7; CLOSED_GROUP_MESSAGE = 7;
} }
// @required // @required

@ -65,7 +65,7 @@ export async function handleClosedGroupControlMessage(
// We drop New closed group message from our other devices, as they will come as ConfigurationMessage instead // We drop New closed group message from our other devices, as they will come as ConfigurationMessage instead
if (type === Type.ENCRYPTION_KEY_PAIR) { if (type === Type.ENCRYPTION_KEY_PAIR) {
const isComingFromGroupPubkey = const isComingFromGroupPubkey =
envelope.type === SignalService.Envelope.Type.CLOSED_GROUP_CIPHERTEXT; envelope.type === SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE;
await handleClosedGroupEncryptionKeyPair(envelope, groupUpdate, isComingFromGroupPubkey); await handleClosedGroupEncryptionKeyPair(envelope, groupUpdate, isComingFromGroupPubkey);
return; return;
} }

@ -228,10 +228,10 @@ async function doDecrypt(
} }
switch (envelope.type) { switch (envelope.type) {
// Only UNIDENTIFIED_SENDER and CLOSED_GROUP_CIPHERTEXT are supported // Only SESSION_MESSAGE and CLOSED_GROUP_MESSAGE are supported
case SignalService.Envelope.Type.CLOSED_GROUP_CIPHERTEXT: case SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE:
return decryptForClosedGroup(envelope, ciphertext); return decryptForClosedGroup(envelope, ciphertext);
case SignalService.Envelope.Type.UNIDENTIFIED_SENDER: { case SignalService.Envelope.Type.SESSION_MESSAGE: {
return decryptUnidentifiedSender(envelope, ciphertext); return decryptUnidentifiedSender(envelope, ciphertext);
} }
default: default:

@ -26,7 +26,7 @@ export async function encrypt(
plainTextBuffer: Uint8Array, plainTextBuffer: Uint8Array,
encryptionType: EncryptionType encryptionType: EncryptionType
): Promise<EncryptResult> { ): Promise<EncryptResult> {
const { CLOSED_GROUP_CIPHERTEXT, UNIDENTIFIED_SENDER } = SignalService.Envelope.Type; const { CLOSED_GROUP_MESSAGE, SESSION_MESSAGE } = SignalService.Envelope.Type;
if (encryptionType !== EncryptionType.ClosedGroup && encryptionType !== EncryptionType.Fallback) { if (encryptionType !== EncryptionType.ClosedGroup && encryptionType !== EncryptionType.Fallback) {
throw new Error(`Invalid encryption type:${encryptionType}`); throw new Error(`Invalid encryption type:${encryptionType}`);
} }
@ -35,7 +35,7 @@ export async function encrypt(
if (encryptForClosedGroup) { if (encryptForClosedGroup) {
// window?.log?.info( // window?.log?.info(
// 'Encrypting message with SessionProtocol and envelope type is CLOSED_GROUP_CIPHERTEXT' // 'Encrypting message with SessionProtocol and envelope type is CLOSED_GROUP_MESSAGE'
// ); // );
const hexEncryptionKeyPair = await getLatestClosedGroupEncryptionKeyPair(device.key); const hexEncryptionKeyPair = await getLatestClosedGroupEncryptionKeyPair(device.key);
if (!hexEncryptionKeyPair) { if (!hexEncryptionKeyPair) {
@ -52,13 +52,13 @@ export async function encrypt(
); );
return { return {
envelopeType: CLOSED_GROUP_CIPHERTEXT, envelopeType: CLOSED_GROUP_MESSAGE,
cipherText: cipherTextClosedGroup, cipherText: cipherTextClosedGroup,
}; };
} }
const cipherText = await exports.encryptUsingSessionProtocol(device, plainText); const cipherText = await exports.encryptUsingSessionProtocol(device, plainText);
return { envelopeType: UNIDENTIFIED_SENDER, cipherText }; return { envelopeType: SESSION_MESSAGE, cipherText };
} }
export async function encryptUsingSessionProtocol( export async function encryptUsingSessionProtocol(

@ -59,7 +59,7 @@ async function buildEnvelope(
): Promise<SignalService.Envelope> { ): Promise<SignalService.Envelope> {
let source: string | undefined; let source: string | undefined;
if (type === SignalService.Envelope.Type.CLOSED_GROUP_CIPHERTEXT) { if (type === SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE) {
source = sskSource; source = sskSource;
} }

@ -125,7 +125,7 @@ describe('MessageEncrypter', () => {
describe('EncryptionType', () => { describe('EncryptionType', () => {
describe('ClosedGroup', () => { describe('ClosedGroup', () => {
it('should return a CLOSED_GROUP_CIPHERTEXT envelope type for ClosedGroup', async () => { it('should return a CLOSED_GROUP_MESSAGE envelope type for ClosedGroup', async () => {
const hexKeyPair = { const hexKeyPair = {
publicHex: `05${ourUserEd25516Keypair.pubKey}`, publicHex: `05${ourUserEd25516Keypair.pubKey}`,
privateHex: '0123456789abcdef', privateHex: '0123456789abcdef',
@ -142,10 +142,10 @@ describe('MessageEncrypter', () => {
); );
chai chai
.expect(result.envelopeType) .expect(result.envelopeType)
.to.deep.equal(SignalService.Envelope.Type.CLOSED_GROUP_CIPHERTEXT); .to.deep.equal(SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE);
}); });
it('should return a UNIDENTIFIED_SENDER envelope type for Fallback', async () => { it('should return a SESSION_MESSAGE envelope type for Fallback', async () => {
const data = crypto.randomBytes(10); const data = crypto.randomBytes(10);
const result = await MessageEncrypter.encrypt( const result = await MessageEncrypter.encrypt(
@ -153,9 +153,7 @@ describe('MessageEncrypter', () => {
data, data,
EncryptionType.Fallback EncryptionType.Fallback
); );
chai chai.expect(result.envelopeType).to.deep.equal(SignalService.Envelope.Type.SESSION_MESSAGE);
.expect(result.envelopeType)
.to.deep.equal(SignalService.Envelope.Type.UNIDENTIFIED_SENDER);
}); });
it('should throw an error for anything else than Fallback or ClosedGroup', () => { it('should throw an error for anything else than Fallback or ClosedGroup', () => {

@ -29,7 +29,7 @@ describe('MessageSender', () => {
lokiMessageAPISendStub = sandbox.stub(LokiMessageApi, 'sendMessage').resolves(); lokiMessageAPISendStub = sandbox.stub(LokiMessageApi, 'sendMessage').resolves();
encryptStub = sandbox.stub(MessageEncrypter, 'encrypt').resolves({ encryptStub = sandbox.stub(MessageEncrypter, 'encrypt').resolves({
envelopeType: SignalService.Envelope.Type.UNIDENTIFIED_SENDER, envelopeType: SignalService.Envelope.Type.SESSION_MESSAGE,
cipherText: crypto.randomBytes(10), cipherText: crypto.randomBytes(10),
}); });
@ -77,7 +77,7 @@ describe('MessageSender', () => {
}); });
describe('logic', () => { describe('logic', () => {
let messageEncyrptReturnEnvelopeType = SignalService.Envelope.Type.UNIDENTIFIED_SENDER; let messageEncyrptReturnEnvelopeType = SignalService.Envelope.Type.SESSION_MESSAGE;
beforeEach(() => { beforeEach(() => {
encryptStub.callsFake(async (_device, plainTextBuffer, _type) => ({ encryptStub.callsFake(async (_device, plainTextBuffer, _type) => ({
@ -107,7 +107,7 @@ describe('MessageSender', () => {
}); });
it('should correctly build the envelope', async () => { it('should correctly build the envelope', async () => {
messageEncyrptReturnEnvelopeType = SignalService.Envelope.Type.UNIDENTIFIED_SENDER; messageEncyrptReturnEnvelopeType = SignalService.Envelope.Type.SESSION_MESSAGE;
// This test assumes the encryption stub returns the plainText passed into it. // This test assumes the encryption stub returns the plainText passed into it.
const device = TestUtils.generateFakePubKey().key; const device = TestUtils.generateFakePubKey().key;
@ -137,15 +137,15 @@ describe('MessageSender', () => {
const envelope = SignalService.Envelope.decode( const envelope = SignalService.Envelope.decode(
webSocketMessage.request?.body as Uint8Array webSocketMessage.request?.body as Uint8Array
); );
expect(envelope.type).to.equal(SignalService.Envelope.Type.UNIDENTIFIED_SENDER); expect(envelope.type).to.equal(SignalService.Envelope.Type.SESSION_MESSAGE);
expect(envelope.source).to.equal(''); expect(envelope.source).to.equal('');
expect(toNumber(envelope.timestamp)).to.equal(timestamp); expect(toNumber(envelope.timestamp)).to.equal(timestamp);
expect(envelope.content).to.deep.equal(plainTextBuffer); expect(envelope.content).to.deep.equal(plainTextBuffer);
}); });
describe('UNIDENTIFIED_SENDER', () => { describe('SESSION_MESSAGE', () => {
it('should set the envelope source to be empty', async () => { it('should set the envelope source to be empty', async () => {
messageEncyrptReturnEnvelopeType = SignalService.Envelope.Type.UNIDENTIFIED_SENDER; messageEncyrptReturnEnvelopeType = SignalService.Envelope.Type.SESSION_MESSAGE;
// This test assumes the encryption stub returns the plainText passed into it. // This test assumes the encryption stub returns the plainText passed into it.
const device = TestUtils.generateFakePubKey().key; const device = TestUtils.generateFakePubKey().key;
@ -175,10 +175,10 @@ describe('MessageSender', () => {
const envelope = SignalService.Envelope.decode( const envelope = SignalService.Envelope.decode(
webSocketMessage.request?.body as Uint8Array webSocketMessage.request?.body as Uint8Array
); );
expect(envelope.type).to.equal(SignalService.Envelope.Type.UNIDENTIFIED_SENDER); expect(envelope.type).to.equal(SignalService.Envelope.Type.SESSION_MESSAGE);
expect(envelope.source).to.equal( expect(envelope.source).to.equal(
'', '',
'envelope source should be empty in UNIDENTIFIED_SENDER' 'envelope source should be empty in SESSION_MESSAGE'
); );
}); });
}); });

@ -10,7 +10,7 @@ export function generateEnvelopePlusClosedGroup(groupId: string, sender: string)
receivedAt: Date.now(), receivedAt: Date.now(),
timestamp: Date.now() - 2000, timestamp: Date.now() - 2000,
id: uuid(), id: uuid(),
type: SignalService.Envelope.Type.CLOSED_GROUP_CIPHERTEXT, type: SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE,
source: groupId, source: groupId,
content: new Uint8Array(), content: new Uint8Array(),
toJSON: () => ['fake'], toJSON: () => ['fake'],
@ -24,7 +24,7 @@ export function generateEnvelopePlus(sender: string): EnvelopePlus {
receivedAt: Date.now(), receivedAt: Date.now(),
timestamp: Date.now() - 2000, timestamp: Date.now() - 2000,
id: uuid(), id: uuid(),
type: SignalService.Envelope.Type.UNIDENTIFIED_SENDER, type: SignalService.Envelope.Type.SESSION_MESSAGE,
source: sender, source: sender,
senderIdentity: sender, senderIdentity: sender,
content: new Uint8Array(), content: new Uint8Array(),

Loading…
Cancel
Save