aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/main/java/org
diff options
context:
space:
mode:
authorAshley Hughes <spirit.returned@gmail.com>2014-03-06 23:47:11 +0000
committerAshley Hughes <spirit.returned@gmail.com>2014-03-06 23:47:11 +0000
commit04fa0e9cc7fbfc117948d60a3ad8bfab0b0060ba (patch)
tree8b248117c6c7d4f9907a46846b0ac11a45f94dec /OpenPGP-Keychain/src/main/java/org
parent01951810ae1b3a0e4fefab7d55c090fc8f776ce5 (diff)
downloadopen-keychain-04fa0e9cc7fbfc117948d60a3ad8bfab0b0060ba.tar.gz
open-keychain-04fa0e9cc7fbfc117948d60a3ad8bfab0b0060ba.tar.bz2
open-keychain-04fa0e9cc7fbfc117948d60a3ad8bfab0b0060ba.zip
use parcel to save keys, but saving existing keys is disabled, pending a rewrite...
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org')
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java18
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java45
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java18
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java46
4 files changed, 49 insertions, 78 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
index 66665df3c..0073107a0 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
@@ -65,6 +65,7 @@ import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
+import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Primes;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
@@ -346,23 +347,24 @@ public class PgpKeyOperation {
updateProgress(R.string.progress_done, 100, 100);
}
- public void buildSecretKey(ArrayList<String> userIds, ArrayList<String> OriginalIDs, ArrayList<String> deletedIDs, boolean primaryIDChanged, boolean[] modded_keys, ArrayList<PGPSecretKey> deleted_keys, ArrayList<GregorianCalendar> keysExpiryDates, ArrayList<Integer> keysUsages, String newPassPhrase, String oldPassPhrase, boolean[] new_keys, ArrayList<PGPSecretKey> keys) throws PgpGeneralException,
+ public void buildSecretKey(SaveKeyringParcel saveParcel) throws PgpGeneralException,
PGPException, SignatureException, IOException {
updateProgress(R.string.progress_building_key, 0, 100);
- PGPSecretKey masterKey = keys.get(0);
+ PGPSecretKey masterKey = saveParcel.keys.get(0);
PGPSecretKeyRing mKR = ProviderHelper.getPGPSecretKeyRingByKeyId(mContext, masterKey.getKeyID());
- if (oldPassPhrase == null) {
- oldPassPhrase = "";
+ if (saveParcel.oldPassPhrase == null) {
+ saveParcel.oldPassPhrase = "";
}
- if (newPassPhrase == null) {
- newPassPhrase = "";
+ if (saveParcel.newPassPhrase == null) {
+ saveParcel.newPassPhrase = "";
}
if (mKR == null) {
- buildNewSecretKey(userIds, keys, keysExpiryDates, keysUsages, newPassPhrase, oldPassPhrase); //new Keyring
+ buildNewSecretKey(saveParcel.userIDs, saveParcel.keys, saveParcel.keysExpiryDates,
+ saveParcel.keysUsages, saveParcel.newPassPhrase, saveParcel.oldPassPhrase); //new Keyring
return;
}
@@ -381,6 +383,7 @@ public class PgpKeyOperation {
do we need to remove and add in?
*/
+ /*
for (PGPSecretKey dKey : deleted_keys) {
mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey);
}
@@ -567,6 +570,7 @@ public class PgpKeyOperation {
ProviderHelper.saveKeyRing(mContext, publicKeyRing);
updateProgress(R.string.progress_done, 100, 100);
+ */
}
public PGPPublicKeyRing certifyKey(long masterKeyId, long pubKeyId, String passphrase)
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 9d6e24d30..24bce8eeb 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
@@ -125,20 +125,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial
public static final String DECRYPT_ASSUME_SYMMETRIC = "assume_symmetric";
// save keyring
- public static final String SAVE_KEYRING_NEW_PASSPHRASE = "new_passphrase";
- public static final String SAVE_KEYRING_CURRENT_PASSPHRASE = "current_passphrase";
- public static final String SAVE_KEYRING_USER_IDS = "user_ids";
- public static final String SAVE_KEYRING_PRIMARY_ID_CHANGED = "primary_id_changed";
- public static final String SAVE_KEYRING_KEYS = "keys";
- public static final String SAVE_KEYRING_KEYS_USAGES = "keys_usages";
- public static final String SAVE_KEYRING_KEYS_EXPIRY_DATES = "keys_expiry_dates";
- public static final String SAVE_KEYRING_MASTER_KEY_ID = "master_key_id";
+ public static final String SAVE_KEYRING_PARCEL = "save_parcel";
public static final String SAVE_KEYRING_CAN_SIGN = "can_sign";
- public static final String SAVE_KEYRING_ORIGINAL_IDS = "original_ids";
- public static final String SAVE_KEYRING_DELETED_IDS = "deleted_ids";
- public static final String SAVE_KEYRING_MODDED_KEYS = "modified_keys";
- public static final String SAVE_KEYRING_DELETED_KEYS = "deleted_keys";
- public static final String SAVE_KEYRING_NEW_KEYS = "new_keys";
+
// generate key
public static final String GENERATE_KEY_ALGORITHM = "algorithm";
@@ -530,8 +519,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} else if (ACTION_SAVE_KEYRING.equals(action)) {
try {
/* Input */
- String oldPassPhrase = data.getString(SAVE_KEYRING_CURRENT_PASSPHRASE);
- String newPassPhrase = data.getString(SAVE_KEYRING_NEW_PASSPHRASE);
+ SaveKeyringParcel saveParams = data.getParcelable(SAVE_KEYRING_PARCEL);
+ String oldPassPhrase = saveParams.oldPassPhrase;
+ String newPassPhrase = saveParams.newPassPhrase;
boolean canSign = true;
if (data.containsKey(SAVE_KEYRING_CAN_SIGN)) {
@@ -541,25 +531,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
if (newPassPhrase == null) {
newPassPhrase = oldPassPhrase;
}
- ArrayList<String> userIds = data.getStringArrayList(SAVE_KEYRING_USER_IDS);
- ArrayList<PGPSecretKey> keys = PgpConversionHelper.BytesToPGPSecretKeyList(data
- .getByteArray(SAVE_KEYRING_KEYS));
- ArrayList<Integer> keysUsages = data.getIntegerArrayList(SAVE_KEYRING_KEYS_USAGES);
- ArrayList<GregorianCalendar> keysExpiryDates = (ArrayList<GregorianCalendar>) data.getSerializable(SAVE_KEYRING_KEYS_EXPIRY_DATES);
- ArrayList<String> original_ids = data.getStringArrayList(SAVE_KEYRING_ORIGINAL_IDS);
- ArrayList<String> deleted_ids = data.getStringArrayList(SAVE_KEYRING_DELETED_IDS);
- boolean[] modded_keys = data.getBooleanArray(SAVE_KEYRING_MODDED_KEYS);
- boolean[] new_keys = data.getBooleanArray(SAVE_KEYRING_NEW_KEYS);
- byte[] tmp = data.getByteArray(SAVE_KEYRING_DELETED_KEYS);
- ArrayList<PGPSecretKey> deletedKeys;
- if (tmp != null)
- deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(data
- .getByteArray(SAVE_KEYRING_DELETED_KEYS));
- else
- deletedKeys = new ArrayList<PGPSecretKey>();
- boolean primaryChanged = data.getBoolean(SAVE_KEYRING_PRIMARY_ID_CHANGED);
-
- long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID);
+
+ long masterKeyId = saveParams.keys.get(0).getKeyID();
PgpKeyOperation keyOperations = new PgpKeyOperation(this, this);
/* Operation */
@@ -568,9 +541,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId),
oldPassPhrase, newPassPhrase);
} else {
- keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, primaryChanged,
- modded_keys, deletedKeys, keysExpiryDates, keysUsages, newPassPhrase,
- oldPassPhrase, new_keys, keys);
+ keyOperations.buildSecretKey(saveParams);
}
PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase);
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java
index 9e290c1b6..ae481aa80 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java
@@ -42,20 +42,25 @@ public class SaveKeyringParcel implements Parcelable {
public boolean[] newKeys;
public ArrayList<PGPSecretKey> keys;
+ public SaveKeyringParcel() {}
+
private SaveKeyringParcel(Parcel source)
{
- byte[] tmpB;
userIDs = (ArrayList<String>)source.readSerializable();
originalIDs = (ArrayList<String>)source.readSerializable();
deletedIDs = (ArrayList<String>)source.readSerializable();
primaryIDChanged = source.readByte() != 0;
- source.readBooleanArray(moddedKeys);
- deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray());
+ moddedKeys = source.createBooleanArray();
+ byte[] tmp = source.createByteArray();
+ if (tmp == null)
+ deletedKeys = null;
+ else
+ deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(tmp);
keysExpiryDates = (ArrayList<GregorianCalendar>)source.readSerializable();
keysUsages = source.readArrayList(Integer.class.getClassLoader());
newPassPhrase = source.readString();
oldPassPhrase = source.readString();
- source.readBooleanArray(newKeys);
+ newKeys = source.createBooleanArray();
keys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray());
}
@@ -67,7 +72,10 @@ public class SaveKeyringParcel implements Parcelable {
destination.writeSerializable(deletedIDs);
destination.writeByte((byte) (primaryIDChanged ? 1 : 0));
destination.writeBooleanArray(moddedKeys);
- destination.writeByteArray(PgpConversionHelper.PGPSecretKeyArrayListToBytes(deletedKeys));
+ byte[] tmp = null;
+ if (deletedKeys.size() != 0)
+ tmp = PgpConversionHelper.PGPSecretKeyArrayListToBytes(deletedKeys);
+ destination.writeByteArray(tmp);
destination.writeSerializable(keysExpiryDates);
destination.writeList(keysUsages);
destination.writeString(newPassPhrase);
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
index 044d15ec7..6ce2a8f6b 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
@@ -36,6 +36,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
+import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
@@ -570,38 +571,25 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);
+ SaveKeyringParcel saveParams = new SaveKeyringParcel();
+ saveParams.userIDs = getUserIds(mUserIdsView);
+ saveParams.originalIDs = mUserIdsView.getOriginalIDs();
+ saveParams.deletedIDs = mUserIdsView.getDeletedIDs();
+ saveParams.primaryIDChanged = mUserIdsView.primaryChanged();
+ saveParams.moddedKeys = toPrimitiveArray(mKeysView.getNeedsSavingArray());
+ saveParams.deletedKeys = mKeysView.getDeletedKeys();
+ saveParams.keysExpiryDates = getKeysExpiryDates(mKeysView);
+ saveParams.keysUsages = getKeysUsages(mKeysView);
+ saveParams.newPassPhrase = mNewPassPhrase;
+ saveParams.oldPassPhrase = mCurrentPassPhrase;
+ saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray());
+ saveParams.keys = getKeys(mKeysView);
+
+
// fill values for this action
Bundle data = new Bundle();
- data.putString(KeychainIntentService.SAVE_KEYRING_CURRENT_PASSPHRASE,
- mCurrentPassPhrase);
- data.putString(KeychainIntentService.SAVE_KEYRING_NEW_PASSPHRASE, mNewPassPhrase);
- data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_USER_IDS,
- getUserIds(mUserIdsView));
- ArrayList<PGPSecretKey> keys = getKeys(mKeysView);
- data.putByteArray(KeychainIntentService.SAVE_KEYRING_KEYS,
- PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys));
- ArrayList<PGPSecretKey> dKeys = mKeysView.getDeletedKeys();
- byte[] tmp = null;
- if (dKeys.size() != 0)
- tmp = PgpConversionHelper.PGPSecretKeyArrayListToBytes(dKeys);
- data.putByteArray(KeychainIntentService.SAVE_KEYRING_DELETED_KEYS,
- tmp);
- data.putIntegerArrayList(KeychainIntentService.SAVE_KEYRING_KEYS_USAGES,
- getKeysUsages(mKeysView));
- data.putSerializable(KeychainIntentService.SAVE_KEYRING_KEYS_EXPIRY_DATES,
- getKeysExpiryDates(mKeysView));
- data.putLong(KeychainIntentService.SAVE_KEYRING_MASTER_KEY_ID, getMasterKeyId());
data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign);
- data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_DELETED_IDS,
- mUserIdsView.getDeletedIDs());
- data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS,
- mUserIdsView.getOriginalIDs());
- data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_MODDED_KEYS,
- toPrimitiveArray(mKeysView.getNeedsSavingArray()));
- data.putBoolean(KeychainIntentService.SAVE_KEYRING_PRIMARY_ID_CHANGED,
- mUserIdsView.primaryChanged());
- data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_NEW_KEYS,
- toPrimitiveArray(mKeysView.getNewKeysArray()));
+ data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, saveParams);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);