From 34668920106e89ed5872d4446fbcc14887396d71 Mon Sep 17 00:00:00 2001 From: Dominik Date: Wed, 31 Oct 2012 16:26:32 +0100 Subject: [PATCH] removed unused code, fixed certification bug when editing existing key --- .../android/apg/helper/PGPMain.java | 44 +++++++++++-------- .../android/apg/service/ApgService.java | 4 +- .../android/apg/ui/KeyListFragment.java | 6 --- .../android/apg/ui/KeyListPublicActivity.java | 2 +- .../android/apg/ui/KeyListPublicFragment.java | 6 --- .../android/apg/ui/KeyListSecretActivity.java | 23 +--------- .../android/apg/ui/KeyListSecretFragment.java | 17 ------- 7 files changed, 30 insertions(+), 72 deletions(-) diff --git a/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java b/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java index 2c117f288..2af1e2453 100644 --- a/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java +++ b/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java @@ -311,10 +311,10 @@ public class PGPMain { updateProgress(progress, R.string.progress_buildingKey, 0, 100); - if (oldPassPhrase == null || oldPassPhrase.equals("")) { + if (oldPassPhrase == null) { oldPassPhrase = ""; } - if (newPassPhrase == null || newPassPhrase.equals("")) { + if (newPassPhrase == null) { newPassPhrase = ""; } @@ -329,9 +329,13 @@ public class PGPMain { PGPSecretKey masterKey = keys.get(0); PGPPublicKey masterPublicKey = masterKey.getPublicKey(); - // Somehow, the PGPPublicKey already has an empty certification attached to it, we remove - // that now before adding the new ones - masterPublicKey = PGPPublicKey.removeCertification(masterPublicKey, ""); + // Somehow, the PGPPublicKey already has an empty certification attached to it when the + // keyRing is generated the first time, we remove that when it exists, before adding the new + // ones + PGPPublicKey masterPublicKeyRmCert = PGPPublicKey.removeCertification(masterPublicKey, ""); + if (masterPublicKeyRmCert != null) { + masterPublicKey = masterPublicKeyRmCert; + } PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray()); @@ -611,13 +615,13 @@ public class PGPMain { updateProgress(progress, i * 100 / keyRingIds.size(), 100); // try to get it as a PGPPublicKeyRing, if that fails try to get it as a SecretKeyRing - PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context, - keyRingIds.get(i)); + PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId( + context, keyRingIds.get(i)); if (publicKeyRing != null) { publicKeyRing.encode(out); } else { - PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context, - keyRingIds.get(i)); + PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId( + context, keyRingIds.get(i)); if (secretKeyRing != null) { secretKeyRing.encode(out); } else { @@ -729,7 +733,8 @@ public class PGPMain { } if (signatureKeyId != Id.key.none) { - signingKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context, signatureKeyId); + signingKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context, + signatureKeyId); signingKey = PGPHelper.getSigningKey(context, signatureKeyId); if (signingKey == null) { throw new ApgGeneralException(context.getString(R.string.error_signatureFailed)); @@ -1098,7 +1103,8 @@ public class PGPMain { if (passphrase == null || passphrase.length() <= 0) { throw new ApgGeneralException("Unable to obtain passphrase"); } else { - PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context, pubKeyId); + PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context, + pubKeyId); PGPSecretKey signingKey = PGPHelper.getSigningKey(context, masterKeyId); if (signingKey == null) { @@ -1356,10 +1362,10 @@ public class PGPMain { signatureIndex = i; signatureKeyId = signature.getKeyID(); String userId = null; - PGPPublicKeyRing sigKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context, - signatureKeyId); - if (sigKeyRing != null) { - userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing)); + PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId( + context, signatureKeyId); + if (signKeyRing != null) { + userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(signKeyRing)); } returnData.putString(ApgService.RESULT_SIGNATURE_USER_ID, userId); break; @@ -1522,10 +1528,10 @@ public class PGPMain { } else { signatureKeyId = signature.getKeyID(); String userId = null; - PGPPublicKeyRing sigKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context, - signatureKeyId); - if (sigKeyRing != null) { - userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing)); + PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId( + context, signatureKeyId); + if (signKeyRing != null) { + userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(signKeyRing)); } returnData.putString(ApgService.RESULT_SIGNATURE_USER_ID, userId); break; diff --git a/org_apg/src/org/thialfihar/android/apg/service/ApgService.java b/org_apg/src/org/thialfihar/android/apg/service/ApgService.java index 4a38e8af7..a6a9f3a4c 100644 --- a/org_apg/src/org/thialfihar/android/apg/service/ApgService.java +++ b/org_apg/src/org/thialfihar/android/apg/service/ApgService.java @@ -28,7 +28,6 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Vector; -import org.spongycastle.openpgp.PGPKeyRing; import org.spongycastle.openpgp.PGPPublicKeyRing; import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKeyRing; @@ -743,7 +742,8 @@ public class ApgService extends IntentService implements ProgressDialogUpdater { /* Operation */ HkpKeyServer server = new HkpKeyServer(keyServer); - PGPPublicKeyRing keyring = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(this, keyRingId); + PGPPublicKeyRing keyring = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(this, + keyRingId); if (keyring != null) { boolean uploaded = PGPMain.uploadKeyRingToServer(server, (PGPPublicKeyRing) keyring); diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListFragment.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListFragment.java index 82fa89fa2..613f32ae9 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListFragment.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListFragment.java @@ -51,12 +51,6 @@ public class KeyListFragment extends ExpandableListFragment { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - // TODO: better inflate menu from xml - // android.view.MenuInflater inflater = (android.view.MenuInflater) mActivity - // .getMenuInflater(); - // menu.setHeaderTitle(R.string.checkbox_list_context_title); - // inflater.inflate(R.menu.checkbox_list_context, menu); - menu.add(0, Id.menu.export, 0, R.string.menu_exportKey); menu.add(0, Id.menu.delete, 1, R.string.menu_deleteKey); } diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java index 759fb577b..73bb3790a 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java @@ -58,7 +58,7 @@ public class KeyListPublicActivity extends KeyListActivity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case Id.menu.option.key_server: { - startActivity(new Intent(this, KeyServerQueryActivity.class)); + startActivityForResult(new Intent(this, KeyServerQueryActivity.class), 0); return true; } diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java index 174f683f1..58dedf64d 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java @@ -73,12 +73,6 @@ public class KeyListPublicFragment extends KeyListFragment implements @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - // TODO: better inflate menu from xml - // android.view.MenuInflater inflater = (android.view.MenuInflater) mActivity - // .getMenuInflater(); - // menu.setHeaderTitle(R.string.checkbox_list_context_title); - // inflater.inflate(R.menu.checkbox_list_context, menu); - menu.add(0, Id.menu.update, 1, R.string.menu_updateKey); menu.add(0, Id.menu.exportToServer, 1, R.string.menu_exportKeyToServer); menu.add(0, Id.menu.signKey, 1, R.string.menu_signKey); diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java index 6b75c8e0a..97abd2296 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretActivity.java @@ -112,32 +112,13 @@ public class KeyListSecretActivity extends KeyListActivity { private void createKey() { PGPMain.setEditPassPhrase(""); Intent intent = new Intent(EditKeyActivity.ACTION_CREATE_KEY); - startActivityForResult(intent, Id.message.create_key); + startActivityForResult(intent, 0); } private void editKey(long keyId) { Intent intent = new Intent(EditKeyActivity.ACTION_EDIT_KEY); intent.putExtra(EditKeyActivity.EXTRA_KEY_ID, keyId); - startActivityForResult(intent, Id.message.edit_key); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { - case Id.message.create_key: // intentionally no break - case Id.message.edit_key: { - if (resultCode == RESULT_OK) { - // refreshList(); - } - break; - } - - default: { - break; - } - } - - super.onActivityResult(requestCode, resultCode, data); + startActivityForResult(intent, 0); } } diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretFragment.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretFragment.java index 546928223..12a0bb131 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretFragment.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListSecretFragment.java @@ -73,23 +73,6 @@ public class KeyListSecretFragment extends KeyListFragment implements @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - // TODO: better inflate menu from xml - // android.view.MenuInflater inflater = (android.view.MenuInflater) mActivity - // .getMenuInflater(); - // menu.setHeaderTitle(R.string.checkbox_list_context_title); - // inflater.inflate(R.menu.checkbox_list_context, menu); - - // ExpandableListView.ExpandableListContextMenuInfo info = - // (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; - // int type = ExpandableListView.getPackedPositionType(info.packedPosition); - // - // if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { - // // TODO: user id? menu.setHeaderTitle("Key"); - // menu.add(0, Id.menu.edit, 0, R.string.menu_editKey); - // menu.add(0, Id.menu.export, 1, R.string.menu_exportKey); - // menu.add(0, Id.menu.delete, 2, R.string.menu_deleteKey); - // menu.add(0, Id.menu.share_qr_code, 2, R.string.menu_share); - // } menu.add(0, Id.menu.edit, 0, R.string.menu_editKey); menu.add(0, Id.menu.share_qr_code, 2, R.string.menu_share);