mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-18 05:15:06 +00:00
Expose chat read positions and E2EE errors
Add optional chat activity and read-position details to the unread-count endpoint. Return stable E2EE rejection codes for stale timestamps and untrusted signing devices, with tests for both behaviors.
This commit is contained in:
@@ -224,9 +224,10 @@ public sealed class E2eeService(GovorDbContext context)
|
||||
envelope.RecipientType != (int)type || envelope.ReplyToMessageId != replyTo ||
|
||||
envelope.IsEdit != editedMessage.HasValue ||
|
||||
(editedMessage.HasValue && envelope.MessageId != editedMessage) ||
|
||||
!envelope.MediaIds.Order().SequenceEqual(media.Order()) ||
|
||||
Math.Abs((double)envelope.CreatedAt - DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) > 300_000)
|
||||
throw new ArgumentException("E2EE routing, attachment or time context does not match.");
|
||||
!envelope.MediaIds.Order().SequenceEqual(media.Order()))
|
||||
throw new ArgumentException("E2EE routing or attachment context does not match.");
|
||||
if (Math.Abs((double)envelope.CreatedAt - DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()) > 300_000)
|
||||
throw new ArgumentException(E2eeProtocol.TimestampOutOfRangeError);
|
||||
|
||||
var signingSession = await context.UserSessions.AsNoTracking().Include(s => s.CryptoSession)
|
||||
.ThenInclude(c => c.SignedPreKey).SingleOrDefaultAsync(s => s.Id == envelope.Sender.SessionId &&
|
||||
@@ -235,7 +236,7 @@ public sealed class E2eeService(GovorDbContext context)
|
||||
ToDeviceKey(signingSession.CryptoSession, sender).Fingerprint != envelope.Sender.Fingerprint ||
|
||||
signingSession.CryptoSession.AccountIdentityKey != envelope.Sender.AccountIdentityKey ||
|
||||
signingSession.CryptoSession.Generation != envelope.Sender.Generation)
|
||||
throw new UnauthorizedAccessException("E2EE signing device is unknown or revoked.");
|
||||
throw new UnauthorizedAccessException(E2eeProtocol.SigningDeviceRejectedError);
|
||||
var directory = await GetConversationKeysAsync(sender, conversation, type);
|
||||
var expected = directory.Devices.Select(k => k.Fingerprint).Distinct().Order(StringComparer.Ordinal);
|
||||
if (!expected.SequenceEqual(envelope.Recipients.Order(StringComparer.Ordinal)))
|
||||
|
||||
Reference in New Issue
Block a user