Fix using wrong sequence counter for key replies

This commit is contained in:
Jonas Lochmann 2022-07-25 02:00:00 +02:00
parent 8a5e46811e
commit 30a47a336c
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36

View file

@ -18,7 +18,7 @@
import { ReplyToKeyRequestAction } from '../../../../action' import { ReplyToKeyRequestAction } from '../../../../action'
import { Cache } from '../cache' import { Cache } from '../cache'
import { EventHandler } from '../../../../monitoring/eventhandler' import { EventHandler } from '../../../../monitoring/eventhandler'
import { SourceDeviceNotFoundException } from '../exception/illegal-state' import { IllegalStateException } from '../exception/illegal-state'
export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache, eventHandler }: { export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache, eventHandler }: {
deviceId: string deviceId: string
@ -65,14 +65,16 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
const deviceEntryUnsafe = await cache.database.device.findOne({ const deviceEntryUnsafe = await cache.database.device.findOne({
where: { where: {
familyId: cache.familyId, familyId: cache.familyId,
deviceId deviceId: request.senderDeviceId
}, },
transaction: cache.transaction, transaction: cache.transaction,
attributes: ['nextKeyReplySequenceNumber'] attributes: ['nextKeyReplySequenceNumber']
}) })
if (!deviceEntryUnsafe) { if (!deviceEntryUnsafe) {
throw new SourceDeviceNotFoundException() throw new IllegalStateException({
staticMessage: 'target device entry not found'
})
} }
const deviceEntry = { const deviceEntry = {
@ -84,7 +86,7 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
}, { }, {
where: { where: {
familyId: cache.familyId, familyId: cache.familyId,
deviceId deviceId: request.senderDeviceId
}, },
transaction: cache.transaction transaction: cache.transaction
}) })