Let UNTRUSTED/UNDECIDED keys become INACTIVE

This commit is contained in:
Andreas Straub 2015-08-01 18:27:52 +02:00
parent 60cd307f73
commit 6cd9383e53
9 changed files with 138 additions and 116 deletions

View file

@ -191,11 +191,11 @@ public class AxolotlService {
return axolotlStore.getIdentityKeyPair().getPublicKey(); return axolotlStore.getIdentityKeyPair().getPublicKey();
} }
public Set<IdentityKey> getKeysWithTrust(SQLiteAxolotlStore.Trust trust) { public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust) {
return axolotlStore.getContactKeysWithTrust(account.getJid().toBareJid().toString(), trust); return axolotlStore.getContactKeysWithTrust(account.getJid().toBareJid().toString(), trust);
} }
public Set<IdentityKey> getKeysWithTrust(SQLiteAxolotlStore.Trust trust, Contact contact) { public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Contact contact) {
return axolotlStore.getContactKeysWithTrust(contact.getJid().toBareJid().toString(), trust); return axolotlStore.getContactKeysWithTrust(contact.getJid().toBareJid().toString(), trust);
} }
@ -241,8 +241,8 @@ public class AxolotlService {
} }
private void setTrustOnSessions(final Jid jid, @NonNull final Set<Integer> deviceIds, private void setTrustOnSessions(final Jid jid, @NonNull final Set<Integer> deviceIds,
final SQLiteAxolotlStore.Trust from, final XmppAxolotlSession.Trust from,
final SQLiteAxolotlStore.Trust to) { final XmppAxolotlSession.Trust to) {
for (Integer deviceId : deviceIds) { for (Integer deviceId : deviceIds) {
AxolotlAddress address = new AxolotlAddress(jid.toBareJid().toString(), deviceId); AxolotlAddress address = new AxolotlAddress(jid.toBareJid().toString(), deviceId);
XmppAxolotlSession session = sessions.get(address); XmppAxolotlSession session = sessions.get(address);
@ -267,11 +267,19 @@ public class AxolotlService {
} }
Set<Integer> expiredDevices = new HashSet<>(axolotlStore.getSubDeviceSessions(jid.toBareJid().toString())); Set<Integer> expiredDevices = new HashSet<>(axolotlStore.getSubDeviceSessions(jid.toBareJid().toString()));
expiredDevices.removeAll(deviceIds); expiredDevices.removeAll(deviceIds);
setTrustOnSessions(jid, expiredDevices, SQLiteAxolotlStore.Trust.TRUSTED, setTrustOnSessions(jid, expiredDevices, XmppAxolotlSession.Trust.TRUSTED,
SQLiteAxolotlStore.Trust.INACTIVE); XmppAxolotlSession.Trust.INACTIVE_TRUSTED);
setTrustOnSessions(jid, expiredDevices, XmppAxolotlSession.Trust.UNDECIDED,
XmppAxolotlSession.Trust.INACTIVE_UNDECIDED);
setTrustOnSessions(jid, expiredDevices, XmppAxolotlSession.Trust.UNTRUSTED,
XmppAxolotlSession.Trust.INACTIVE_UNTRUSTED);
Set<Integer> newDevices = new HashSet<>(deviceIds); Set<Integer> newDevices = new HashSet<>(deviceIds);
setTrustOnSessions(jid, newDevices, SQLiteAxolotlStore.Trust.INACTIVE, setTrustOnSessions(jid, newDevices, XmppAxolotlSession.Trust.INACTIVE_TRUSTED,
SQLiteAxolotlStore.Trust.TRUSTED); XmppAxolotlSession.Trust.TRUSTED);
setTrustOnSessions(jid, newDevices, XmppAxolotlSession.Trust.INACTIVE_UNDECIDED,
XmppAxolotlSession.Trust.UNDECIDED);
setTrustOnSessions(jid, newDevices, XmppAxolotlSession.Trust.INACTIVE_UNTRUSTED,
XmppAxolotlSession.Trust.UNTRUSTED);
this.deviceIds.put(jid, deviceIds); this.deviceIds.put(jid, deviceIds);
mXmppConnectionService.keyStatusUpdated(); mXmppConnectionService.keyStatusUpdated();
publishOwnDeviceIdIfNeeded(); publishOwnDeviceIdIfNeeded();
@ -291,7 +299,7 @@ public class AxolotlService {
} }
public void purgeKey(IdentityKey identityKey) { public void purgeKey(IdentityKey identityKey) {
axolotlStore.setFingerprintTrust(identityKey.getFingerprint().replaceAll("\\s", ""), SQLiteAxolotlStore.Trust.COMPROMISED); axolotlStore.setFingerprintTrust(identityKey.getFingerprint().replaceAll("\\s", ""), XmppAxolotlSession.Trust.COMPROMISED);
} }
public void publishOwnDeviceIdIfNeeded() { public void publishOwnDeviceIdIfNeeded() {
@ -419,11 +427,11 @@ public class AxolotlService {
(deviceIds.containsKey(jid) && !deviceIds.get(jid).isEmpty()); (deviceIds.containsKey(jid) && !deviceIds.get(jid).isEmpty());
} }
public SQLiteAxolotlStore.Trust getFingerprintTrust(String fingerprint) { public XmppAxolotlSession.Trust getFingerprintTrust(String fingerprint) {
return axolotlStore.getFingerprintTrust(fingerprint); return axolotlStore.getFingerprintTrust(fingerprint);
} }
public void setFingerprintTrust(String fingerprint, SQLiteAxolotlStore.Trust trust) { public void setFingerprintTrust(String fingerprint, XmppAxolotlSession.Trust trust) {
axolotlStore.setFingerprintTrust(fingerprint, trust); axolotlStore.setFingerprintTrust(fingerprint, trust);
} }

View file

@ -15,9 +15,7 @@ import org.whispersystems.libaxolotl.state.SessionRecord;
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord; import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
import org.whispersystems.libaxolotl.util.KeyHelper; import org.whispersystems.libaxolotl.util.KeyHelper;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
@ -51,64 +49,14 @@ public class SQLiteAxolotlStore implements AxolotlStore {
private int localRegistrationId; private int localRegistrationId;
private int currentPreKeyId = 0; private int currentPreKeyId = 0;
private final LruCache<String, Trust> trustCache = private final LruCache<String, XmppAxolotlSession.Trust> trustCache =
new LruCache<String, Trust>(NUM_TRUSTS_TO_CACHE) { new LruCache<String, XmppAxolotlSession.Trust>(NUM_TRUSTS_TO_CACHE) {
@Override @Override
protected Trust create(String fingerprint) { protected XmppAxolotlSession.Trust create(String fingerprint) {
return mXmppConnectionService.databaseBackend.isIdentityKeyTrusted(account, fingerprint); return mXmppConnectionService.databaseBackend.isIdentityKeyTrusted(account, fingerprint);
} }
}; };
public enum Trust {
UNDECIDED(0),
TRUSTED(1),
UNTRUSTED(2),
COMPROMISED(3),
INACTIVE(4);
private static final Map<Integer, Trust> trustsByValue = new HashMap<>();
static {
for (Trust trust : Trust.values()) {
trustsByValue.put(trust.getCode(), trust);
}
}
private final int code;
Trust(int code) {
this.code = code;
}
public int getCode() {
return this.code;
}
public String toString() {
switch (this) {
case UNDECIDED:
return "Trust undecided " + getCode();
case TRUSTED:
return "Trusted " + getCode();
case COMPROMISED:
return "Compromised " + getCode();
case INACTIVE:
return "Inactive " + getCode();
case UNTRUSTED:
default:
return "Untrusted " + getCode();
}
}
public static Trust fromBoolean(Boolean trusted) {
return trusted ? TRUSTED : UNTRUSTED;
}
public static Trust fromCode(int code) {
return trustsByValue.get(code);
}
}
private static IdentityKeyPair generateIdentityKeyPair() { private static IdentityKeyPair generateIdentityKeyPair() {
Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl IdentityKeyPair..."); Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl IdentityKeyPair...");
ECKeyPair identityKeyPairKeys = Curve.generateKeyPair(); ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();
@ -258,16 +206,16 @@ public class SQLiteAxolotlStore implements AxolotlStore {
return true; return true;
} }
public Trust getFingerprintTrust(String fingerprint) { public XmppAxolotlSession.Trust getFingerprintTrust(String fingerprint) {
return (fingerprint == null)? null : trustCache.get(fingerprint); return (fingerprint == null)? null : trustCache.get(fingerprint);
} }
public void setFingerprintTrust(String fingerprint, Trust trust) { public void setFingerprintTrust(String fingerprint, XmppAxolotlSession.Trust trust) {
mXmppConnectionService.databaseBackend.setIdentityKeyTrust(account, fingerprint, trust); mXmppConnectionService.databaseBackend.setIdentityKeyTrust(account, fingerprint, trust);
trustCache.remove(fingerprint); trustCache.remove(fingerprint);
} }
public Set<IdentityKey> getContactKeysWithTrust(String bareJid, Trust trust) { public Set<IdentityKey> getContactKeysWithTrust(String bareJid, XmppAxolotlSession.Trust trust) {
return mXmppConnectionService.databaseBackend.loadIdentityKeys(account, bareJid, trust); return mXmppConnectionService.databaseBackend.loadIdentityKeys(account, bareJid, trust);
} }

View file

@ -18,6 +18,9 @@ import org.whispersystems.libaxolotl.protocol.CiphertextMessage;
import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage; import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage;
import org.whispersystems.libaxolotl.protocol.WhisperMessage; import org.whispersystems.libaxolotl.protocol.WhisperMessage;
import java.util.HashMap;
import java.util.Map;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
@ -30,6 +33,62 @@ public class XmppAxolotlSession {
private Integer preKeyId = null; private Integer preKeyId = null;
private boolean fresh = true; private boolean fresh = true;
public enum Trust {
UNDECIDED(0),
TRUSTED(1),
UNTRUSTED(2),
COMPROMISED(3),
INACTIVE_TRUSTED(4),
INACTIVE_UNDECIDED(5),
INACTIVE_UNTRUSTED(6);
private static final Map<Integer, Trust> trustsByValue = new HashMap<>();
static {
for (Trust trust : Trust.values()) {
trustsByValue.put(trust.getCode(), trust);
}
}
private final int code;
Trust(int code) {
this.code = code;
}
public int getCode() {
return this.code;
}
public String toString() {
switch (this) {
case UNDECIDED:
return "Trust undecided " + getCode();
case TRUSTED:
return "Trusted " + getCode();
case COMPROMISED:
return "Compromised " + getCode();
case INACTIVE_TRUSTED:
return "Inactive (Trusted)" + getCode();
case INACTIVE_UNDECIDED:
return "Inactive (Undecided)" + getCode();
case INACTIVE_UNTRUSTED:
return "Inactive (Untrusted)" + getCode();
case UNTRUSTED:
default:
return "Untrusted " + getCode();
}
}
public static Trust fromBoolean(Boolean trusted) {
return trusted ? TRUSTED : UNTRUSTED;
}
public static Trust fromCode(int code) {
return trustsByValue.get(code);
}
}
public XmppAxolotlSession(Account account, SQLiteAxolotlStore store, AxolotlAddress remoteAddress, String fingerprint) { public XmppAxolotlSession(Account account, SQLiteAxolotlStore store, AxolotlAddress remoteAddress, String fingerprint) {
this(account, store, remoteAddress); this(account, store, remoteAddress);
this.fingerprint = fingerprint; this.fingerprint = fingerprint;
@ -67,21 +126,21 @@ public class XmppAxolotlSession {
this.fresh = false; this.fresh = false;
} }
protected void setTrust(SQLiteAxolotlStore.Trust trust) { protected void setTrust(Trust trust) {
sqLiteAxolotlStore.setFingerprintTrust(fingerprint, trust); sqLiteAxolotlStore.setFingerprintTrust(fingerprint, trust);
} }
protected SQLiteAxolotlStore.Trust getTrust() { protected Trust getTrust() {
SQLiteAxolotlStore.Trust trust = sqLiteAxolotlStore.getFingerprintTrust(fingerprint); Trust trust = sqLiteAxolotlStore.getFingerprintTrust(fingerprint);
return (trust == null) ? SQLiteAxolotlStore.Trust.UNDECIDED : trust; return (trust == null) ? Trust.UNDECIDED : trust;
} }
@Nullable @Nullable
public byte[] processReceiving(byte[] encryptedKey) { public byte[] processReceiving(byte[] encryptedKey) {
byte[] plaintext = null; byte[] plaintext = null;
SQLiteAxolotlStore.Trust trust = getTrust(); Trust trust = getTrust();
switch (trust) { switch (trust) {
case INACTIVE: case INACTIVE_TRUSTED:
case UNDECIDED: case UNDECIDED:
case UNTRUSTED: case UNTRUSTED:
case TRUSTED: case TRUSTED:
@ -110,8 +169,8 @@ public class XmppAxolotlSession {
Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Error decrypting axolotl header, " + e.getClass().getName() + ": " + e.getMessage()); Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Error decrypting axolotl header, " + e.getClass().getName() + ": " + e.getMessage());
} }
if (plaintext != null && trust == SQLiteAxolotlStore.Trust.INACTIVE) { if (plaintext != null && trust == Trust.INACTIVE_TRUSTED) {
setTrust(SQLiteAxolotlStore.Trust.TRUSTED); setTrust(Trust.TRUSTED);
} }
break; break;
@ -126,8 +185,8 @@ public class XmppAxolotlSession {
@Nullable @Nullable
public byte[] processSending(@NonNull byte[] outgoingMessage) { public byte[] processSending(@NonNull byte[] outgoingMessage) {
SQLiteAxolotlStore.Trust trust = getTrust(); Trust trust = getTrust();
if (trust == SQLiteAxolotlStore.Trust.TRUSTED) { if (trust == Trust.TRUSTED) {
CiphertextMessage ciphertextMessage = cipher.encrypt(outgoingMessage); CiphertextMessage ciphertextMessage = cipher.encrypt(outgoingMessage);
return ciphertextMessage.serialize(); return ciphertextMessage.serialize();
} else { } else {

View file

@ -8,7 +8,7 @@ import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.axolotl.SQLiteAxolotlStore; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.MimeUtils; import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
@ -707,7 +707,7 @@ public class Message extends AbstractEntity {
public boolean isTrusted() { public boolean isTrusted() {
return conversation.getAccount().getAxolotlService().getFingerprintTrust(axolotlFingerprint) return conversation.getAccount().getAxolotlService().getFingerprintTrust(axolotlFingerprint)
== SQLiteAxolotlStore.Trust.TRUSTED; == XmppAxolotlSession.Trust.TRUSTED;
} }
private int getPreviousEncryption() { private int getPreviousEncryption() {

View file

@ -28,6 +28,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.SQLiteAxolotlStore; import eu.siacs.conversations.crypto.axolotl.SQLiteAxolotlStore;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
@ -844,7 +845,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return loadIdentityKeys(account, name, null); return loadIdentityKeys(account, name, null);
} }
public Set<IdentityKey> loadIdentityKeys(Account account, String name, SQLiteAxolotlStore.Trust trust) { public Set<IdentityKey> loadIdentityKeys(Account account, String name, XmppAxolotlSession.Trust trust) {
Set<IdentityKey> identityKeys = new HashSet<>(); Set<IdentityKey> identityKeys = new HashSet<>();
Cursor cursor = getIdentityKeyCursor(account, name, false); Cursor cursor = getIdentityKeyCursor(account, name, false);
@ -870,7 +871,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
String[] args = { String[] args = {
account.getUuid(), account.getUuid(),
name, name,
String.valueOf(SQLiteAxolotlStore.Trust.TRUSTED.getCode()) String.valueOf(XmppAxolotlSession.Trust.TRUSTED.getCode())
}; };
return DatabaseUtils.queryNumEntries(db, SQLiteAxolotlStore.IDENTITIES_TABLENAME, return DatabaseUtils.queryNumEntries(db, SQLiteAxolotlStore.IDENTITIES_TABLENAME,
SQLiteAxolotlStore.ACCOUNT + " = ?" SQLiteAxolotlStore.ACCOUNT + " = ?"
@ -881,10 +882,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
} }
private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized) { private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized) {
storeIdentityKey(account, name, own, fingerprint, base64Serialized, SQLiteAxolotlStore.Trust.UNDECIDED); storeIdentityKey(account, name, own, fingerprint, base64Serialized, XmppAxolotlSession.Trust.UNDECIDED);
} }
private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized, SQLiteAxolotlStore.Trust trusted) { private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized, XmppAxolotlSession.Trust trusted) {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid()); values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
@ -896,19 +897,19 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.insert(SQLiteAxolotlStore.IDENTITIES_TABLENAME, null, values); db.insert(SQLiteAxolotlStore.IDENTITIES_TABLENAME, null, values);
} }
public SQLiteAxolotlStore.Trust isIdentityKeyTrusted(Account account, String fingerprint) { public XmppAxolotlSession.Trust isIdentityKeyTrusted(Account account, String fingerprint) {
Cursor cursor = getIdentityKeyCursor(account, fingerprint); Cursor cursor = getIdentityKeyCursor(account, fingerprint);
SQLiteAxolotlStore.Trust trust = null; XmppAxolotlSession.Trust trust = null;
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
cursor.moveToFirst(); cursor.moveToFirst();
int trustValue = cursor.getInt(cursor.getColumnIndex(SQLiteAxolotlStore.TRUSTED)); int trustValue = cursor.getInt(cursor.getColumnIndex(SQLiteAxolotlStore.TRUSTED));
trust = SQLiteAxolotlStore.Trust.fromCode(trustValue); trust = XmppAxolotlSession.Trust.fromCode(trustValue);
} }
cursor.close(); cursor.close();
return trust; return trust;
} }
public boolean setIdentityKeyTrust(Account account, String fingerprint, SQLiteAxolotlStore.Trust trust) { public boolean setIdentityKeyTrust(Account account, String fingerprint, XmppAxolotlSession.Trust trust) {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
String[] selectionArgs = { String[] selectionArgs = {
account.getUuid(), account.getUuid(),
@ -928,7 +929,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
} }
public void storeOwnIdentityKeyPair(Account account, String name, IdentityKeyPair identityKeyPair) { public void storeOwnIdentityKeyPair(Account account, String name, IdentityKeyPair identityKeyPair) {
storeIdentityKey(account, name, true, identityKeyPair.getPublicKey().getFingerprint().replaceAll("\\s", ""), Base64.encodeToString(identityKeyPair.serialize(), Base64.DEFAULT), SQLiteAxolotlStore.Trust.TRUSTED); storeIdentityKey(account, name, true, identityKeyPair.getPublicKey().getFingerprint().replaceAll("\\s", ""), Base64.encodeToString(identityKeyPair.serialize(), Base64.DEFAULT), XmppAxolotlSession.Trust.TRUSTED);
} }
public void recreateAxolotlDb() { public void recreateAxolotlDb() {

View file

@ -38,7 +38,7 @@ import de.timroes.android.listview.EnhancedListView;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.SQLiteAxolotlStore.Trust; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Blockable; import eu.siacs.conversations.entities.Blockable;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
@ -1260,7 +1260,7 @@ public class ConversationActivity extends XmppActivity
protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) { protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) {
AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService(); AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService();
boolean hasPendingKeys = !axolotlService.getKeysWithTrust(Trust.UNDECIDED, boolean hasPendingKeys = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED,
mSelectedConversation.getContact()).isEmpty() mSelectedConversation.getContact()).isEmpty()
|| !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty(); || !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
boolean hasNoTrustedKeys = axolotlService.getNumTrustedKeys(mSelectedConversation.getContact()) == 0; boolean hasNoTrustedKeys = axolotlService.getNumTrustedKeys(mSelectedConversation.getContact()) == 0;

View file

@ -16,7 +16,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.SQLiteAxolotlStore.Trust; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
@ -119,7 +119,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
for(final IdentityKey identityKey : ownKeysToTrust.keySet()) { for(final IdentityKey identityKey : ownKeysToTrust.keySet()) {
hasOwnKeys = true; hasOwnKeys = true;
addFingerprintRowWithListeners(ownKeys, contact.getAccount(), identityKey, false, addFingerprintRowWithListeners(ownKeys, contact.getAccount(), identityKey, false,
Trust.fromBoolean(ownKeysToTrust.get(identityKey)), false, XmppAxolotlSession.Trust.fromBoolean(ownKeysToTrust.get(identityKey)), false,
new CompoundButton.OnCheckedChangeListener() { new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -135,7 +135,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
for(final IdentityKey identityKey : foreignKeysToTrust.keySet()) { for(final IdentityKey identityKey : foreignKeysToTrust.keySet()) {
hasForeignKeys = true; hasForeignKeys = true;
addFingerprintRowWithListeners(foreignKeys, contact.getAccount(), identityKey, false, addFingerprintRowWithListeners(foreignKeys, contact.getAccount(), identityKey, false,
Trust.fromBoolean(foreignKeysToTrust.get(identityKey)), false, XmppAxolotlSession.Trust.fromBoolean(foreignKeysToTrust.get(identityKey)), false,
new CompoundButton.OnCheckedChangeListener() { new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -171,11 +171,11 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
} }
private void getFingerprints(final Account account) { private void getFingerprints(final Account account) {
Set<IdentityKey> ownKeysSet = account.getAxolotlService().getKeysWithTrust(Trust.UNDECIDED); Set<IdentityKey> ownKeysSet = account.getAxolotlService().getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED);
Set<IdentityKey> foreignKeysSet = account.getAxolotlService().getKeysWithTrust(Trust.UNDECIDED, contact); Set<IdentityKey> foreignKeysSet = account.getAxolotlService().getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED, contact);
if (hasNoTrustedKeys) { if (hasNoTrustedKeys) {
ownKeysSet.addAll(account.getAxolotlService().getKeysWithTrust(Trust.UNTRUSTED)); ownKeysSet.addAll(account.getAxolotlService().getKeysWithTrust(XmppAxolotlSession.Trust.UNTRUSTED));
foreignKeysSet.addAll(account.getAxolotlService().getKeysWithTrust(Trust.UNTRUSTED, contact)); foreignKeysSet.addAll(account.getAxolotlService().getKeysWithTrust(XmppAxolotlSession.Trust.UNTRUSTED, contact));
} }
for(final IdentityKey identityKey : ownKeysSet) { for(final IdentityKey identityKey : ownKeysSet) {
if(!ownKeysToTrust.containsKey(identityKey)) { if(!ownKeysToTrust.containsKey(identityKey)) {
@ -226,12 +226,12 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate
for(IdentityKey identityKey:ownKeysToTrust.keySet()) { for(IdentityKey identityKey:ownKeysToTrust.keySet()) {
contact.getAccount().getAxolotlService().setFingerprintTrust( contact.getAccount().getAxolotlService().setFingerprintTrust(
identityKey.getFingerprint().replaceAll("\\s", ""), identityKey.getFingerprint().replaceAll("\\s", ""),
Trust.fromBoolean(ownKeysToTrust.get(identityKey))); XmppAxolotlSession.Trust.fromBoolean(ownKeysToTrust.get(identityKey)));
} }
for(IdentityKey identityKey:foreignKeysToTrust.keySet()) { for(IdentityKey identityKey:foreignKeysToTrust.keySet()) {
contact.getAccount().getAxolotlService().setFingerprintTrust( contact.getAccount().getAxolotlService().setFingerprintTrust(
identityKey.getFingerprint().replaceAll("\\s", ""), identityKey.getFingerprint().replaceAll("\\s", ""),
Trust.fromBoolean(foreignKeysToTrust.get(identityKey))); XmppAxolotlSession.Trust.fromBoolean(foreignKeysToTrust.get(identityKey)));
} }
} }

View file

@ -70,7 +70,7 @@ import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.SQLiteAxolotlStore; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
@ -615,24 +615,22 @@ public abstract class XmppActivity extends Activity {
protected boolean addFingerprintRow(LinearLayout keys, final Account account, IdentityKey identityKey, boolean highlight) { protected boolean addFingerprintRow(LinearLayout keys, final Account account, IdentityKey identityKey, boolean highlight) {
final String fingerprint = identityKey.getFingerprint().replaceAll("\\s", ""); final String fingerprint = identityKey.getFingerprint().replaceAll("\\s", "");
final SQLiteAxolotlStore.Trust trust = account.getAxolotlService() final XmppAxolotlSession.Trust trust = account.getAxolotlService()
.getFingerprintTrust(fingerprint); .getFingerprintTrust(fingerprint);
return addFingerprintRowWithListeners(keys, account, identityKey, highlight, trust, true, return addFingerprintRowWithListeners(keys, account, identityKey, highlight, trust, true,
new CompoundButton.OnCheckedChangeListener() { new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked != (trust == SQLiteAxolotlStore.Trust.TRUSTED)) { account.getAxolotlService().setFingerprintTrust(fingerprint,
account.getAxolotlService().setFingerprintTrust(fingerprint, (isChecked) ? XmppAxolotlSession.Trust.TRUSTED :
(isChecked) ? SQLiteAxolotlStore.Trust.TRUSTED : XmppAxolotlSession.Trust.UNTRUSTED);
SQLiteAxolotlStore.Trust.UNTRUSTED);
}
} }
}, },
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
account.getAxolotlService().setFingerprintTrust(fingerprint, account.getAxolotlService().setFingerprintTrust(fingerprint,
SQLiteAxolotlStore.Trust.UNTRUSTED); XmppAxolotlSession.Trust.UNTRUSTED);
v.setEnabled(true); v.setEnabled(true);
} }
} }
@ -643,12 +641,12 @@ public abstract class XmppActivity extends Activity {
protected boolean addFingerprintRowWithListeners(LinearLayout keys, final Account account, protected boolean addFingerprintRowWithListeners(LinearLayout keys, final Account account,
final IdentityKey identityKey, final IdentityKey identityKey,
boolean highlight, boolean highlight,
SQLiteAxolotlStore.Trust trust, XmppAxolotlSession.Trust trust,
boolean showTag, boolean showTag,
CompoundButton.OnCheckedChangeListener CompoundButton.OnCheckedChangeListener
onCheckedChangeListener, onCheckedChangeListener,
View.OnClickListener onClickListener) { View.OnClickListener onClickListener) {
if (trust == SQLiteAxolotlStore.Trust.COMPROMISED) { if (trust == XmppAxolotlSession.Trust.COMPROMISED) {
return false; return false;
} }
View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false); View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
@ -669,7 +667,7 @@ public abstract class XmppActivity extends Activity {
switch (trust) { switch (trust) {
case UNTRUSTED: case UNTRUSTED:
case TRUSTED: case TRUSTED:
trustToggle.setChecked(trust == SQLiteAxolotlStore.Trust.TRUSTED, false); trustToggle.setChecked(trust == XmppAxolotlSession.Trust.TRUSTED, false);
trustToggle.setEnabled(true); trustToggle.setEnabled(true);
key.setTextColor(getPrimaryTextColor()); key.setTextColor(getPrimaryTextColor());
keyType.setTextColor(getSecondaryTextColor()); keyType.setTextColor(getSecondaryTextColor());
@ -680,7 +678,15 @@ public abstract class XmppActivity extends Activity {
key.setTextColor(getPrimaryTextColor()); key.setTextColor(getPrimaryTextColor());
keyType.setTextColor(getSecondaryTextColor()); keyType.setTextColor(getSecondaryTextColor());
break; break;
case INACTIVE: case INACTIVE_UNTRUSTED:
case INACTIVE_UNDECIDED:
trustToggle.setOnClickListener(null);
trustToggle.setChecked(false, false);
trustToggle.setEnabled(false);
key.setTextColor(getTertiaryTextColor());
keyType.setTextColor(getTertiaryTextColor());
break;
case INACTIVE_TRUSTED:
trustToggle.setOnClickListener(null); trustToggle.setOnClickListener(null);
trustToggle.setChecked(true, false); trustToggle.setChecked(true, false);
trustToggle.setEnabled(false); trustToggle.setEnabled(false);

View file

@ -27,7 +27,7 @@ import android.widget.Toast;
import java.util.List; import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.SQLiteAxolotlStore; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
@ -169,11 +169,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} else { } else {
viewHolder.indicator.setVisibility(View.VISIBLE); viewHolder.indicator.setVisibility(View.VISIBLE);
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
SQLiteAxolotlStore.Trust trust = message.getConversation() XmppAxolotlSession.Trust trust = message.getConversation()
.getAccount().getAxolotlService().getFingerprintTrust( .getAccount().getAxolotlService().getFingerprintTrust(
message.getAxolotlFingerprint()); message.getAxolotlFingerprint());
if(trust == null || trust != SQLiteAxolotlStore.Trust.TRUSTED) { if(trust == null || trust != XmppAxolotlSession.Trust.TRUSTED) {
viewHolder.indicator.setColorFilter(activity.getWarningTextColor()); viewHolder.indicator.setColorFilter(activity.getWarningTextColor());
viewHolder.indicator.setAlpha(1.0f); viewHolder.indicator.setAlpha(1.0f);
} else { } else {