mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-11 11:35:07 -05:00
use certification keys to sign keyrings
This commit is contained in:
parent
cf34a1720e
commit
0075c522a6
@ -122,6 +122,19 @@ public class PgpHelper {
|
|||||||
return signingKeys;
|
return signingKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Vector<PGPSecretKey> getCertificationKeys(PGPSecretKeyRing keyRing) {
|
||||||
|
Vector<PGPSecretKey> signingKeys = new Vector<PGPSecretKey>();
|
||||||
|
|
||||||
|
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(keyRing.getSecretKeys())) {
|
||||||
|
if (isCertificationKey(key)) {
|
||||||
|
signingKeys.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return signingKeys;
|
||||||
|
}
|
||||||
|
|
||||||
public static Vector<PGPPublicKey> getUsableEncryptKeys(PGPPublicKeyRing keyRing) {
|
public static Vector<PGPPublicKey> getUsableEncryptKeys(PGPPublicKeyRing keyRing) {
|
||||||
Vector<PGPPublicKey> usableKeys = new Vector<PGPPublicKey>();
|
Vector<PGPPublicKey> usableKeys = new Vector<PGPPublicKey>();
|
||||||
Vector<PGPPublicKey> encryptKeys = getEncryptKeys(keyRing);
|
Vector<PGPPublicKey> encryptKeys = getEncryptKeys(keyRing);
|
||||||
@ -157,6 +170,24 @@ public class PgpHelper {
|
|||||||
return isExpired(key.getPublicKey());
|
return isExpired(key.getPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vector<PGPSecretKey> getUsableCertificationKeys(PGPSecretKeyRing keyRing) {
|
||||||
|
Vector<PGPSecretKey> usableKeys = new Vector<PGPSecretKey>();
|
||||||
|
Vector<PGPSecretKey> signingKeys = getCertificationKeys(keyRing);
|
||||||
|
PGPSecretKey masterKey = null;
|
||||||
|
for (int i = 0; i < signingKeys.size(); ++i) {
|
||||||
|
PGPSecretKey key = signingKeys.get(i);
|
||||||
|
if (key.isMasterKey()) {
|
||||||
|
masterKey = key;
|
||||||
|
} else {
|
||||||
|
usableKeys.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (masterKey != null) {
|
||||||
|
usableKeys.add(masterKey);
|
||||||
|
}
|
||||||
|
return usableKeys;
|
||||||
|
}
|
||||||
|
|
||||||
public static Vector<PGPSecretKey> getUsableSigningKeys(PGPSecretKeyRing keyRing) {
|
public static Vector<PGPSecretKey> getUsableSigningKeys(PGPSecretKeyRing keyRing) {
|
||||||
Vector<PGPSecretKey> usableKeys = new Vector<PGPSecretKey>();
|
Vector<PGPSecretKey> usableKeys = new Vector<PGPSecretKey>();
|
||||||
Vector<PGPSecretKey> signingKeys = getSigningKeys(keyRing);
|
Vector<PGPSecretKey> signingKeys = getSigningKeys(keyRing);
|
||||||
@ -208,6 +239,19 @@ public class PgpHelper {
|
|||||||
return encryptKeys.get(0);
|
return encryptKeys.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PGPSecretKey getCertificationKey(Context context, long masterKeyId) {
|
||||||
|
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context,
|
||||||
|
masterKeyId);
|
||||||
|
if (keyRing == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Vector<PGPSecretKey> signingKeys = getUsableCertificationKeys(keyRing);
|
||||||
|
if (signingKeys.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return signingKeys.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
public static PGPSecretKey getSigningKey(Context context, long masterKeyId) {
|
public static PGPSecretKey getSigningKey(Context context, long masterKeyId) {
|
||||||
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context,
|
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context,
|
||||||
masterKeyId);
|
masterKeyId);
|
||||||
|
@ -1132,7 +1132,7 @@ public class PgpMain {
|
|||||||
} else {
|
} else {
|
||||||
PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRingByKeyId(context, pubKeyId);
|
PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRingByKeyId(context, pubKeyId);
|
||||||
|
|
||||||
PGPSecretKey signingKey = PgpHelper.getSigningKey(context, masterKeyId);
|
PGPSecretKey signingKey = PgpHelper.getCertificationKey(context, masterKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new PgpGeneralException(context.getString(R.string.error_signatureFailed));
|
throw new PgpGeneralException(context.getString(R.string.error_signatureFailed));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user