Fix session logic: enforce same type of encryption

This commit is contained in:
Andreas Straub 2015-07-30 19:16:58 +02:00
parent 1ed550b5c5
commit 74ab36fda2
2 changed files with 34 additions and 25 deletions

View file

@ -709,4 +709,35 @@ public class Message extends AbstractEntity {
return conversation.getAccount().getAxolotlService().getFingerprintTrust(axolotlFingerprint) return conversation.getAccount().getAxolotlService().getFingerprintTrust(axolotlFingerprint)
== SQLiteAxolotlStore.Trust.TRUSTED; == 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;
}
} }

View file

@ -569,32 +569,10 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
if (type == RECEIVED) { if (type == RECEIVED) {
boolean wasEncrypted = false; if(message.isValidInSession()) {
for (Message iterator = message.prev(); iterator != null; iterator = iterator.prev()){
if (iterator.getEncryption() != Message.ENCRYPTION_NONE) {
wasEncrypted = true;
break;
}
if (!iterator.isCarbon() && iterator.getType() == SENT) {
break;
}
}
boolean willBeEncrypted = conversation.getNextEncryption(false) != Message.ENCRYPTION_NONE;
for (Message iterator = message.next(); iterator != null; iterator = iterator.next()){
if (iterator.getEncryption() != Message.ENCRYPTION_NONE) {
willBeEncrypted = true;
break;
}
if (!iterator.isCarbon() && iterator.getType() == SENT) {
break;
}
}
if ( willBeEncrypted && wasEncrypted
&& message.getEncryption() == Message.ENCRYPTION_NONE) {
viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning);
} else {
viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received); viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received);
} else {
viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning);
} }
} }