Disallow stripping of primary secret keys

This commit is contained in:
Paul Schaub 2022-05-07 14:11:39 +02:00
parent 64a50266f1
commit 3e7e6df3f9
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 5 additions and 0 deletions

View File

@ -451,6 +451,11 @@ public final class KeyRingUtils {
public static PGPSecretKeyRing stripSecretKey(@Nonnull PGPSecretKeyRing secretKeys,
long secretKeyId)
throws IOException, PGPException {
if (secretKeys.getPublicKey().getKeyID() == secretKeyId) {
throw new IllegalArgumentException("Bouncy Castle currently cannot deal with stripped secret primary keys.");
}
if (secretKeys.getSecretKey(secretKeyId) == null) {
throw new NoSuchElementException("PGPSecretKeyRing does not contain secret key " + Long.toHexString(secretKeyId));
}