PassphraseDialogActivity usage in Remote API

This commit is contained in:
Dominik Schürmann 2014-09-17 21:36:38 +02:00
parent 7d917fa39c
commit a139be29ba
3 changed files with 33 additions and 45 deletions

View File

@ -48,6 +48,7 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.results.OperationResult.LogEntryParcel; import org.sufficientlysecure.keychain.service.results.OperationResult.LogEntryParcel;
import org.sufficientlysecure.keychain.service.results.SignEncryptResult; import org.sufficientlysecure.keychain.service.results.SignEncryptResult;
import org.sufficientlysecure.keychain.ui.ImportKeysActivity; import org.sufficientlysecure.keychain.ui.ImportKeysActivity;
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
import org.sufficientlysecure.keychain.ui.ViewKeyActivity; import org.sufficientlysecure.keychain.ui.ViewKeyActivity;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -203,11 +204,10 @@ public class OpenPgpService extends RemoteService {
private Intent getPassphraseIntent(Intent data, long keyId) { private Intent getPassphraseIntent(Intent data, long keyId) {
// build PendingIntent for passphrase input // build PendingIntent for passphrase input
Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class); Intent intent = new Intent(getBaseContext(), PassphraseDialogActivity.class);
intent.setAction(RemoteServiceActivity.ACTION_CACHE_PASSPHRASE); intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, keyId);
intent.putExtra(RemoteServiceActivity.EXTRA_SECRET_KEY_ID, keyId);
// pass params through to activity that it can be returned again later to repeat pgp operation // pass params through to activity that it can be returned again later to repeat pgp operation
intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data); intent.putExtra(PassphraseDialogActivity.EXTRA_DATA, data);
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 0, PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 0,
intent, intent,
PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent.FLAG_CANCEL_CURRENT);

View File

@ -54,8 +54,6 @@ public class RemoteServiceActivity extends ActionBarActivity {
public static final String ACTION_REGISTER = Constants.INTENT_PREFIX + "API_ACTIVITY_REGISTER"; public static final String ACTION_REGISTER = Constants.INTENT_PREFIX + "API_ACTIVITY_REGISTER";
public static final String ACTION_CREATE_ACCOUNT = Constants.INTENT_PREFIX public static final String ACTION_CREATE_ACCOUNT = Constants.INTENT_PREFIX
+ "API_ACTIVITY_CREATE_ACCOUNT"; + "API_ACTIVITY_CREATE_ACCOUNT";
public static final String ACTION_CACHE_PASSPHRASE = Constants.INTENT_PREFIX
+ "API_ACTIVITY_CACHE_PASSPHRASE";
public static final String ACTION_SELECT_PUB_KEYS = Constants.INTENT_PREFIX public static final String ACTION_SELECT_PUB_KEYS = Constants.INTENT_PREFIX
+ "API_ACTIVITY_SELECT_PUB_KEYS"; + "API_ACTIVITY_SELECT_PUB_KEYS";
public static final String ACTION_ERROR_MESSAGE = Constants.INTENT_PREFIX public static final String ACTION_ERROR_MESSAGE = Constants.INTENT_PREFIX
@ -215,26 +213,6 @@ public class RemoteServiceActivity extends ActionBarActivity {
} }
); );
} else if (ACTION_CACHE_PASSPHRASE.equals(action)) {
long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID);
final Intent resultData = extras.getParcelable(EXTRA_DATA);
PassphraseDialogFragment.show(this, secretKeyId,
new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
// return given params again, for calling the service method again
RemoteServiceActivity.this.setResult(RESULT_OK, resultData);
} else {
RemoteServiceActivity.this.setResult(RESULT_CANCELED);
}
RemoteServiceActivity.this.finish();
}
}
);
} else if (ACTION_SELECT_PUB_KEYS.equals(action)) { } else if (ACTION_SELECT_PUB_KEYS.equals(action)) {
long[] selectedMasterKeyIds = intent.getLongArrayExtra(EXTRA_SELECTED_MASTER_KEY_IDS); long[] selectedMasterKeyIds = intent.getLongArrayExtra(EXTRA_SELECTED_MASTER_KEY_IDS);
boolean noUserIdsCheck = intent.getBooleanExtra(EXTRA_NO_USER_IDS_CHECK, true); boolean noUserIdsCheck = intent.getBooleanExtra(EXTRA_NO_USER_IDS_CHECK, true);

View File

@ -64,7 +64,6 @@ public class PassphraseDialogActivity extends FragmentActivity {
// special extra for OpenPgpService // special extra for OpenPgpService
public static final String EXTRA_DATA = "data"; public static final String EXTRA_DATA = "data";
private Intent mServiceIntent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -83,9 +82,9 @@ public class PassphraseDialogActivity extends FragmentActivity {
long keyId = getIntent().getLongExtra(EXTRA_SUBKEY_ID, 0); long keyId = getIntent().getLongExtra(EXTRA_SUBKEY_ID, 0);
mServiceIntent = getIntent().getParcelableExtra(EXTRA_DATA); Intent serviceIntent = getIntent().getParcelableExtra(EXTRA_DATA);
show(this, keyId); show(this, keyId, serviceIntent);
} }
/** /**
@ -93,13 +92,14 @@ public class PassphraseDialogActivity extends FragmentActivity {
* encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks * encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks
* for a symmetric passphrase * for a symmetric passphrase
*/ */
public static void show(final FragmentActivity context, final long keyId) { public static void show(final FragmentActivity context, final long keyId, final Intent serviceIntent) {
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
public void run() { public void run() {
// do NOT check if the key even needs a passphrase. that's not our job here. // do NOT check if the key even needs a passphrase. that's not our job here.
PassphraseDialogFragment frag = new PassphraseDialogFragment(); PassphraseDialogFragment frag = new PassphraseDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong(EXTRA_SUBKEY_ID, keyId); args.putLong(EXTRA_SUBKEY_ID, keyId);
args.putParcelable(EXTRA_DATA, serviceIntent);
frag.setArguments(args); frag.setArguments(args);
@ -112,9 +112,11 @@ public class PassphraseDialogActivity extends FragmentActivity {
private EditText mPassphraseEditText; private EditText mPassphraseEditText;
private View mInput, mProgress; private View mInput, mProgress;
CanonicalizedSecretKeyRing mSecretRing = null; private CanonicalizedSecretKeyRing mSecretRing = null;
boolean mIsCancelled = false; private boolean mIsCancelled = false;
long mSubKeyId; private long mSubKeyId;
private Intent mServiceIntent;
/** /**
* Creates dialog * Creates dialog
@ -129,6 +131,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
R.style.Theme_AppCompat_Light); R.style.Theme_AppCompat_Light);
mSubKeyId = getArguments().getLong(EXTRA_SUBKEY_ID); mSubKeyId = getArguments().getLong(EXTRA_SUBKEY_ID);
mServiceIntent = getArguments().getParcelable(EXTRA_DATA);
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme); CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme);
@ -250,12 +253,8 @@ public class PassphraseDialogActivity extends FragmentActivity {
if (mSecretRing == null) { if (mSecretRing == null) {
PassphraseCacheService.addCachedPassphrase(getActivity(), Constants.key.symmetric, PassphraseCacheService.addCachedPassphrase(getActivity(), Constants.key.symmetric,
passphrase, getString(R.string.passp_cache_notif_pwd)); passphrase, getString(R.string.passp_cache_notif_pwd));
// also return passphrase back to activity
Intent returnIntent = new Intent(); finishCaching(passphrase);
returnIntent.putExtra(MESSAGE_DATA_PASSPHRASE, passphrase);
getActivity().setResult(RESULT_OK, returnIntent);
dismiss();
getActivity().finish();
return; return;
} }
@ -316,17 +315,28 @@ public class PassphraseDialogActivity extends FragmentActivity {
Log.e(Constants.TAG, "adding of a passphrase failed", e); Log.e(Constants.TAG, "adding of a passphrase failed", e);
} }
// also return passphrase back to activity finishCaching(passphrase);
Intent returnIntent = new Intent();
returnIntent.putExtra(MESSAGE_DATA_PASSPHRASE, passphrase);
getActivity().setResult(RESULT_OK, returnIntent);
dismiss();
getActivity().finish();
} }
}.execute(); }.execute();
} }
}); });
}
private void finishCaching(String passphrase) {
if (mServiceIntent != null) {
// TODO: Not routing passphrase through OpenPGP API currently
// due to security concerns...
// BUT this means you need to _cache_ passphrases!
getActivity().setResult(RESULT_OK, mServiceIntent);
} else {
// also return passphrase back to activity
Intent returnIntent = new Intent();
returnIntent.putExtra(MESSAGE_DATA_PASSPHRASE, passphrase);
getActivity().setResult(RESULT_OK, returnIntent);
}
dismiss();
getActivity().finish();
} }
@Override @Override