diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-04-15 23:54:05 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-04-15 23:54:05 +0200 |
commit | 08399dec4bbd63e6377b2bd876fbc07c235c65cb (patch) | |
tree | 2e85d39fb5fad2c91bc84bcd4dcd81f89a6fd9c6 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java | |
parent | 9df498b7144dcb77cbdcef70a4f609c01e7d3bbc (diff) | |
download | open-keychain-08399dec4bbd63e6377b2bd876fbc07c235c65cb.tar.gz open-keychain-08399dec4bbd63e6377b2bd876fbc07c235c65cb.tar.bz2 open-keychain-08399dec4bbd63e6377b2bd876fbc07c235c65cb.zip |
Fix PgpDecryptVerify signature verification: search for right signature subkey instead of using first subkey for verification
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java index d36dd8efe..6450ad63d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java @@ -60,6 +60,34 @@ public class PgpKeyHelper { return key.getPublicKey().getCreationTime(); } + public static Date getExpiryDate(PGPPublicKey key) { + Date creationDate = getCreationDate(key); + if (key.getValidDays() == 0) { + // no expiry + return null; + } + Calendar calendar = GregorianCalendar.getInstance(); + calendar.setTime(creationDate); + calendar.add(Calendar.DATE, key.getValidDays()); + + return calendar.getTime(); + } + + public static Date getExpiryDate(PGPSecretKey key) { + return getExpiryDate(key.getPublicKey()); + } + + public static boolean isExpired(PGPPublicKey key) { + Date creationDate = getCreationDate(key); + Date expiryDate = getExpiryDate(key); + Date now = new Date(); + if (now.compareTo(creationDate) >= 0 + && (expiryDate == null || now.compareTo(expiryDate) <= 0)) { + return false; + } + return true; + } + @SuppressWarnings("unchecked") public static PGPSecretKey getKeyNum(PGPSecretKeyRing keyRing, long num) { long cnt = 0; @@ -77,7 +105,7 @@ public class PgpKeyHelper { } @SuppressWarnings("unchecked") - public static Vector<PGPPublicKey> getEncryptKeys(PGPPublicKeyRing keyRing) { + private static Vector<PGPPublicKey> getEncryptKeys(PGPPublicKeyRing keyRing) { Vector<PGPPublicKey> encryptKeys = new Vector<PGPPublicKey>(); for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(keyRing.getPublicKeys())) { @@ -90,7 +118,7 @@ public class PgpKeyHelper { } @SuppressWarnings("unchecked") - public static Vector<PGPSecretKey> getSigningKeys(PGPSecretKeyRing keyRing) { + private static Vector<PGPSecretKey> getSigningKeys(PGPSecretKeyRing keyRing) { Vector<PGPSecretKey> signingKeys = new Vector<PGPSecretKey>(); for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(keyRing.getSecretKeys())) { @@ -103,7 +131,7 @@ public class PgpKeyHelper { } @SuppressWarnings("unchecked") - public static Vector<PGPSecretKey> getCertificationKeys(PGPSecretKeyRing keyRing) { + private static Vector<PGPSecretKey> getCertificationKeys(PGPSecretKeyRing keyRing) { Vector<PGPSecretKey> signingKeys = new Vector<PGPSecretKey>(); for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(keyRing.getSecretKeys())) { @@ -115,7 +143,7 @@ public class PgpKeyHelper { return signingKeys; } - public static Vector<PGPPublicKey> getUsableEncryptKeys(PGPPublicKeyRing keyRing) { + private static Vector<PGPPublicKey> getUsableEncryptKeys(PGPPublicKeyRing keyRing) { Vector<PGPPublicKey> usableKeys = new Vector<PGPPublicKey>(); Vector<PGPPublicKey> encryptKeys = getEncryptKeys(keyRing); PGPPublicKey masterKey = null; @@ -135,18 +163,7 @@ public class PgpKeyHelper { return usableKeys; } - public static boolean isExpired(PGPPublicKey key) { - Date creationDate = getCreationDate(key); - Date expiryDate = getExpiryDate(key); - Date now = new Date(); - if (now.compareTo(creationDate) >= 0 - && (expiryDate == null || now.compareTo(expiryDate) <= 0)) { - return false; - } - return true; - } - - public static Vector<PGPSecretKey> getUsableCertificationKeys(PGPSecretKeyRing keyRing) { + private static Vector<PGPSecretKey> getUsableCertificationKeys(PGPSecretKeyRing keyRing) { Vector<PGPSecretKey> usableKeys = new Vector<PGPSecretKey>(); Vector<PGPSecretKey> signingKeys = getCertificationKeys(keyRing); PGPSecretKey masterKey = null; @@ -164,7 +181,7 @@ public class PgpKeyHelper { return usableKeys; } - public static Vector<PGPSecretKey> getUsableSigningKeys(PGPSecretKeyRing keyRing) { + private static Vector<PGPSecretKey> getUsableSigningKeys(PGPSecretKeyRing keyRing) { Vector<PGPSecretKey> usableKeys = new Vector<PGPSecretKey>(); Vector<PGPSecretKey> signingKeys = getSigningKeys(keyRing); PGPSecretKey masterKey = null; @@ -182,22 +199,6 @@ public class PgpKeyHelper { return usableKeys; } - public static Date getExpiryDate(PGPPublicKey key) { - Date creationDate = getCreationDate(key); - if (key.getValidDays() == 0) { - // no expiry - return null; - } - Calendar calendar = GregorianCalendar.getInstance(); - calendar.setTime(creationDate); - calendar.add(Calendar.DATE, key.getValidDays()); - - return calendar.getTime(); - } - - public static Date getExpiryDate(PGPSecretKey key) { - return getExpiryDate(key.getPublicKey()); - } public static PGPPublicKey getFirstEncryptSubkey(PGPPublicKeyRing keyRing) { Vector<PGPPublicKey> encryptKeys = getUsableEncryptKeys(keyRing); |