fix undecryptable self-copies by preserving the self-session
iOS CI / Build and Test SwiftUI App (push) Canceled after 0s
Build Unsigned iOS and macOS Apps / Build Unsigned iOS IPA (push) Canceled after 0s
Build Unsigned iOS and macOS Apps / Build macOS ZIP (push) Canceled after 0s

- Purge the poisoned self-session only once per account instead of on
  every connect, and rebuild it from the own published bundle when
  missing: deleting it repeatedly broke encrypt-to-self, so archived
  copies of own messages (most visibly in the self-chat) failed with
  "could not decrypt".
- Detect OMEMO 2 (urn:xmpp:omemo:2) payloads, which the pinned
  MartinOMEMO does not implement, and show them as undecryptable
  instead of empty plaintext bubbles.
- Guard both behaviours in verify.sh and document the namespace
  limitation in SECURITY.md.
This commit is contained in:
wt committed 2026-08-30 00:32:40 +07:00
1 parent 5a7fc36722
commit 8b86e33186
5 files changed
+92 -20

No files matched your search

+19 -6
View File
@@ -103,12 +103,15 @@ final class LumaOMEMOStore: SignalStorage {
sessionAdapter.containsSessionRecord(forAddress: address)
}
/// Removes a session record with our own current device. A self-session is
/// cryptographically invalid (Signal sessions exist between two distinct
/// identities) and makes Martin's `_encode(..., forSelf: true)` encrypt to
/// the local device itself, producing messages that later fail with
/// "Bad MAC". Such a record can only be created by a bug; deleting it is
/// always safe and idempotent.
var accountJID: String { repository.accountJID }
var localRegistrationID: UInt32 { identityAdapter.localRegistrationId() }
/// Removes a session record with our own current device. A poisoned
/// self-session (created by a buggy older build) makes encrypt-to-self
/// fail with "Bad MAC". Deleting it is safe, but the session is then
/// legitimately rebuilt from our own bundle and must never be purged
/// again: archived self-copies depend on its ratchet continuity.
func removeSessionWithOwnDevice() {
let registrationID = identityAdapter.localRegistrationId()
guard registrationID != 0 else { return }
@@ -119,6 +122,16 @@ final class LumaOMEMOStore: SignalStorage {
_ = sessionAdapter.deleteSessionRecord(forAddress: address)
}
/// One-time migration purge of the poisoned self-session, keyed per
/// account. Running it on every connect destroys the self-session ratchet
/// and turns every archived encrypt-to-self copy into "could not decrypt".
func removeSessionWithOwnDeviceOnce() {
let flagKey = "app.luma.chat.selfSessionPurged." + repository.accountJID
guard !UserDefaults.standard.bool(forKey: flagKey) else { return }
UserDefaults.standard.set(true, forKey: flagKey)
removeSessionWithOwnDevice()
}
func flushPendingPersistence() {
repository.flush()
}