aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service
diff options
context:
space:
mode:
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service')
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java34
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java105
2 files changed, 112 insertions, 27 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 bd3a0421b..846eb8cf9 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
@@ -105,15 +105,10 @@ public class KeychainIntentService extends IntentService
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_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";
+
// generate key
public static final String GENERATE_KEY_ALGORITHM = "algorithm";
public static final String GENERATE_KEY_KEY_SIZE = "key_size";
@@ -516,8 +511,9 @@ public class KeychainIntentService extends IntentService
} 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)) {
@@ -527,14 +523,8 @@ public class KeychainIntentService extends IntentService
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);
- long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID);
+ long masterKeyId = saveParams.keys.get(0).getKeyID();
PgpKeyOperation keyOperations = new PgpKeyOperation(this, this);
/* Operation */
@@ -543,17 +533,7 @@ public class KeychainIntentService extends IntentService
ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId),
oldPassPhrase, newPassPhrase);
} else {
- //TODO: Workaround due to ProviderHelper.getPGPPublicKeyByKeyId can not resolve public key of master-key id with uri/cursor
- PGPPublicKey pubkey = null;
- for(PGPSecretKey key : keys) {
- PGPPublicKey tempKey = key.getPublicKey();
- if (tempKey.getKeyID() == masterKeyId) {
- pubkey = tempKey;
- }
- }
- //PGPPublicKey pubkey = ProviderHelper.getPGPPublicKeyByKeyId(this, masterKeyId);
- keyOperations.buildSecretKey(userIds, keys, keysUsages, keysExpiryDates,
- pubkey, oldPassPhrase, newPassPhrase);
+ 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
new file mode 100644
index 000000000..c99284847
--- /dev/null
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2014 Ash Hughes <ashes-iontach@hotmail.com>
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+package org.sufficientlysecure.keychain.service;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import org.spongycastle.openpgp.PGPSecretKey;
+import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
+
+import java.util.ArrayList;
+import java.util.GregorianCalendar;
+
+public class SaveKeyringParcel implements Parcelable {
+
+ public ArrayList<String> userIDs;
+ public ArrayList<String> originalIDs;
+ public ArrayList<String> deletedIDs;
+ public boolean primaryIDChanged;
+ public boolean[] moddedKeys;
+ public ArrayList<PGPSecretKey> deletedKeys;
+ public ArrayList<GregorianCalendar> keysExpiryDates;
+ public ArrayList<Integer> keysUsages;
+ public String newPassPhrase;
+ public String oldPassPhrase;
+ public boolean[] newKeys;
+ public ArrayList<PGPSecretKey> keys;
+ public String originalPrimaryID;
+
+ public SaveKeyringParcel() {}
+
+ private SaveKeyringParcel(Parcel source)
+ {
+ userIDs = (ArrayList<String>)source.readSerializable();
+ originalIDs = (ArrayList<String>)source.readSerializable();
+ deletedIDs = (ArrayList<String>)source.readSerializable();
+ primaryIDChanged = source.readByte() != 0;
+ 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();
+ newKeys = source.createBooleanArray();
+ keys = PgpConversionHelper.BytesToPGPSecretKeyList(source.createByteArray());
+ originalPrimaryID = source.readString();
+ }
+
+ @Override
+ public void writeToParcel(Parcel destination, int flags)
+ {
+ destination.writeSerializable(userIDs); //might not be the best method to store.
+ destination.writeSerializable(originalIDs);
+ destination.writeSerializable(deletedIDs);
+ destination.writeByte((byte) (primaryIDChanged ? 1 : 0));
+ destination.writeBooleanArray(moddedKeys);
+ byte[] tmp = null;
+ if (deletedKeys.size() != 0)
+ tmp = PgpConversionHelper.PGPSecretKeyArrayListToBytes(deletedKeys);
+ destination.writeByteArray(tmp);
+ destination.writeSerializable(keysExpiryDates);
+ destination.writeList(keysUsages);
+ destination.writeString(newPassPhrase);
+ destination.writeString(oldPassPhrase);
+ destination.writeBooleanArray(newKeys);
+ destination.writeByteArray(PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys));
+ destination.writeString(originalPrimaryID);
+ }
+
+ public static final Creator<SaveKeyringParcel> CREATOR = new Creator<SaveKeyringParcel>() {
+ public SaveKeyringParcel createFromParcel(final Parcel source) {
+ return new SaveKeyringParcel(source);
+ }
+
+ public SaveKeyringParcel[] newArray(final int size) {
+ return new SaveKeyringParcel[size];
+ }
+ };
+
+ @Override
+ public int describeContents()
+ {
+ return 0;
+ }
+}