diff options
author | Andreas Straub <andy@strb.org> | 2015-07-20 14:56:41 +0200 |
---|---|---|
committer | Andreas Straub <andy@strb.org> | 2015-07-20 14:56:41 +0200 |
commit | 19a0ae42d667644ee3400c92c53ad0ad093c52fe (patch) | |
tree | 4716f57d55329b87683743f3b6e4fc0bf6e78a50 /src | |
parent | 012f036840ade8f46462eafcc96d1f223f8ba845 (diff) |
Lock TrustKeys if no trusted keys are availableCryptoNextBeta
Diffstat (limited to 'src')
3 files changed, 48 insertions, 4 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 4189aba4..827ea44d 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -281,6 +281,10 @@ public class AxolotlService { return mXmppConnectionService.databaseBackend.loadIdentityKeys(account, bareJid, Trust.UNDECIDED); } + public long getContactNumTrustedKeys(String bareJid) { + return mXmppConnectionService.databaseBackend.numTrustedKeys(account, bareJid); + } + // -------------------------------------- // SessionStore // -------------------------------------- @@ -672,6 +676,10 @@ public class AxolotlService { return axolotlStore.getContactUndecidedKeys(contact.getJid().toBareJid().toString()); } + public long getNumTrustedKeys(Contact contact) { + return axolotlStore.getContactNumTrustedKeys(contact.getJid().toBareJid().toString()); + } + private AxolotlAddress getAddressForJid(Jid jid) { return new AxolotlAddress(jid.toString(), 0); } diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index 8168b1a6..71b4cba9 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -3,6 +3,7 @@ package eu.siacs.conversations.persistance; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; +import android.database.DatabaseUtils; import android.database.sqlite.SQLiteCantOpenDatabaseException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; @@ -858,6 +859,19 @@ public class DatabaseBackend extends SQLiteOpenHelper { return identityKeys; } + public long numTrustedKeys(Account account, String name) { + SQLiteDatabase db = getReadableDatabase(); + String[] args = { + account.getUuid(), + name + }; + return DatabaseUtils.queryNumEntries(db, AxolotlService.SQLiteAxolotlStore.IDENTITIES_TABLENAME, + AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ?" + + " AND " + AxolotlService.SQLiteAxolotlStore.NAME + " = ?", + args + ); + } + private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized) { storeIdentityKey(account, name, own, fingerprint, base64Serialized, AxolotlService.SQLiteAxolotlStore.Trust.UNDECIDED); } diff --git a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index ab32e61a..e93cacd4 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -27,6 +27,8 @@ import eu.siacs.conversations.xmpp.jid.Jid; public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailable { private Jid accountJid; private Jid contactJid; + private boolean hasOtherTrustedKeys = false; + private boolean hasPendingFetches = false; private Contact contact; private TextView ownKeysTitle; @@ -153,6 +155,17 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl foreignKeysTitle.setText(contactJid.toString()); foreignKeysCard.setVisibility(View.VISIBLE); } + if(hasPendingFetches) { + setFetching(); + lock(); + } else { + if (!hasOtherTrustedKeys && !foreignKeysToTrust.values().contains(true)){ + lock(); + } else { + unlock(); + } + setDone(); + } } private void getFingerprints(final Account account) { @@ -183,9 +196,12 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl foreignKeysToTrust.clear(); getFingerprints(account); + if(account.getAxolotlService().getNumTrustedKeys(contact) > 0) { + hasOtherTrustedKeys = true; + } Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contactJid, false); if(account.getAxolotlService().hasPendingKeyFetches(conversation)) { - lock(); + hasPendingFetches = true; } populateView(); @@ -199,7 +215,7 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl public void run() { final Account account = xmppConnectionService .findAccountByJid(accountJid); - unlock(); + hasPendingFetches = false; getFingerprints(account); refreshUi(); } @@ -221,13 +237,19 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl private void unlock() { mSaveButton.setEnabled(true); - mSaveButton.setText(getString(R.string.done)); mSaveButton.setTextColor(getPrimaryTextColor()); } private void lock() { mSaveButton.setEnabled(false); - mSaveButton.setText(getString(R.string.fetching_keys)); mSaveButton.setTextColor(getSecondaryTextColor()); } + + private void setDone() { + mSaveButton.setText(getString(R.string.done)); + } + + private void setFetching() { + mSaveButton.setText(getString(R.string.fetching_keys)); + } } |