mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-11 01:42:16 -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 calendar = GregorianCalendar.getInstance();
|
||||||
calendar.setTime(creationDate);
|
calendar.setTime(creationDate);
|
||||||
calendar.add(Calendar.DATE, key.getValidDays());
|
calendar.add(Calendar.DATE, key.getValidDays());
|
||||||
Date expiryDate = calendar.getTime();
|
|
||||||
|
|
||||||
return expiryDate;
|
return calendar.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Date getExpiryDate(PGPSecretKey key) {
|
public static Date getExpiryDate(PGPSecretKey key) {
|
||||||
@ -291,6 +290,28 @@ public class PgpKeyHelper {
|
|||||||
return userId;
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
public static boolean isEncryptionKey(PGPPublicKey key) {
|
public static boolean isEncryptionKey(PGPPublicKey key) {
|
||||||
if (!key.isEncryptionKey()) {
|
if (!key.isEncryptionKey()) {
|
||||||
@ -440,7 +461,7 @@ public class PgpKeyHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getAlgorithmInfo(int algorithm, int keySize) {
|
public static String getAlgorithmInfo(int algorithm, int keySize) {
|
||||||
String algorithmStr = null;
|
String algorithmStr;
|
||||||
|
|
||||||
switch (algorithm) {
|
switch (algorithm) {
|
||||||
case PGPPublicKey.RSA_ENCRYPT:
|
case PGPPublicKey.RSA_ENCRYPT:
|
||||||
|
@ -66,6 +66,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
CheckBox mChkSign;
|
CheckBox mChkSign;
|
||||||
CheckBox mChkEncrypt;
|
CheckBox mChkEncrypt;
|
||||||
CheckBox mChkAuthenticate;
|
CheckBox mChkAuthenticate;
|
||||||
|
int mUsage;
|
||||||
|
|
||||||
private int mDatePickerResultCount = 0;
|
private int mDatePickerResultCount = 0;
|
||||||
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||||
@ -189,6 +190,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
mChkSign.setChecked(PgpKeyHelper.isSigningKey(key));
|
mChkSign.setChecked(PgpKeyHelper.isSigningKey(key));
|
||||||
mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key));
|
mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key));
|
||||||
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key));
|
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key));
|
||||||
|
mUsage = PgpKeyHelper.getKeyUsage(key);
|
||||||
// TODO: use usage argument?
|
// TODO: use usage argument?
|
||||||
|
|
||||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||||
@ -237,17 +239,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getUsage() {
|
public int getUsage() {
|
||||||
int result = 0; // TODO: preserve other flags
|
mUsage = (mUsage & ~KeyFlags.CERTIFY_OTHER) | (mChkCertify.isChecked() ? KeyFlags.CERTIFY_OTHER : 0);
|
||||||
if (mChkCertify.isChecked())
|
mUsage = (mUsage & ~KeyFlags.SIGN_DATA) | (mChkSign.isChecked() ? KeyFlags.SIGN_DATA : 0);
|
||||||
result |= KeyFlags.CERTIFY_OTHER;
|
mUsage = (mUsage & ~KeyFlags.ENCRYPT_COMMS) | (mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_COMMS : 0);
|
||||||
if (mChkSign.isChecked()) //TODO: fix what happens when we remove sign flag from master - should still be able to certify
|
mUsage = (mUsage & ~KeyFlags.ENCRYPT_STORAGE) | (mChkEncrypt.isChecked() ? KeyFlags.ENCRYPT_STORAGE : 0);
|
||||||
result |= KeyFlags.SIGN_DATA;
|
mUsage = (mUsage & ~KeyFlags.AUTHENTICATION) | (mChkAuthenticate.isChecked() ? KeyFlags.AUTHENTICATION : 0);
|
||||||
if (mChkEncrypt.isChecked())
|
|
||||||
result |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
|
|
||||||
if (mChkAuthenticate.isChecked())
|
|
||||||
result |= KeyFlags.AUTHENTICATION;
|
|
||||||
|
|
||||||
return result;
|
return mUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user