diff options
author | Ash Hughes <ashes-iontach@hotmail.com> | 2013-03-14 17:24:22 +0000 |
---|---|---|
committer | Ash Hughes <ashes-iontach@hotmail.com> | 2013-03-14 17:24:22 +0000 |
commit | 935274960d6a81c64fe829dd3cada4436e044e90 (patch) | |
tree | 06d37b3b8387295a7e24509928d49be90db21f85 /OpenPGP-Keychain/src | |
parent | 00afc2e8acd73ff031417d70208d9a955a7086de (diff) | |
download | open-keychain-935274960d6a81c64fe829dd3cada4436e044e90.tar.gz open-keychain-935274960d6a81c64fe829dd3cada4436e044e90.tar.bz2 open-keychain-935274960d6a81c64fe829dd3cada4436e044e90.zip |
remove signing icon for master keys which can't sign
Diffstat (limited to 'OpenPGP-Keychain/src')
-rw-r--r-- | OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpHelper.java | 24 | ||||
-rw-r--r-- | OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyListAdapter.java | 12 |
2 files changed, 33 insertions, 3 deletions
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpHelper.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpHelper.java index b77fc71d1..697eb1aaa 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpHelper.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpHelper.java @@ -415,6 +415,30 @@ public class PgpHelper { return convertFingerprintToHex(key.getFingerprint()); } + public static boolean isSecretKeyPrivateEmpty(PGPSecretKey secretKey) { + try { + PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder() + .setProvider(PgpMain.BOUNCY_CASTLE_PROVIDER_NAME).build(new char[] {}); + PGPPrivateKey testKey = secretKey.extractPrivateKey( + keyDecryptor); + if (testKey != null) { + return false; + } + } catch (PGPException e) { + // all good if this fails, we likely didn't use the right password + } + return true; + } + + public static boolean isSecretKeyPrivateEmpty(Context context, long keyId) { + PGPSecretKey secretKey = ProviderHelper.getPGPSecretKeyByKeyId(context, keyId); + if (secretKey == null) { + Log.e(Constants.TAG, "Key could not be found!"); + return false; //could be a public key, assume it is not empty + } + return isSecretKeyPrivateEmpty(secretKey); + } + public static String getSmallFingerPrint(long keyId) { String fingerPrint = Long.toHexString(keyId & 0xffffffffL).toUpperCase(Locale.US); while (fingerPrint.length() < 8) { diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyListAdapter.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyListAdapter.java index 8e8d33886..61ca0e9d0 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyListAdapter.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyListAdapter.java @@ -159,8 +159,14 @@ public class KeyListAdapter extends CursorTreeAdapter { } ImageView signIcon = (ImageView) view.findViewById(R.id.ic_signKey); - if (cursor.getInt(cursor.getColumnIndex(Keys.CAN_SIGN)) != 1) { - signIcon.setVisibility(View.GONE); + boolean privateEmpty = false; //Don't show signing icon for master keys without private keys + //TODO: does this need to be done for encrypting icon? Does anyone use master key for encrypt? + if (cursor.getInt(cursor.getColumnIndex(Keys.IS_MASTER_KEY)) == 1) { + privateEmpty = PgpHelper.isSecretKeyPrivateEmpty(context, + cursor.getLong(cursor.getColumnIndex(Keys.KEY_ID))); + } + if (privateEmpty || cursor.getInt(cursor.getColumnIndex(Keys.CAN_SIGN)) != 1) { + signIcon.setVisibility(View.GONE); } else { signIcon.setVisibility(View.VISIBLE); } @@ -261,4 +267,4 @@ public class KeyListAdapter extends CursorTreeAdapter { return mContext.getContentResolver().query(uri, projection, selection, null, sortOrder); } -}
\ No newline at end of file +} |