From f491158b3f1e8e51a74db1cda75a1914f8ceb9f1 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 14 Jul 2020 12:33:07 +1000 Subject: [PATCH 1/2] add the group id from mobile as valid pubkey key --- ts/session/types/PubKey.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ts/session/types/PubKey.ts b/ts/session/types/PubKey.ts index b64e899dc..8fad0664f 100644 --- a/ts/session/types/PubKey.ts +++ b/ts/session/types/PubKey.ts @@ -1,10 +1,14 @@ export class PubKey { public static readonly PUBKEY_LEN = 66; + public static readonly MOBILE_GROUP_PUBKEY_LEN = 32; + + private static readonly regexForMobileGroupID = `__textsecure_group__![0-9a-fA-F]{${PubKey.MOBILE_GROUP_PUBKEY_LEN}}`; + // prettier-ignore + private static readonly regexForPubkeys = `((05)?[0-9a-fA-F]{${PubKey.PUBKEY_LEN - 2}})`; private static readonly regex: RegExp = new RegExp( - `^(05)?[0-9a-fA-F]{${PubKey.PUBKEY_LEN - 2}}$` + `^${PubKey.regexForPubkeys}|${PubKey.regexForMobileGroupID}$` ); public readonly key: string; - /** * A PubKey object. * If `pubKeyString` is not valid then this will throw an `Error`. @@ -44,11 +48,7 @@ export class PubKey { } public static validate(pubkeyString: string): boolean { - if (this.regex.test(pubkeyString)) { - return true; - } - - return false; + return this.regex.test(pubkeyString); } public isEqual(comparator: PubKey | string) { From 20a286d2880fb39c0e775be86f6dc3d298644686 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 15 Jul 2020 11:12:52 +1000 Subject: [PATCH 2/2] add comments about temporary fix with mobile group pubkeys regex --- ts/session/types/PubKey.ts | 3 +++ ts/test/session/crypto/MessageEncrypter_test.ts | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ts/session/types/PubKey.ts b/ts/session/types/PubKey.ts index 8fad0664f..06d07e94d 100644 --- a/ts/session/types/PubKey.ts +++ b/ts/session/types/PubKey.ts @@ -1,5 +1,8 @@ export class PubKey { public static readonly PUBKEY_LEN = 66; + // This is a temporary fix to allow groupPubkeys created from mobile to be handled correctly + // They have a different regex to match + // FIXME move this to a new class which validates group ids and use it in all places where we have group ids (message sending included) public static readonly MOBILE_GROUP_PUBKEY_LEN = 32; private static readonly regexForMobileGroupID = `__textsecure_group__![0-9a-fA-F]{${PubKey.MOBILE_GROUP_PUBKEY_LEN}}`; diff --git a/ts/test/session/crypto/MessageEncrypter_test.ts b/ts/test/session/crypto/MessageEncrypter_test.ts index 2e1753512..6fcb3119e 100644 --- a/ts/test/session/crypto/MessageEncrypter_test.ts +++ b/ts/test/session/crypto/MessageEncrypter_test.ts @@ -52,10 +52,9 @@ describe('MessageEncrypter', () => { it('should return a MEDIUM_GROUP_CIPHERTEXT envelope type', async () => { const data = crypto.randomBytes(10); - sandbox.stub( - Ratchet, - 'encryptWithSenderKey' - ).resolves({ ciphertext: '' }); + sandbox + .stub(Ratchet, 'encryptWithSenderKey') + .resolves({ ciphertext: '' }); const result = await MessageEncrypter.encrypt( TestUtils.generateFakePubKey(),