diff options
author | Ashley Hughes <spirit.returned@gmail.com> | 2014-03-27 14:48:27 +0000 |
---|---|---|
committer | Ashley Hughes <spirit.returned@gmail.com> | 2014-03-27 14:48:27 +0000 |
commit | 56447ad0b55d2ff41e5acb6b8f8ee85393eee05c (patch) | |
tree | 1ba532e2dc45e68a1ec6538617da5bebb4e8077d | |
parent | 140646fa121958ba3b19decd8a92f470fe13ac43 (diff) | |
download | open-keychain-56447ad0b55d2ff41e5acb6b8f8ee85393eee05c.tar.gz open-keychain-56447ad0b55d2ff41e5acb6b8f8ee85393eee05c.tar.bz2 open-keychain-56447ad0b55d2ff41e5acb6b8f8ee85393eee05c.zip |
fix for editing master keys and IDs, case of change primary ID and modify master key props fails
-rw-r--r-- | OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 9bf9ecc73..603b8dcd1 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -440,12 +440,12 @@ public class PgpKeyOperation { //this happens anyway } - if (saveParcel.primaryIDChanged) { + if (saveParcel.primaryIDChanged || !saveParcel.originalIDs.get(0).equals(saveParcel.userIDs.get(0))) { anyIDChanged = true; ArrayList<Pair<String, PGPSignature>> sigList = new ArrayList<Pair<String, PGPSignature>>(); for (String userId : saveParcel.userIDs) { String orig_id = saveParcel.originalIDs.get(user_id_index); - if (orig_id.equals(userId)) { + if (orig_id.equals(userId) && !userId.equals(saveParcel.originalPrimaryID) && user_id_index != 0) { Iterator<PGPSignature> orig_sigs = masterPublicKey.getSignaturesForID(orig_id); //TODO: make sure this iterator only has signatures we are interested in while (orig_sigs.hasNext()) { PGPSignature orig_sig = orig_sigs.next(); @@ -498,8 +498,23 @@ public class PgpKeyOperation { } } + ArrayList<Pair<String, PGPSignature>> sigList = new ArrayList<Pair<String, PGPSignature>>(); if (saveParcel.moddedKeys[0]) { - masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, saveParcel.originalIDs.get(0)); + user_id_index = 0; + for (String userId : saveParcel.userIDs) { + String orig_id = saveParcel.originalIDs.get(user_id_index); + if (!orig_id.equals(saveParcel.originalPrimaryID) && !saveParcel.primaryIDChanged) { + Iterator<PGPSignature> sigs = masterPublicKey.getSignaturesForID(userId); //TODO: make sure this iterator only has signatures we are interested in + while (sigs.hasNext()) { + PGPSignature sig = sigs.next(); + sigList.add(new Pair<String, PGPSignature>(userId, sig)); + } + } + if (!userId.equals("")) { + masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, userId); + } + user_id_index++; + } anyIDChanged = true; } @@ -606,6 +621,17 @@ public class PgpKeyOperation { pKR = PGPPublicKeyRing.insertPublicKey(pKR, theNextKey.getPublicKey()); } } + + //replace lost IDs + if (saveParcel.moddedKeys[0]) { + masterPublicKey = mKR.getPublicKey(); + for (Pair<String, PGPSignature> to_add : sigList) { + masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, to_add.first, to_add.second); + } + pKR = PGPPublicKeyRing.insertPublicKey(pKR, masterPublicKey); + mKR = PGPSecretKeyRing.replacePublicKeys(mKR, pKR); + } + // Build key encryptor based on new passphrase PBESecretKeyEncryptor keyEncryptorNew = new JcePBESecretKeyEncryptorBuilder( PGPEncryptedData.CAST5, sha1Calc) |