aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
diff options
context:
space:
mode:
authorAndreas Straub <andy@strb.org>2015-07-20 15:13:14 +0200
committerAndreas Straub <andy@strb.org>2015-07-20 15:13:14 +0200
commitaaa8fe8978ac0513a013a9c77efef663f32eda47 (patch)
tree16cc60f67a4fbded2eeeb7ba1001ebb1b1a004a5 /src/main/java/eu/siacs/conversations/ui/XmppActivity.java
parent9c91b9036aa57c610c26b4cdf52ee295eaa0dc95 (diff)
parent19a0ae42d667644ee3400c92c53ad0ad093c52fe (diff)
Merge branch 'CryptoNextBeta' into development
* CryptoNextBeta: (60 commits) Lock TrustKeys if no trusted keys are available Optimize imports Use MD style for key trust toggle switch Fix set/remove OnUpdateBlocklistListener Fix axolotl database migration Remove device list from EditAccount Add clear devices to overflow menu in EditAccount Ask for key trust when sending messages Encrypt files for HTTP upload in encrypted chats Refactor trust key ui and show in account details Send correct body for HTTP files Handle file transmission properly in axolotl Remove unneccessary code Fix trust status for outgoing messages Don't merge messages with different trust statuses Fix copying of axolotl keys to clipboard Add refresh icon to v21 theme Disable Axolotl option if not usable Show trust status of messages' originating session Add key trust toggle to ContactDetailsActivity ...
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/XmppActivity.java')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java87
1 files changed, 86 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index 7c994c31a..77001f20c 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -43,8 +43,11 @@ import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
+import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.BarcodeFormat;
@@ -56,6 +59,8 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import net.java.otr4j.session.SessionID;
+import org.whispersystems.libaxolotl.IdentityKey;
+
import java.io.FileNotFoundException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -65,6 +70,7 @@ import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
@@ -74,7 +80,10 @@ import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
+import eu.siacs.conversations.ui.widget.Switch;
+import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.ExceptionHelper;
+import eu.siacs.conversations.xmpp.OnNewKeysAvailable;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -287,6 +296,9 @@ public abstract class XmppActivity extends Activity {
if (this instanceof XmppConnectionService.OnShowErrorToast) {
this.xmppConnectionService.setOnShowErrorToastListener((XmppConnectionService.OnShowErrorToast) this);
}
+ if (this instanceof OnNewKeysAvailable) {
+ this.xmppConnectionService.setOnNewKeysAvailableListener((OnNewKeysAvailable) this);
+ }
}
protected void unregisterListeners() {
@@ -308,6 +320,9 @@ public abstract class XmppActivity extends Activity {
if (this instanceof XmppConnectionService.OnShowErrorToast) {
this.xmppConnectionService.removeOnShowErrorToastListener();
}
+ if (this instanceof OnNewKeysAvailable) {
+ this.xmppConnectionService.removeOnNewKeysAvailableListener();
+ }
}
@Override
@@ -443,7 +458,7 @@ public abstract class XmppActivity extends Activity {
@Override
public void userInputRequried(PendingIntent pi,
- Account account) {
+ Account account) {
try {
startIntentSenderForResult(pi.getIntentSender(),
REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
@@ -588,6 +603,76 @@ public abstract class XmppActivity extends Activity {
builder.create().show();
}
+ protected void addFingerprintRow(LinearLayout keys, final Account account, IdentityKey identityKey) {
+ final String fingerprint = identityKey.getFingerprint().replaceAll("\\s", "");
+ final AxolotlService.SQLiteAxolotlStore.Trust trust = account.getAxolotlService()
+ .getFingerprintTrust(fingerprint);
+ addFingerprintRowWithListeners(keys, account, identityKey, trust, true,
+ new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (isChecked != (trust == AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED)) {
+ account.getAxolotlService().setFingerprintTrust(fingerprint,
+ (isChecked) ? AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED :
+ AxolotlService.SQLiteAxolotlStore.Trust.UNTRUSTED);
+ }
+ refreshUi();
+ xmppConnectionService.updateAccountUi();
+ xmppConnectionService.updateConversationUi();
+ }
+ },
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ account.getAxolotlService().setFingerprintTrust(fingerprint,
+ AxolotlService.SQLiteAxolotlStore.Trust.UNTRUSTED);
+ refreshUi();
+ xmppConnectionService.updateAccountUi();
+ xmppConnectionService.updateConversationUi();
+ }
+ }
+
+ );
+ }
+
+ protected void addFingerprintRowWithListeners(LinearLayout keys, final Account account,
+ IdentityKey identityKey,
+ AxolotlService.SQLiteAxolotlStore.Trust trust,
+ boolean showTag,
+ CompoundButton.OnCheckedChangeListener
+ onCheckedChangeListener,
+ View.OnClickListener onClickListener) {
+ View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
+ TextView key = (TextView) view.findViewById(R.id.key);
+ TextView keyType = (TextView) view.findViewById(R.id.key_type);
+ Switch trustToggle = (Switch) view.findViewById(R.id.tgl_trust);
+ trustToggle.setVisibility(View.VISIBLE);
+ trustToggle.setOnCheckedChangeListener(onCheckedChangeListener);
+ trustToggle.setOnClickListener(onClickListener);
+
+ switch (trust) {
+ case UNTRUSTED:
+ case TRUSTED:
+ trustToggle.setChecked(trust == AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED, false);
+ trustToggle.setEnabled(true);
+ break;
+ case UNDECIDED:
+ trustToggle.setChecked(false, false);
+ trustToggle.setEnabled(false);
+ break;
+ }
+
+ if (showTag) {
+ keyType.setText(getString(R.string.axolotl_fingerprint));
+ } else {
+ keyType.setVisibility(View.GONE);
+ }
+
+ key.setText(CryptoHelper.prettifyFingerprint(identityKey.getFingerprint()));
+ keys.addView(view);
+
+ }
+
public void selectPresence(final Conversation conversation,
final OnPresenceSelected listener) {
final Contact contact = conversation.getContact();