1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-10 14:21:09 +01:00

In PasswordBasedSecretKeyRingProtector.forKey(ring, passphrase): Return passphrase also for subkeys

Fixes #97, thanks @DenBond7
This commit is contained in:
Paul Schaub 2021-03-18 21:28:08 +01:00
parent 7bd12fe5d4
commit 8c97b6ead1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 24 additions and 2 deletions

View file

@ -15,11 +15,13 @@
*/
package org.pgpainless.key.protection;
import java.util.Iterator;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPKeyRing;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
@ -55,8 +57,11 @@ public class PasswordBasedSecretKeyRingProtector implements SecretKeyRingProtect
@Override
@Nullable
public Passphrase getPassphraseFor(Long keyId) {
if (keyRing.getPublicKey().getKeyID() == keyId) {
return passphrase;
for (Iterator<PGPPublicKey> it = keyRing.getPublicKeys(); it.hasNext(); ) {
PGPPublicKey key = it.next();
if (key.getKeyID() == keyId) {
return passphrase;
}
}
return null;
}