mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-16 22:05:05 -05:00
save work, this code doesn't work...
This commit is contained in:
parent
e150004e32
commit
076a7ec4a1
@ -23,7 +23,6 @@ import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.SignatureException;
|
||||
import java.util.ArrayList;
|
||||
@ -35,7 +34,6 @@ import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||
import org.spongycastle.bcpg.HashAlgorithmTags;
|
||||
import org.spongycastle.bcpg.SymmetricKeyAlgorithmTags;
|
||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.spongycastle.jce.spec.ElGamalParameterSpec;
|
||||
import org.spongycastle.openpgp.PGPEncryptedData;
|
||||
import org.spongycastle.openpgp.PGPException;
|
||||
@ -57,7 +55,6 @@ import org.spongycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||
import org.spongycastle.openpgp.operator.PGPDigestCalculator;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyConverter;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
|
||||
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
|
||||
@ -201,9 +198,7 @@ public class PgpKeyOperation {
|
||||
|
||||
}
|
||||
|
||||
public void buildSecretKey(ArrayList<String> userIds, ArrayList<PGPSecretKey> keys,
|
||||
ArrayList<Integer> keysUsages, ArrayList<GregorianCalendar> keysExpiryDates,
|
||||
String oldPassPhrase, String newPassPhrase) throws PgpGeneralException,
|
||||
public void buildSecretKey(ArrayList<String> userIds, ArrayList<String> OriginalIDs, ArrayList<String> deletedIDs, ArrayList<PGPSecretKey> keys, boolean[] modded_keys, String newPassPhrase, ArrayList<GregorianCalendar> keysExpiryDates, String oldPassPhrase, ArrayList<Integer> keysUsages) throws PgpGeneralException,
|
||||
PGPException, SignatureException, IOException {
|
||||
|
||||
Log.d(Constants.TAG, "userIds: " + userIds.toString());
|
||||
@ -226,10 +221,7 @@ public class PgpKeyOperation {
|
||||
PGPSecretKey masterKey = keys.get(0);
|
||||
|
||||
// this removes all userIds and certifications previously attached to the masterPublicKey
|
||||
PGPPublicKey tmpKey = masterKey.getPublicKey();
|
||||
PublicKey tmpPuK = new JcaPGPKeyConverter().setProvider(new BouncyCastleProvider()).getPublicKey(tmpKey);
|
||||
PGPPublicKey masterPublicKey = new JcaPGPKeyConverter().getPGPPublicKey(tmpKey.getAlgorithm(),
|
||||
tmpPuK, tmpKey.getCreationTime());
|
||||
PGPPublicKey masterPublicKey = masterKey.getPublicKey();
|
||||
|
||||
// already done by code above:
|
||||
// PGPPublicKey masterPublicKey = masterKey.getPublicKey();
|
||||
@ -243,6 +235,8 @@ public class PgpKeyOperation {
|
||||
// masterPublicKey = masterPublicKeyRmCert;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
|
||||
Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray());
|
||||
PGPPrivateKey masterPrivateKey = masterKey.extractPrivateKey(keyDecryptor);
|
||||
@ -250,18 +244,22 @@ public class PgpKeyOperation {
|
||||
updateProgress(R.string.progress_certifying_master_key, 20, 100);
|
||||
|
||||
// TODO: if we are editing a key, keep old certs, don't remake certs we don't have to.
|
||||
|
||||
int user_id_index = 0;
|
||||
for (String userId : userIds) {
|
||||
PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder(
|
||||
masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1)
|
||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
||||
PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder);
|
||||
if (OriginalIDs[user_id_index]) {
|
||||
PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder(
|
||||
masterPublicKey.getAlgorithm(), HashAlgorithmTags.SHA1)
|
||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
||||
PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder);
|
||||
|
||||
sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey);
|
||||
sGen.init(PGPSignature.POSITIVE_CERTIFICATION, masterPrivateKey);
|
||||
|
||||
PGPSignature certification = sGen.generateCertification(userId, masterPublicKey);
|
||||
PGPSignature certification = sGen.generateCertification(userId, masterPublicKey);
|
||||
|
||||
masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification);
|
||||
masterPublicKey = PGPPublicKey.removeCertification();
|
||||
masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, userId, certification);
|
||||
}
|
||||
user_id_index++;
|
||||
}
|
||||
|
||||
PGPKeyPair masterKeyPair = new PGPKeyPair(masterPublicKey, masterPrivateKey);
|
||||
|
@ -54,7 +54,6 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
||||
import org.sufficientlysecure.keychain.util.HkpKeyServer;
|
||||
import org.sufficientlysecure.keychain.util.InputData;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.PositionAwareInputStream;
|
||||
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
|
||||
|
||||
import android.app.IntentService;
|
||||
@ -135,6 +134,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
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_ORIGINAL_IDS = "original_ids";
|
||||
public static final String SAVE_KEYRING_DELETED_IDS = "deleted_ids";
|
||||
public static final String SAVE_KEYRING_MODDED_KEYS = "modified_keys";
|
||||
|
||||
// generate key
|
||||
public static final String GENERATE_KEY_ALGORITHM = "algorithm";
|
||||
@ -532,6 +534,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
.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);
|
||||
|
||||
long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID);
|
||||
|
||||
@ -542,8 +547,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId),
|
||||
oldPassPhrase, newPassPhrase);
|
||||
} else {
|
||||
keyOperations.buildSecretKey(userIds, keys, keysUsages, keysExpiryDates,
|
||||
oldPassPhrase, newPassPhrase);
|
||||
keyOperations.buildSecretKey(userIds, original_ids, deleted_ids, keys, modded_keys,
|
||||
newPassPhrase, keysExpiryDates, oldPassPhrase, keysUsages);
|
||||
}
|
||||
PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase);
|
||||
|
||||
|
@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||
@ -553,6 +554,15 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
}
|
||||
}
|
||||
|
||||
private boolean[] toPrimitiveArray(final List<Boolean> booleanList) {
|
||||
final boolean[] primitives = new boolean[booleanList.size()];
|
||||
int index = 0;
|
||||
for (Boolean object : booleanList) {
|
||||
primitives[index++] = object;
|
||||
}
|
||||
return primitives;
|
||||
}
|
||||
|
||||
private void finallySaveClicked() {
|
||||
try {
|
||||
// Send all information needed to service to edit key in other thread
|
||||
@ -576,6 +586,11 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
getKeysExpiryDates(mKeysView));
|
||||
data.putLong(KeychainIntentService.SAVE_KEYRING_MASTER_KEY_ID, getMasterKeyId());
|
||||
data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign);
|
||||
data.putStringArrayList(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS, );
|
||||
data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_ORIGINAL_IDS,
|
||||
toPrimitiveArray(mUserIdsView.getNeedsSavingArray()));
|
||||
data.putBooleanArray(KeychainIntentService.SAVE_KEYRING_MODDED_KEYS,
|
||||
toPrimitiveArray(mKeysView.getNeedsSavingArray()));
|
||||
|
||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui.widget;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.spongycastle.openpgp.PGPKeyFlags;
|
||||
@ -162,6 +164,23 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Boolean> getNeedsSavingArray()
|
||||
{
|
||||
ArrayList<Boolean> mList = new ArrayList<Boolean>();
|
||||
for (int i = 0; i < mEditors.getChildCount(); ++i) {
|
||||
Editor editor = (Editor) mEditors.getChildAt(i);
|
||||
if (mType == Id.type.user_id) {
|
||||
try {
|
||||
if (((UserIdEditor)editor).getValue().equals("")) //other code ignores empty user id
|
||||
continue;
|
||||
} catch (UserIdEditor.InvalidEmailException e) {
|
||||
}
|
||||
}
|
||||
mList.add(editor.needsSaving());
|
||||
}
|
||||
return mList;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void onClick(View v) {
|
||||
if (canEdit) {
|
||||
|
Loading…
Reference in New Issue
Block a user