mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 20:42:17 -05:00
use parcel to save keys, but saving existing keys is disabled, pending a rewrite...
This commit is contained in:
parent
01951810ae
commit
04fa0e9cc7
@ -65,6 +65,7 @@ import org.sufficientlysecure.keychain.Id;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Primes;
|
import org.sufficientlysecure.keychain.util.Primes;
|
||||||
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
|
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
|
||||||
@ -346,23 +347,24 @@ public class PgpKeyOperation {
|
|||||||
updateProgress(R.string.progress_done, 100, 100);
|
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 {
|
PGPException, SignatureException, IOException {
|
||||||
|
|
||||||
updateProgress(R.string.progress_building_key, 0, 100);
|
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());
|
PGPSecretKeyRing mKR = ProviderHelper.getPGPSecretKeyRingByKeyId(mContext, masterKey.getKeyID());
|
||||||
|
|
||||||
if (oldPassPhrase == null) {
|
if (saveParcel.oldPassPhrase == null) {
|
||||||
oldPassPhrase = "";
|
saveParcel.oldPassPhrase = "";
|
||||||
}
|
}
|
||||||
if (newPassPhrase == null) {
|
if (saveParcel.newPassPhrase == null) {
|
||||||
newPassPhrase = "";
|
saveParcel.newPassPhrase = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mKR == null) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,6 +383,7 @@ public class PgpKeyOperation {
|
|||||||
do we need to remove and add in?
|
do we need to remove and add in?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
for (PGPSecretKey dKey : deleted_keys) {
|
for (PGPSecretKey dKey : deleted_keys) {
|
||||||
mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey);
|
mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey);
|
||||||
}
|
}
|
||||||
@ -567,6 +570,7 @@ public class PgpKeyOperation {
|
|||||||
ProviderHelper.saveKeyRing(mContext, publicKeyRing);
|
ProviderHelper.saveKeyRing(mContext, publicKeyRing);
|
||||||
|
|
||||||
updateProgress(R.string.progress_done, 100, 100);
|
updateProgress(R.string.progress_done, 100, 100);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public PGPPublicKeyRing certifyKey(long masterKeyId, long pubKeyId, String passphrase)
|
public PGPPublicKeyRing certifyKey(long masterKeyId, long pubKeyId, String passphrase)
|
||||||
|
@ -125,20 +125,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
|||||||
public static final String DECRYPT_ASSUME_SYMMETRIC = "assume_symmetric";
|
public static final String DECRYPT_ASSUME_SYMMETRIC = "assume_symmetric";
|
||||||
|
|
||||||
// save keyring
|
// save keyring
|
||||||
public static final String SAVE_KEYRING_NEW_PASSPHRASE = "new_passphrase";
|
public static final String SAVE_KEYRING_PARCEL = "save_parcel";
|
||||||
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_CAN_SIGN = "can_sign";
|
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
|
// generate key
|
||||||
public static final String GENERATE_KEY_ALGORITHM = "algorithm";
|
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)) {
|
} else if (ACTION_SAVE_KEYRING.equals(action)) {
|
||||||
try {
|
try {
|
||||||
/* Input */
|
/* Input */
|
||||||
String oldPassPhrase = data.getString(SAVE_KEYRING_CURRENT_PASSPHRASE);
|
SaveKeyringParcel saveParams = data.getParcelable(SAVE_KEYRING_PARCEL);
|
||||||
String newPassPhrase = data.getString(SAVE_KEYRING_NEW_PASSPHRASE);
|
String oldPassPhrase = saveParams.oldPassPhrase;
|
||||||
|
String newPassPhrase = saveParams.newPassPhrase;
|
||||||
boolean canSign = true;
|
boolean canSign = true;
|
||||||
|
|
||||||
if (data.containsKey(SAVE_KEYRING_CAN_SIGN)) {
|
if (data.containsKey(SAVE_KEYRING_CAN_SIGN)) {
|
||||||
@ -541,25 +531,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
|||||||
if (newPassPhrase == null) {
|
if (newPassPhrase == null) {
|
||||||
newPassPhrase = oldPassPhrase;
|
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);
|
PgpKeyOperation keyOperations = new PgpKeyOperation(this, this);
|
||||||
/* Operation */
|
/* Operation */
|
||||||
@ -568,9 +541,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
|||||||
ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId),
|
ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId),
|
||||||
oldPassPhrase, newPassPhrase);
|
oldPassPhrase, newPassPhrase);
|
||||||
} else {
|
} else {
|
||||||
keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, primaryChanged,
|
keyOperations.buildSecretKey(saveParams);
|
||||||
modded_keys, deletedKeys, keysExpiryDates, keysUsages, newPassPhrase,
|
|
||||||
oldPassPhrase, new_keys, keys);
|
|
||||||
}
|
}
|
||||||
PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase);
|
PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase);
|
||||||
|
|
||||||
|
@ -42,20 +42,25 @@ public class SaveKeyringParcel implements Parcelable {
|
|||||||
public boolean[] newKeys;
|
public boolean[] newKeys;
|
||||||
public ArrayList<PGPSecretKey> keys;
|
public ArrayList<PGPSecretKey> keys;
|
||||||
|
|
||||||
|
public SaveKeyringParcel() {}
|
||||||
|
|
||||||
private SaveKeyringParcel(Parcel source)
|
private SaveKeyringParcel(Parcel source)
|
||||||
{
|
{
|
||||||
byte[] tmpB;
|
|
||||||
userIDs = (ArrayList<String>)source.readSerializable();
|
userIDs = (ArrayList<String>)source.readSerializable();
|
||||||
originalIDs = (ArrayList<String>)source.readSerializable();
|
originalIDs = (ArrayList<String>)source.readSerializable();
|
||||||
deletedIDs = (ArrayList<String>)source.readSerializable();
|
deletedIDs = (ArrayList<String>)source.readSerializable();
|
||||||
primaryIDChanged = source.readByte() != 0;
|
primaryIDChanged = source.readByte() != 0;
|
||||||
source.readBooleanArray(moddedKeys);
|
moddedKeys = source.createBooleanArray();
|
||||||
deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray());
|
byte[] tmp = source.createByteArray();
|
||||||
|
if (tmp == null)
|
||||||
|
deletedKeys = null;
|
||||||
|
else
|
||||||
|
deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(tmp);
|
||||||
keysExpiryDates = (ArrayList<GregorianCalendar>)source.readSerializable();
|
keysExpiryDates = (ArrayList<GregorianCalendar>)source.readSerializable();
|
||||||
keysUsages = source.readArrayList(Integer.class.getClassLoader());
|
keysUsages = source.readArrayList(Integer.class.getClassLoader());
|
||||||
newPassPhrase = source.readString();
|
newPassPhrase = source.readString();
|
||||||
oldPassPhrase = source.readString();
|
oldPassPhrase = source.readString();
|
||||||
source.readBooleanArray(newKeys);
|
newKeys = source.createBooleanArray();
|
||||||
keys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray());
|
keys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +72,10 @@ public class SaveKeyringParcel implements Parcelable {
|
|||||||
destination.writeSerializable(deletedIDs);
|
destination.writeSerializable(deletedIDs);
|
||||||
destination.writeByte((byte) (primaryIDChanged ? 1 : 0));
|
destination.writeByte((byte) (primaryIDChanged ? 1 : 0));
|
||||||
destination.writeBooleanArray(moddedKeys);
|
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.writeSerializable(keysExpiryDates);
|
||||||
destination.writeList(keysUsages);
|
destination.writeList(keysUsages);
|
||||||
destination.writeString(newPassPhrase);
|
destination.writeString(newPassPhrase);
|
||||||
|
@ -36,6 +36,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
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.DeleteKeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
||||||
@ -570,38 +571,25 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
|
|
||||||
intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);
|
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
|
// fill values for this action
|
||||||
Bundle data = new Bundle();
|
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.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign);
|
||||||
data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_DELETED_IDS,
|
data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, saveParams);
|
||||||
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()));
|
|
||||||
|
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user