From ecf6fc26c5139f6e3ce593e59c4d1ad79c1f3f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 29 Jan 2014 03:24:42 +0100 Subject: [PATCH] Use intent data instead of IDs for upload and sign, fixes #205 --- .../service/KeychainIntentService.java | 8 ++--- .../keychain/ui/KeyServerUploadActivity.java | 24 +++++++------ .../keychain/ui/SignKeyActivity.java | 35 +++++++++++++------ .../keychain/ui/ViewKeyActivity.java | 18 ++-------- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index ba3169b18..44a4fe74c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -156,7 +156,6 @@ public class KeychainIntentService extends IntentService implements ProgressDial // upload key public static final String UPLOAD_KEY_SERVER = "upload_key_server"; - public static final String UPLOAD_KEY_KEYRING_ROW_ID = "upload_key_ring_id"; // query key public static final String QUERY_KEY_SERVER = "query_key_server"; @@ -231,6 +230,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial return; } + Uri dataUri = intent.getData(); + mMessenger = (Messenger) extras.get(EXTRA_MESSENGER); Bundle data = extras.getBundle(EXTRA_DATA); @@ -727,14 +728,13 @@ public class KeychainIntentService extends IntentService implements ProgressDial try { /* Input */ - int keyRingRowId = data.getInt(UPLOAD_KEY_KEYRING_ROW_ID); String keyServer = data.getString(UPLOAD_KEY_SERVER); + // and dataUri! /* Operation */ HkpKeyServer server = new HkpKeyServer(keyServer); - PGPPublicKeyRing keyring = ProviderHelper.getPGPPublicKeyRingByRowId(this, - keyRingRowId); + PGPPublicKeyRing keyring = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, dataUri); if (keyring != null) { PgpImportExport pgpImportExport = new PgpImportExport(this, null); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyServerUploadActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyServerUploadActivity.java index 9dca1094f..7b410e461 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyServerUploadActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyServerUploadActivity.java @@ -22,9 +22,11 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; +import org.sufficientlysecure.keychain.util.Log; import android.app.ProgressDialog; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.os.Message; import android.os.Messenger; @@ -43,16 +45,11 @@ import com.beardedhen.androidbootstrap.BootstrapButton; * Sends the selected public key to a key server */ public class KeyServerUploadActivity extends SherlockFragmentActivity { - - // Not used in sourcode, but listed in AndroidManifest! - public static final String ACTION_EXPORT_KEY_TO_SERVER = Constants.INTENT_PREFIX - + "EXPORT_KEY_TO_SERVER"; - - public static final String EXTRA_KEYRING_ROW_ID = "key_row_id"; - private BootstrapButton mUploadButton; private Spinner mKeyServerSpinner; + private Uri mDataUri; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -79,6 +76,13 @@ public class KeyServerUploadActivity extends SherlockFragmentActivity { uploadKey(); } }); + + mDataUri = getIntent().getData(); + if (mDataUri == null) { + Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); + finish(); + return; + } } private void uploadKey() { @@ -87,12 +91,12 @@ public class KeyServerUploadActivity extends SherlockFragmentActivity { intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING); + // set data uri as path to keyring + intent.setData(mDataUri); + // fill values for this action Bundle data = new Bundle(); - int keyRingId = getIntent().getIntExtra(EXTRA_KEYRING_ROW_ID, -1); - data.putInt(KeychainIntentService.UPLOAD_KEY_KEYRING_ROW_ID, keyRingId); - String server = (String) mKeyServerSpinner.getSelectedItem(); data.putString(KeychainIntentService.UPLOAD_KEY_SERVER, server); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SignKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SignKeyActivity.java index b3843a34f..58c31076f 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SignKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SignKeyActivity.java @@ -24,6 +24,7 @@ import org.spongycastle.openpgp.PGPSignature; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.Preferences; +import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; @@ -34,6 +35,7 @@ import org.sufficientlysecure.keychain.util.Log; import android.app.ProgressDialog; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -58,18 +60,16 @@ import com.beardedhen.androidbootstrap.BootstrapButton; */ public class SignKeyActivity extends SherlockFragmentActivity implements SelectSecretKeyLayoutFragment.SelectSecretKeyCallback { - - public static final String EXTRA_KEY_ID = "key_id"; - - private long mPubKeyId = 0; - private long mMasterKeyId = 0; - private BootstrapButton mSignButton; private CheckBox mUploadKeyCheckbox; private Spinner mSelectKeyserverSpinner; private SelectSecretKeyLayoutFragment mSelectKeyFragment; + private Uri mDataUri; + private long mPubKeyId = 0; + private long mMasterKeyId = 0; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -126,10 +126,22 @@ public class SignKeyActivity extends SherlockFragmentActivity implements } }); - mPubKeyId = getIntent().getLongExtra(EXTRA_KEY_ID, 0); - if (mPubKeyId == 0) { - Log.e(Constants.TAG, "No pub key id given!"); + mDataUri = getIntent().getData(); + if (mDataUri == null) { + Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); finish(); + return; + } + + PGPPublicKeyRing signKey = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, mDataUri); + + if (signKey != null) { + mPubKeyId = PgpKeyHelper.getMasterKey(signKey).getKeyID(); + } + if (mPubKeyId == 0) { + Log.e(Constants.TAG, "this shouldn't happen. KeyId == 0!"); + finish(); + return; } } @@ -260,11 +272,12 @@ public class SignKeyActivity extends SherlockFragmentActivity implements intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING); + // set data uri as path to keyring + intent.setData(mDataUri); + // fill values for this action Bundle data = new Bundle(); - data.putLong(KeychainIntentService.UPLOAD_KEY_KEYRING_ROW_ID, mPubKeyId); - Spinner keyServer = (Spinner) findViewById(R.id.sign_key_keyserver); String server = (String) keyServer.getSelectedItem(); data.putString(KeychainIntentService.UPLOAD_KEY_SERVER, server); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 26d0e8bc7..f5ad69e99 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -382,11 +382,8 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements } private void uploadToKeyserver(Uri dataUri) { - long keyRingRowId = Long.valueOf(dataUri.getLastPathSegment()); - Intent uploadIntent = new Intent(this, KeyServerUploadActivity.class); - uploadIntent.setAction(KeyServerUploadActivity.ACTION_EXPORT_KEY_TO_SERVER); - uploadIntent.putExtra(KeyServerUploadActivity.EXTRA_KEYRING_ROW_ID, (int) keyRingRowId); + uploadIntent.setData(mDataUri); startActivityForResult(uploadIntent, Id.request.export_to_server); } @@ -412,19 +409,8 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements } private void signKey(Uri dataUri) { - long keyId = 0; - PGPPublicKeyRing signKey = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, dataUri); - - if (signKey != null) { - keyId = PgpKeyHelper.getMasterKey(signKey).getKeyID(); - } - if (keyId == 0) { - Log.e(Constants.TAG, "this shouldn't happen. KeyId == 0!"); - return; - } - Intent signIntent = new Intent(this, SignKeyActivity.class); - signIntent.putExtra(SignKeyActivity.EXTRA_KEY_ID, keyId); + signIntent.setData(mDataUri); startActivity(signIntent); }