aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-09-02 01:24:16 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-09-02 01:24:16 +0200
commite0905a3afbba7f96822becb378b7e8fd9c51e85a (patch)
tree72f463174e322bea66c7702c236739a196b6514d /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp
parenta97ebc1ec9afa4951f676b4483c6db871c4704ab (diff)
downloadopen-keychain-e0905a3afbba7f96822becb378b7e8fd9c51e85a.tar.gz
open-keychain-e0905a3afbba7f96822becb378b7e8fd9c51e85a.tar.bz2
open-keychain-e0905a3afbba7f96822becb378b7e8fd9c51e85a.zip
cache key s2k type in database, for later use
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java53
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java13
2 files changed, 53 insertions, 13 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
index 51770f930..833e1ad3d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
@@ -80,6 +80,59 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
return (CanonicalizedSecretKeyRing) mRing;
}
+ public enum SecretKeyType {
+ UNAVAILABLE(0), GNU_DUMMY (1), PASSPHRASE (2), PASSPHRASE_EMPTY (3), DIVERT_TO_CARD (4);
+
+ final int mNum;
+ SecretKeyType(int num) {
+ mNum = num;
+ }
+
+ public static SecretKeyType fromNum(int num) {
+ switch (num) {
+ case 1: return GNU_DUMMY;
+ case 2: return PASSPHRASE;
+ case 3: return PASSPHRASE_EMPTY;
+ case 4: return DIVERT_TO_CARD;
+ // if this case happens, it's probably a check from a database value
+ default: return UNAVAILABLE;
+ }
+ }
+
+ public int getNum() {
+ return mNum;
+ }
+
+ public boolean isUsable() {
+ return this != UNAVAILABLE && this != GNU_DUMMY;
+ }
+
+ }
+
+ public SecretKeyType getSecretKeyType() {
+ if (mSecretKey.getS2K().getType() == S2K.GNU_DUMMY_S2K) {
+ // divert to card is special
+ if (mSecretKey.getS2K().getProtectionMode() == S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD) {
+ return SecretKeyType.DIVERT_TO_CARD;
+ }
+ // no matter the exact protection mode, it's some kind of dummy key
+ return SecretKeyType.GNU_DUMMY;
+ }
+
+ try {
+ PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
+ Constants.BOUNCY_CASTLE_PROVIDER_NAME).build("".toCharArray());
+ // If this doesn't throw
+ mSecretKey.extractPrivateKey(keyDecryptor);
+ // It means the passphrase is empty
+ return SecretKeyType.PASSPHRASE_EMPTY;
+ } catch (PGPException e) {
+ // Otherwise, it's just a regular ol' passphrase
+ return SecretKeyType.PASSPHRASE;
+ }
+
+ }
+
/**
* Returns true on right passphrase
*/
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java
index d8b873d31..48a2aaeb6 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java
@@ -74,19 +74,6 @@ public class CanonicalizedSecretKeyRing extends CanonicalizedKeyRing {
return new CanonicalizedSecretKey(this, mRing.getSecretKey(id));
}
- public HashSet<Long> getAvailableSubkeys() {
- HashSet<Long> result = new HashSet<Long>();
- // then, mark exactly the keys we have available
- for (PGPSecretKey sub : new IterableIterator<PGPSecretKey>(getRing().getSecretKeys())) {
- S2K s2k = sub.getS2K();
- // add key, except if the private key has been stripped (GNU extension)
- if(s2k == null || (s2k.getProtectionMode() != S2K.GNU_PROTECTION_MODE_NO_PRIVATE_KEY)) {
- result.add(sub.getKeyID());
- }
- }
- return result;
- }
-
/** Getter that returns the subkey that should be used for signing. */
CanonicalizedSecretKey getSigningSubKey() throws PgpGeneralException {
PGPSecretKey key = mRing.getSecretKey(getSignId());