wrapped-key-ring: get rid of bc objects in key editor

This commit is contained in:
Vincent Breitmoser 2014-05-04 16:59:55 +02:00
parent cd8af25ba7
commit 9baddb7d71
10 changed files with 97 additions and 99 deletions

View File

@ -40,6 +40,14 @@ public class CachedSecretKey extends CachedPublicKey {
return (CachedSecretKeyRing) mRing; return (CachedSecretKeyRing) mRing;
} }
/** Returns the wrapped PGPSecretKeyRing.
* This function is for compatibility only, should not be used anymore and will be removed
*/
@Deprecated
public PGPSecretKey getKeyExternal() {
return mSecretKey;
}
public boolean unlock(String passphrase) throws PgpGeneralException { public boolean unlock(String passphrase) throws PgpGeneralException {
try { try {
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(

View File

@ -26,12 +26,10 @@ import org.spongycastle.openpgp.PGPSignatureList;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
public class PgpConversionHelper { public class PgpConversionHelper {
/** /**
@ -60,10 +58,10 @@ public class PgpConversionHelper {
* @param keysBytes * @param keysBytes
* @return * @return
*/ */
public static ArrayList<PGPSecretKey> BytesToPGPSecretKeyList(byte[] keysBytes) { public static ArrayList<UncachedSecretKey> BytesToPGPSecretKeyList(byte[] keysBytes) {
PGPObjectFactory factory = new PGPObjectFactory(keysBytes); PGPObjectFactory factory = new PGPObjectFactory(keysBytes);
Object obj = null; Object obj = null;
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>(); ArrayList<UncachedSecretKey> keys = new ArrayList<UncachedSecretKey>();
try { try {
while ((obj = factory.nextObject()) != null) { while ((obj = factory.nextObject()) != null) {
PGPSecretKey secKey = null; PGPSecretKey secKey = null;
@ -72,7 +70,7 @@ public class PgpConversionHelper {
if (secKey == null) { if (secKey == null) {
Log.e(Constants.TAG, "No keys given!"); Log.e(Constants.TAG, "No keys given!");
} }
keys.add(secKey); keys.add(new UncachedSecretKey(secKey));
} else if (obj instanceof PGPSecretKeyRing) { //master keys are sent as keyrings } else if (obj instanceof PGPSecretKeyRing) { //master keys are sent as keyrings
PGPSecretKeyRing keyRing = null; PGPSecretKeyRing keyRing = null;
keyRing = (PGPSecretKeyRing) obj; keyRing = (PGPSecretKeyRing) obj;
@ -82,7 +80,7 @@ public class PgpConversionHelper {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Iterator<PGPSecretKey> itr = keyRing.getSecretKeys(); Iterator<PGPSecretKey> itr = keyRing.getSecretKeys();
while (itr.hasNext()) { while (itr.hasNext()) {
keys.add(itr.next()); keys.add(new UncachedSecretKey(itr.next()));
} }
} }
} }
@ -100,7 +98,7 @@ public class PgpConversionHelper {
* @param keyBytes * @param keyBytes
* @return * @return
*/ */
public static PGPSecretKey BytesToPGPSecretKey(byte[] keyBytes) { public static UncachedSecretKey BytesToPGPSecretKey(byte[] keyBytes) {
PGPObjectFactory factory = new PGPObjectFactory(keyBytes); PGPObjectFactory factory = new PGPObjectFactory(keyBytes);
Object obj = null; Object obj = null;
try { try {
@ -121,7 +119,7 @@ public class PgpConversionHelper {
secKey = keyRing.getSecretKey(); secKey = keyRing.getSecretKey();
} }
return secKey; return new UncachedSecretKey(secKey);
} }
/** /**
@ -146,23 +144,4 @@ public class PgpConversionHelper {
return signatures.get(0); return signatures.get(0);
} }
/**
* Convert from ArrayList<PGPSecretKey> to byte[]
*
* @param keys
* @return
*/
public static byte[] PGPSecretKeyArrayListToBytes(ArrayList<PGPSecretKey> keys) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
for (PGPSecretKey key : keys) {
try {
key.encode(os);
} catch (IOException e) {
Log.e(Constants.TAG, "Error while converting ArrayList<PGPSecretKey> to byte[]!", e);
}
}
return os.toByteArray();
}
} }

View File

@ -200,7 +200,7 @@ public class PgpKeyOperation {
boolean canSign; boolean canSign;
String mainUserId = saveParcel.userIds.get(0); String mainUserId = saveParcel.userIds.get(0);
PGPSecretKey masterKey = saveParcel.keys.get(0); PGPSecretKey masterKey = saveParcel.keys.get(0).getSecretKeyExternal();
// this removes all userIds and certifications previously attached to the masterPublicKey // this removes all userIds and certifications previously attached to the masterPublicKey
PGPPublicKey masterPublicKey = masterKey.getPublicKey(); PGPPublicKey masterPublicKey = masterKey.getPublicKey();
@ -275,7 +275,7 @@ public class PgpKeyOperation {
for (int i = 1; i < saveParcel.keys.size(); ++i) { for (int i = 1; i < saveParcel.keys.size(); ++i) {
updateProgress(40 + 40 * (i - 1) / (saveParcel.keys.size() - 1), 100); updateProgress(40 + 40 * (i - 1) / (saveParcel.keys.size() - 1), 100);
PGPSecretKey subKey = saveParcel.keys.get(i); PGPSecretKey subKey = saveParcel.keys.get(i).getSecretKeyExternal();
PGPPublicKey subPublicKey = subKey.getPublicKey(); PGPPublicKey subPublicKey = subKey.getPublicKey();
PBESecretKeyDecryptor keyDecryptor2 = new JcePBESecretKeyDecryptorBuilder() PBESecretKeyDecryptor keyDecryptor2 = new JcePBESecretKeyDecryptorBuilder()
@ -377,8 +377,8 @@ public class PgpKeyOperation {
*/ */
if (saveParcel.deletedKeys != null) { if (saveParcel.deletedKeys != null) {
for (PGPSecretKey dKey : saveParcel.deletedKeys) { for (UncachedSecretKey dKey : saveParcel.deletedKeys) {
mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey); mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey.getSecretKeyExternal());
} }
} }
@ -542,7 +542,7 @@ public class PgpKeyOperation {
for (int i = 1; i < saveParcel.keys.size(); ++i) { for (int i = 1; i < saveParcel.keys.size(); ++i) {
updateProgress(40 + 50 * i / saveParcel.keys.size(), 100); updateProgress(40 + 50 * i / saveParcel.keys.size(), 100);
if (saveParcel.moddedKeys[i]) { if (saveParcel.moddedKeys[i]) {
PGPSecretKey subKey = saveParcel.keys.get(i); PGPSecretKey subKey = saveParcel.keys.get(i).getSecretKeyExternal();
PGPPublicKey subPublicKey = subKey.getPublicKey(); PGPPublicKey subPublicKey = subKey.getPublicKey();
PBESecretKeyDecryptor keyDecryptor2; PBESecretKeyDecryptor keyDecryptor2;

View File

@ -412,7 +412,7 @@ public class OpenPgpService extends RemoteService {
try { try {
// try to find key, throws NotFoundException if not in db! // try to find key, throws NotFoundException if not in db!
mProviderHelper.getPGPPublicKeyRing(masterKeyId); mProviderHelper.getCachedPublicKeyRing(masterKeyId);
Intent result = new Intent(); Intent result = new Intent();
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);

View File

@ -504,7 +504,7 @@ public class KeychainIntentService extends IntentService
newPassphrase = oldPassphrase; newPassphrase = oldPassphrase;
} }
long masterKeyId = saveParcel.keys.get(0).getKeyID(); long masterKeyId = saveParcel.keys.get(0).getKeyId();
/* Operation */ /* Operation */
ProviderHelper providerHelper = new ProviderHelper(this); ProviderHelper providerHelper = new ProviderHelper(this);

View File

@ -20,9 +20,14 @@ package org.sufficientlysecure.keychain.service;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import org.spongycastle.openpgp.PGPSecretKey; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; 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.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -34,13 +39,13 @@ public class SaveKeyringParcel implements Parcelable {
public boolean[] newIDs; public boolean[] newIDs;
public boolean primaryIDChanged; public boolean primaryIDChanged;
public boolean[] moddedKeys; public boolean[] moddedKeys;
public ArrayList<PGPSecretKey> deletedKeys; public ArrayList<UncachedSecretKey> deletedKeys;
public ArrayList<Calendar> keysExpiryDates; public ArrayList<Calendar> keysExpiryDates;
public ArrayList<Integer> keysUsages; public ArrayList<Integer> keysUsages;
public String newPassphrase; public String newPassphrase;
public String oldPassphrase; public String oldPassphrase;
public boolean[] newKeys; public boolean[] newKeys;
public ArrayList<PGPSecretKey> keys; public ArrayList<UncachedSecretKey> keys;
public String originalPrimaryID; public String originalPrimaryID;
public SaveKeyringParcel() {} public SaveKeyringParcel() {}
@ -75,17 +80,13 @@ public class SaveKeyringParcel implements Parcelable {
destination.writeBooleanArray(newIDs); destination.writeBooleanArray(newIDs);
destination.writeByte((byte) (primaryIDChanged ? 1 : 0)); destination.writeByte((byte) (primaryIDChanged ? 1 : 0));
destination.writeBooleanArray(moddedKeys); destination.writeBooleanArray(moddedKeys);
byte[] tmp = null; destination.writeByteArray(encodeArrayList(deletedKeys));
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);
destination.writeString(oldPassphrase); destination.writeString(oldPassphrase);
destination.writeBooleanArray(newKeys); destination.writeBooleanArray(newKeys);
destination.writeByteArray(PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys)); destination.writeByteArray(encodeArrayList(keys));
destination.writeString(originalPrimaryID); destination.writeString(originalPrimaryID);
} }
@ -99,6 +100,22 @@ public class SaveKeyringParcel implements Parcelable {
} }
}; };
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 @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

View File

@ -43,7 +43,6 @@ import android.widget.TextView;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;
import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.helper.Preferences;
@ -51,7 +50,6 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
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;

View File

@ -44,16 +44,17 @@ import android.widget.Toast;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;
import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ActionBarHelper; import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.helper.ExportHelper;
import org.sufficientlysecure.keychain.pgp.CachedSecretKey;
import org.sufficientlysecure.keychain.pgp.CachedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper; 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;
@ -66,7 +67,6 @@ import org.sufficientlysecure.keychain.ui.widget.Editor.EditorListener;
import org.sufficientlysecure.keychain.ui.widget.KeyEditor; import org.sufficientlysecure.keychain.ui.widget.KeyEditor;
import org.sufficientlysecure.keychain.ui.widget.SectionView; import org.sufficientlysecure.keychain.ui.widget.SectionView;
import org.sufficientlysecure.keychain.ui.widget.UserIdEditor; import org.sufficientlysecure.keychain.ui.widget.UserIdEditor;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
@ -88,8 +88,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
// EDIT // EDIT
private Uri mDataUri; private Uri mDataUri;
private PGPSecretKeyRing mKeyRing = null;
private SectionView mUserIdsView; private SectionView mUserIdsView;
private SectionView mKeysView; private SectionView mKeysView;
@ -105,7 +103,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
private CheckBox mNoPassphrase; private CheckBox mNoPassphrase;
Vector<String> mUserIds; Vector<String> mUserIds;
Vector<PGPSecretKey> mKeys; Vector<UncachedSecretKey> mKeys;
Vector<Integer> mKeysUsages; Vector<Integer> mKeysUsages;
boolean mMasterCanSign = true; boolean mMasterCanSign = true;
@ -158,7 +156,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
); );
mUserIds = new Vector<String>(); mUserIds = new Vector<String>();
mKeys = new Vector<PGPSecretKey>(); mKeys = new Vector<UncachedSecretKey>();
mKeysUsages = new Vector<Integer>(); mKeysUsages = new Vector<Integer>();
// Catch Intents opened from other apps // Catch Intents opened from other apps
@ -239,7 +237,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
// get new key from data bundle returned from service // get new key from data bundle returned from service
Bundle data = message.getData(); Bundle data = message.getData();
ArrayList<PGPSecretKey> newKeys = ArrayList<UncachedSecretKey> newKeys =
PgpConversionHelper.BytesToPGPSecretKeyList(data PgpConversionHelper.BytesToPGPSecretKeyList(data
.getByteArray(KeychainIntentService.RESULT_NEW_KEY)); .getByteArray(KeychainIntentService.RESULT_NEW_KEY));
@ -287,18 +285,18 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
Log.d(Constants.TAG, "uri: " + mDataUri); Log.d(Constants.TAG, "uri: " + mDataUri);
try { try {
Uri secretUri = KeychainContract.KeyRingData.buildSecretKeyRingUri(mDataUri); Uri secretUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
mKeyRing = (PGPSecretKeyRing) new ProviderHelper(this).getPGPKeyRing(secretUri); CachedSecretKeyRing keyRing = new ProviderHelper(this).getCachedSecretKeyRing(secretUri);
PGPSecretKey masterKey = mKeyRing.getSecretKey(); mMasterCanSign = keyRing.getSubKey().canCertify();
mMasterCanSign = PgpKeyHelper.isCertificationKey(mKeyRing.getSecretKey()); for (CachedSecretKey key : keyRing.iterator()) {
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) { // Turn into uncached instance
mKeys.add(key); mKeys.add(key.getUncached());
mKeysUsages.add(-1); // get usage when view is created mKeysUsages.add(key.getKeyUsage()); // get usage when view is created
} }
boolean isSet = false; boolean isSet = false;
for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) { for (String userId : keyRing.getSubKey().getUserIds()) {
Log.d(Constants.TAG, "Added userId " + userId); Log.d(Constants.TAG, "Added userId " + userId);
if (!isSet) { if (!isSet) {
isSet = true; isSet = true;
@ -313,7 +311,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
buildLayout(false); buildLayout(false);
mCurrentPassphrase = ""; mCurrentPassphrase = "";
mIsPassphraseSet = PassphraseCacheService.hasPassphrase(mKeyRing); mIsPassphraseSet = keyRing.hasPassphrase();
if (!mIsPassphraseSet) { if (!mIsPassphraseSet) {
// check "no passphrase" checkbox and remove button // check "no passphrase" checkbox and remove button
mNoPassphrase.setChecked(true); mNoPassphrase.setChecked(true);
@ -431,7 +429,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
if (mKeysView.getEditors().getChildCount() == 0) { if (mKeysView.getEditors().getChildCount() == 0) {
return 0; return 0;
} }
return ((KeyEditor) mKeysView.getEditors().getChildAt(0)).getValue().getKeyID(); return ((KeyEditor) mKeysView.getEditors().getChildAt(0)).getValue().getKeyId();
} }
public boolean isPassphraseSet() { public boolean isPassphraseSet() {
@ -571,7 +569,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
saveParams.keys = getKeys(mKeysView); saveParams.keys = getKeys(mKeysView);
saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID(); saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID();
// fill values for this action // fill values for this action
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, mMasterCanSign); data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, mMasterCanSign);
@ -590,7 +587,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
Intent data = new Intent(); Intent data = new Intent();
// return uri pointing to new created key // return uri pointing to new created key
Uri uri = KeychainContract.KeyRings.buildGenericKeyRingUri( Uri uri = KeyRings.buildGenericKeyRingUri(
String.valueOf(getMasterKeyId())); String.valueOf(getMasterKeyId()));
data.setData(uri); data.setData(uri);
@ -689,8 +686,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
* @param keysView * @param keysView
* @return * @return
*/ */
private ArrayList<PGPSecretKey> getKeys(SectionView keysView) throws PgpGeneralException { private ArrayList<UncachedSecretKey> getKeys(SectionView keysView) throws PgpGeneralException {
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>(); ArrayList<UncachedSecretKey> keys = new ArrayList<UncachedSecretKey>();
ViewGroup keyEditors = keysView.getEditors(); ViewGroup keyEditors = keysView.getEditors();

View File

@ -39,21 +39,18 @@ import android.widget.TextView;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPSecretKey;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.util.Choice; import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.Vector;
public class KeyEditor extends LinearLayout implements Editor, OnClickListener { public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
private PGPSecretKey mKey; private UncachedSecretKey mKey;
private EditorListener mEditorListener = null; private EditorListener mEditorListener = null;
@ -208,7 +205,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
} }
} }
public void setValue(PGPSecretKey key, boolean isMasterKey, int usage, boolean isNewKey) { public void setValue(UncachedSecretKey key, boolean isMasterKey, int usage, boolean isNewKey) {
mKey = key; mKey = key;
mIsMasterKey = isMasterKey; mIsMasterKey = isMasterKey;
@ -216,13 +213,12 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
mDeleteButton.setVisibility(View.INVISIBLE); mDeleteButton.setVisibility(View.INVISIBLE);
} }
mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(getContext(), key)); mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(getContext(), key.getAlgorithm()));
String keyIdStr = PgpKeyHelper.convertKeyIdToHex(key.getKeyID()); String keyIdStr = PgpKeyHelper.convertKeyIdToHex(key.getKeyId());
mKeyId.setText(keyIdStr); mKeyId.setText(keyIdStr);
Vector<Choice> choices = new Vector<Choice>(); boolean isElGamalKey = (key.isElGamalEncrypt());
boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT); boolean isDSAKey = (key.isDSA());
boolean isDSAKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.DSA);
if (isElGamalKey) { if (isElGamalKey) {
mChkSign.setVisibility(View.INVISIBLE); mChkSign.setVisibility(View.INVISIBLE);
TableLayout table = (TableLayout) findViewById(R.id.table_keylayout); TableLayout table = (TableLayout) findViewById(R.id.table_keylayout);
@ -254,32 +250,35 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
((usage & KeyFlags.ENCRYPT_STORAGE) == KeyFlags.ENCRYPT_STORAGE)); ((usage & KeyFlags.ENCRYPT_STORAGE) == KeyFlags.ENCRYPT_STORAGE));
mChkAuthenticate.setChecked((usage & KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION); mChkAuthenticate.setChecked((usage & KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION);
} else { } else {
mUsage = PgpKeyHelper.getKeyUsage(key); mUsage = key.getKeyUsage();
mOriginalUsage = mUsage; mOriginalUsage = mUsage;
if (key.isMasterKey()) { if (key.isMasterKey()) {
mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key)); mChkCertify.setChecked(key.canCertify());
} }
mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); mChkSign.setChecked(key.canSign());
mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); mChkEncrypt.setChecked(key.canEncrypt());
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key)); mChkAuthenticate.setChecked(key.canAuthenticate());
} }
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); {
cal.setTime(PgpKeyHelper.getCreationDate(key)); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
setCreatedDate(cal); cal.setTime(key.getCreationTime());
cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); setCreatedDate(cal);
Date expiryDate = PgpKeyHelper.getExpiryDate(key); }
Date expiryDate = key.getExpiryTime();
if (expiryDate == null) { if (expiryDate == null) {
setExpiryDate(null); setExpiryDate(null);
} else { } else {
cal.setTime(PgpKeyHelper.getExpiryDate(key)); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.setTime(expiryDate);
setExpiryDate(cal); setExpiryDate(cal);
mOriginalExpiryDate = cal; mOriginalExpiryDate = cal;
} }
} }
public PGPSecretKey getValue() { public UncachedSecretKey getValue() {
return mKey; return mKey;
} }

View File

@ -36,9 +36,9 @@ import android.widget.TextView;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import org.spongycastle.openpgp.PGPKeyFlags; import org.spongycastle.openpgp.PGPKeyFlags;
import org.spongycastle.openpgp.PGPSecretKey;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
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;
@ -63,7 +63,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
private int mNewKeySize; private int mNewKeySize;
private boolean mOldItemDeleted = false; private boolean mOldItemDeleted = false;
private ArrayList<String> mDeletedIDs = new ArrayList<String>(); private ArrayList<String> mDeletedIDs = new ArrayList<String>();
private ArrayList<PGPSecretKey> mDeletedKeys = new ArrayList<PGPSecretKey>(); private ArrayList<UncachedSecretKey> mDeletedKeys = new ArrayList<UncachedSecretKey>();
private boolean mCanBeEdited = true; private boolean mCanBeEdited = true;
private ActionBarActivity mActivity; private ActionBarActivity mActivity;
@ -227,7 +227,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
return mDeletedIDs; return mDeletedIDs;
} }
public ArrayList<PGPSecretKey> getDeletedKeys() { public ArrayList<UncachedSecretKey> getDeletedKeys() {
return mDeletedKeys; return mDeletedKeys;
} }
@ -325,7 +325,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
this.updateEditorsVisible(); this.updateEditorsVisible();
} }
public void setKeys(Vector<PGPSecretKey> list, Vector<Integer> usages, boolean newKeys) { public void setKeys(Vector<UncachedSecretKey> list, Vector<Integer> usages, boolean newKeys) {
if (mType != TYPE_KEY) { if (mType != TYPE_KEY) {
return; return;
} }
@ -358,9 +358,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
String passphrase; String passphrase;
if (mEditors.getChildCount() > 0) { if (mEditors.getChildCount() > 0) {
PGPSecretKey masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue(); UncachedSecretKey masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
passphrase = PassphraseCacheService passphrase = PassphraseCacheService
.getCachedPassphrase(mActivity, masterKey.getKeyID()); .getCachedPassphrase(mActivity, masterKey.getKeyId());
isMasterKey = false; isMasterKey = false;
} else { } else {
passphrase = ""; passphrase = "";
@ -395,7 +395,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
// get new key from data bundle returned from service // get new key from data bundle returned from service
Bundle data = message.getData(); Bundle data = message.getData();
PGPSecretKey newKey = (PGPSecretKey) PgpConversionHelper UncachedSecretKey newKey = PgpConversionHelper
.BytesToPGPSecretKey(data .BytesToPGPSecretKey(data
.getByteArray(KeychainIntentService.RESULT_NEW_KEY)); .getByteArray(KeychainIntentService.RESULT_NEW_KEY));
addGeneratedKeyToView(newKey); addGeneratedKeyToView(newKey);
@ -413,7 +413,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
mActivity.startService(intent); mActivity.startService(intent);
} }
private void addGeneratedKeyToView(PGPSecretKey newKey) { private void addGeneratedKeyToView(UncachedSecretKey newKey) {
// add view with new key // add view with new key
KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item, KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item,
mEditors, false); mEditors, false);