diff --git a/packages/snjs/mocha/001.test.js b/packages/snjs/mocha/001.test.js index b3f41fbbf..56a49f0d6 100644 --- a/packages/snjs/mocha/001.test.js +++ b/packages/snjs/mocha/001.test.js @@ -82,6 +82,29 @@ describe('001 protocol operations', () => { expect(decrypted.content.text).to.equal('Decryptable Sentence') }) + it('should decrypt string with case-insensitive uuid check for aad', async () => { + /** If the server returns a lowercase uuid for the item, but the encrypted payload uses uppercase uuids, should still decrypt */ + const uppercaseUuid = '959B042A-3892-461E-8C50-477C10C7C40A' + const lowercaseUuid = '959b042a-3892-461e-8c50-477c10c7c40a' + + const payload = new DecryptedPayload({ + uuid: uppercaseUuid, + content_type: ContentType.TYPES.Note, + content: FillItemContent({ + title: 'hello', + text: 'world', + }), + }) + + const key = await protocol001.createItemsKey() + const params = await protocol001.generateEncryptedParametersAsync(payload, key) + + params.uuid = lowercaseUuid + + const decrypted = await protocol001.generateDecryptedParametersAsync(params, key) + expect(decrypted.content).to.eql(payload.content) + }) + it('properly encrypts and decrypts', async () => { const text = 'hello world' const key = _key.masterKey diff --git a/packages/snjs/mocha/002.test.js b/packages/snjs/mocha/002.test.js index ff47fd240..d167b3e20 100644 --- a/packages/snjs/mocha/002.test.js +++ b/packages/snjs/mocha/002.test.js @@ -78,6 +78,29 @@ describe('002 protocol operations', () => { expect(decrypted.content.text).to.equal('Decryptable Sentence') }) + it('should decrypt string with case-insensitive uuid check for aad', async () => { + /** If the server returns a lowercase uuid for the item, but the encrypted payload uses uppercase uuids, should still decrypt */ + const uppercaseUuid = '959B042A-3892-461E-8C50-477C10C7C40A' + const lowercaseUuid = '959b042a-3892-461e-8c50-477c10c7c40a' + + const payload = new DecryptedPayload({ + uuid: uppercaseUuid, + content_type: ContentType.TYPES.Note, + content: FillItemContent({ + title: 'hello', + text: 'world', + }), + }) + + const key = await protocol002.createItemsKey() + const params = await protocol002.generateEncryptedParametersAsync(payload, key) + + params.uuid = lowercaseUuid + + const decrypted = await protocol002.generateDecryptedParametersAsync(params, key) + expect(decrypted.content).to.eql(payload.content) + }) + it('properly encrypts and decrypts strings', async () => { const text = 'hello world' const key = _key.masterKey diff --git a/packages/snjs/mocha/004.test.js b/packages/snjs/mocha/004.test.js index 503fe953a..949c602ae 100644 --- a/packages/snjs/mocha/004.test.js +++ b/packages/snjs/mocha/004.test.js @@ -128,6 +128,29 @@ describe('004 protocol operations', function () { expect(decrypted.content).to.eql(payload.content) }) + it('should decrypt string with case-insensitive uuid check for aad', async () => { + /** If the server returns a lowercase uuid for the item, but the encrypted payload uses uppercase uuids, should still decrypt */ + const uppercaseUuid = '959B042A-3892-461E-8C50-477C10C7C40A' + const lowercaseUuid = '959b042a-3892-461e-8c50-477c10c7c40a' + + const payload = new DecryptedPayload({ + uuid: uppercaseUuid, + content_type: ContentType.TYPES.Note, + content: FillItemContent({ + title: 'hello', + text: 'world', + }), + }) + + const key = await protocol004.createItemsKey() + const params = await protocol004.generateEncryptedParameters(payload, key) + + params.uuid = lowercaseUuid + + const decrypted = await protocol004.generateDecryptedParameters(params, key) + expect(decrypted.content).to.eql(payload.content) + }) + it('modifying the uuid of the payload should fail to decrypt', async function () { const payload = Factory.createNotePayload() const key = await protocol004.createItemsKey()