aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-06-17 20:03:58 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-06-17 20:03:58 +0200
commita0f546739d518a924770540795bca71bfacd4b1d (patch)
tree8433209832f1f3afe83d4be7fcc9133707dd866c /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
parent02fbaaf8580c4988d9e4e5031586ad4328ee21c2 (diff)
downloadopen-keychain-a0f546739d518a924770540795bca71bfacd4b1d.tar.gz
open-keychain-a0f546739d518a924770540795bca71bfacd4b1d.tar.bz2
open-keychain-a0f546739d518a924770540795bca71bfacd4b1d.zip
new-edit: remove old save keyring stuff
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java156
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OldSaveKeyringParcel.java128
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java2
3 files changed, 23 insertions, 263 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
index 3ddcdfcf4..d3f46a7a4 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -44,7 +44,6 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
-import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKey;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
@@ -87,9 +86,6 @@ public class KeychainIntentService extends IntentService
public static final String ACTION_DECRYPT_VERIFY = Constants.INTENT_PREFIX + "DECRYPT_VERIFY";
public static final String ACTION_SAVE_KEYRING = Constants.INTENT_PREFIX + "SAVE_KEYRING";
- public static final String ACTION_GENERATE_KEY = Constants.INTENT_PREFIX + "GENERATE_KEY";
- public static final String ACTION_GENERATE_DEFAULT_RSA_KEYS = Constants.INTENT_PREFIX
- + "GENERATE_DEFAULT_RSA_KEYS";
public static final String ACTION_DELETE_FILE_SECURELY = Constants.INTENT_PREFIX
+ "DELETE_FILE_SECURELY";
@@ -127,14 +123,7 @@ public class KeychainIntentService extends IntentService
// save keyring
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";
- public static final String GENERATE_KEY_SYMMETRIC_PASSPHRASE = "passphrase";
- public static final String GENERATE_KEY_MASTER_KEY = "master_key";
+ public static final String SAVE_KEYRING_PASSPHRASE = "passphrase";
// delete file securely
public static final String DELETE_FILE = "deleteFile";
@@ -164,9 +153,6 @@ public class KeychainIntentService extends IntentService
/*
* possible data keys as result send over messenger
*/
- // keys
- public static final String RESULT_NEW_KEY = "new_key";
- public static final String RESULT_KEY_USAGES = "new_key_usages";
// encrypt
public static final String RESULT_BYTES = "encrypted_data";
@@ -490,133 +476,35 @@ public class KeychainIntentService extends IntentService
} else if (ACTION_SAVE_KEYRING.equals(action)) {
try {
/* Input */
- OldSaveKeyringParcel saveParcel = data.getParcelable(SAVE_KEYRING_PARCEL);
- String oldPassphrase = saveParcel.oldPassphrase;
- String newPassphrase = saveParcel.newPassphrase;
- boolean canSign = true;
-
- if (data.containsKey(SAVE_KEYRING_CAN_SIGN)) {
- canSign = data.getBoolean(SAVE_KEYRING_CAN_SIGN);
- }
-
- if (newPassphrase == null) {
- newPassphrase = oldPassphrase;
- }
-
- long masterKeyId = saveParcel.keys.get(0).getKeyId();
+ SaveKeyringParcel saveParcel = data.getParcelable(SAVE_KEYRING_PARCEL);
+ long masterKeyId = saveParcel.mMasterKeyId;
/* Operation */
ProviderHelper providerHelper = new ProviderHelper(this);
- if (!canSign) {
- setProgress(R.string.progress_building_key, 0, 100);
- WrappedSecretKeyRing keyRing = providerHelper.getWrappedSecretKeyRing(masterKeyId);
- UncachedKeyRing newKeyRing =
- keyRing.changeSecretKeyPassphrase(oldPassphrase, newPassphrase);
- setProgress(R.string.progress_saving_key_ring, 50, 100);
- providerHelper.saveSecretKeyRing(newKeyRing);
- setProgress(R.string.progress_done, 100, 100);
- } else {
- PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 90, 100));
- try {
- WrappedSecretKeyRing seckey = providerHelper.getWrappedSecretKeyRing(masterKeyId);
- WrappedPublicKeyRing pubkey = providerHelper.getWrappedPublicKeyRing(masterKeyId);
-
- PgpKeyOperation.Pair<UncachedKeyRing,UncachedKeyRing> pair =
- keyOperations.buildSecretKey(seckey, pubkey, saveParcel); // edit existing
- setProgress(R.string.progress_saving_key_ring, 90, 100);
- providerHelper.saveKeyRing(pair.first, pair.second);
- } catch (ProviderHelper.NotFoundException e) {
- PgpKeyOperation.Pair<UncachedKeyRing,UncachedKeyRing> pair =
- keyOperations.buildNewSecretKey(saveParcel); //new Keyring
- // save the pair
- setProgress(R.string.progress_saving_key_ring, 90, 100);
- providerHelper.saveKeyRing(pair.first, pair.second);
- }
-
- setProgress(R.string.progress_done, 100, 100);
+ PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 90, 100));
+ try {
+ String passphrase = data.getString(SAVE_KEYRING_PASSPHRASE);
+ WrappedSecretKeyRing secRing = providerHelper.getWrappedSecretKeyRing(masterKeyId);
+
+ UncachedKeyRing ring = keyOperations.modifySecretKeyRing(secRing, saveParcel, passphrase);
+ setProgress(R.string.progress_saving_key_ring, 90, 100);
+ providerHelper.saveSecretKeyRing(ring);
+ } catch (ProviderHelper.NotFoundException e) {
+ // UncachedKeyRing ring = keyOperations.(saveParcel); //new Keyring
+ // save the pair
+ setProgress(R.string.progress_saving_key_ring, 90, 100);
+ // providerHelper.saveSecretKeyRing(ring);
+ sendErrorToHandler(e);
}
- PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassphrase);
- /* Output */
- sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
- } else if (ACTION_GENERATE_KEY.equals(action)) {
- try {
- /* Input */
- int algorithm = data.getInt(GENERATE_KEY_ALGORITHM);
- String passphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
- int keysize = data.getInt(GENERATE_KEY_KEY_SIZE);
- boolean masterKey = data.getBoolean(GENERATE_KEY_MASTER_KEY);
+ setProgress(R.string.progress_done, 100, 100);
- /* Operation */
- PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 100, 100));
- byte[] newKey = keyOperations.createKey(algorithm, keysize, passphrase, masterKey);
-
- /* Output */
- Bundle resultData = new Bundle();
- resultData.putByteArray(RESULT_NEW_KEY, newKey);
-
- OtherHelper.logDebugBundle(resultData, "resultData");
-
- sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
- } else if (ACTION_GENERATE_DEFAULT_RSA_KEYS.equals(action)) {
- // generate one RSA 4096 key for signing and one subkey for encrypting!
- try {
- /* Input */
- String passphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
- ArrayList<Integer> keyUsageList = new ArrayList<Integer>();
-
- /* Operation */
- int keysTotal = 3;
- int keysCreated = 0;
- setProgress(
- getApplicationContext().getResources().
- getQuantityString(R.plurals.progress_generating, keysTotal),
- keysCreated,
- keysTotal);
- PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 100, 100));
-
- ByteArrayOutputStream os = new ByteArrayOutputStream();
-
- byte[] buf;
-
- buf = keyOperations.createKey(Constants.choice.algorithm.rsa,
- 4096, passphrase, true);
- os.write(buf);
- keyUsageList.add(UncachedSecretKey.CERTIFY_OTHER);
- keysCreated++;
- setProgress(keysCreated, keysTotal);
-
- buf = keyOperations.createKey(Constants.choice.algorithm.rsa,
- 4096, passphrase, false);
- os.write(buf);
- keyUsageList.add(UncachedSecretKey.ENCRYPT_COMMS | UncachedSecretKey.ENCRYPT_STORAGE);
- keysCreated++;
- setProgress(keysCreated, keysTotal);
-
- buf = keyOperations.createKey(Constants.choice.algorithm.rsa,
- 4096, passphrase, false);
- os.write(buf);
- keyUsageList.add(UncachedSecretKey.SIGN_DATA);
- keysCreated++;
- setProgress(keysCreated, keysTotal);
-
- // TODO: default to one master for cert, one sub for encrypt and one sub
- // for sign
+ if (saveParcel.newPassphrase != null) {
+ PassphraseCacheService.addCachedPassphrase(this, masterKeyId, saveParcel.newPassphrase);
+ }
/* Output */
- Bundle resultData = new Bundle();
- resultData.putByteArray(RESULT_NEW_KEY, os.toByteArray());
- resultData.putIntegerArrayList(RESULT_KEY_USAGES, keyUsageList);
-
- OtherHelper.logDebugBundle(resultData, "resultData");
-
- sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
+ sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
} catch (Exception e) {
sendErrorToHandler(e);
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OldSaveKeyringParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OldSaveKeyringParcel.java
deleted file mode 100644
index b722393ad..000000000
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OldSaveKeyringParcel.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * 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.sufficientlysecure.keychain.Constants;
-import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
-import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
-import org.sufficientlysecure.keychain.util.IterableIterator;
-import org.sufficientlysecure.keychain.util.Log;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Calendar;
-
-/** Class for parcelling data between ui and services.
- * This class is outdated and scheduled for removal, pending a rewrite of the
- * EditKeyActivity and save keyring routines.
- */
-@Deprecated
-public class OldSaveKeyringParcel implements Parcelable {
-
- public ArrayList<String> userIds;
- public ArrayList<String> originalIDs;
- public ArrayList<String> deletedIDs;
- public boolean[] newIDs;
- public boolean primaryIDChanged;
- public boolean[] moddedKeys;
- public ArrayList<UncachedSecretKey> deletedKeys;
- public ArrayList<Calendar> keysExpiryDates;
- public ArrayList<Integer> keysUsages;
- public String newPassphrase;
- public String oldPassphrase;
- public boolean[] newKeys;
- public ArrayList<UncachedSecretKey> keys;
- public String originalPrimaryID;
-
- public OldSaveKeyringParcel() {}
-
- private OldSaveKeyringParcel(Parcel source) {
- userIds = (ArrayList<String>) source.readSerializable();
- originalIDs = (ArrayList<String>) source.readSerializable();
- deletedIDs = (ArrayList<String>) source.readSerializable();
- newIDs = source.createBooleanArray();
- primaryIDChanged = source.readByte() != 0;
- moddedKeys = source.createBooleanArray();
- byte[] tmp = source.createByteArray();
- if (tmp == null) {
- deletedKeys = null;
- } else {
- deletedKeys = PgpConversionHelper.BytesToPGPSecretKeyList(tmp);
- }
- keysExpiryDates = (ArrayList<Calendar>) 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.writeBooleanArray(newIDs);
- destination.writeByte((byte) (primaryIDChanged ? 1 : 0));
- destination.writeBooleanArray(moddedKeys);
- destination.writeByteArray(encodeArrayList(deletedKeys));
- destination.writeSerializable(keysExpiryDates);
- destination.writeList(keysUsages);
- destination.writeString(newPassphrase);
- destination.writeString(oldPassphrase);
- destination.writeBooleanArray(newKeys);
- destination.writeByteArray(encodeArrayList(keys));
- destination.writeString(originalPrimaryID);
- }
-
- public static final Creator<OldSaveKeyringParcel> CREATOR = new Creator<OldSaveKeyringParcel>() {
- public OldSaveKeyringParcel createFromParcel(final Parcel source) {
- return new OldSaveKeyringParcel(source);
- }
-
- public OldSaveKeyringParcel[] newArray(final int size) {
- return new OldSaveKeyringParcel[size];
- }
- };
-
- private static byte[] encodeArrayList(ArrayList<UncachedSecretKey> list) {
- if(list.isEmpty()) {
- return null;
- }
-
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- for(UncachedSecretKey key : new IterableIterator<UncachedSecretKey>(list.iterator())) {
- try {
- key.encodeSecretKey(os);
- } catch (IOException e) {
- Log.e(Constants.TAG, "Error while converting ArrayList<UncachedSecretKey> to byte[]!", e);
- }
- }
- return os.toByteArray();
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java
index 3514ab2e5..ca7da5ae3 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java
@@ -23,7 +23,7 @@ import java.util.HashMap;
public class SaveKeyringParcel implements Parcelable {
// the master key id to be edited
- private final long mMasterKeyId;
+ public final long mMasterKeyId;
// the key fingerprint, for safety
private final byte[] mFingerprint;