From 5f39cb3ec0d1d3f77d48fdbb428a2147dfe11d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sat, 15 Feb 2014 02:08:27 +0100 Subject: fix passtrough of params --- .../keychain/service/remote/OpenPgpService.java | 35 +++++++------- .../service/remote/RemoteServiceActivity.java | 53 ++++++++++++---------- 2 files changed, 45 insertions(+), 43 deletions(-) (limited to 'OpenPGP-Keychain') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java index 4c65f6b70..0f5aa9e3b 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java @@ -56,7 +56,7 @@ public class OpenPgpService extends RemoteService { * @param encryptionUserIds * @return */ - private Bundle getKeyIdsFromEmails(String[] encryptionUserIds) { + private Bundle getKeyIdsFromEmails(Bundle params, String[] encryptionUserIds) { // find key ids to given emails in database ArrayList keyIds = new ArrayList(); @@ -97,6 +97,7 @@ public class OpenPgpService extends RemoteService { intent.putExtra(RemoteServiceActivity.EXTRA_SELECTED_MASTER_KEY_IDS, keyIdsArray); intent.putExtra(RemoteServiceActivity.EXTRA_MISSING_USER_IDS, missingUserIds); intent.putExtra(RemoteServiceActivity.EXTRA_DUBLICATE_USER_IDS, dublicateUserIds); + intent.putExtra(OpenPgpConstants.PI_RESULT_PARAMS, params); PendingIntent pi = PendingIntent.getActivity(getBaseContext(), PRIVATE_REQUEST_CODE_USER_IDS, intent, 0); @@ -118,11 +119,13 @@ public class OpenPgpService extends RemoteService { return result; } - private Bundle getPassphraseBundleIntent(long keyId) { + private Bundle getPassphraseBundleIntent(Bundle params, long keyId) { // build PendingIntent for passphrase input Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class); intent.setAction(RemoteServiceActivity.ACTION_CACHE_PASSPHRASE); intent.putExtra(RemoteServiceActivity.EXTRA_SECRET_KEY_ID, keyId); + // pass params through to activity that it can be returned again later to repeat pgp operation + intent.putExtra(OpenPgpConstants.PI_RESULT_PARAMS, params); PendingIntent pi = PendingIntent.getActivity(getBaseContext(), PRIVATE_REQUEST_CODE_PASSPHRASE, intent, 0); // return PendingIntent to be executed by client @@ -141,9 +144,8 @@ public class OpenPgpService extends RemoteService { String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId()); if (passphrase == null) { // get PendingIntent for passphrase input, add it to given params and return to client - Bundle passphraseBundle = getPassphraseBundleIntent(appSettings.getKeyId()); - params.putAll(passphraseBundle); - return params; + Bundle passphraseBundle = getPassphraseBundleIntent(params, appSettings.getKeyId()); + return passphraseBundle; } // Get Input- and OutputStream from ParcelFileDescriptor @@ -185,15 +187,14 @@ public class OpenPgpService extends RemoteService { } else { // get key ids based on given user ids String[] userIds = params.getStringArray(OpenPgpConstants.PARAMS_USER_IDS); - Bundle result = getKeyIdsFromEmails(userIds); + // give params through to activity... + Bundle result = getKeyIdsFromEmails(params, userIds); if (result.getInt(OpenPgpConstants.RESULT_CODE, 0) == OpenPgpConstants.RESULT_CODE_SUCCESS) { keyIds = result.getLongArray(OpenPgpConstants.PARAMS_KEY_IDS); } else { // if not success -> result contains a PendingIntent for user interaction - // return all old params with the new PendingIntent to client! - params.putAll(result); - return params; + return result; } } @@ -215,9 +216,8 @@ public class OpenPgpService extends RemoteService { appSettings.getKeyId()); if (passphrase == null) { // get PendingIntent for passphrase input, add it to given params and return to client - Bundle passphraseBundle = getPassphraseBundleIntent(appSettings.getKeyId()); - params.putAll(passphraseBundle); - return params; + Bundle passphraseBundle = getPassphraseBundleIntent(params, appSettings.getKeyId()); + return passphraseBundle; } operation.signAndEncrypt(asciiArmor, appSettings.getCompression(), keyIds, null, @@ -338,9 +338,8 @@ public class OpenPgpService extends RemoteService { String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId()); if (passphrase == null) { // get PendingIntent for passphrase input, add it to given params and return to client - Bundle passphraseBundle = getPassphraseBundleIntent(appSettings.getKeyId()); - params.putAll(passphraseBundle); - return params; + Bundle passphraseBundle = getPassphraseBundleIntent(params, appSettings.getKeyId()); + return passphraseBundle; } // } @@ -407,10 +406,8 @@ public class OpenPgpService extends RemoteService { private Bundle getKeyIdsImpl(Bundle params) { // get key ids based on given user ids String[] userIds = params.getStringArray(OpenPgpConstants.PARAMS_USER_IDS); - Bundle result = getKeyIdsFromEmails(userIds); - - params.putAll(result); - return params; + Bundle result = getKeyIdsFromEmails(params, userIds); + return result; } /** diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java index 4ca713c1d..8f619f37e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Dominik Schürmann + * Copyright (C) 2013-2014 Dominik Schürmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,14 @@ package org.sufficientlysecure.keychain.service.remote; -import java.util.ArrayList; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; +import android.support.v7.app.ActionBarActivity; +import android.view.View; import org.openintents.openpgp.util.OpenPgpConstants; import org.sufficientlysecure.htmltextview.HtmlTextView; @@ -31,15 +38,7 @@ import org.sufficientlysecure.keychain.ui.SelectPublicKeyFragment; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.util.Log; -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.os.Messenger; -import android.os.RemoteException; -import android.support.v7.app.ActionBarActivity; -import android.view.View; -import android.widget.Toast; +import java.util.ArrayList; public class RemoteServiceActivity extends ActionBarActivity { @@ -102,11 +101,7 @@ public class RemoteServiceActivity extends ActionBarActivity { finishHandled = false; String action = intent.getAction(); - Bundle extras = intent.getExtras(); - - if (extras == null) { - extras = new Bundle(); - } + final Bundle extras = intent.getExtras(); mMessenger = extras.getParcelable(EXTRA_MESSENGER); @@ -176,8 +171,9 @@ public class RemoteServiceActivity extends ActionBarActivity { mSettingsFragment.setAppSettings(settings); } else if (ACTION_CACHE_PASSPHRASE.equals(action)) { long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID); + Bundle oldParams = extras.getBundle(OpenPgpConstants.PI_RESULT_PARAMS); - showPassphraseDialog(secretKeyId); + showPassphraseDialog(oldParams, secretKeyId); } else if (ACTION_SELECT_PUB_KEYS.equals(action)) { long[] selectedMasterKeyIds = intent.getLongArrayExtra(EXTRA_SELECTED_MASTER_KEY_IDS); ArrayList missingUserIds = intent @@ -213,10 +209,13 @@ public class RemoteServiceActivity extends ActionBarActivity { new View.OnClickListener() { @Override public void onClick(View v) { - // return key ids to requesting activity - Intent finishIntent = new Intent(); - finishIntent.putExtra(OpenPgpConstants.PARAMS_KEY_IDS, + // sdd key ids to params Bundle for new request + Bundle params = extras.getBundle(OpenPgpConstants.PI_RESULT_PARAMS); + params.putLongArray(OpenPgpConstants.PARAMS_KEY_IDS, mSelectFragment.getSelectedMasterKeyIds()); + + Intent finishIntent = new Intent(); + finishIntent.putExtra(OpenPgpConstants.PI_RESULT_PARAMS, params); setResult(RESULT_OK, finishIntent); finish(); } @@ -289,13 +288,16 @@ public class RemoteServiceActivity extends ActionBarActivity { * encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks * for a symmetric passphrase */ - private void showPassphraseDialog(long secretKeyId) { + private void showPassphraseDialog(final Bundle params, long secretKeyId) { // Message is received after passphrase is cached Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { - RemoteServiceActivity.this.setResult(RESULT_OK); + // return given params again, for calling the service method again + Intent finishIntent = new Intent(); + finishIntent.putExtra(OpenPgpConstants.PI_RESULT_PARAMS, params); + RemoteServiceActivity.this.setResult(RESULT_OK, finishIntent); } else { RemoteServiceActivity.this.setResult(RESULT_CANCELED); } @@ -314,8 +316,11 @@ public class RemoteServiceActivity extends ActionBarActivity { passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog"); } catch (PgpGeneralException e) { Log.d(Constants.TAG, "No passphrase for this secret key, encrypt directly!"); - RemoteServiceActivity.this.setResult(RESULT_OK); - RemoteServiceActivity.this.finish(); + // return given params again, for calling the service method again + Intent finishIntent = new Intent(); + finishIntent.putExtras(params); + setResult(RESULT_OK, finishIntent); + finish(); } } } -- cgit v1.2.3