aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-04-11 01:48:08 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-04-11 02:58:08 +0200
commit9af532880c728ccd343769078b008a9b31dc4ce1 (patch)
treeff371e7db10f4507e607234a878950f164922720 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
parent0f06b8a1d6df7682d4216ec685c907bbf5774ff0 (diff)
downloadopen-keychain-9af532880c728ccd343769078b008a9b31dc4ce1.tar.gz
open-keychain-9af532880c728ccd343769078b008a9b31dc4ce1.tar.bz2
open-keychain-9af532880c728ccd343769078b008a9b31dc4ce1.zip
fix EditKeyActivity
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java56
1 files changed, 25 insertions, 31 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
index 84f0c41cf..a009410a6 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
@@ -39,10 +39,12 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
+import android.widget.Toast;
import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg;
+import org.spongycastle.openpgp.PGPException;
import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.sufficientlysecure.keychain.Constants;
@@ -287,34 +289,16 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
Log.d(Constants.TAG, "uri: " + mDataUri);
try {
- // get master key id using row id
- long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
- finallyEdit(masterKeyId);
- } catch (ProviderHelper.NotFoundException e) {
- Log.e(Constants.TAG, "key not found!", e);
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private void finallyEdit(final long masterKeyId) {
- if (masterKeyId != 0) {
- PGPSecretKey masterKey = null;
- try {
- mKeyRing = ProviderHelper.getPGPSecretKeyRing(this, masterKeyId);
+ Uri secretUri = KeychainContract.KeyRingData.buildSecretKeyRingUri(mDataUri);
+ mKeyRing = (PGPSecretKeyRing) ProviderHelper.getPGPKeyRing(this, secretUri);
- masterKey = mKeyRing.getSecretKey();
+ PGPSecretKey masterKey = mKeyRing.getSecretKey();
mMasterCanSign = PgpKeyHelper.isCertificationKey(mKeyRing.getSecretKey());
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) {
mKeys.add(key);
mKeysUsages.add(-1); // get usage when view is created
}
- } catch (ProviderHelper.NotFoundException e) {
- Log.e(Constants.TAG, "Keyring not found with masterKeyId: " + masterKeyId);
- AppMsg.makeText(this, R.string.error_no_secret_key_found, AppMsg.STYLE_ALERT).show();
- // TODO
- }
- if (masterKey != null) {
+
boolean isSet = false;
for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) {
Log.d(Constants.TAG, "Added userId " + userId);
@@ -327,17 +311,27 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
}
mUserIds.add(userId);
}
- }
- }
- mCurrentPassphrase = "";
- buildLayout(false);
+ buildLayout(false);
+
+ mCurrentPassphrase = "";
+ mIsPassphraseSet = PassphraseCacheService.hasPassphrase(mKeyRing);
+ if (!mIsPassphraseSet) {
+ // check "no passphrase" checkbox and remove button
+ mNoPassphrase.setChecked(true);
+ mChangePassphrase.setVisibility(View.GONE);
+ }
+
+ } catch (ProviderHelper.NotFoundException e) {
+ Log.e(Constants.TAG, "Keyring not found: " + e.getMessage(), e);
+ Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_SHORT).show();
+ finish();
+ } catch (PGPException e) {
+ Log.e(Constants.TAG, "Error extracting key: " + e.getMessage(), e);
+ Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_LONG).show();
+ finish();
+ }
- mIsPassphraseSet = PassphraseCacheService.hasPassphrase(this, masterKeyId);
- if (!mIsPassphraseSet) {
- // check "no passphrase" checkbox and remove button
- mNoPassphrase.setChecked(true);
- mChangePassphrase.setVisibility(View.GONE);
}
}