tls-psk: show warning dialog before actually sending a key

This commit is contained in:
Vincent Breitmoser
2017-06-13 01:53:58 +02:00
parent b6586c6620
commit 39be6b166d
3 changed files with 85 additions and 12 deletions

View File

@@ -73,6 +73,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
private final TransferMvpView view;
private final LoaderManager loaderManager;
private final int loaderId;
private final KeyRepository databaseInteractor;
private final TransferKeyAdapter secretKeyAdapter;
private final ReceivedKeyAdapter receivedKeyAdapter;
@@ -84,6 +85,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
private boolean wasConnected = false;
private boolean sentData = false;
private boolean waitingForWifi = false;
private Long confirmingMasterKeyId;
public TransferPresenter(Context context, LoaderManager loaderManager, int loaderId, TransferMvpView view) {
@@ -91,6 +93,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
this.view = view;
this.loaderManager = loaderManager;
this.loaderId = loaderId;
this.databaseInteractor = KeyRepository.createDatabaseInteractor(context);
secretKeyAdapter = new TransferKeyAdapter(context, LayoutInflater.from(context), this);
view.setSecretKeyAdapter(secretKeyAdapter);
@@ -117,6 +120,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
if (wasConnected) {
view.showViewDisconnected();
view.dismissConfirmationIfExists();
secretKeyAdapter.setAllDisabled(true);
}
}
@@ -143,17 +147,24 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
@Override
public void onUiClickTransferKey(long masterKeyId) {
try {
byte[] armoredSecretKey =
KeyRepository.createDatabaseInteractor(context).getSecretKeyRingAsArmoredData(masterKeyId);
secretKeyAdapter.focusItem(masterKeyId);
connectionSend(armoredSecretKey, Long.toString(masterKeyId));
} catch (IOException | NotFoundException | PgpGeneralException e) {
// TODO
e.printStackTrace();
if (sentData) {
prepareAndSendKey(masterKeyId);
} else {
confirmingMasterKeyId = masterKeyId;
view.showConfirmSendDialog();
}
}
public void onUiClickConfirmSend() {
if (confirmingMasterKeyId == null) {
return;
}
long masterKeyId = confirmingMasterKeyId;
confirmingMasterKeyId = null;
prepareAndSendKey(masterKeyId);
}
@Override
public void onUiClickImportKey(final long masterKeyId, String keyData) {
receivedKeyAdapter.focusItem(masterKeyId);
@@ -227,9 +238,13 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
@Override
public void onConnectionLost() {
if (!wasConnected) {
view.showErrorConnectionFailed();
checkWifiResetAndStartListen();
view.showErrorConnectionFailed();
} else {
connectionClear();
view.dismissConfirmationIfExists();
view.showViewDisconnected();
secretKeyAdapter.setAllDisabled(true);
}
@@ -349,6 +364,17 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
}
}
private void prepareAndSendKey(long masterKeyId) {
try {
byte[] armoredSecretKey = databaseInteractor.getSecretKeyRingAsArmoredData(masterKeyId);
secretKeyAdapter.focusItem(masterKeyId);
connectionSend(armoredSecretKey, Long.toString(masterKeyId));
} catch (IOException | NotFoundException | PgpGeneralException e) {
// TODO
e.printStackTrace();
}
}
private void connectionSend(byte[] armoredSecretKey, String passthrough) {
sentData = true;
if (keyTransferClientInteractor != null) {
@@ -407,5 +433,8 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
void addFakeBackStackItem(String tag);
void finishFragmentOrActivity();
void showConfirmSendDialog();
void dismissConfirmationIfExists();
}
}

View File

@@ -21,6 +21,8 @@ package org.sufficientlysecure.keychain.ui.transfer.view;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
@@ -36,6 +38,8 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AlertDialog.Builder;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
@@ -103,6 +107,7 @@ public class TransferFragment extends Fragment implements TransferMvpView {
}
};
private boolean showDoneIcon;
private AlertDialog confirmationDialog;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -358,6 +363,41 @@ public class TransferFragment extends Fragment implements TransferMvpView {
}
}
@Override
public void showConfirmSendDialog() {
if (confirmationDialog != null) {
return;
}
confirmationDialog = new Builder(getContext())
.setTitle(R.string.transfer_confirm_title)
.setMessage(R.string.transfer_confirm_text)
.setPositiveButton(R.string.transfer_confirm_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (whichButton == DialogInterface.BUTTON_POSITIVE) {
presenter.onUiClickConfirmSend();
} else {
dialog.dismiss();
}
}
})
.setNegativeButton(R.string.transfer_confirm_cancel, null)
.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
confirmationDialog = null;
}
})
.create();
confirmationDialog.show();
}
@Override
public void dismissConfirmationIfExists() {
if (confirmationDialog != null && confirmationDialog.isShowing()) {
confirmationDialog.dismiss();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (currentCryptoOperationHelper != null &&

View File

@@ -1904,8 +1904,12 @@
<string name="transfer_error_generic">"Unknown communication error!"</string>
<string name="transfer_error_generic_msg">"Communication error: %s"</string>
<string name="transfer_not_available">"Sorry, this feature can only be used on Android 5 or newer :("</string>
<string name="transfer_list_empty">No keys on this device that could be sent. Waiting for incoming keys…</string>
<string name="transfer_connecting">Connecting…</string>
<string name="first_time_secure_device_setup">Secure Device Setup</string>
<string name="transfer_list_empty">"No keys on this device that could be sent. Waiting for incoming keys…"</string>
<string name="transfer_connecting">"Connecting…"</string>
<string name="first_time_secure_device_setup">"Secure Device Setup"</string>
<string name="transfer_confirm_cancel">"Cancel"</string>
<string name="transfer_confirm_ok">"Send"</string>
<string name="transfer_confirm_title">"Send your key?"</string>
<string name="transfer_confirm_text">"This will transfer full access to your key to the connected device. You should never send your own keys to devices you don't own!"</string>
</resources>