aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java16
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java37
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java6
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java8
5 files changed, 43 insertions, 28 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
index 23adbad8..57e57f7f 100644
--- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
@@ -267,12 +267,12 @@ public class AxolotlService {
return true;
}
- public Trust getFingerprintTrust(String name, String fingerprint) {
- return mXmppConnectionService.databaseBackend.isIdentityKeyTrusted(account, name, fingerprint);
+ public Trust getFingerprintTrust(String fingerprint) {
+ return mXmppConnectionService.databaseBackend.isIdentityKeyTrusted(account, fingerprint);
}
- public void setFingerprintTrust(String name, String fingerprint, Trust trust) {
- mXmppConnectionService.databaseBackend.setIdentityKeyTrust(account, name, fingerprint, trust);
+ public void setFingerprintTrust(String fingerprint, Trust trust) {
+ mXmppConnectionService.databaseBackend.setIdentityKeyTrust(account, fingerprint, trust);
}
// --------------------------------------
@@ -844,12 +844,12 @@ public class AxolotlService {
return sessions.hasAny(address) ||
( deviceIds.containsKey(jid) && !deviceIds.get(jid).isEmpty());
}
- public SQLiteAxolotlStore.Trust getFingerprintTrust(String name, String fingerprint) {
- return axolotlStore.getFingerprintTrust(name, fingerprint);
+ public SQLiteAxolotlStore.Trust getFingerprintTrust(String fingerprint) {
+ return axolotlStore.getFingerprintTrust(fingerprint);
}
- public void setFingerprintTrust(String name, String fingerprint, SQLiteAxolotlStore.Trust trust) {
- axolotlStore.setFingerprintTrust(name, fingerprint, trust);
+ public void setFingerprintTrust(String fingerprint, SQLiteAxolotlStore.Trust trust) {
+ axolotlStore.setFingerprintTrust(fingerprint, trust);
}
private void buildSessionFromPEP(final Conversation conversation, final AxolotlAddress address) {
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index 4c6bf221..39ef5d36 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -785,20 +785,28 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return getIdentityKeyCursor(account, name, own, null);
}
- private Cursor getIdentityKeyCursor(Account account, String name, boolean own, String fingerprint) {
+ private Cursor getIdentityKeyCursor(Account account, String fingerprint) {
+ return getIdentityKeyCursor(account, null, null, fingerprint);
+ }
+
+ private Cursor getIdentityKeyCursor(Account account, String name, Boolean own, String fingerprint) {
final SQLiteDatabase db = this.getReadableDatabase();
String[] columns = {AxolotlService.SQLiteAxolotlStore.TRUSTED,
AxolotlService.SQLiteAxolotlStore.KEY};
ArrayList<String> selectionArgs = new ArrayList<>(4);
selectionArgs.add(account.getUuid());
- selectionArgs.add(name);
- selectionArgs.add(own?"1":"0");
- String selectionString = AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ? AND "
- + AxolotlService.SQLiteAxolotlStore.NAME + " = ? AND "
- + AxolotlService.SQLiteAxolotlStore.OWN + " = ? ";
+ String selectionString = AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ?";
+ if (name != null){
+ selectionArgs.add(name);
+ selectionString += " AND " +AxolotlService.SQLiteAxolotlStore.NAME + " = ?";
+ }
if (fingerprint != null){
selectionArgs.add(fingerprint);
- selectionString += "AND " +AxolotlService.SQLiteAxolotlStore.FINGERPRINT + " = ? ";
+ selectionString += " AND " +AxolotlService.SQLiteAxolotlStore.FINGERPRINT + " = ?";
+ }
+ if (own != null){
+ selectionArgs.add(own?"1":"0");
+ selectionString += " AND " +AxolotlService.SQLiteAxolotlStore.OWN + " = ?";
}
Cursor cursor = db.query(AxolotlService.SQLiteAxolotlStore.IDENTITIES_TABLENAME,
columns,
@@ -842,6 +850,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized) {
+ storeIdentityKey(account, name, own, fingerprint, base64Serialized, AxolotlService.SQLiteAxolotlStore.Trust.UNDECIDED);
+ }
+
+ private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized, AxolotlService.SQLiteAxolotlStore.Trust trusted) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(AxolotlService.SQLiteAxolotlStore.ACCOUNT, account.getUuid());
@@ -849,11 +861,12 @@ public class DatabaseBackend extends SQLiteOpenHelper {
values.put(AxolotlService.SQLiteAxolotlStore.OWN, own ? 1 : 0);
values.put(AxolotlService.SQLiteAxolotlStore.FINGERPRINT, fingerprint);
values.put(AxolotlService.SQLiteAxolotlStore.KEY, base64Serialized);
+ values.put(AxolotlService.SQLiteAxolotlStore.TRUSTED, trusted.ordinal());
db.insert(AxolotlService.SQLiteAxolotlStore.IDENTITIES_TABLENAME, null, values);
}
- public AxolotlService.SQLiteAxolotlStore.Trust isIdentityKeyTrusted(Account account, String name, String fingerprint) {
- Cursor cursor = getIdentityKeyCursor(account, name, false, fingerprint);
+ public AxolotlService.SQLiteAxolotlStore.Trust isIdentityKeyTrusted(Account account, String fingerprint) {
+ Cursor cursor = getIdentityKeyCursor(account, fingerprint);
AxolotlService.SQLiteAxolotlStore.Trust trust = null;
if (cursor.getCount() > 0) {
cursor.moveToFirst();
@@ -864,18 +877,16 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return trust;
}
- public boolean setIdentityKeyTrust(Account account, String name, String fingerprint, AxolotlService.SQLiteAxolotlStore.Trust trust) {
+ public boolean setIdentityKeyTrust(Account account, String fingerprint, AxolotlService.SQLiteAxolotlStore.Trust trust) {
SQLiteDatabase db = this.getWritableDatabase();
String[] selectionArgs = {
account.getUuid(),
- name,
fingerprint
};
ContentValues values = new ContentValues();
values.put(AxolotlService.SQLiteAxolotlStore.TRUSTED, trust.ordinal());
int rows = db.update(AxolotlService.SQLiteAxolotlStore.IDENTITIES_TABLENAME, values,
AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ? AND "
- + AxolotlService.SQLiteAxolotlStore.NAME + " = ? AND "
+ AxolotlService.SQLiteAxolotlStore.FINGERPRINT + " = ? ",
selectionArgs);
return rows == 1;
@@ -886,7 +897,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
public void storeOwnIdentityKeyPair(Account account, String name, IdentityKeyPair identityKeyPair) {
- storeIdentityKey(account, name, true, identityKeyPair.getPublicKey().getFingerprint().replaceAll("\\s", ""), Base64.encodeToString(identityKeyPair.serialize(), Base64.DEFAULT));
+ storeIdentityKey(account, name, true, identityKeyPair.getPublicKey().getFingerprint().replaceAll("\\s", ""), Base64.encodeToString(identityKeyPair.serialize(), Base64.DEFAULT), AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED);
}
public void recreateAxolotlDb() {
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index ca62b7db..92e4cf35 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -759,6 +759,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
packet = account.getAxolotlService().fetchPacketFromCache(message);
if (packet == null && account.isOnlineAndConnected()) {
account.getAxolotlService().prepareMessage(message);
+ message.setAxolotlFingerprint(account.getAxolotlService().getOwnPublicKey().getFingerprint().replaceAll("\\s", ""));
}
break;
@@ -789,6 +790,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
conversation.startOtrSession(message.getCounterpart().getResourcepart(), false);
}
break;
+ case Message.ENCRYPTION_AXOLOTL:
+ message.setAxolotlFingerprint(account.getAxolotlService().getOwnPublicKey().getFingerprint().replaceAll("\\s", ""));
+ break;
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
index ebc1ae83..ef99b491 100644
--- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
@@ -393,7 +393,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
final String fingerprint = identityKey.getFingerprint().replaceAll("\\s", "");
final Jid bareJid = contactJid.toBareJid();
AxolotlService.SQLiteAxolotlStore.Trust trust = contact.getAccount().getAxolotlService()
- .getFingerprintTrust(bareJid.toString(), fingerprint);
+ .getFingerprintTrust(fingerprint);
switch (trust) {
case TRUSTED:
removeButton.setVisibility(View.VISIBLE);
@@ -413,7 +413,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
removeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- axolotlService.setFingerprintTrust(bareJid.toString(), fingerprint,
+ axolotlService.setFingerprintTrust(fingerprint,
AxolotlService.SQLiteAxolotlStore.Trust.UNTRUSTED);
refreshUi();
xmppConnectionService.updateConversationUi();
@@ -422,7 +422,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
trustButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- axolotlService.setFingerprintTrust(bareJid.toString(), fingerprint,
+ axolotlService.setFingerprintTrust(fingerprint,
AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED);
refreshUi();
xmppConnectionService.updateConversationUi();
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index d2c75a5e..df3a391b 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -156,15 +156,15 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.indicator.setVisibility(View.GONE);
} else {
viewHolder.indicator.setVisibility(View.VISIBLE);
- if (message.getMergedStatus() == Message.STATUS_RECEIVED
- && message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
+ if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
AxolotlService.SQLiteAxolotlStore.Trust trust = message.getConversation()
.getAccount().getAxolotlService().getFingerprintTrust(
- message.getContact().getJid().toBareJid().toString(),
message.getAxolotlFingerprint());
- if (trust == null || trust != AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED) {
+ if(trust == null || trust != AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED) {
viewHolder.indicator.setColorFilter(Color.RED);
+ } else {
+ viewHolder.indicator.clearColorFilter();
}
}
}