remove signing icon for master keys which can't sign

This commit is contained in:
Ash Hughes 2013-03-14 17:24:22 +00:00
parent 00afc2e8ac
commit 935274960d
2 changed files with 33 additions and 3 deletions

View File

@ -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) {

View File

@ -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);
}
}
}