Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit d9d1771

Browse files
committed
fix: Increase encryption test robustness & improve decryption failure error messages.
1 parent bc64e3f commit d9d1771

File tree

2 files changed

+525
-595
lines changed

2 files changed

+525
-595
lines changed

src/subscribe/Decrypt.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function Decrypt(client, options = {}) {
1010
// noop unless message encrypted
1111
return (streamMessage) => {
1212
if (streamMessage.groupKeyId) {
13-
throw new Error('No keyExchange configured, cannot decrypt message.')
13+
throw new UnableToDecryptError('No keyExchange configured, cannot decrypt any message.', streamMessage)
1414
}
1515

1616
return streamMessage
@@ -43,11 +43,17 @@ export default function Decrypt(client, options = {}) {
4343
})
4444

4545
if (!groupKey) {
46-
throw new UnableToDecryptError(`Group key not found: ${streamMessage.groupKeyId}`, streamMessage)
46+
throw new UnableToDecryptError([
47+
`Could not get GroupKey: ${streamMessage.groupKeyId}`,
48+
'Publisher is offline, key does not exist or no permission to access key.',
49+
].join(' '), streamMessage)
4750
}
51+
4852
await EncryptionUtil.decryptStreamMessage(streamMessage, groupKey)
4953
await keyExchange.addNewKey(streamMessage)
5054
} catch (err) {
55+
// clear cached permissions if cannot decrypt, likely permissions need updating
56+
client.cached.clearStream(streamMessage.getStreamId())
5157
await onError(err, streamMessage)
5258
} finally {
5359
yield streamMessage

0 commit comments

Comments
 (0)