diff options
author | Ashley Hughes <spirit.returned@gmail.com> | 2014-02-02 10:24:03 +0000 |
---|---|---|
committer | Ashley Hughes <spirit.returned@gmail.com> | 2014-02-02 10:24:03 +0000 |
commit | f916c8f5af5fd46037dd7d4be28155dac67b1634 (patch) | |
tree | 142484c8e2960e5ba639181bbfa3acd9ad898193 /OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java | |
parent | 0b8036fbefd5b47363cd9fe6f0391c3e217417d3 (diff) | |
download | open-keychain-f916c8f5af5fd46037dd7d4be28155dac67b1634.tar.gz open-keychain-f916c8f5af5fd46037dd7d4be28155dac67b1634.tar.bz2 open-keychain-f916c8f5af5fd46037dd7d4be28155dac67b1634.zip |
update hasPassphrase for subkey only keyrings
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java')
-rw-r--r-- | OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 08b9c26e6..abd2320e3 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.service; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import org.spongycastle.openpgp.PGPException; import org.spongycastle.openpgp.PGPPrivateKey; @@ -210,8 +211,21 @@ public class PassphraseCacheService extends Service { public static boolean hasPassphrase(Context context, long secretKeyId) { // check if the key has no passphrase try { - PGPSecretKey secretKey = PgpKeyHelper.getMasterKey(ProviderHelper - .getPGPSecretKeyRingByKeyId(context, secretKeyId)); + PGPSecretKeyRing secRing = ProviderHelper + .getPGPSecretKeyRingByKeyId(context, secretKeyId); + PGPSecretKey secretKey = null; + boolean foundValidKey = false; + for (Iterator keys = secRing.getSecretKeys(); keys.hasNext();) { + secretKey = (PGPSecretKey)keys.next(); + if (!secretKey.isPrivateKeyEmpty()) { + foundValidKey = true; + break; + } + } + + if (!foundValidKey) + return false; + PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( "SC").build("".toCharArray()); PGPPrivateKey testKey = secretKey.extractPrivateKey(keyDecryptor); |