mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
wrapped-key-ring: get rid of bc objects in key editor
This commit is contained in:
parent
cd8af25ba7
commit
9baddb7d71
@ -40,6 +40,14 @@ public class CachedSecretKey extends CachedPublicKey {
|
||||
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 {
|
||||
try {
|
||||
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
|
||||
|
@ -26,12 +26,10 @@ import org.spongycastle.openpgp.PGPSignatureList;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class PgpConversionHelper {
|
||||
|
||||
/**
|
||||
@ -60,10 +58,10 @@ public class PgpConversionHelper {
|
||||
* @param keysBytes
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<PGPSecretKey> BytesToPGPSecretKeyList(byte[] keysBytes) {
|
||||
public static ArrayList<UncachedSecretKey> BytesToPGPSecretKeyList(byte[] keysBytes) {
|
||||
PGPObjectFactory factory = new PGPObjectFactory(keysBytes);
|
||||
Object obj = null;
|
||||
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>();
|
||||
ArrayList<UncachedSecretKey> keys = new ArrayList<UncachedSecretKey>();
|
||||
try {
|
||||
while ((obj = factory.nextObject()) != null) {
|
||||
PGPSecretKey secKey = null;
|
||||
@ -72,7 +70,7 @@ public class PgpConversionHelper {
|
||||
if (secKey == null) {
|
||||
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
|
||||
PGPSecretKeyRing keyRing = null;
|
||||
keyRing = (PGPSecretKeyRing) obj;
|
||||
@ -82,7 +80,7 @@ public class PgpConversionHelper {
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<PGPSecretKey> itr = keyRing.getSecretKeys();
|
||||
while (itr.hasNext()) {
|
||||
keys.add(itr.next());
|
||||
keys.add(new UncachedSecretKey(itr.next()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,7 +98,7 @@ public class PgpConversionHelper {
|
||||
* @param keyBytes
|
||||
* @return
|
||||
*/
|
||||
public static PGPSecretKey BytesToPGPSecretKey(byte[] keyBytes) {
|
||||
public static UncachedSecretKey BytesToPGPSecretKey(byte[] keyBytes) {
|
||||
PGPObjectFactory factory = new PGPObjectFactory(keyBytes);
|
||||
Object obj = null;
|
||||
try {
|
||||
@ -121,7 +119,7 @@ public class PgpConversionHelper {
|
||||
secKey = keyRing.getSecretKey();
|
||||
}
|
||||
|
||||
return secKey;
|
||||
return new UncachedSecretKey(secKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,23 +144,4 @@ public class PgpConversionHelper {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ public class PgpKeyOperation {
|
||||
boolean canSign;
|
||||
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
|
||||
PGPPublicKey masterPublicKey = masterKey.getPublicKey();
|
||||
@ -275,7 +275,7 @@ public class PgpKeyOperation {
|
||||
for (int i = 1; i < saveParcel.keys.size(); ++i) {
|
||||
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();
|
||||
|
||||
PBESecretKeyDecryptor keyDecryptor2 = new JcePBESecretKeyDecryptorBuilder()
|
||||
@ -377,8 +377,8 @@ public class PgpKeyOperation {
|
||||
*/
|
||||
|
||||
if (saveParcel.deletedKeys != null) {
|
||||
for (PGPSecretKey dKey : saveParcel.deletedKeys) {
|
||||
mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey);
|
||||
for (UncachedSecretKey dKey : saveParcel.deletedKeys) {
|
||||
mKR = PGPSecretKeyRing.removeSecretKey(mKR, dKey.getSecretKeyExternal());
|
||||
}
|
||||
}
|
||||
|
||||
@ -542,7 +542,7 @@ public class PgpKeyOperation {
|
||||
for (int i = 1; i < saveParcel.keys.size(); ++i) {
|
||||
updateProgress(40 + 50 * i / saveParcel.keys.size(), 100);
|
||||
if (saveParcel.moddedKeys[i]) {
|
||||
PGPSecretKey subKey = saveParcel.keys.get(i);
|
||||
PGPSecretKey subKey = saveParcel.keys.get(i).getSecretKeyExternal();
|
||||
PGPPublicKey subPublicKey = subKey.getPublicKey();
|
||||
|
||||
PBESecretKeyDecryptor keyDecryptor2;
|
||||
|
@ -412,7 +412,7 @@ public class OpenPgpService extends RemoteService {
|
||||
|
||||
try {
|
||||
// try to find key, throws NotFoundException if not in db!
|
||||
mProviderHelper.getPGPPublicKeyRing(masterKeyId);
|
||||
mProviderHelper.getCachedPublicKeyRing(masterKeyId);
|
||||
|
||||
Intent result = new Intent();
|
||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
|
||||
|
@ -504,7 +504,7 @@ public class KeychainIntentService extends IntentService
|
||||
newPassphrase = oldPassphrase;
|
||||
}
|
||||
|
||||
long masterKeyId = saveParcel.keys.get(0).getKeyID();
|
||||
long masterKeyId = saveParcel.keys.get(0).getKeyId();
|
||||
|
||||
/* Operation */
|
||||
ProviderHelper providerHelper = new ProviderHelper(this);
|
||||
|
@ -20,9 +20,14 @@ package org.sufficientlysecure.keychain.service;
|
||||
import android.os.Parcel;
|
||||
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.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;
|
||||
|
||||
@ -34,13 +39,13 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
public boolean[] newIDs;
|
||||
public boolean primaryIDChanged;
|
||||
public boolean[] moddedKeys;
|
||||
public ArrayList<PGPSecretKey> deletedKeys;
|
||||
public ArrayList<UncachedSecretKey> deletedKeys;
|
||||
public ArrayList<Calendar> keysExpiryDates;
|
||||
public ArrayList<Integer> keysUsages;
|
||||
public String newPassphrase;
|
||||
public String oldPassphrase;
|
||||
public boolean[] newKeys;
|
||||
public ArrayList<PGPSecretKey> keys;
|
||||
public ArrayList<UncachedSecretKey> keys;
|
||||
public String originalPrimaryID;
|
||||
|
||||
public SaveKeyringParcel() {}
|
||||
@ -75,17 +80,13 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
destination.writeBooleanArray(newIDs);
|
||||
destination.writeByte((byte) (primaryIDChanged ? 1 : 0));
|
||||
destination.writeBooleanArray(moddedKeys);
|
||||
byte[] tmp = null;
|
||||
if (deletedKeys.size() != 0) {
|
||||
tmp = PgpConversionHelper.PGPSecretKeyArrayListToBytes(deletedKeys);
|
||||
}
|
||||
destination.writeByteArray(tmp);
|
||||
destination.writeByteArray(encodeArrayList(deletedKeys));
|
||||
destination.writeSerializable(keysExpiryDates);
|
||||
destination.writeList(keysUsages);
|
||||
destination.writeString(newPassphrase);
|
||||
destination.writeString(oldPassphrase);
|
||||
destination.writeBooleanArray(newKeys);
|
||||
destination.writeByteArray(PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys));
|
||||
destination.writeByteArray(encodeArrayList(keys));
|
||||
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
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
@ -43,7 +43,6 @@ import android.widget.TextView;
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
import com.devspark.appmsg.AppMsg;
|
||||
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
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.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||
|
@ -44,16 +44,17 @@ import android.widget.Toast;
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
import com.devspark.appmsg.AppMsg;
|
||||
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.helper.ActionBarHelper;
|
||||
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.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
|
||||
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.service.KeychainIntentService;
|
||||
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.SectionView;
|
||||
import org.sufficientlysecure.keychain.ui.widget.UserIdEditor;
|
||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -88,8 +88,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
// EDIT
|
||||
private Uri mDataUri;
|
||||
|
||||
private PGPSecretKeyRing mKeyRing = null;
|
||||
|
||||
private SectionView mUserIdsView;
|
||||
private SectionView mKeysView;
|
||||
|
||||
@ -105,7 +103,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
private CheckBox mNoPassphrase;
|
||||
|
||||
Vector<String> mUserIds;
|
||||
Vector<PGPSecretKey> mKeys;
|
||||
Vector<UncachedSecretKey> mKeys;
|
||||
Vector<Integer> mKeysUsages;
|
||||
boolean mMasterCanSign = true;
|
||||
|
||||
@ -158,7 +156,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
);
|
||||
|
||||
mUserIds = new Vector<String>();
|
||||
mKeys = new Vector<PGPSecretKey>();
|
||||
mKeys = new Vector<UncachedSecretKey>();
|
||||
mKeysUsages = new Vector<Integer>();
|
||||
|
||||
// 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
|
||||
Bundle data = message.getData();
|
||||
|
||||
ArrayList<PGPSecretKey> newKeys =
|
||||
ArrayList<UncachedSecretKey> newKeys =
|
||||
PgpConversionHelper.BytesToPGPSecretKeyList(data
|
||||
.getByteArray(KeychainIntentService.RESULT_NEW_KEY));
|
||||
|
||||
@ -287,18 +285,18 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
Log.d(Constants.TAG, "uri: " + mDataUri);
|
||||
|
||||
try {
|
||||
Uri secretUri = KeychainContract.KeyRingData.buildSecretKeyRingUri(mDataUri);
|
||||
mKeyRing = (PGPSecretKeyRing) new ProviderHelper(this).getPGPKeyRing(secretUri);
|
||||
Uri secretUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
|
||||
CachedSecretKeyRing keyRing = new ProviderHelper(this).getCachedSecretKeyRing(secretUri);
|
||||
|
||||
PGPSecretKey masterKey = mKeyRing.getSecretKey();
|
||||
mMasterCanSign = PgpKeyHelper.isCertificationKey(mKeyRing.getSecretKey());
|
||||
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) {
|
||||
mKeys.add(key);
|
||||
mKeysUsages.add(-1); // get usage when view is created
|
||||
mMasterCanSign = keyRing.getSubKey().canCertify();
|
||||
for (CachedSecretKey key : keyRing.iterator()) {
|
||||
// Turn into uncached instance
|
||||
mKeys.add(key.getUncached());
|
||||
mKeysUsages.add(key.getKeyUsage()); // get usage when view is created
|
||||
}
|
||||
|
||||
boolean isSet = false;
|
||||
for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) {
|
||||
for (String userId : keyRing.getSubKey().getUserIds()) {
|
||||
Log.d(Constants.TAG, "Added userId " + userId);
|
||||
if (!isSet) {
|
||||
isSet = true;
|
||||
@ -313,7 +311,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
buildLayout(false);
|
||||
|
||||
mCurrentPassphrase = "";
|
||||
mIsPassphraseSet = PassphraseCacheService.hasPassphrase(mKeyRing);
|
||||
mIsPassphraseSet = keyRing.hasPassphrase();
|
||||
if (!mIsPassphraseSet) {
|
||||
// check "no passphrase" checkbox and remove button
|
||||
mNoPassphrase.setChecked(true);
|
||||
@ -431,7 +429,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
if (mKeysView.getEditors().getChildCount() == 0) {
|
||||
return 0;
|
||||
}
|
||||
return ((KeyEditor) mKeysView.getEditors().getChildAt(0)).getValue().getKeyID();
|
||||
return ((KeyEditor) mKeysView.getEditors().getChildAt(0)).getValue().getKeyId();
|
||||
}
|
||||
|
||||
public boolean isPassphraseSet() {
|
||||
@ -571,7 +569,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
saveParams.keys = getKeys(mKeysView);
|
||||
saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID();
|
||||
|
||||
|
||||
// fill values for this action
|
||||
Bundle data = new Bundle();
|
||||
data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, mMasterCanSign);
|
||||
@ -590,7 +587,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
Intent data = new Intent();
|
||||
|
||||
// return uri pointing to new created key
|
||||
Uri uri = KeychainContract.KeyRings.buildGenericKeyRingUri(
|
||||
Uri uri = KeyRings.buildGenericKeyRingUri(
|
||||
String.valueOf(getMasterKeyId()));
|
||||
data.setData(uri);
|
||||
|
||||
@ -689,8 +686,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
* @param keysView
|
||||
* @return
|
||||
*/
|
||||
private ArrayList<PGPSecretKey> getKeys(SectionView keysView) throws PgpGeneralException {
|
||||
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>();
|
||||
private ArrayList<UncachedSecretKey> getKeys(SectionView keysView) throws PgpGeneralException {
|
||||
ArrayList<UncachedSecretKey> keys = new ArrayList<UncachedSecretKey>();
|
||||
|
||||
ViewGroup keyEditors = keysView.getEditors();
|
||||
|
||||
|
@ -39,21 +39,18 @@ import android.widget.TextView;
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
|
||||
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.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.util.Choice;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
import java.util.Vector;
|
||||
|
||||
public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
private PGPSecretKey mKey;
|
||||
private UncachedSecretKey mKey;
|
||||
|
||||
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;
|
||||
|
||||
mIsMasterKey = isMasterKey;
|
||||
@ -216,13 +213,12 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
mDeleteButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(getContext(), key));
|
||||
String keyIdStr = PgpKeyHelper.convertKeyIdToHex(key.getKeyID());
|
||||
mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(getContext(), key.getAlgorithm()));
|
||||
String keyIdStr = PgpKeyHelper.convertKeyIdToHex(key.getKeyId());
|
||||
mKeyId.setText(keyIdStr);
|
||||
|
||||
Vector<Choice> choices = new Vector<Choice>();
|
||||
boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT);
|
||||
boolean isDSAKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.DSA);
|
||||
boolean isElGamalKey = (key.isElGamalEncrypt());
|
||||
boolean isDSAKey = (key.isDSA());
|
||||
if (isElGamalKey) {
|
||||
mChkSign.setVisibility(View.INVISIBLE);
|
||||
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));
|
||||
mChkAuthenticate.setChecked((usage & KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION);
|
||||
} else {
|
||||
mUsage = PgpKeyHelper.getKeyUsage(key);
|
||||
mUsage = key.getKeyUsage();
|
||||
mOriginalUsage = mUsage;
|
||||
if (key.isMasterKey()) {
|
||||
mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key));
|
||||
mChkCertify.setChecked(key.canCertify());
|
||||
}
|
||||
mChkSign.setChecked(PgpKeyHelper.isSigningKey(key));
|
||||
mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key));
|
||||
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key));
|
||||
mChkSign.setChecked(key.canSign());
|
||||
mChkEncrypt.setChecked(key.canEncrypt());
|
||||
mChkAuthenticate.setChecked(key.canAuthenticate());
|
||||
}
|
||||
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
cal.setTime(PgpKeyHelper.getCreationDate(key));
|
||||
setCreatedDate(cal);
|
||||
cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
Date expiryDate = PgpKeyHelper.getExpiryDate(key);
|
||||
{
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
cal.setTime(key.getCreationTime());
|
||||
setCreatedDate(cal);
|
||||
}
|
||||
|
||||
Date expiryDate = key.getExpiryTime();
|
||||
if (expiryDate == null) {
|
||||
setExpiryDate(null);
|
||||
} else {
|
||||
cal.setTime(PgpKeyHelper.getExpiryDate(key));
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
cal.setTime(expiryDate);
|
||||
setExpiryDate(cal);
|
||||
mOriginalExpiryDate = cal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public PGPSecretKey getValue() {
|
||||
public UncachedSecretKey getValue() {
|
||||
return mKey;
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,9 @@ import android.widget.TextView;
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
|
||||
import org.spongycastle.openpgp.PGPKeyFlags;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||
@ -63,7 +63,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
private int mNewKeySize;
|
||||
private boolean mOldItemDeleted = false;
|
||||
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 ActionBarActivity mActivity;
|
||||
@ -227,7 +227,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
return mDeletedIDs;
|
||||
}
|
||||
|
||||
public ArrayList<PGPSecretKey> getDeletedKeys() {
|
||||
public ArrayList<UncachedSecretKey> getDeletedKeys() {
|
||||
return mDeletedKeys;
|
||||
}
|
||||
|
||||
@ -325,7 +325,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -358,9 +358,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
|
||||
String passphrase;
|
||||
if (mEditors.getChildCount() > 0) {
|
||||
PGPSecretKey masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
|
||||
UncachedSecretKey masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
|
||||
passphrase = PassphraseCacheService
|
||||
.getCachedPassphrase(mActivity, masterKey.getKeyID());
|
||||
.getCachedPassphrase(mActivity, masterKey.getKeyId());
|
||||
isMasterKey = false;
|
||||
} else {
|
||||
passphrase = "";
|
||||
@ -395,7 +395,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||
// get new key from data bundle returned from service
|
||||
Bundle data = message.getData();
|
||||
PGPSecretKey newKey = (PGPSecretKey) PgpConversionHelper
|
||||
UncachedSecretKey newKey = PgpConversionHelper
|
||||
.BytesToPGPSecretKey(data
|
||||
.getByteArray(KeychainIntentService.RESULT_NEW_KEY));
|
||||
addGeneratedKeyToView(newKey);
|
||||
@ -413,7 +413,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
mActivity.startService(intent);
|
||||
}
|
||||
|
||||
private void addGeneratedKeyToView(PGPSecretKey newKey) {
|
||||
private void addGeneratedKeyToView(UncachedSecretKey newKey) {
|
||||
// add view with new key
|
||||
KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item,
|
||||
mEditors, false);
|
||||
|
Loading…
Reference in New Issue
Block a user