editKey: add support for sripping keys

This commit is contained in:
Vincent Breitmoser 2014-09-11 22:49:21 +02:00
parent 8e665d829e
commit f744488017
3 changed files with 32 additions and 2 deletions

View File

@ -709,7 +709,7 @@ public class PgpKeyOperation {
// error log entry has already been added by updateMasterCertificates itself // error log entry has already been added by updateMasterCertificates itself
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null); return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
} }
masterSecretKey = PGPSecretKey.replacePublicKey(masterSecretKey, pKey); masterSecretKey = PGPSecretKey.replacePublicKey(sKey, pKey);
masterPublicKey = pKey; masterPublicKey = pKey;
sKR = PGPSecretKeyRing.insertSecretKey(sKR, masterSecretKey); sKR = PGPSecretKeyRing.insertSecretKey(sKR, masterSecretKey);
continue; continue;
@ -750,7 +750,7 @@ public class PgpKeyOperation {
subProgressPop(); subProgressPop();
// 4b. For each subkey revocation, generate new subkey revocation certificate // 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++) { for (int i = 0; i < saveParcel.mRevokeSubKeys.size(); i++) {
progress(R.string.progress_modify_subkeyrevoke, (i-1) * (100 / saveParcel.mRevokeSubKeys.size())); progress(R.string.progress_modify_subkeyrevoke, (i-1) * (100 / saveParcel.mRevokeSubKeys.size()));
@ -774,6 +774,30 @@ public class PgpKeyOperation {
} }
subProgressPop(); 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 // 5. Generate and add new subkeys
subProgressPush(70, 90); subProgressPush(70, 90);
for (int i = 0; i < saveParcel.mAddSubKeys.size(); i++) { for (int i = 0; i < saveParcel.mAddSubKeys.size(); i++) {

View File

@ -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_ID (R.string.msg_mf_subkey_new_id),
MSG_MF_SUBKEY_NEW (R.string.msg_mf_subkey_new), MSG_MF_SUBKEY_NEW (R.string.msg_mf_subkey_new),
MSG_MF_SUBKEY_REVOKE (R.string.msg_mf_subkey_revoke), 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_SUCCESS (R.string.msg_mf_success),
MSG_MF_UID_ADD (R.string.msg_mf_uid_add), MSG_MF_UID_ADD (R.string.msg_mf_uid_add),
MSG_MF_UID_PRIMARY (R.string.msg_mf_uid_primary), MSG_MF_UID_PRIMARY (R.string.msg_mf_uid_primary),

View File

@ -56,6 +56,7 @@ public class SaveKeyringParcel implements Parcelable {
public ArrayList<String> mRevokeUserIds; public ArrayList<String> mRevokeUserIds;
public ArrayList<Long> mRevokeSubKeys; public ArrayList<Long> mRevokeSubKeys;
public ArrayList<Long> mStripSubKeys;
public SaveKeyringParcel() { public SaveKeyringParcel() {
reset(); reset();
@ -75,6 +76,7 @@ public class SaveKeyringParcel implements Parcelable {
mChangeSubKeys = new ArrayList<SubkeyChange>(); mChangeSubKeys = new ArrayList<SubkeyChange>();
mRevokeUserIds = new ArrayList<String>(); mRevokeUserIds = new ArrayList<String>();
mRevokeSubKeys = new ArrayList<Long>(); mRevokeSubKeys = new ArrayList<Long>();
mStripSubKeys = new ArrayList<Long>();
} }
// performance gain for using Parcelable here would probably be negligible, // performance gain for using Parcelable here would probably be negligible,
@ -167,6 +169,7 @@ public class SaveKeyringParcel implements Parcelable {
mRevokeUserIds = source.createStringArrayList(); mRevokeUserIds = source.createStringArrayList();
mRevokeSubKeys = (ArrayList<Long>) source.readSerializable(); mRevokeSubKeys = (ArrayList<Long>) source.readSerializable();
mStripSubKeys = (ArrayList<Long>) source.readSerializable();
} }
@Override @Override
@ -187,6 +190,7 @@ public class SaveKeyringParcel implements Parcelable {
destination.writeStringList(mRevokeUserIds); destination.writeStringList(mRevokeUserIds);
destination.writeSerializable(mRevokeSubKeys); destination.writeSerializable(mRevokeSubKeys);
destination.writeSerializable(mStripSubKeys);
} }
public static final Creator<SaveKeyringParcel> CREATOR = new Creator<SaveKeyringParcel>() { public static final Creator<SaveKeyringParcel> CREATOR = new Creator<SaveKeyringParcel>() {
@ -214,6 +218,7 @@ public class SaveKeyringParcel implements Parcelable {
out += "mChangePrimaryUserId: " + mChangePrimaryUserId + "\n"; out += "mChangePrimaryUserId: " + mChangePrimaryUserId + "\n";
out += "mRevokeUserIds: " + mRevokeUserIds + "\n"; out += "mRevokeUserIds: " + mRevokeUserIds + "\n";
out += "mRevokeSubKeys: " + mRevokeSubKeys; out += "mRevokeSubKeys: " + mRevokeSubKeys;
out += "mStripSubKeys: " + mStripSubKeys;
return out; return out;
} }