mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 11:42:15 -05:00
Start TrustKeysActivity if no keys are TRUSTED
If there are no UNDECIDED keys, but none of the contact's keys are trusted, redirect the user to the TrustKeysActivity
This commit is contained in:
parent
4ee3f330f5
commit
8be0e8a27d
@ -278,8 +278,8 @@ public class AxolotlService {
|
|||||||
mXmppConnectionService.databaseBackend.setIdentityKeyTrust(account, fingerprint, trust);
|
mXmppConnectionService.databaseBackend.setIdentityKeyTrust(account, fingerprint, trust);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<IdentityKey> getContactUndecidedKeys(String bareJid) {
|
public Set<IdentityKey> getContactUndecidedKeys(String bareJid, Trust trust) {
|
||||||
return mXmppConnectionService.databaseBackend.loadIdentityKeys(account, bareJid, Trust.UNDECIDED);
|
return mXmppConnectionService.databaseBackend.loadIdentityKeys(account, bareJid, trust);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getContactNumTrustedKeys(String bareJid) {
|
public long getContactNumTrustedKeys(String bareJid) {
|
||||||
@ -692,12 +692,12 @@ public class AxolotlService {
|
|||||||
return axolotlStore.getIdentityKeyPair().getPublicKey();
|
return axolotlStore.getIdentityKeyPair().getPublicKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<IdentityKey> getPendingKeys() {
|
public Set<IdentityKey> getKeysWithTrust(SQLiteAxolotlStore.Trust trust) {
|
||||||
return axolotlStore.getContactUndecidedKeys(account.getJid().toBareJid().toString());
|
return axolotlStore.getContactUndecidedKeys(account.getJid().toBareJid().toString(), trust);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<IdentityKey> getPendingKeys(Contact contact) {
|
public Set<IdentityKey> getKeysWithTrust(SQLiteAxolotlStore.Trust trust, Contact contact) {
|
||||||
return axolotlStore.getContactUndecidedKeys(contact.getJid().toBareJid().toString());
|
return axolotlStore.getContactUndecidedKeys(contact.getJid().toBareJid().toString(), trust);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getNumTrustedKeys(Contact contact) {
|
public long getNumTrustedKeys(Contact contact) {
|
||||||
|
@ -38,6 +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.AxolotlService.SQLiteAxolotlStore.Trust;
|
||||||
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;
|
||||||
@ -1255,13 +1256,17 @@ 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();
|
||||||
if(!axolotlService.getPendingKeys(mSelectedConversation.getContact()).isEmpty()
|
boolean hasPendingKeys = !axolotlService.getKeysWithTrust(Trust.UNDECIDED,
|
||||||
|| !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty()) {
|
mSelectedConversation.getContact()).isEmpty()
|
||||||
|
|| !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
|
||||||
|
boolean hasNoTrustedKeys = axolotlService.getNumTrustedKeys(mSelectedConversation.getContact()) == 0;
|
||||||
|
if( hasPendingKeys || hasNoTrustedKeys) {
|
||||||
axolotlService.createSessionsIfNeeded(mSelectedConversation, false);
|
axolotlService.createSessionsIfNeeded(mSelectedConversation, false);
|
||||||
Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
|
Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
|
||||||
intent.putExtra("contact", mSelectedConversation.getContact().getJid().toBareJid().toString());
|
intent.putExtra("contact", mSelectedConversation.getContact().getJid().toBareJid().toString());
|
||||||
intent.putExtra("account", mSelectedConversation.getAccount().getJid().toBareJid().toString());
|
intent.putExtra("account", mSelectedConversation.getAccount().getJid().toBareJid().toString());
|
||||||
intent.putExtra("choice", attachmentChoice);
|
intent.putExtra("choice", attachmentChoice);
|
||||||
|
intent.putExtra("has_no_trusted", hasNoTrustedKeys);
|
||||||
startActivityForResult(intent, requestCode);
|
startActivityForResult(intent, requestCode);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,6 +29,7 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
|
|||||||
private Jid contactJid;
|
private Jid contactJid;
|
||||||
private boolean hasOtherTrustedKeys = false;
|
private boolean hasOtherTrustedKeys = false;
|
||||||
private boolean hasPendingFetches = false;
|
private boolean hasPendingFetches = false;
|
||||||
|
private boolean hasNoTrustedKeys = true;
|
||||||
|
|
||||||
private Contact contact;
|
private Contact contact;
|
||||||
private TextView ownKeysTitle;
|
private TextView ownKeysTitle;
|
||||||
@ -89,6 +90,7 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
|
|||||||
this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
|
this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
|
||||||
} catch (final InvalidJidException ignored) {
|
} catch (final InvalidJidException ignored) {
|
||||||
}
|
}
|
||||||
|
hasNoTrustedKeys = getIntent().getBooleanExtra("has_no_trusted", false);
|
||||||
|
|
||||||
ownKeysTitle = (TextView) findViewById(R.id.own_keys_title);
|
ownKeysTitle = (TextView) findViewById(R.id.own_keys_title);
|
||||||
ownKeys = (LinearLayout) findViewById(R.id.own_keys_details);
|
ownKeys = (LinearLayout) findViewById(R.id.own_keys_details);
|
||||||
@ -169,13 +171,17 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getFingerprints(final Account account) {
|
private void getFingerprints(final Account account) {
|
||||||
Set<IdentityKey> ownKeysSet = account.getAxolotlService().getPendingKeys();
|
Set<IdentityKey> ownKeysSet = account.getAxolotlService().getKeysWithTrust(Trust.UNDECIDED);
|
||||||
|
Set<IdentityKey> foreignKeysSet = account.getAxolotlService().getKeysWithTrust(Trust.UNDECIDED, contact);
|
||||||
|
if (hasNoTrustedKeys) {
|
||||||
|
ownKeysSet.addAll(account.getAxolotlService().getKeysWithTrust(Trust.UNTRUSTED));
|
||||||
|
foreignKeysSet.addAll(account.getAxolotlService().getKeysWithTrust(Trust.UNTRUSTED, contact));
|
||||||
|
}
|
||||||
for(final IdentityKey identityKey : ownKeysSet) {
|
for(final IdentityKey identityKey : ownKeysSet) {
|
||||||
if(!ownKeysToTrust.containsKey(identityKey)) {
|
if(!ownKeysToTrust.containsKey(identityKey)) {
|
||||||
ownKeysToTrust.put(identityKey, false);
|
ownKeysToTrust.put(identityKey, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set<IdentityKey> foreignKeysSet = account.getAxolotlService().getPendingKeys(contact);
|
|
||||||
for(final IdentityKey identityKey : foreignKeysSet) {
|
for(final IdentityKey identityKey : foreignKeysSet) {
|
||||||
if(!foreignKeysToTrust.containsKey(identityKey)) {
|
if(!foreignKeysToTrust.containsKey(identityKey)) {
|
||||||
foreignKeysToTrust.put(identityKey, false);
|
foreignKeysToTrust.put(identityKey, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user