mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-25 08:28:50 -05:00
update hasPassphrase for subkey only keyrings
This commit is contained in:
parent
0b8036fbef
commit
f916c8f5af
@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.service;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.spongycastle.openpgp.PGPException;
|
import org.spongycastle.openpgp.PGPException;
|
||||||
import org.spongycastle.openpgp.PGPPrivateKey;
|
import org.spongycastle.openpgp.PGPPrivateKey;
|
||||||
@ -210,8 +211,21 @@ public class PassphraseCacheService extends Service {
|
|||||||
public static boolean hasPassphrase(Context context, long secretKeyId) {
|
public static boolean hasPassphrase(Context context, long secretKeyId) {
|
||||||
// check if the key has no passphrase
|
// check if the key has no passphrase
|
||||||
try {
|
try {
|
||||||
PGPSecretKey secretKey = PgpKeyHelper.getMasterKey(ProviderHelper
|
PGPSecretKeyRing secRing = ProviderHelper
|
||||||
.getPGPSecretKeyRingByKeyId(context, secretKeyId));
|
.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(
|
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
|
||||||
"SC").build("".toCharArray());
|
"SC").build("".toCharArray());
|
||||||
PGPPrivateKey testKey = secretKey.extractPrivateKey(keyDecryptor);
|
PGPPrivateKey testKey = secretKey.extractPrivateKey(keyDecryptor);
|
||||||
|
Loading…
Reference in New Issue
Block a user