diff options
author | Andreas Straub <andy@strb.org> | 2015-07-30 19:16:58 +0200 |
---|---|---|
committer | Andreas Straub <andy@strb.org> | 2015-07-30 19:18:09 +0200 |
commit | 74ab36fda2d977e1b97b755a8298c488e6d74ba2 (patch) | |
tree | 8b25de1e9b204166f1ac8a0c7dc396b4247b7411 /src/main/java/eu/siacs/conversations/entities | |
parent | 1ed550b5c54ff873375c30fd94e4f20523f15187 (diff) |
Fix session logic: enforce same type of encryption
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r-- | src/main/java/eu/siacs/conversations/entities/Message.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 99b78d14f..e66877012 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -709,4 +709,35 @@ public class Message extends AbstractEntity { return conversation.getAccount().getAxolotlService().getFingerprintTrust(axolotlFingerprint) == SQLiteAxolotlStore.Trust.TRUSTED; } + + private int getPreviousEncryption() { + for (Message iterator = this.prev(); iterator != null; iterator = iterator.prev()){ + if( iterator.isCarbon() || iterator.getStatus() == STATUS_RECEIVED ) { + continue; + } + return iterator.getEncryption(); + } + return ENCRYPTION_NONE; + } + + private int getNextEncryption() { + for (Message iterator = this.next(); iterator != null; iterator = iterator.next()){ + if( iterator.isCarbon() || iterator.getStatus() == STATUS_RECEIVED ) { + continue; + } + return iterator.getEncryption(); + } + return conversation.getNextEncryption(false); + } + + public boolean isValidInSession() { + int pastEncryption = this.getPreviousEncryption(); + int futureEncryption = this.getNextEncryption(); + + boolean inUnencryptedSession = pastEncryption == ENCRYPTION_NONE + || futureEncryption == ENCRYPTION_NONE + || pastEncryption != futureEncryption; + + return inUnencryptedSession || this.getEncryption() == pastEncryption; + } } |