aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-11-17 20:48:13 +0100
committerChristian Schneppe <christian@pix-art.de>2016-11-17 20:48:13 +0100
commit3765d552926951452b34fb024e8d50f000c6baab (patch)
tree56505fd28ba971f66f7ac806f3c244e9200ef57d /src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
parent120c1d903b670f1621d9eea8cdbe94e6ec002ef1 (diff)
refactore trust enum to be FingerprintStatus class with trust and active
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java105
1 files changed, 47 insertions, 58 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
index a7503c089..384a19067 100644
--- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
@@ -185,8 +185,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
private void fillMap(SQLiteAxolotlStore store) {
- List<Integer> deviceIds = store.getSubDeviceSessions(account.getJid().toBareJid().toPreppedString());
- putDevicesForJid(account.getJid().toBareJid().toPreppedString(), deviceIds, store);
+ List<Integer> deviceIds = store.getSubDeviceSessions(account.getJid().toBareJid().toPreppedString());
+ putDevicesForJid(account.getJid().toBareJid().toPreppedString(), deviceIds, store);
for (Contact contact : account.getRoster().getContacts()) {
Jid bareJid = contact.getJid().toBareJid();
String address = bareJid.toString();
@@ -256,18 +256,18 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
return axolotlStore.getIdentityKeyPair().getPublicKey().getFingerprint().replaceAll("\\s", "");
}
- public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust) {
- return axolotlStore.getContactKeysWithTrust(account.getJid().toBareJid().toPreppedString(), trust);
+ public Set<IdentityKey> getKeysWithTrust(FingerprintStatus status) {
+ return axolotlStore.getContactKeysWithTrust(account.getJid().toBareJid().toPreppedString(), status);
}
- public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, Jid jid) {
- return axolotlStore.getContactKeysWithTrust(jid.toBareJid().toPreppedString(), trust);
+ public Set<IdentityKey> getKeysWithTrust(FingerprintStatus status, Jid jid) {
+ return axolotlStore.getContactKeysWithTrust(jid.toBareJid().toPreppedString(), status);
}
- public Set<IdentityKey> getKeysWithTrust(XmppAxolotlSession.Trust trust, List<Jid> jids) {
+ public Set<IdentityKey> getKeysWithTrust(FingerprintStatus status, List<Jid> jids) {
Set<IdentityKey> keys = new HashSet<>();
for(Jid jid : jids) {
- keys.addAll(axolotlStore.getContactKeysWithTrust(jid.toPreppedString(), trust));
+ keys.addAll(axolotlStore.getContactKeysWithTrust(jid.toPreppedString(), status));
}
return keys;
}
@@ -355,19 +355,6 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
return this.deviceIds.get(account.getJid().toBareJid());
}
- private void setTrustOnSessions(final Jid jid, @NonNull final Set<Integer> deviceIds,
- final XmppAxolotlSession.Trust from,
- final XmppAxolotlSession.Trust to) {
- for (Integer deviceId : deviceIds) {
- AxolotlAddress address = new AxolotlAddress(jid.toBareJid().toPreppedString(), deviceId);
- XmppAxolotlSession session = sessions.get(address);
- if (session != null && session.getFingerprint() != null
- && session.getTrust() == from) {
- session.setTrust(to);
- }
- }
- }
-
public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) {
if (jid.toBareJid().equals(account.getJid().toBareJid())) {
if (!deviceIds.isEmpty()) {
@@ -389,23 +376,25 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
Set<Integer> expiredDevices = new HashSet<>(axolotlStore.getSubDeviceSessions(jid.toBareJid().toPreppedString()));
expiredDevices.removeAll(deviceIds);
- setTrustOnSessions(jid, expiredDevices, XmppAxolotlSession.Trust.TRUSTED,
- XmppAxolotlSession.Trust.INACTIVE_TRUSTED);
- setTrustOnSessions(jid, expiredDevices, XmppAxolotlSession.Trust.TRUSTED_X509,
- XmppAxolotlSession.Trust.INACTIVE_TRUSTED_X509);
- setTrustOnSessions(jid, expiredDevices, XmppAxolotlSession.Trust.UNDECIDED,
- XmppAxolotlSession.Trust.INACTIVE_UNDECIDED);
- setTrustOnSessions(jid, expiredDevices, XmppAxolotlSession.Trust.UNTRUSTED,
- XmppAxolotlSession.Trust.INACTIVE_UNTRUSTED);
+ for (Integer deviceId : expiredDevices) {
+ AxolotlAddress address = new AxolotlAddress(jid.toBareJid().toPreppedString(), deviceId);
+ XmppAxolotlSession session = sessions.get(address);
+ if (session != null && session.getFingerprint() != null) {
+ if (session.getTrust().isActive()) {
+ session.setTrust(session.getTrust().toInactive());
+ }
+ }
+ }
Set<Integer> newDevices = new HashSet<>(deviceIds);
- setTrustOnSessions(jid, newDevices, XmppAxolotlSession.Trust.INACTIVE_TRUSTED,
- XmppAxolotlSession.Trust.TRUSTED);
- setTrustOnSessions(jid, newDevices, XmppAxolotlSession.Trust.INACTIVE_TRUSTED_X509,
- XmppAxolotlSession.Trust.TRUSTED_X509);
- setTrustOnSessions(jid, newDevices, XmppAxolotlSession.Trust.INACTIVE_UNDECIDED,
- XmppAxolotlSession.Trust.UNDECIDED);
- setTrustOnSessions(jid, newDevices, XmppAxolotlSession.Trust.INACTIVE_UNTRUSTED,
- XmppAxolotlSession.Trust.UNTRUSTED);
+ for (Integer deviceId : newDevices) {
+ AxolotlAddress address = new AxolotlAddress(jid.toBareJid().toPreppedString(), deviceId);
+ XmppAxolotlSession session = sessions.get(address);
+ if (session != null && session.getFingerprint() != null) {
+ if (!session.getTrust().isActive()) {
+ session.setTrust(session.getTrust().toActive());
+ }
+ }
+ }
this.deviceIds.put(jid, deviceIds);
mXmppConnectionService.keyStatusUpdated(null);
}
@@ -428,7 +417,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
public void purgeKey(final String fingerprint) {
- axolotlStore.setFingerprintTrust(fingerprint.replaceAll("\\s", ""), XmppAxolotlSession.Trust.COMPROMISED);
+ axolotlStore.setFingerprintTrust(fingerprint.replaceAll("\\s", ""), FingerprintStatus.createCompromised());
}
public void publishOwnDeviceIdIfNeeded() {
@@ -660,24 +649,24 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
public Pair<AxolotlCapability,Jid> isConversationAxolotlCapableDetailed(Conversation conversation) {
- if (conversation.getMode() == Conversation.MODE_SINGLE || (conversation.getMucOptions().membersOnly() && conversation.getMucOptions().nonanonymous())) {
- final List<Jid> jids = getCryptoTargets(conversation);
- for(Jid jid : jids) {
- if (!hasAny(jid) && (!deviceIds.containsKey(jid) || deviceIds.get(jid).isEmpty())) {
- if (conversation.getAccount().getRoster().getContact(jid).mutualPresenceSubscription()) {
- return new Pair<>(AxolotlCapability.MISSING_KEYS,jid);
- } else {
- return new Pair<>(AxolotlCapability.MISSING_PRESENCE,jid);
- }
+ if (conversation.getMode() == Conversation.MODE_SINGLE || (conversation.getMucOptions().membersOnly() && conversation.getMucOptions().nonanonymous())) {
+ final List<Jid> jids = getCryptoTargets(conversation);
+ for(Jid jid : jids) {
+ if (!hasAny(jid) && (!deviceIds.containsKey(jid) || deviceIds.get(jid).isEmpty())) {
+ if (conversation.getAccount().getRoster().getContact(jid).mutualPresenceSubscription()) {
+ return new Pair<>(AxolotlCapability.MISSING_KEYS,jid);
+ } else {
+ return new Pair<>(AxolotlCapability.MISSING_PRESENCE,jid);
+ }
}
}
- if (jids.size() > 0) {
- return new Pair<>(AxolotlCapability.FULL, null);
+ if (jids.size() > 0) {
+ return new Pair<>(AxolotlCapability.FULL, null);
} else {
return new Pair<>(AxolotlCapability.NO_MEMBERS, null);
}
- } else {
- return new Pair<>(AxolotlCapability.WRONG_CONFIGURATION, null);
+ } else {
+ return new Pair<>(AxolotlCapability.WRONG_CONFIGURATION, null);
}
}
@@ -691,16 +680,16 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
return jids;
}
- public XmppAxolotlSession.Trust getFingerprintTrust(String fingerprint) {
- return axolotlStore.getFingerprintTrust(fingerprint);
+ public FingerprintStatus getFingerprintTrust(String fingerprint) {
+ return axolotlStore.getFingerprintStatus(fingerprint);
}
public X509Certificate getFingerprintCertificate(String fingerprint) {
return axolotlStore.getFingerprintCertificate(fingerprint);
}
- public void setFingerprintTrust(String fingerprint, XmppAxolotlSession.Trust trust) {
- axolotlStore.setFingerprintTrust(fingerprint, trust);
+ public void setFingerprintTrust(String fingerprint, FingerprintStatus status) {
+ axolotlStore.setFingerprintTrust(fingerprint, status);
}
private void verifySessionWithPEP(final XmppAxolotlSession session) {
@@ -723,7 +712,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
mXmppConnectionService.getMemorizingTrustManager().getNonInteractive().checkClientTrusted(verification.first, "RSA");
String fingerprint = session.getFingerprint();
Log.d(Config.LOGTAG, "verified session with x.509 signature. fingerprint was: "+fingerprint);
- setFingerprintTrust(fingerprint, XmppAxolotlSession.Trust.TRUSTED_X509);
+ setFingerprintTrust(fingerprint, FingerprintStatus.createActiveVerified(true));
axolotlStore.setFingerprintCertificate(fingerprint, verification.first[0]);
fetchStatusMap.put(address, FetchStatus.SUCCESS_VERIFIED);
Bundle information = CryptoHelper.extractCertificateInformation(verification.first[0]);
@@ -920,8 +909,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
sessions.addAll(findOwnSessions());
boolean verified = false;
for(XmppAxolotlSession session : sessions) {
- if (session.getTrust().trusted()) {
- if (session.getTrust() == XmppAxolotlSession.Trust.TRUSTED_X509) {
+ if (session.getTrust().isTrustedAndActive()) {
+ if (session.getTrust().getTrust() == FingerprintStatus.Trust.VERIFIED_X509) {
verified = true;
} else {
return false;