mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
preserve keys that we don\'t use in the app
This commit is contained in:
parent
64aa2b7701
commit
fe3db8f0e6
@ -209,9 +209,8 @@ public class PgpKeyHelper {
|
||||
Calendar calendar = GregorianCalendar.getInstance();
|
||||
calendar.setTime(creationDate);
|
||||
calendar.add(Calendar.DATE, key.getValidDays());
|
||||
Date expiryDate = calendar.getTime();
|
||||
|
||||
return expiryDate;
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getExpiryDate(PGPSecretKey key) {
|
||||
@ -291,6 +290,28 @@ public class PgpKeyHelper {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public static int getKeyUsage(PGPSecretKey key)
|
||||
{
|
||||
return getKeyUsage(key.getPublicKey());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static int getKeyUsage(PGPPublicKey key) {
|
||||
int usage = 0;
|
||||
if (key.getVersion() >= 4) {
|
||||
for (PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) {
|
||||
if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) continue;
|
||||
|
||||
PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
|
||||
if (hashed != null) usage |= hashed.getKeyFlags();
|
||||
|
||||
PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets();
|
||||
if (unhashed != null) usage |= unhashed.getKeyFlags();
|
||||
}
|
||||
}
|
||||
return usage;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean isEncryptionKey(PGPPublicKey key) {
|
||||
if (!key.isEncryptionKey()) {
|
||||
@ -440,7 +461,7 @@ public class PgpKeyHelper {
|
||||
}
|
||||
|
||||
public static String getAlgorithmInfo(int algorithm, int keySize) {
|
||||
String algorithmStr = null;
|
||||
String algorithmStr;
|
||||
|
||||
switch (algorithm) {
|
||||
case PGPPublicKey.RSA_ENCRYPT:
|
||||
|
@ -66,6 +66,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
CheckBox mChkSign;
|
||||
CheckBox mChkEncrypt;
|
||||
CheckBox mChkAuthenticate;
|
||||
int mUsage;
|
||||
|
||||
private int mDatePickerResultCount = 0;
|
||||
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||
@ -189,6 +190,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
mChkSign.setChecked(PgpKeyHelper.isSigningKey(key));
|
||||
mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key));
|
||||
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key));
|
||||
mUsage = PgpKeyHelper.getKeyUsage(key);
|
||||
// TODO: use usage argument?
|
||||
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
@ -237,17 +239,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
}
|
||||
|
||||
public int getUsage() {
|
||||
int result = 0; // TODO: preserve other flags
|
||||
if (mChkCertify.isChecked())
|
||||
result |= KeyFlags.CERTIFY_OTHER;
|
||||
if (mChkSign.isChecked()) //TODO: fix what happens when we remove sign flag from master - should still be able to certify
|
||||
result |= KeyFlags.SIGN_DATA;
|
||||
if (mChkEncrypt.isChecked())
|
||||
result |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
|
||||
if (mChkAuthenticate.isChecked())
|
||||
result |= KeyFlags.AUTHENTICATION;
|
||||
mUsage = (mUsage & ~KeyFlags.CERTIFY_OTHER) | (mChkCertify.isChecked() ? KeyFlags.CERTIFY_OTHER : 0);
|
||||
mUsage = (mUsage & ~KeyFlags.SIGN_DATA) | (mChkSign.isChecked() ? KeyFlags.SIGN_DATA : 0);
|
||||
mUsage = (mUsage & ~KeyFlags.ENCRYPT_COMMS) | (mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_COMMS : 0);
|
||||
mUsage = (mUsage & ~KeyFlags.ENCRYPT_STORAGE) | (mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_STORAGE : 0);
|
||||
mUsage = (mUsage & ~KeyFlags.AUTHENTICATION) | (mChkAuthenticate.isChecked() ? KeyFlags.AUTHENTICATION : 0);
|
||||
|
||||
return result;
|
||||
return mUsage;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user