mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
remove signing icon for master keys which can't sign
This commit is contained in:
parent
00afc2e8ac
commit
935274960d
@ -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) {
|
||||
|
@ -159,7 +159,13 @@ public class KeyListAdapter extends CursorTreeAdapter {
|
||||
}
|
||||
|
||||
ImageView signIcon = (ImageView) view.findViewById(R.id.ic_signKey);
|
||||
if (cursor.getInt(cursor.getColumnIndex(Keys.CAN_SIGN)) != 1) {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user