diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 8b4f7dac9..9bfea2414 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -709,7 +709,7 @@ public class PgpKeyOperation { // error log entry has already been added by updateMasterCertificates itself return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null); } - masterSecretKey = PGPSecretKey.replacePublicKey(masterSecretKey, pKey); + masterSecretKey = PGPSecretKey.replacePublicKey(sKey, pKey); masterPublicKey = pKey; sKR = PGPSecretKeyRing.insertSecretKey(sKR, masterSecretKey); continue; @@ -750,7 +750,7 @@ public class PgpKeyOperation { subProgressPop(); // 4b. For each subkey revocation, generate new subkey revocation certificate - subProgressPush(60, 70); + subProgressPush(60, 65); for (int i = 0; i < saveParcel.mRevokeSubKeys.size(); i++) { progress(R.string.progress_modify_subkeyrevoke, (i-1) * (100 / saveParcel.mRevokeSubKeys.size())); @@ -774,6 +774,30 @@ public class PgpKeyOperation { } subProgressPop(); + // 4c. For each subkey to be stripped... do so + subProgressPush(65, 70); + for (int i = 0; i < saveParcel.mStripSubKeys.size(); i++) { + + progress(R.string.progress_modify_subkeystrip, (i-1) * (100 / saveParcel.mStripSubKeys.size())); + long strip = saveParcel.mStripSubKeys.get(i); + log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_STRIP, + indent, PgpKeyHelper.convertKeyIdToHex(strip)); + + PGPSecretKey sKey = sKR.getSecretKey(strip); + if (sKey == null) { + log.add(LogLevel.ERROR, LogType.MSG_MF_ERROR_SUBKEY_MISSING, + indent+1, PgpKeyHelper.convertKeyIdToHex(strip)); + return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null); + } + + // IT'S DANGEROUS~ + // no really, it is. this operation irrevocably removes the private key data from the key + sKey = PGPSecretKey.constructGnuDummyKey(sKey.getPublicKey()); + sKR = PGPSecretKeyRing.insertSecretKey(sKR, sKey); + + } + subProgressPop(); + // 5. Generate and add new subkeys subProgressPush(70, 90); for (int i = 0; i < saveParcel.mAddSubKeys.size(); i++) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java index fefc3e4b1..02caca145 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java @@ -394,6 +394,7 @@ public class OperationResultParcel implements Parcelable { MSG_MF_SUBKEY_NEW_ID (R.string.msg_mf_subkey_new_id), MSG_MF_SUBKEY_NEW (R.string.msg_mf_subkey_new), MSG_MF_SUBKEY_REVOKE (R.string.msg_mf_subkey_revoke), + MSG_MF_SUBKEY_STRIP (R.string.msg_mf_subkey_strip), MSG_MF_SUCCESS (R.string.msg_mf_success), MSG_MF_UID_ADD (R.string.msg_mf_uid_add), MSG_MF_UID_PRIMARY (R.string.msg_mf_uid_primary), 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 996ce6a5a..4e06fc9f3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -56,6 +56,7 @@ public class SaveKeyringParcel implements Parcelable { public ArrayList mRevokeUserIds; public ArrayList mRevokeSubKeys; + public ArrayList mStripSubKeys; public SaveKeyringParcel() { reset(); @@ -75,6 +76,7 @@ public class SaveKeyringParcel implements Parcelable { mChangeSubKeys = new ArrayList(); mRevokeUserIds = new ArrayList(); mRevokeSubKeys = new ArrayList(); + mStripSubKeys = new ArrayList(); } // performance gain for using Parcelable here would probably be negligible, @@ -167,6 +169,7 @@ public class SaveKeyringParcel implements Parcelable { mRevokeUserIds = source.createStringArrayList(); mRevokeSubKeys = (ArrayList) source.readSerializable(); + mStripSubKeys = (ArrayList) source.readSerializable(); } @Override @@ -187,6 +190,7 @@ public class SaveKeyringParcel implements Parcelable { destination.writeStringList(mRevokeUserIds); destination.writeSerializable(mRevokeSubKeys); + destination.writeSerializable(mStripSubKeys); } public static final Creator CREATOR = new Creator() { @@ -214,6 +218,7 @@ public class SaveKeyringParcel implements Parcelable { out += "mChangePrimaryUserId: " + mChangePrimaryUserId + "\n"; out += "mRevokeUserIds: " + mRevokeUserIds + "\n"; out += "mRevokeSubKeys: " + mRevokeSubKeys; + out += "mStripSubKeys: " + mStripSubKeys; return out; }