tls-psk: show warning dialog before actually sending a key
This commit is contained in:
@@ -73,6 +73,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||||||
private final TransferMvpView view;
|
private final TransferMvpView view;
|
||||||
private final LoaderManager loaderManager;
|
private final LoaderManager loaderManager;
|
||||||
private final int loaderId;
|
private final int loaderId;
|
||||||
|
private final KeyRepository databaseInteractor;
|
||||||
|
|
||||||
private final TransferKeyAdapter secretKeyAdapter;
|
private final TransferKeyAdapter secretKeyAdapter;
|
||||||
private final ReceivedKeyAdapter receivedKeyAdapter;
|
private final ReceivedKeyAdapter receivedKeyAdapter;
|
||||||
@@ -84,6 +85,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||||||
private boolean wasConnected = false;
|
private boolean wasConnected = false;
|
||||||
private boolean sentData = false;
|
private boolean sentData = false;
|
||||||
private boolean waitingForWifi = false;
|
private boolean waitingForWifi = false;
|
||||||
|
private Long confirmingMasterKeyId;
|
||||||
|
|
||||||
|
|
||||||
public TransferPresenter(Context context, LoaderManager loaderManager, int loaderId, TransferMvpView view) {
|
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.view = view;
|
||||||
this.loaderManager = loaderManager;
|
this.loaderManager = loaderManager;
|
||||||
this.loaderId = loaderId;
|
this.loaderId = loaderId;
|
||||||
|
this.databaseInteractor = KeyRepository.createDatabaseInteractor(context);
|
||||||
|
|
||||||
secretKeyAdapter = new TransferKeyAdapter(context, LayoutInflater.from(context), this);
|
secretKeyAdapter = new TransferKeyAdapter(context, LayoutInflater.from(context), this);
|
||||||
view.setSecretKeyAdapter(secretKeyAdapter);
|
view.setSecretKeyAdapter(secretKeyAdapter);
|
||||||
@@ -117,6 +120,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||||||
|
|
||||||
if (wasConnected) {
|
if (wasConnected) {
|
||||||
view.showViewDisconnected();
|
view.showViewDisconnected();
|
||||||
|
view.dismissConfirmationIfExists();
|
||||||
secretKeyAdapter.setAllDisabled(true);
|
secretKeyAdapter.setAllDisabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,17 +147,24 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUiClickTransferKey(long masterKeyId) {
|
public void onUiClickTransferKey(long masterKeyId) {
|
||||||
try {
|
if (sentData) {
|
||||||
byte[] armoredSecretKey =
|
prepareAndSendKey(masterKeyId);
|
||||||
KeyRepository.createDatabaseInteractor(context).getSecretKeyRingAsArmoredData(masterKeyId);
|
} else {
|
||||||
secretKeyAdapter.focusItem(masterKeyId);
|
confirmingMasterKeyId = masterKeyId;
|
||||||
connectionSend(armoredSecretKey, Long.toString(masterKeyId));
|
view.showConfirmSendDialog();
|
||||||
} catch (IOException | NotFoundException | PgpGeneralException e) {
|
|
||||||
// TODO
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onUiClickConfirmSend() {
|
||||||
|
if (confirmingMasterKeyId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long masterKeyId = confirmingMasterKeyId;
|
||||||
|
confirmingMasterKeyId = null;
|
||||||
|
|
||||||
|
prepareAndSendKey(masterKeyId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUiClickImportKey(final long masterKeyId, String keyData) {
|
public void onUiClickImportKey(final long masterKeyId, String keyData) {
|
||||||
receivedKeyAdapter.focusItem(masterKeyId);
|
receivedKeyAdapter.focusItem(masterKeyId);
|
||||||
@@ -227,9 +238,13 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||||||
@Override
|
@Override
|
||||||
public void onConnectionLost() {
|
public void onConnectionLost() {
|
||||||
if (!wasConnected) {
|
if (!wasConnected) {
|
||||||
view.showErrorConnectionFailed();
|
|
||||||
checkWifiResetAndStartListen();
|
checkWifiResetAndStartListen();
|
||||||
|
|
||||||
|
view.showErrorConnectionFailed();
|
||||||
} else {
|
} else {
|
||||||
|
connectionClear();
|
||||||
|
|
||||||
|
view.dismissConfirmationIfExists();
|
||||||
view.showViewDisconnected();
|
view.showViewDisconnected();
|
||||||
secretKeyAdapter.setAllDisabled(true);
|
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) {
|
private void connectionSend(byte[] armoredSecretKey, String passthrough) {
|
||||||
sentData = true;
|
sentData = true;
|
||||||
if (keyTransferClientInteractor != null) {
|
if (keyTransferClientInteractor != null) {
|
||||||
@@ -407,5 +433,8 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||||||
void addFakeBackStackItem(String tag);
|
void addFakeBackStackItem(String tag);
|
||||||
|
|
||||||
void finishFragmentOrActivity();
|
void finishFragmentOrActivity();
|
||||||
|
|
||||||
|
void showConfirmSendDialog();
|
||||||
|
void dismissConfirmationIfExists();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ package org.sufficientlysecure.keychain.ui.transfer.view;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnDismissListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Bitmap;
|
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.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
|
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;
|
||||||
import android.support.v7.widget.RecyclerView.Adapter;
|
import android.support.v7.widget.RecyclerView.Adapter;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -103,6 +107,7 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
private boolean showDoneIcon;
|
private boolean showDoneIcon;
|
||||||
|
private AlertDialog confirmationDialog;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
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
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (currentCryptoOperationHelper != null &&
|
if (currentCryptoOperationHelper != null &&
|
||||||
|
|||||||
@@ -1904,8 +1904,12 @@
|
|||||||
<string name="transfer_error_generic">"Unknown communication error!"</string>
|
<string name="transfer_error_generic">"Unknown communication error!"</string>
|
||||||
<string name="transfer_error_generic_msg">"Communication error: %s"</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_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_list_empty">"No keys on this device that could be sent. Waiting for incoming keys…"</string>
|
||||||
<string name="transfer_connecting">Connecting…</string>
|
<string name="transfer_connecting">"Connecting…"</string>
|
||||||
<string name="first_time_secure_device_setup">Secure Device Setup</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>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user