aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorAndreas Straub <andy@strb.org>2015-07-07 19:36:22 +0200
committerAndreas Straub <andy@strb.org>2015-07-19 22:17:55 +0200
commit7049904c326e6dabc02138fa436d209bf724e0bc (patch)
treeeabe92e13928450df08ce5b9f33eae8165e1a0fa /src/main/java/eu
parent968410ae33f7ed341868847f3fedbd03ebd54f2b (diff)
Add basic PEP managemend UI to EditAccountActivity
EditAccountActivity now show own fingerprint, and gives an option to regenerate local keying material (and wipe all sessions associated with the old keys in the process). It also now displays a list of other own devices, and gives an option to remove all but the current device.
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java33
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java21
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java109
3 files changed, 159 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 2b0954c6d..ec4eb7c57 100644
--- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
@@ -176,6 +176,13 @@ public class AxolotlService {
return reg_id;
}
+ public void regenerate() {
+ mXmppConnectionService.databaseBackend.wipeAxolotlDb(account);
+ account.setKey(JSONKEY_CURRENT_PREKEY_ID, Integer.toString(0));
+ identityKeyPair = loadIdentityKeyPair();
+ currentPreKeyId = 0;
+ mXmppConnectionService.updateAccountUi();
+ }
/**
* Get the local client's identity key pair.
@@ -602,6 +609,10 @@ public class AxolotlService {
this.ownDeviceId = axolotlStore.getLocalRegistrationId();
}
+ public IdentityKey getOwnPublicKey() {
+ return axolotlStore.getIdentityKeyPair().getPublicKey();
+ }
+
public void trustSession(AxolotlAddress counterpart) {
XmppAxolotlSession session = sessions.get(counterpart);
if (session != null) {
@@ -635,10 +646,19 @@ public class AxolotlService {
return sessions.hasAny(contactAddress);
}
+ public void regenerateKeys() {
+ axolotlStore.regenerate();
+ publishBundlesIfNeeded();
+ }
+
public int getOwnDeviceId() {
return ownDeviceId;
}
+ public Set<Integer> getOwnDeviceIds() {
+ return this.deviceIds.get(account.getJid().toBareJid());
+ }
+
public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) {
if(deviceIds.contains(getOwnDeviceId())) {
Log.d(Config.LOGTAG, "Skipping own Device ID:"+ jid + ":"+getOwnDeviceId());
@@ -651,6 +671,19 @@ public class AxolotlService {
publishOwnDeviceIdIfNeeded();
}
+ public void wipeOtherPepDevices() {
+ Set<Integer> deviceIds = new HashSet<>();
+ deviceIds.add(getOwnDeviceId());
+ IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds);
+ Log.d(Config.LOGTAG, "Wiping all other devices from Pep:" + publish);
+ mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() {
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ // TODO: implement this!
+ }
+ });
+ }
+
public void publishOwnDeviceIdIfNeeded() {
IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(account.getJid().toBareJid());
mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index a3868a1d9..1aa2bade9 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -874,4 +874,25 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL("DROP TABLE IF EXISTS " + AxolotlService.SQLiteAxolotlStore.IDENTITIES_TABLENAME);
db.execSQL(CREATE_IDENTITIES_STATEMENT);
}
+
+ public void wipeAxolotlDb(Account account) {
+ String accountName = account.getUuid();
+ Log.d(Config.LOGTAG, ">>> WIPING AXOLOTL DATABASE FOR ACCOUNT " + accountName + " <<<");
+ SQLiteDatabase db = this.getWritableDatabase();
+ String[] deleteArgs= {
+ accountName
+ };
+ db.delete(AxolotlService.SQLiteAxolotlStore.SESSION_TABLENAME,
+ AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ?",
+ deleteArgs);
+ db.delete(AxolotlService.SQLiteAxolotlStore.PREKEY_TABLENAME,
+ AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ?",
+ deleteArgs);
+ db.delete(AxolotlService.SQLiteAxolotlStore.SIGNED_PREKEY_TABLENAME,
+ AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ?",
+ deleteArgs);
+ db.delete(AxolotlService.SQLiteAxolotlStore.IDENTITIES_TABLENAME,
+ AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ?",
+ deleteArgs);
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
index 908c29d21..ab4dc0592 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -1,9 +1,13 @@
package eu.siacs.conversations.ui;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
import android.app.PendingIntent;
+import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
+import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
@@ -23,6 +27,8 @@ import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
+import java.util.Set;
+
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
@@ -54,9 +60,16 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private TextView mServerInfoPep;
private TextView mSessionEst;
private TextView mOtrFingerprint;
+ private TextView mAxolotlFingerprint;
+ private TextView mAxolotlDevicelist;
private ImageView mAvatar;
private RelativeLayout mOtrFingerprintBox;
+ private RelativeLayout mAxolotlFingerprintBox;
+ private RelativeLayout mAxolotlDevicelistBox;
private ImageButton mOtrFingerprintToClipboardButton;
+ private ImageButton mAxolotlFingerprintToClipboardButton;
+ private ImageButton mWipeAxolotlPepButton;
+ private ImageButton mRegenerateAxolotlKeyButton;
private Jid jidToEdit;
private Account mAccount;
@@ -310,6 +323,13 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint);
this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box);
this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard);
+ this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint);
+ this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
+ this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard);
+ this.mRegenerateAxolotlKeyButton = (ImageButton) findViewById(R.id.action_regenerate_axolotl_key);
+ this.mAxolotlDevicelist = (TextView) findViewById(R.id.axolotl_devicelist);
+ this.mAxolotlDevicelistBox = (RelativeLayout) findViewById(R.id.axolotl_devices_box);
+ this.mWipeAxolotlPepButton = (ImageButton) findViewById(R.id.action_wipe_axolotl_pep);
this.mSaveButton = (Button) findViewById(R.id.save_button);
this.mCancelButton = (Button) findViewById(R.id.cancel_button);
this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
@@ -477,10 +497,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} else {
this.mServerInfoPep.setText(R.string.server_info_unavailable);
}
- final String fingerprint = this.mAccount.getOtrFingerprint();
- if (fingerprint != null) {
+ final String otrFingerprint = this.mAccount.getOtrFingerprint();
+ if (otrFingerprint != null) {
this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
- this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(fingerprint));
+ this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
this.mOtrFingerprintToClipboardButton
.setVisibility(View.VISIBLE);
this.mOtrFingerprintToClipboardButton
@@ -489,7 +509,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override
public void onClick(final View v) {
- if (copyTextToClipboard(fingerprint, R.string.otr_fingerprint)) {
+ if (copyTextToClipboard(otrFingerprint, R.string.otr_fingerprint)) {
Toast.makeText(
EditAccountActivity.this,
R.string.toast_message_otr_fingerprint,
@@ -500,6 +520,55 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} else {
this.mOtrFingerprintBox.setVisibility(View.GONE);
}
+ final Set<Integer> ownDevices = this.mAccount.getAxolotlService().getOwnDeviceIds();
+ if (ownDevices != null && !ownDevices.isEmpty()) {
+ this.mAxolotlDevicelistBox.setVisibility(View.VISIBLE);
+ this.mAxolotlDevicelist.setText(TextUtils.join(", ", ownDevices));
+ this.mWipeAxolotlPepButton
+ .setVisibility(View.VISIBLE);
+ this.mWipeAxolotlPepButton
+ .setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ showWipePepDialog();
+ }
+ });
+ } else {
+ this.mAxolotlDevicelistBox.setVisibility(View.GONE);
+ }
+ final String axolotlFingerprint = this.mAccount.getAxolotlService().getOwnPublicKey().getFingerprint();
+ if (axolotlFingerprint != null) {
+ this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
+ this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(axolotlFingerprint));
+ this.mAxolotlFingerprintToClipboardButton
+ .setVisibility(View.VISIBLE);
+ this.mAxolotlFingerprintToClipboardButton
+ .setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(final View v) {
+
+ if (copyTextToClipboard(axolotlFingerprint, R.string.axolotl_fingerprint)) {
+ Toast.makeText(
+ EditAccountActivity.this,
+ R.string.toast_message_axolotl_fingerprint,
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ this.mRegenerateAxolotlKeyButton
+ .setVisibility(View.VISIBLE);
+ this.mRegenerateAxolotlKeyButton
+ .setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(final View v) {
+ showRegenerateAxolotlKeyDialog();
+ }
+ });
+ } else {
+ this.mAxolotlFingerprintBox.setVisibility(View.GONE);
+ }
} else {
if (this.mAccount.errorStatus()) {
this.mAccountJid.setError(getString(this.mAccount.getStatus().getReadableId()));
@@ -512,4 +581,36 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mStats.setVisibility(View.GONE);
}
}
+
+ public void showRegenerateAxolotlKeyDialog() {
+ Builder builder = new Builder(this);
+ builder.setTitle("Regenerate Key");
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setMessage("Are you sure you want to regenerate your Identity Key? (This will also wipe all established sessions and contact Identity Keys)");
+ builder.setNegativeButton(getString(R.string.cancel), null);
+ builder.setPositiveButton("Yes",
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mAccount.getAxolotlService().regenerateKeys();
+ }
+ });
+ builder.create().show();
+ }
+
+ public void showWipePepDialog() {
+ Builder builder = new Builder(this);
+ builder.setTitle("Wipe PEP");
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setMessage("Are you sure you want to wipe all other devices from the PEP device ID list?");
+ builder.setNegativeButton(getString(R.string.cancel), null);
+ builder.setPositiveButton("Yes",
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mAccount.getAxolotlService().wipeOtherPepDevices();
+ }
+ });
+ builder.create().show();
+ }
}