aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Account.java7
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Contact.java62
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java14
3 files changed, 54 insertions, 29 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java
index 383125667..7a2dc3f76 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -20,6 +20,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OtrService;
+import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
@@ -122,6 +123,7 @@ public class Account extends AbstractEntity {
protected String avatar;
protected boolean online = false;
private OtrService mOtrService = null;
+ private AxolotlService axolotlService = null;
private XmppConnection xmppConnection = null;
private long mEndGracePeriod = 0L;
private String otrFingerprint;
@@ -281,8 +283,13 @@ public class Account extends AbstractEntity {
return values;
}
+ public AxolotlService getAxolotlService() {
+ return axolotlService;
+ }
+
public void initAccountServices(final XmppConnectionService context) {
this.mOtrService = new OtrService(context, this);
+ this.axolotlService = new AxolotlService(this, context);
}
public OtrService getOtrService() {
diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java
index 2f9b375df..45b55e49d 100644
--- a/src/main/java/eu/siacs/conversations/entities/Contact.java
+++ b/src/main/java/eu/siacs/conversations/entities/Contact.java
@@ -2,6 +2,7 @@ package eu.siacs.conversations.entities;
import android.content.ContentValues;
import android.database.Cursor;
+import android.util.Base64;
import android.util.Log;
import org.json.JSONArray;
@@ -349,20 +350,38 @@ public class Contact implements ListItem, Blockable {
}
}
- public List<IdentityKey> getTrustedAxolotlIdentityKeys() {
+ public List<IdentityKey> getAxolotlIdentityKeys() {
synchronized (this.keys) {
JSONArray serializedKeyItems = this.keys.optJSONArray("axolotl_identity_key");
List<IdentityKey> identityKeys = new ArrayList<>();
+ List<Integer> toDelete = new ArrayList<>();
if(serializedKeyItems != null) {
for(int i = 0; i<serializedKeyItems.length();++i) {
try {
String serializedKeyItem = serializedKeyItems.getString(i);
- IdentityKey identityKey = new IdentityKey(serializedKeyItem.getBytes(), 0);
+ IdentityKey identityKey = new IdentityKey(Base64.decode(serializedKeyItem, Base64.DEFAULT), 0);
identityKeys.add(identityKey);
} catch (InvalidKeyException e) {
- Log.e(Config.LOGTAG, "Invalid axolotl identity key encountered at" + this.getJid() + ": " + e.getMessage());
+ Log.e(Config.LOGTAG, "Invalid axolotl identity key encountered at contact" + this.getJid() + ": " + e.getMessage() + ", marking for deletion...");
+ toDelete.add(i);
} catch (JSONException e) {
- Log.e(Config.LOGTAG, "Error retrieving axolotl identity key at" + this.getJid() + ": " + e.getMessage());
+ Log.e(Config.LOGTAG, "Error retrieving axolotl identity key at contact " + this.getJid() + ": " + e.getMessage());
+ } catch (IllegalArgumentException e) {
+ Log.e(Config.LOGTAG, "Encountered malformed identity key for contact" + this.getJid() + ": " + e.getMessage() + ", marking for deletion... ");
+ toDelete.add(i);
+ }
+ }
+ if(!toDelete.isEmpty()) {
+ try {
+ JSONArray filteredKeyItems = new JSONArray();
+ for (int i = 0; i < serializedKeyItems.length(); ++i) {
+ if (!toDelete.contains(i)) {
+ filteredKeyItems.put(serializedKeyItems.get(i));
+ }
+ }
+ this.keys.put("axolotl_identity_key", filteredKeyItems);
+ } catch (JSONException e) {
+ //should never happen
}
}
}
@@ -370,23 +389,28 @@ public class Contact implements ListItem, Blockable {
}
}
- public boolean addAxolotlIdentityKey(IdentityKey identityKey, boolean trusted) {
+ public boolean addAxolotlIdentityKey(IdentityKey identityKey) {
synchronized (this.keys) {
- JSONArray keysList;
- try {
- keysList = this.keys.getJSONArray("axolotl_identity_key");
- } catch (JSONException e) {
- keysList = new JSONArray();
- }
- keysList.put(new String(identityKey.serialize()));
- try {
- this.keys.put("axolotl_identity_key", keysList);
- } catch (JSONException e) {
- Log.e(Config.LOGTAG, "Error adding Identity Key to Contact " + this.getJid() + ": " + e.getMessage());
- return false;
- }
+ if(!getAxolotlIdentityKeys().contains(identityKey)) {
+ JSONArray keysList;
+ try {
+ keysList = this.keys.getJSONArray("axolotl_identity_key");
+ } catch (JSONException e) {
+ keysList = new JSONArray();
+ }
+
+ keysList.put(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT));
+ try {
+ this.keys.put("axolotl_identity_key", keysList);
+ } catch (JSONException e) {
+ Log.e(Config.LOGTAG, "Error adding Identity Key to Contact " + this.getJid() + ": " + e.getMessage());
+ return false;
+ }
+ return true;
+ } else {
+ return false;
+ }
}
- return true;
}
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index b429354b8..336af9721 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -8,6 +8,7 @@ import java.net.URL;
import java.util.Arrays;
import eu.siacs.conversations.Config;
+import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.utils.UIHelper;
@@ -34,6 +35,7 @@ public class Message extends AbstractEntity {
public static final int ENCRYPTION_OTR = 2;
public static final int ENCRYPTION_DECRYPTED = 3;
public static final int ENCRYPTION_DECRYPTION_FAILED = 4;
+ public static final int ENCRYPTION_AXOLOTL = 5;
public static final int TYPE_TEXT = 0;
public static final int TYPE_IMAGE = 1;
@@ -65,7 +67,7 @@ public class Message extends AbstractEntity {
protected int encryption;
protected int status;
protected int type;
- private boolean isTrusted = true;
+ private AxolotlService.XmppAxolotlSession axolotlSession = null;
protected String relativeFilePath;
protected boolean read = true;
protected String remoteMsgId = null;
@@ -665,15 +667,7 @@ public class Message extends AbstractEntity {
public int height = 0;
}
- public void trust() {
- this.isTrusted = true;
- }
-
- public void distrust() {
- this.isTrusted = false;
- }
-
public boolean isTrusted() {
- return this.isTrusted;
+ return this.axolotlSession != null && this.axolotlSession.isTrusted();
}
}